Version: {$version}
"; // Check if the user has a ".htninja" script loaded: if ( @file_exists($nfw_['file'] = dirname($_SERVER['DOCUMENT_ROOT']) .'/.htninja') || @file_exists($nfw_['file'] = $_SERVER['DOCUMENT_ROOT'] .'/.htninja') ) { echo "Found .htninja file, parsing it.
"; @include $nfw_['file']; } if ( file_exists( __DIR__ . '/wp-config.php' ) ) { $wp_config = __DIR__ . '/wp-config.php'; echo "Found $wp_config.
"; } elseif ( file_exists( dirname( __DIR__ ) . '/wp-config.php' ) ) { $wp_config = dirname( __DIR__ ) . '/wp-config.php'; echo "Found $wp_config.
"; } else { die("cannot find wp-config.php"); } if (! $nfw_['fh'] = fopen($wp_config, 'r') ) { die("cannot open wp-config.php"); } echo 'Opening it for reading.
Looking for DB_NAME, DB_USER, DB_PASSWORD, DB_HOST and $table_prefix:'; $nfw_['MYSQL_CLIENT_FLAGS'] = 0; $available_flags = array( 'MYSQLI_CLIENT_COMPRESS' => MYSQLI_CLIENT_COMPRESS, 'MYSQLI_CLIENT_FOUND_ROWS' => MYSQLI_CLIENT_FOUND_ROWS, 'MYSQLI_CLIENT_IGNORE_SPACE' => MYSQLI_CLIENT_IGNORE_SPACE, 'MYSQLI_CLIENT_INTERACTIVE' => MYSQLI_CLIENT_INTERACTIVE, 'MYSQLI_CLIENT_SSL' => MYSQLI_CLIENT_SSL, 'MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT' => MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT ); while (! feof($nfw_['fh'])) { $nfw_['line'] = fgets($nfw_['fh']); if ( preg_match('/^\s*define\s*\(\s*[\'"]DB_NAME[\'"]\s*,\s*[\'"](.+?)[\'"]/', $nfw_['line'], $nfw_['match']) ) { $nfw_['DB_NAME'] = $nfw_['match'][1]; } elseif ( preg_match('/^\s*define\s*\(\s*[\'"]DB_USER[\'"]\s*,\s*[\'"](.+?)[\'"]/', $nfw_['line'], $nfw_['match']) ) { $nfw_['DB_USER'] = $nfw_['match'][1]; } elseif ( preg_match('/^\s*define\s*\(\s*[\'"]DB_PASSWORD[\'"]\s*,\s*([\'"])(.+?)\1\s*\);/', $nfw_['line'], $nfw_['match']) ) { $nfw_['DB_PASSWORD'] = str_replace( '\\'.$nfw_['match'][1], $nfw_['match'][1], $nfw_['match'][2] ); if ( $nfw_['match'][1] == '"' ) { $nfw_['DB_PASSWORD'] = str_replace( '\$', '$', $nfw_['DB_PASSWORD'] ); } } elseif ( preg_match('/^\s*define\s*\(\s*[\'"]DB_HOST[\'"]\s*,\s*[\'"](.+?)[\'"]/', $nfw_['line'], $nfw_['match']) ) { $nfw_['DB_HOST'] = $nfw_['match'][1]; } elseif ( preg_match('/^\s*\$table_prefix\s*=\s*[\'"](.+?)[\'"]/', $nfw_['line'], $nfw_['match']) ) { $nfw_['table_prefix'] = $nfw_['match'][1]; } elseif ( preg_match('/^\s*define\s*\(\s*[\'"]MYSQL_CLIENT_FLAGS[\'"]\s*,\s*(.+?)\s*\)/', $nfw_['line'], $nfw_['match']) ) { if ( empty( $nfw_['MYSQL_CLIENT_FLAGS'] ) ) { // There could be one or more flags, e.g., 'MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT' $tmp_flags = explode( '|', $nfw_['match'][1] ); foreach( $tmp_flags as $tmp_flag ) { $tmp_flag = trim( $tmp_flag ); if ( isset( $available_flags[$tmp_flag] ) ) { $nfw_['MYSQL_CLIENT_FLAGS'] += $available_flags[$tmp_flag]; } } } } } fclose($nfw_['fh']); echo ''; nfwcheck_dbhost(); echo 'Attempting to connect to the DB: '; @$nfw_['mysqli'] = mysqli_init(); if (! $nfw_['mysqli'] ) { echo 'mysqli_init error
'; goto STOPTEST; } mysqli_real_connect( $nfw_['mysqli'], $nfw_['DB_HOST'], $nfw_['DB_USER'], $nfw_['DB_PASSWORD'], $nfw_['DB_NAME'], $nfw_['port'], $nfw_['socket'], $nfw_['MYSQL_CLIENT_FLAGS'] ); if ($nfw_['mysqli']->connect_error) { echo 'Connection Error: ' . $nfw_['mysqli']->connect_error . '
'; goto STOPTEST; } else { echo 'OK

'; } echo "Attempting to read NinjaFirewall's options (nfw_options) from the DB: "; if (! $nfw_['result'] = $nfw_['mysqli']->query('SELECT * FROM `' . $nfw_['mysqli']->real_escape_string($nfw_['table_prefix']) . "options` WHERE `option_name` = 'nfw_options'")) { echo 'Error: ' . $nfw_['mysqli']->error . '
'; goto STOPTEST; } else { echo 'OK
'; } echo "Calling fetch_object: "; if (! $nfw_['nfw_options'] = $nfw_['result']->fetch_object() ) { echo 'Error: ' . $nfw_['mysqli']->error . '
'; goto STOPTEST; } else { echo 'OK
'; } echo "Checking options integrity: "; if (! $nfw_['nfw_options'] = @unserialize($nfw_['nfw_options']->option_value) ) { echo 'Error: Unserialize failed
'; goto STOPTEST; } if (! isset( $nfw_['nfw_options']['engine_version'] ) ) { echo 'Error: Options array is corrupted
'; goto STOPTEST; } echo 'OK

'; echo "Attempting to read NinjaFirewall's rules (nfw_rules) from the DB: "; if (! $nfw_['result'] = $nfw_['mysqli']->query('SELECT * FROM `' . $nfw_['mysqli']->real_escape_string($nfw_['table_prefix']) . "options` WHERE `option_name` = 'nfw_rules'")) { echo 'Error: ' . $nfw_['mysqli']->error . '
'; goto STOPTEST; } else { echo 'OK
'; } echo "Calling fetch_object: "; if (! $nfw_['nfw_rules'] = $nfw_['result']->fetch_object() ) { echo 'Error: ' . $nfw_['mysqli']->error . '
'; goto STOPTEST; } else { echo 'OK
'; } echo "Checking rules integrity: "; if (! $nfw_['nfw_rules'] = @unserialize($nfw_['nfw_rules']->option_value) ) { echo 'Error: Unserialize failed
'; goto STOPTEST; } if (! isset( $nfw_['nfw_rules'][1] ) ) { echo 'Error: rules array is corrupted
'; goto STOPTEST; } echo 'OK
'; STOPTEST: echo '

Exiting.

'; exit; function nfwcheck_dbhost() { global $nfw_; $nfw_['port'] = null; $nfw_['socket'] = null; $port_or_socket = strstr( $nfw_['DB_HOST'], ':' ); if ( ! empty( $port_or_socket ) ) { $nfw_['DB_HOST'] = substr( $nfw_['DB_HOST'], 0, strpos( $nfw_['DB_HOST'], ':' ) ); $port_or_socket = substr( $port_or_socket, 1 ); if ( 0 !== strpos( $port_or_socket, '/' ) ) { $nfw_['port'] = intval( $port_or_socket ); $maybe_socket = strstr( $port_or_socket, ':' ); if ( ! empty( $maybe_socket ) ) { $nfw_['socket'] = substr( $maybe_socket, 1 ); } } else { $nfw_['socket'] = $port_or_socket; } } } // EOF