'. $aitpro_bullet . '
'.$status_DDiv;
echo $text;
}
if ( $BPSoptionsACE['bps_ace'] == 'Off' ) {
$text = '
'. $aitpro_bullet . '
'.__('ACE', 'bulletproof-security').':
'.__('Off', 'bulletproof-security').''.$status_DDiv;
echo $text;
}
}
}
}
}
// GET HTTP Status Response from /mod-test/ images to determine which Apache Modules are Loaded,
// Directive Backward Compatibility & if Host is allowing/processing IfModule conditions (Known Hosts: HostGator).
// System Info page updates the DB option on page load in real-time, but does not create htaccess files.
// htaccess Core updates/creates the DB option and creates htaccess files if needed inpage on page load based on timestamp: once per 15 minute time restriction.
// BPS plugin upgrades & Pre-Installation Wizard checks: new htaccess files created if needed.
// bpsPro_apache_mod_create_htaccess_files() executed in this function which creates new htaccess files if needed.
// .52.6: fallback to mod_access_compat. see .53.6
// .53: The Setup Wizard no longer has a time restriction so that it can create new htaccess files on each page load if
// htaccess files do not already exist or new htaccess files need to be created.
// .53.6: Fubar condition added for servers that do not have either mod_access_compat and mod_authz_core or mod_rewrite Loaded.
// A user can override this check by enabling Enable|Disable htaccess Files: htaccess Files Enabled in the Setup Wizard.
// If an override is chosen then the fallback used is mod_access_compat.
function bpsPro_apache_mod_directive_check() {
if ( current_user_can('manage_options') ) {
if ( esc_html($_SERVER['QUERY_STRING']) == 'page=bulletproof-security/admin/system-info/system-info.php' ) {
// 2: 403: mod_access_compat Module IS loaded. "Deny from all". Allows "Order, Deny, Allow" directives
$url2 = plugins_url( '/bulletproof-security/admin/mod-test/mod_access_compat-od-denied.png' );
// 3: 403: mod_authz_core Module IS loaded. "Require all denied" Conditional
$url3 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_core-denied.png' );
// 4: 403: mod_authz_core|mod_access_compat Order Directive Denied Conditional
$url4 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_core-od-cond-denied.png' );
// 5: 403: mod_authz_host Module IS loaded. "Require ip 127.9.9.1" Conditional
$url5 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_host-require-ip.png' );
// 6: 403: mod_authz_host|mod_access_compat Order Directive Denied Conditional
$url6 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_host-od-cond-denied.png' );
// 8: 403: mod_access_compat: No IfModule Condition Order Directive Deny from all
// if 2 is a 200 response and 8 is a 403 response then the host is not allowing/processing IfModule conditions
// 8: 500 error if mod_access_compat is not loaded.
$url8 = plugins_url( '/bulletproof-security/admin/mod-test/mod_access_compat-od-nc-denied.png' );
// 9: 302 or 200: mod_rewrite Module IS loaded.
// 9: 500 error if mod_rewrite Module is not loaded.
$url9 = plugins_url( '/bulletproof-security/admin/mod-test/mod_rewrite-nc.png' );
// 10: mod_authz_core: No IfModule Condition Require all denied
// 10: 403 if mod_authz_core IS loaded.
// 10: 500 error if mod_authz_core is NOT loaded
$url10 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_core-nc-denied.png' );
// 11: mod_authz_host: No IfModule Condition Require host
// 11: 403 if mod_authz_host IS loaded.
// 11: 500 error if mod_authz_host is NOT loaded
$url11 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_host-nc-require-host.png' );
// 12: mod_security: 403 if mod_security IS loaded.
$url12 = plugins_url( '/bulletproof-security/admin/mod-test/mod_security.png' );
// 13: mod_security2: 403 if mod_security2 IS loaded.
$url13 = plugins_url( '/bulletproof-security/admin/mod-test/mod_security-2.png' );
$view_test_page = plugins_url( '/bulletproof-security/admin/mod-test/' );
$url_array = array( $url2, $url3, $url4, $url5, $url6, $url8, $url9, $url10, $url11, $url12, $url13 );
echo '
'.__('Apache Modules|Directives|Backward Compatibility(Yes|No)|IfModule(Yes|No): ', 'bulletproof-security').'View Visual Test';
foreach ( $url_array as $key => $value ) {
$response = wp_remote_get( $value );
if ( ! is_wp_error( $response ) ) {
if ( $key == 0 ) { // 2
$status_code2 = $response['response']['code'];
}
if ( $key == 1 ) { // 3
$status_code3 = $response['response']['code'];
}
if ( $key == 2 ) { // 4
$status_code4 = $response['response']['code'];
}
if ( $key == 3 ) { // 5
$status_code5 = $response['response']['code'];
}
if ( $key == 4 ) { // 6
$status_code6 = $response['response']['code'];
}
if ( $key == 5 ) { // 8
$status_code8 = $response['response']['code'];
}
if ( $key == 6 ) { // 9
$status_code9 = $response['response']['code'];
}
if ( $key == 7 ) { // 10
$status_code10 = $response['response']['code'];
}
if ( $key == 8 ) { // 11
$status_code11 = $response['response']['code'];
}
if ( $key == 9 ) { // 12
$status_code12 = $response['response']['code'];
}
if ( $key == 10 ) { // 13
$status_code13 = $response['response']['code'];
}
} else {
$text = '
'.__('ERROR: wp_remote_get() function is blocked or unable to get the URL path', 'bulletproof-security').'';
echo $text;;
}
}
// Fubar: Server does not have necessary Modules loaded to use htaccess files
// if $status_code8 && $status_code10 are 500 errors then neither mod_access_compat or mod_authz_core are loaded.
// if $status_code9 is a 500 error then mod_rewrite is not loaded.
if ( 500 == $status_code8 && 500 == $status_code10 || 500 == $status_code9 ) {
$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
$apache_ifmodule = 'No';
} else {
$apache_ifmodule = 'fubar';
}
$text = '
'.$status_code8.':'.$status_code10.':'.$status_code9.': '.__('mod_access_compat and mod_authz_core or mod_rewrite is NOT Loaded', 'bulletproof-security').'
';
echo $text;
} else {
// mod_access_compat loaded, IfModule condition working, Order, Allow, Deny directives are supported
if ( 403 == $status_code2 && 403 == $status_code8 ) {
$apache_ifmodule = 'Yes';
$text = '
'.$status_code2.': '.__('mod_access_compat is Loaded|Order, Allow, Deny directives are supported|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 != $status_code2 && 403 == $status_code8 ) {
$apache_ifmodule = 'No';
$text = '
'.$status_code2.': '.__('mod_access_compat is Loaded|Order, Allow, Deny directives are supported|IfModule: No', 'bulletproof-security').'
';
echo $text;
} else { // BPS 11.1: mod_access_compat fallback. 11.8: Fubar condition added so this is a safe fallback.
$apache_ifmodule = 'No';
$text = '
'.$status_code8.': '.__('mod_access_compat is Loaded', 'bulletproof-security').'
';
echo $text;
}
// mod_authz_core loaded, IfModule condition working, Order, Allow, Deny directives are supported
if ( 403 == $status_code3 && 403 == $status_code4 ) {
$text = '
'.$status_code3.': '.__('mod_authz_core is Loaded|Order, Allow, Deny directives are supported|BC: Yes|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 == $status_code3 && 403 != $status_code4 ) {
$text = '
'.$status_code4.': '.__('mod_authz_core is Loaded|Order, Allow, Deny directives are NOT supported|BC: No|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 == $status_code10 && 403 != $status_code3 ) {
$text = '
'.$status_code3.': '.__('mod_authz_core is Loaded|IfModule: No', 'bulletproof-security').'
';
echo $text;
} elseif ( 500 == $status_code10 && 200 == $status_code3 ) {
$text = '
'.$status_code3.': '.__('mod_authz_core is NOT Loaded|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 500 == $status_code10 ) {
$text = '
'.$status_code3.': '.__('mod_authz_core is NOT Loaded', 'bulletproof-security').'
';
echo $text;
}
// mod_authz_host loaded, IfModule condition working, Order, Allow, Deny directives are supported
if ( 403 == $status_code5 && 403 == $status_code6 ) {
$text = '
'.$status_code5.': '.__('mod_authz_host is Loaded|Order, Allow, Deny directives are supported|BC: Yes|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 == $status_code5 && 403 != $status_code6 ) {
$text = '
'.$status_code6.': '.__('mod_authz_host is Loaded|Order, Allow, Deny directives are NOT supported|BC: No|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 == $status_code11 && 403 != $status_code5 ) {
$text = '
'.$status_code5.': '.__('mod_authz_host is Loaded|IfModule: No', 'bulletproof-security').'
';
echo $text;
} elseif ( 500 == $status_code11 && 403 == $status_code6 ) {
$text = '
'.$status_code6.': '.__('mod_authz_host is NOT Loaded|IfModule: Yes', 'bulletproof-security').'
';
echo $text;
} elseif ( 500 == $status_code11 ) {
$text = '
'.$status_code11.': '.__('mod_authz_host is NOT Loaded', 'bulletproof-security').'
';
echo $text;
}
// 11.8: mod_rewrite Module IS loaded.
if ( 301 == $status_code9 || 302 == $status_code9 || 200 == $status_code9 || 404 == $status_code9 || 403 == $status_code9 ) {
$text = '
'.$status_code9.': '.__('mod_rewrite Module is Loaded', 'bulletproof-security').'
';
echo $text;
} else {
$text = '
'.$status_code9.': '.__('mod_rewrite Inconclusive: Status is not 200, 301, 302, 403 or 404', 'bulletproof-security').'
';
echo $text;
}
} // End: Fubar condition
$apache_modules_Options = array(
'bps_apache_mod_ifmodule' => $apache_ifmodule,
'bps_apache_mod_time' => time() + 900
);
foreach( $apache_modules_Options as $key => $value ) {
update_option('bulletproof_security_options_apache_modules', $apache_modules_Options);
}
if ( $apache_ifmodule == 'fubar' ) {
$htaccess_files_Options = array(
'bps_htaccess_files' => 'disabled'
);
foreach( $htaccess_files_Options as $key => $value ) {
update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
}
}
// 2.9: mod_security or mod_security2 Module loaded.
if ( 403 == $status_code12 || 403 == $status_code13 ) {
if ( 403 == $status_code12 ) {
$text = '
'.$status_code12.': '.__('mod_security Module is Loaded|Enabled', 'bulletproof-security').'
';
echo $text;
} elseif ( 403 == $status_code13 ) {
$text = '
'.$status_code13.': '.__('mod_security2 Module is Loaded|Enabled', 'bulletproof-security').'
';
echo $text;
}
$bps_mod_security_options = array( 'bps_mod_security_check' => '1' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
} else {
$text = '
'.$status_code12.': '.__('mod_security Module is not Loaded|Enabled', 'bulletproof-security').'
';
echo $text;
$bps_mod_security_options = array( 'bps_mod_security_check' => '0' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
}
// End: System Info page check
// BEGIN: Pre-Installation Wizard, BPS Upgrade & Core Inpage check. Create/update db options and new htaccess files
} else {
// 2: 403: mod_access_compat Module IS loaded. "Deny from all". Allows "Order, Deny, Allow" directives
$url2 = plugins_url( '/bulletproof-security/admin/mod-test/mod_access_compat-od-denied.png' );
// 8: 403: mod_access_compat: No IfModule Condition Order Directive Deny from all
// if 2 is a 200 response and 8 is a 403 response then the host is not allowing/processing IfModule conditions
// 8: 500 error if mod_access_compat is not loaded.
$url8 = plugins_url( '/bulletproof-security/admin/mod-test/mod_access_compat-od-nc-denied.png' );
// 9: 302 or 200: mod_rewrite Module IS loaded.
// 9: 500 error if mod_rewrite Module is not loaded.
$url9 = plugins_url( '/bulletproof-security/admin/mod-test/mod_rewrite-nc.png' );
// 10: mod_authz_core: No IfModule Condition Require all denied
// 10: 403 if mod_authz_core IS loaded.
// 10: 500 error if mod_authz_core is NOT loaded
$url10 = plugins_url( '/bulletproof-security/admin/mod-test/mod_authz_core-nc-denied.png' );
// 12: mod_security: 403 if mod_security IS loaded.
$url12 = plugins_url( '/bulletproof-security/admin/mod-test/mod_security.png' );
// 13: mod_security2: 403 if mod_security2 IS loaded.
$url13 = plugins_url( '/bulletproof-security/admin/mod-test/mod_security-2.png' );
$url_array = array( $url2, $url8, $url9, $url10, $url12, $url13 );
// 11.5: Pre-Installation Wizard: No time restriction
if ( esc_html($_SERVER['QUERY_STRING']) == 'page=bulletproof-security/admin/wizard/wizard.php' ) {
foreach ( $url_array as $key => $value ) {
$response = wp_remote_get( $value );
if ( ! is_wp_error( $response ) ) {
if ( $key == 0 ) { // 2
$status_code2 = $response['response']['code'];
}
if ( $key == 1 ) { // 8
$status_code8 = $response['response']['code'];
}
if ( $key == 2 ) { // 9
$status_code9 = $response['response']['code'];
}
if ( $key == 3 ) { // 10
$status_code10 = $response['response']['code'];
}
if ( $key == 4 ) { // 12
$status_code12 = $response['response']['code'];
}
if ( $key == 5 ) { // 13
$status_code13 = $response['response']['code'];
}
}
}
// Fubar: Server does not have necessary Modules loaded to use htaccess files
// if $status_code8 && $status_code10 are 500 errors then neither mod_access_compat or mod_authz_core are loaded.
// if $status_code9 is a 500 error then mod_rewrite is not loaded.
if ( 500 == $status_code8 && 500 == $status_code10 || 500 == $status_code9 ) {
$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
$apache_ifmodule = 'No';
} else {
$apache_ifmodule = 'fubar';
}
} else {
// mod_access_compat loaded, IfModule condition working, Order, Allow, Deny directives are supported
// 11.1: mod_access_compat as fallback. 11.8: Fubar condition added so this is a safe fallback.
if ( 403 == $status_code2 && 403 == $status_code8 ) {
$apache_ifmodule = 'Yes';
} else {
$apache_ifmodule = 'No';
}
} // END: Fubar condition
$apache_modules_Options = array(
'bps_apache_mod_ifmodule' => $apache_ifmodule,
'bps_apache_mod_time' => time() + 900
);
foreach( $apache_modules_Options as $key => $value ) {
update_option('bulletproof_security_options_apache_modules', $apache_modules_Options);
}
if ( $apache_ifmodule == 'fubar' ) {
$htaccess_files_Options = array(
'bps_htaccess_files' => 'disabled'
);
foreach( $htaccess_files_Options as $key => $value ) {
update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
}
}
// 2.9: mod_security or mod_security2 Module loaded.
if ( 403 == $status_code12 || 403 == $status_code13 ) {
$bps_mod_security_options = array( 'bps_mod_security_check' => '1' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
} else {
$bps_mod_security_options = array( 'bps_mod_security_check' => '0' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
}
bpsPro_apache_mod_create_htaccess_files();
} else { // END: Setup Wizard no time restriction.
// BEGIN: BPS upgrade & Core with Time restriction
$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
// Note: if the db option does not exist yet it is created: time now is greater than nothing
if ( time() < $Apache_Mod_options['bps_apache_mod_time'] ) {
// do nothing
} else {
foreach ( $url_array as $key => $value ) {
$response = wp_remote_get( $value );
if ( ! is_wp_error( $response ) ) {
if ( $key == 0 ) { // 2
$status_code2 = $response['response']['code'];
}
if ( $key == 1 ) { // 8
$status_code8 = $response['response']['code'];
}
if ( $key == 2 ) { // 9
$status_code9 = $response['response']['code'];
}
if ( $key == 3 ) { // 10
$status_code10 = $response['response']['code'];
}
if ( $key == 4 ) { // 12
$status_code12 = $response['response']['code'];
}
if ( $key == 5 ) { // 13
$status_code13 = $response['response']['code'];
}
}
}
// Fubar: Server does not have necessary Modules loaded to use htaccess files
// if $status_code8 && $status_code10 are 500 errors then neither mod_access_compat or mod_authz_core are loaded.
// if $status_code9 is a 500 error then mod_rewrite is not loaded.
if ( 500 == $status_code8 && 500 == $status_code10 || 500 == $status_code9 ) {
$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
$apache_ifmodule = 'No';
} else {
$apache_ifmodule = 'fubar';
}
} else {
// mod_access_compat loaded, IfModule condition working, Order, Allow, Deny directives are supported
// 11.1: mod_access_compat as fallback. 11.8: Fubar condition added so this is a safe fallback.
if ( 403 == $status_code2 && 403 == $status_code8 ) {
$apache_ifmodule = 'Yes';
} else {
$apache_ifmodule = 'No';
}
} // END: Fubar condition
$apache_modules_Options = array(
'bps_apache_mod_ifmodule' => $apache_ifmodule,
'bps_apache_mod_time' => time() + 900
);
foreach( $apache_modules_Options as $key => $value ) {
update_option('bulletproof_security_options_apache_modules', $apache_modules_Options);
}
if ( $apache_ifmodule == 'fubar' ) {
$htaccess_files_Options = array(
'bps_htaccess_files' => 'disabled'
);
foreach( $htaccess_files_Options as $key => $value ) {
update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
}
}
// 2.9: mod_security or mod_security2 Module loaded.
if ( 403 == $status_code12 || 403 == $status_code13 ) {
$bps_mod_security_options = array( 'bps_mod_security_check' => '1' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
} else {
$bps_mod_security_options = array( 'bps_mod_security_check' => '0' );
foreach( $bps_mod_security_options as $key => $value ) {
update_option('bulletproof_security_options_mod_security', $bps_mod_security_options);
}
}
bpsPro_apache_mod_create_htaccess_files();
} // end if ( time() < $Apache_Mod_options['bps_apache_mod_time'] ) {
}
}
}
}
// Creates htaccess files based on bps_apache_mod_ifmodule DB value
// 11 htaccess files total
// .53.6: Fubar condition added for servers that do not have either mod_access_compat and mod_authz_core or mod_rewrite Loaded.
function bpsPro_apache_mod_create_htaccess_files() {
if ( is_admin() && current_user_can('manage_options') ) {
$denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/deny-all.htaccess';
$denyall_ifmodule_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/deny-all-ifmodule.htaccess';
$bps_backup = WP_CONTENT_DIR . '/bps-backup/.htaccess';
$bps_master_backups = WP_CONTENT_DIR . '/bps-backup/master-backups/.htaccess';
$bpsPro_pf = WP_PLUGIN_DIR . '/bulletproof-security/';
$core1 = $bpsPro_pf . 'admin/core/.htaccess';
$core2 = $bpsPro_pf . 'admin/db-backup-security/.htaccess';
$core3 = $bpsPro_pf . 'admin/htaccess/.htaccess';
$core4 = $bpsPro_pf . 'admin/login/.htaccess';
$core5 = $bpsPro_pf . 'admin/maintenance/.htaccess';
$core6 = $bpsPro_pf . 'admin/security-log/.htaccess';
$core7 = $bpsPro_pf . 'admin/system-info/.htaccess';
$core8 = $bpsPro_pf . 'admin/theme-skin/.htaccess';
$core9 = $bpsPro_pf . 'admin/wizard/.htaccess';
$core10 = $bpsPro_pf . 'admin/email-log-settings/.htaccess';
$core11 = $bpsPro_pf . 'admin/mscan/.htaccess';
$Zip_download_Options = get_option('bulletproof_security_options_zip_fix');
if ( $Zip_download_Options['bps_zip_download_fix'] == 'On' ) {
$files = array( $bps_backup, $bps_master_backups, $core2, $core3, $core5, $core6, $core7, $core8, $core10, $core11 );
} else {
$files = array( $bps_backup, $bps_master_backups, $core1, $core2, $core3, $core4, $core5, $core6, $core7, $core8, $core9, $core10, $core11 );
}
$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
// .53.6: htaccess Files Enabled|Disabled Override
// If someone manually chooses Disable htaccess files then htaccess files will not be created.
if ( $HFiles_options['bps_htaccess_files'] != 'disabled' ) {
foreach ( $files as $file ) {
$check_string = @file_get_contents($file);
if ( $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' && ! strpos( $check_string, "BPS mod_authz_core IfModule BC" ) ) {
@copy($denyall_ifmodule_htaccess, $file);
} elseif ( $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' && ! strpos( $check_string, "BPS mod_access_compat" ) ) {
@copy($denyall_htaccess, $file);
}
}
}
}
}
?>