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 '';
if ( empty($nfw_['DB_NAME']) ) {
echo "- cannot read DB_NAME
";
} else {
echo "- DB_NAME: found '". htmlspecialchars($nfw_['DB_NAME']) ."'
";
}
if ( empty($nfw_['DB_USER']) ) {
echo "- cannot read DB_USER
";
} else {
echo "- DB_USER: found '". htmlspecialchars($nfw_['DB_USER']) ."'
";
}
if ( empty($nfw_['DB_PASSWORD']) ) {
echo "- cannot read DB_PASSWORD
";
} else {
echo "- DB_PASSWORD: found (click here to view password)
";
}
if ( empty($nfw_['DB_HOST']) ) {
echo "- cannot read DB_HOST
";
} else {
echo "- DB_HOST: found '". htmlspecialchars($nfw_['DB_HOST']) ."'
";
}
if (! empty($nfw_['MYSQL_CLIENT_FLAGS']) ) {
echo "- MYSQL_CLIENT_FLAGS: found '". htmlspecialchars($nfw_['MYSQL_CLIENT_FLAGS']) ."'
";
}
if ( empty($nfw_['table_prefix'])){
echo "- cannot read table_prefix
";
} else {
echo "- table_prefix: found '". htmlspecialchars($nfw_['table_prefix']) ."'
";
}
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.