Automatic WordPress security: local firewall, malware and file-integrity scanning, vulnerability protection, quarantine, scheduled backups, an optional page cache, and automatic global threat intelligence. See README.md for installation, update, and uninstall instructions.
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
if ( ! class_exists( 'Argus_Request_Inputs' ) ) {
|
|
|
|
class Argus_Request_Inputs {
|
|
|
|
public static function collect() {
|
|
$inputs = array();
|
|
|
|
foreach ( (array) $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification
|
|
self::flatten( 'GET:' . $key, $value, $inputs );
|
|
}
|
|
foreach ( (array) $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification
|
|
self::flatten( 'POST:' . $key, $value, $inputs );
|
|
}
|
|
|
|
$raw_body = file_get_contents( 'php://input' ); // phpcs:ignore WordPress.WP.AlternativeFunctions
|
|
if ( is_string( $raw_body ) && '' !== $raw_body ) {
|
|
|
|
$inputs['BODY'] = mb_substr( $raw_body, 0, 8192 );
|
|
}
|
|
|
|
foreach ( array( 'HTTP_USER_AGENT', 'HTTP_REFERER', 'HTTP_X_FORWARDED_FOR', 'REQUEST_URI' ) as $server_key ) {
|
|
if ( ! empty( $_SERVER[ $server_key ] ) ) {
|
|
$inputs[ 'HEADER:' . $server_key ] = stripslashes( (string) $_SERVER[ $server_key ] ); // phpcs:ignore
|
|
}
|
|
}
|
|
|
|
return $inputs;
|
|
}
|
|
|
|
protected static function flatten( $prefix, $value, array &$out, $depth = 0 ) {
|
|
if ( $depth > 3 ) {
|
|
return;
|
|
}
|
|
if ( is_array( $value ) ) {
|
|
foreach ( $value as $k => $v ) {
|
|
self::flatten( $prefix . '.' . $k, $v, $out, $depth + 1 );
|
|
}
|
|
return;
|
|
}
|
|
if ( is_string( $value ) ) {
|
|
$out[ $prefix ] = stripslashes( $value );
|
|
}
|
|
}
|
|
|
|
public static function client_ip() {
|
|
|
|
return isset( $_SERVER['REMOTE_ADDR'] ) ? (string) $_SERVER['REMOTE_ADDR'] : ''; // phpcs:ignore
|
|
}
|
|
}
|
|
|
|
}
|