<?php
#  ________         ____________      _____ ________                       ________      
#  ___  __ )____  _____  /___  /_____ __  /____  __ \______________ ______ ___  __/      
#  __  __  |_  / / /__  / __  / _  _ \_  __/__  /_/ /__  ___/_  __ \_  __ \__  /_        
#  _  /_/ / / /_/ / _  /  _  /  /  __// /_  _  ____/ _  /    / /_/ // /_/ /_  __/        
#  /_____/  \__,_/  /_/   /_/   \___/ \__/  /_/      /_/     \____/ \____/ /_/           
#  ________                             _____ _____              ________                
#  __  ___/_____ ___________  _____________(_)__  /______  __    ___  __ \______________ 
#  _____ \ _  _ \_  ___/_  / / /__  ___/__  / _  __/__  / / /    __  /_/ /__  ___/_  __ \
#  ____/ / /  __// /__  / /_/ / _  /    _  /  / /_  _  /_/ /     _  ____/ _  /    / /_/ /
#  /____/  \___/ \___/  \__,_/  /_/     /_/   \__/  _\__, /      /_/      /_/     \____/ 
#                                                   /____/                               
# 42756C6C657450726F6F66 5365637572697479 50726F 
#
/*	The Copyright, AITpro Software Products License Information must remain
	intact or all BulletProof Security Pro warranties, guarantees, liabilities are void.
	
	Copyright (C) Edward Alexander, AIT-pro.com. All rights reserved.

	AITpro Software Products License Information:
	BY DOWNLOADING, INSTALLING, COPYING, ACCESSING, OR USING BulletProof Security Pro YOU AGREE TO THE TERMS OF THIS AGREEMENT. 
	IF YOU 	ARE ACCEPTING THESE TERMS ON BEHALF OF ANOTHER PERSON OR A COMPANY OR OTHER LEGAL ENTITY, YOU REPRESENT AND WARRANT
	THAT YOU HAVE FULL AUTHORITY TO BIND THAT PERSON, COMPANY, OR LEGAL ENTITY TO THESE TERMS. IF YOU DO NOT AGREE TO THESE TERMS,
	* DO NOT DOWNLOAD, INSTALL, COPY, ACCESS, OR USE BulletProof Security Pro; AND
	* PROMPTLY RETURN BulletProof Security Pro TO THE PARTY FROM WHOM YOU ACQUIRED IT. IF YOU DOWNLOADED BulletProof Security Pro
	FROM THE AITPRO WEBSITE, CONTACT AITPRO FOR A REFUND IF APPLICABLE.
	
	AITpro Software Products License Information continued:
	You agree to keep the AITpro Software Products License for BulletProof Security Pro, unmodified or altered in any way,
	with the original copy of BulletProof Security Pro that you have and any and all copies or partial copies of BulletProof
	Security Pro that You make. 
*/
// Direct calls to this file are Forbidden when core files are not present 
if ( ! function_exists ('add_action') ) {
		header('Status: 403 Forbidden');
		header('HTTP/1.1 403 Forbidden');
		exit();
}

// S-Monitor Display - Root htaccess - BPS Status and Alerts in BPS pages only - bpsOn
function bps_security_status_bps_only() {
$options = get_option('bulletproof_security_options_monitor');

	if ( current_user_can('manage_options') && isset($options['bps_security_status']) && $options['bps_security_status'] == 'bpsOn' ) {

	global $bpspro_version, $bpspro_last_version, $wp_version, $wpdb, $aitpro_bullet;

	if ( esc_html($_SERVER['REQUEST_METHOD']) == 'POST' ) {
		
		if ( esc_html($_SERVER['QUERY_STRING']) == '' ) {
			$bps_base = basename(esc_html($_SERVER['REQUEST_URI']));
		} else {
			$bps_base = str_replace( admin_url(), '', esc_html($_SERVER['REQUEST_URI']) );
		}		
		
		echo '<div id="bps-status-display" style="float:left;margin:0px 0px 0px 6px;padding:3px 5px 3px 5px;background-color:#e8e8e8;border:1px solid gray;"><a href="'.$bps_base.'" style="text-decoration:none;font-weight:bold;">'.__('Reload BPS Pro Status Display', 'bulletproof-security').'</a></div>';
		echo '<div style="clear:both;"></div>';		

		if ( @$_POST['submit-bps-spinner'] == true || @$_POST['Submit-Setup-Wizard-Preinstallation'] == true || @$_POST['Submit-Setup-Wizard'] == true || @$_POST['Submit-DBB-Run-Job'] == true || @$_POST['Submit-DB-Table-Prefix'] == true || @$_POST['Submit-DB-Prefix-Table-Refresh'] == true || @$_POST['Submit-ARCM-RootNR'] == true || @$_POST['Submit-ARCM-Wpadmin'] == true || @$_POST['Submit-ARCM-Wpincludes'] == true || @$_POST['Submit-ARCM-Wpcontent'] == true || @$_POST['Submit-ARCM-Root-Delete'] == true || @$_POST['Submit-ARCM-Wpadmin-Delete'] == true || @$_POST['Submit-ARCM-Wpincludes-Delete'] == true || @$_POST['Submit-ARCM-Wpcontent-Delete'] == true || @$_POST['Submit-ARCM-Root-Restore'] == true || @$_POST['Submit-ARCM-Wpadmin-Restore'] == true || @$_POST['Submit-ARCM-Wpincludes-Restore'] == true || @$_POST['Submit-ARCM-Wpcontent-Restore'] == true || @$_POST['Submit-ARCM-Root-Show-Backup'] == true || @$_POST['Submit-ARCM-Wpadmin-Show-Backup'] == true || @$_POST['Submit-ARCM-Wpincludes-Show-Backup'] == true || @$_POST['Submit-ARCM-Wpcontent-Show-Backup'] == true || @$_POST['Submit-ARCM-Root-Show-Website'] == true || @$_POST['Submit-ARCM-Wpadmin-Show-Website'] == true || @$_POST['Submit-ARCM-Wpincludes-Show-Website'] == true || @$_POST['Submit-ARCM-Wpcontent-Show-Website'] == true || @$_POST['Submit-Quarantine-Search-Radio'] == true || @$_POST['Submit-ARQ-Quarantine-Radio'] == true || @$_POST['submit-bps-zip-install'] == true || @$_POST['Submit-DBD-Diff-Tool'] == true || @$_POST['Submit-DBD-Diff-Large'] == true || @$_POST['Submit-diagnostic-check1'] == true || @$_POST['Submit-diagnostic-check2'] == true || @$_POST['bpsStringFinder'] == true || @$_POST['bpsStringReplacer'] == true || @$_POST['bpsStringReplacerFP'] == true || @$_POST['bpsDBStringFinder9'] == true || @$_POST['bpsMulti-Scan-All-Pages-Submit'] == true || @$_POST['bpsMulti-Scan-Plugins-Submit'] == true || @$_POST['bpsMulti-Scan-Submit'] == true ) {  
		
			$bpsPro_Spinner = get_option('bulletproof_security_options_spinner');	
	
		if ( $bpsPro_Spinner['bps_spinner'] != 'Off' ) {

			echo '<div id="bps-status-display" style="padding:2px 0px 4px 8px;width:240px;">';
			echo '<div id="bps-spinner" class="bps-spinner" style="">';
			echo '<img id="bps-img-spinner" src="'.plugins_url('/bulletproof-security/admin/images/bps-spinner.gif').'" style="float:left;margin:4px 20px 0px 4px;" />'; 
			echo '<div id="bps-spinner-text-btn" style="padding:20px 0px 26px 0px;font-size:14px;background:#fff;border:4px solid black;">Processing...<br><button style="margin:10px 0px 0px 10px;" onclick="javascript:history.go(-1)">Cancel</button></div>';
			echo '</div>';
			echo '</div>';
?>
    
<style>
<!--
.bps-spinner {
    visibility:visible;
	position:fixed;
    top:7%;
    left:45%;
 	width:240px;
	padding:2px 0px 4px 8px;   
	z-index:99999;
}
-->
</style>

<?php
		}  
		}

	} elseif ( esc_html($_SERVER['QUERY_STRING']) == 'page=bulletproof-security/admin/system-info/system-info.php' ) {
		echo '<div id="bps-status-display" style="float:left;padding:0px 0px 10px 0px;">'.__('The BPS Pro Status Display is set to Off by default on the System Info page', 'bulletproof-security').'</div>';
		echo '<div style="clear:both;"></div>';	

	} else {

	$options2 = get_option('bulletproof_security_options_autolock');
	$Flockoptions = get_option('bulletproof_security_options_flock');
	$HFiles_options = get_option('bulletproof_security_options_htaccess_files');

	$filename = ABSPATH . '.htaccess';

	if ( file_exists($filename) ) {
	$permsRootHtaccess = @substr(sprintf('%o', fileperms($filename)), -4);
	$sapi_type = php_sapi_name();	
	$check_string = @file_get_contents($filename);
	$section = @file_get_contents($filename, NULL, NULL, 3, 46);	
	$htaccessARRoot = WP_CONTENT_DIR . '/bps-backup/autorestore/root-files/auto_.htaccess';
	$bps_get_domain_root = bpsGetDomainRoot();
	$bps_get_wp_root_secure = bps_wp_get_root_folder();
	$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR);
	$bps_root_upgrade = '';
	$hostaddress = esc_html( @gethostbyaddr( $_SERVER['SERVER_ADDR'] ) );

	$patterna = '/RedirectMatch\s403\s\/\\\.\.\*\$/';
	$pattern0 = '/#{1,}(\s|){1,}ErrorDocument\s405(.*)\/bulletproof-security\/405\.php/';
	$pattern1 = '/#\sFORBID\sEMPTY\sREFFERER\sSPAMBOTS(.*)RewriteCond\s%{HTTP_USER_AGENT}\s\^\$\sRewriteRule\s\.\*\s\-\s\[F\]/s';	
	// Only match 2 or more identical duplicate referer lines: 1 will not match and 2, 3, 4... will match
	$pattern2 = '/AnotherWebsite\.com\)\.\*\s*(RewriteCond\s%\{HTTP_REFERER\}\s\^\.\*'.$bps_get_domain_root.'\.\*\s*){2,}\s*RewriteRule\s\.\s\-\s\[S=1\]/s';	
	$pattern4 = '/\.\*\(allow_url_include\|allow_url_fopen\|safe_mode\|disable_functions\|auto_prepend_file\) \[NC,OR\]/s';
	$pattern6 = '/(\[|\]|\(|\)|<|>|%3c|%3e|%5b|%5d)/s';
	$pattern7 = '/RewriteCond %{QUERY_STRING} \^\.\*(.*)[3](.*)[5](.*)[5](.*)[7](.*)\)/';
	$pattern8 = '/\[NC\]\s*RewriteCond\s%{HTTP_REFERER}\s\^\.\*(.*)\.\*\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*RewriteRule\s\.\s\-\s\[S=1\]/';	
	$pattern9 = '/RewriteCond\s%{QUERY_STRING}\s\(sp_executesql\)\s\[NC\]\s*(.*)\s*(.*)END\sBPSQSE(.*)\s*RewriteCond\s%{REQUEST_FILENAME}\s!-f\s*RewriteCond\s%{REQUEST_FILENAME}\s!-d\s*RewriteRule\s\.(.*)\/index\.php\s\[L\]\s*(.*)LOOP\sEND/';
	$pattern10 = '/#\sBEGIN\sBPSQSE\sBPS\sQUERY\sSTRING\sEXPLOITS\s*#\sThe\slibwww-perl\sUser\sAgent\sis\sforbidden/';
	$pattern10a = '/RewriteCond\s%\{THE_REQUEST\}\s(.*)\?(.*)\sHTTP\/\s\[NC,OR\]\s*RewriteCond\s%\{THE_REQUEST\}\s(.*)\*(.*)\sHTTP\/\s\[NC,OR\]/';
	$pattern10b = '/RewriteCond\s%\{THE_REQUEST\}\s.*\?\+\(%20\{1,\}.*\s*RewriteCond\s%\{THE_REQUEST\}\s.*\+\(.*\*\|%2a.*\s\[NC,OR\]/';	
	$pattern10c = '/RewriteCond\s%\{THE_REQUEST\}\s\(\\\\?.*%2a\)\+\(%20\+\|\\\\s\+.*HTTP\(:\/.*\[NC,OR\]/';
	$pattern11 = '/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]\=http:\/\/\s\[OR\]/';
	$pattern12 = '/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]\=\(\\\.\\\.\/\/\?\)\+\s\[OR\]/';
	$pattern13 = '/RewriteCond\s%\{QUERY_STRING\}\s\(\\\.\\\.\/\|\\\.\\\.\)\s\[OR\]/';
	$pattern14 = '/RewriteCond\s%{QUERY_STRING}\s\(\\\.\/\|\\\.\.\/\|\\\.\.\.\/\)\+\(motd\|etc\|bin\)\s\[NC,OR\]/';
	$pattern_amod = '/#\sDENY\sBROWSER\sACCESS\sTO\sTHESE\sFILES(.*\s*){6,8}<FilesMatch(.*)wp-config(.*\s*){4,6}<\/FilesMatch>/';
	$pattern15 = '/BPS\sPOST\sRequest\sAttack\sProtection/';
	$pattern16 = '/#\sNEVER\sCOMMENT\sOUT\sTHIS\sLINE\sOF\sCODE\sBELOW\sFOR\sANY\sREASON(\s*){1}RewriteCond\s%\{REQUEST_URI\}\s\!\^\.\*\/wp-admin\/\s\[NC\]/';
	$pattern17 = '/#\sNEVER\sCOMMENT\sOUT\sTHIS\sLINE\sOF\sCODE\sBELOW\sFOR\sANY\sREASON(\s*){1}#{1,}(\s|){1,}RewriteCond\s%\{REQUEST_URI\}\s\!\^\.\*\/wp-admin\/\s\[NC\]/';
	//$pattern18 = '/#\sREQUEST\sMETHODS\sFILTERED(.*)RewriteCond\s\%\{REQUEST_METHOD\}\s\^\(HEAD\|TRACE\|DELETE\|TRACK\|DEBUG\)\s\[NC\](\s*){1}RewriteRule\s\^\(\.\*\)\$\s\-\s\[F\]/s';
	//$pattern19 = '/RewriteRule\s\^\(\.\*\)\$\s\-\s\[R=405,L\]/';
	// 13.2: Reverting: Match R,L for replacement to L
	//$pattern20 = '/RewriteRule\s\^\(\.\*\)\$(.*)\/bulletproof-security\/405\.php\s\[R,L\]/';
	$pattern21 = '/RewriteCond\s%\{THE_REQUEST\}\s\(\\\?.*%2a\)\+\(%20.*HTTP\(:\/.*\[NC,OR\]/';
	$pattern22 = '/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]=http:\/\/\s\[NC,OR\]/';
	$pattern23 = '/RewriteCond\s%\{QUERY_STRING\}\s\^\(\.\*\)cPath=http:\/\/\(\.\*\)\$\s\[NC,OR\]/';
	$pattern24 = '/RewriteCond\s%\{QUERY_STRING\}\shttp\\\:\s\[NC,OR\](.*\s*){1}.*RewriteCond\s%\{QUERY_STRING\}\shttps\\\:\s\[NC,OR\]/';
	}
	
	if ( ! file_exists($filename) && $HFiles_options['bps_htaccess_files'] == 'disabled' ) {
		
		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'.__('BPS Pro ', 'bulletproof-security').$bpspro_version;
		
		if ( $options['bps_autorestore_status'] == 'bpsOn' || $options['bps_dbm_status'] == 'bpsOn' || $options['bps_dbb_status'] == 'bpsOn' || $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {

			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}	

	} elseif ( ! file_exists($filename) && $HFiles_options['bps_htaccess_files'] != 'disabled' ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! An htaccess file was NOT found in your root folder. Go to the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and click the Root Folder BulletProof Mode Activate button.', 'bulletproof-security').'</font></div>';
		echo $text;

	} else {
	
	if ( file_exists($filename) ) {

switch ( $bpspro_version ) {
    case $bpspro_last_version:
		if ( strpos( $check_string, "BULLETPROOF PRO $bpspro_last_version" ) && strpos( $check_string, "BPSQSE" ) ) {
			print($section);
		}
		break;
    case ! strpos( $check_string, "BULLETPROOF" ) && ! strpos( $check_string, "DEFAULT" ):

		global $current_user;
		$user_id = $current_user->ID;		
		
		if ( ! get_user_meta($user_id, 'bps_ignore_root_version_check_notice') ) {
		
		if ( esc_html($_SERVER['QUERY_STRING']) == '' && basename(esc_html($_SERVER['REQUEST_URI'])) != 'wp-admin' ) {
			$bps_base = basename(esc_html($_SERVER['REQUEST_URI'])) . '?';
		} elseif ( esc_html($_SERVER['QUERY_STRING']) == '' && basename(esc_html($_SERVER['REQUEST_URI'])) == 'wp-admin' ) {
			$bps_base = basename( str_replace( 'wp-admin', 'index.php?', esc_html($_SERVER['REQUEST_URI'])));
		} else {
			$bps_base = str_replace( admin_url(), '', esc_html($_SERVER['REQUEST_URI']) ) . '&';
		}

		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! Your site may not be protected by BulletProof Security', 'bulletproof-security').'</font><br>'.__('The BPS version: BULLETPROOF PRO x.x SECURE .HTACCESS line of code was not found at the top of your Root htaccess file.', 'bulletproof-security').'<br>'.__('The BPS version line of code MUST be at the very top of your Root htaccess file.', 'bulletproof-security').'<br>'.__('Go to the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and click the Root Folder BulletProof Mode Activate button.', 'bulletproof-security').'<br>'.__('To Dismiss this Notice click the Dismiss Notice button below. To Reset Dismiss Notices click the Reset|Recheck Dismiss Notices button on the S-Monitor page.', 'bulletproof-security').'<br><div style="float:left;margin:3px 0px 3px 0px;padding:2px 6px 2px 6px;background-color:#e8e8e8;border:1px solid gray;"><a href="'.$bps_base.'bps_root_version_check_nag_ignore=0'.'" style="text-decoration:none;font-weight:bold;">'.__('Dismiss Notice', 'bulletproof-security').'</a></div></div>';
		echo $text;
		}

		break;
	case ! strpos( $check_string, "BULLETPROOF PRO $bpspro_version" ) && strpos( $check_string, "BPSQSE" ):
			
			// Update/Add/Save any New DB options/features on upgrade
			bpsPro_new_feature_autoupdate();
			// mod_authz_core forward/backward compatibility: create new htaccess files if needed
			bpsPro_apache_mod_directive_check();
			$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
			$BPSCustomCodeOptions = get_option('bulletproof_security_options_customcode');
			// Create /wp-includes/version.php ARQ exclude rule
			bps_wp_versionphp_exclude_rule();
			// Create an ARQ single file Exclude rule for /mu-plugins/bps-pro-mu-tools.php
			bpsPro_mu_tools_exclude_rule();
			// Recreate the User Agent filters in the 403.php file on BPS upgrade
			bpsPro_autoupdate_useragent_filters();
			// BPS Pro 9.1 synchronize DB timestamps to GMT file timestamps
			bpsPro_sync_time_gmt();
			
			if ( @substr( $sapi_type, 0, 6 ) != 'apache' || @$permsRootHtaccess != '0666' || @$permsRootHtaccess != '0777' ) { // Windows IIS, XAMPP, etc
				@chmod($filename, 0644);
			}

			$stringReplace = @file_get_contents($filename);
			$stringReplace = preg_replace('/BULLETPROOF PRO(.*)SECURE .HTACCESS/s', "BULLETPROOF PRO $bpspro_version SECURE .HTACCESS", $stringReplace);

			$stringReplace = str_replace("RewriteCond %{HTTP_USER_AGENT} (libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]", "RewriteCond %{HTTP_USER_AGENT} (havij|libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]", $stringReplace);
		
		if ( preg_match( $patterna, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/#\sDENY\sACCESS\sTO\sPROTECTED\sSERVER\sFILES(.*)RedirectMatch\s403\s\/\\\.\.\*\$/s', "# DENY ACCESS TO PROTECTED SERVER FILES AND FOLDERS\n# Files and folders starting with a dot: .htaccess, .htpasswd, .errordocs, .logs\nRedirectMatch 403 \.(htaccess|htpasswd|errordocs|logs)$", $stringReplace);
		}

		// 11.5: Create new block of Error Logging and Tracking code & help text if Custom Code is blank & New ErrorDocument 405 code does not exist.
		if ( $BPSCustomCodeOptions['bps_customcode_error_logging'] == '' && ! preg_match( $pattern0, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/#\sBPS\sPRO\sERROR\sLOGGING\sAND\sTRACKING.*(ErrorDocument\s404(.*)\/404\.php|ErrorDocument\s410(.*)\/bulletproof-security\/410\.php)/s', "# BPS PRO ERROR LOGGING AND TRACKING\n# Use BPS Custom Code to modify/edit/change this code and to save it permanently.\n# BPS Pro has premade 400 Bad Request, 403 Forbidden, 404 Not Found, 405 Method Not Allowed and\n# 410 Gone template logging files that are used to track and log 400, 403, 404, 405 and 410 errors\n# that occur on your website. When a hacker attempts to hack your website the hackers IP address,\n# Host name, Request Method, Referering link, the file name or requested resource, the user agent\n# of the hacker and the query string used in the hack attempt are logged.\n# All BPS Pro log files are htaccess protected so that only you can view them.\n# The 400.php, 403.php, 404.php, 405.php and 410.php files are located in /$bps_plugin_dir/bulletproof-security/\n# The 400, 403, 405 and 410 Error logging files are already set up and will automatically start logging errors\n# after you install BPS Pro and have activated BulletProof Mode for your Root folder.\n# If you would like to log 404 errors you will need to copy the logging code in the BPS Pro 404.php file\n# to your Theme's 404.php template file. Simple instructions are included in the BPS Pro 404.php file.\n# You can open the BPS Pro 404.php file using the WP Plugins Editor or by using the BPS Pro File Manager.\n# NOTE: By default WordPress automatically looks in your Theme's folder for a 404.php Theme template file.\n\nErrorDocument 400 $bps_get_wp_root_secure"."$bps_plugin_dir/bulletproof-security/400.php\nErrorDocument 401 default\nErrorDocument 403 $bps_get_wp_root_secure"."$bps_plugin_dir/bulletproof-security/403.php\nErrorDocument 404 $bps_get_wp_root_secure"."404.php\nErrorDocument 405 $bps_get_wp_root_secure"."$bps_plugin_dir/bulletproof-security/405.php\nErrorDocument 410 $bps_get_wp_root_secure"."$bps_plugin_dir/bulletproof-security/410.php", $stringReplace);
		}

		// 11.5: Create new block of Request Methods Filtered code & help text.
		// 11.6: Old RMF Code exists: Conditional host check added to create either R=405 for Go Daddy or dumbed down code for all other hosts.
		// 14.4: removing this RMF cleanup code. Only dumbed down RMF code is created now.
		/*		
		if ( preg_match( $pattern18, $stringReplace, $matches ) && preg_match( '/secureserver\.net/', $hostaddress, $matches ) ) {
			$stringReplace = preg_replace( $pattern18, "# REQUEST METHODS FILTERED\n# If you want to allow HEAD Requests use BPS Custom Code and copy\n# this entire REQUEST METHODS FILTERED section of code to this BPS Custom Code\n# text box: CUSTOM CODE REQUEST METHODS FILTERED.\n# See the CUSTOM CODE REQUEST METHODS FILTERED help text for additional steps.\nRewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK|DEBUG) [NC]\nRewriteRule ^(.*)$ - [F]\nRewriteCond %{REQUEST_METHOD} ^(HEAD) [NC]\nRewriteRule ^(.*)$ - [R=405,L]", $stringReplace);
		} elseif ( preg_match( $pattern18, $stringReplace, $matches ) && ! preg_match( '/secureserver\.net/', $hostaddress, $matches ) ) {
			$stringReplace = preg_replace( $pattern18, "# REQUEST METHODS FILTERED\n# If you want to allow HEAD Requests use BPS Custom Code and copy\n# this entire REQUEST METHODS FILTERED section of code to this BPS Custom Code\n# text box: CUSTOM CODE REQUEST METHODS FILTERED.\n# See the CUSTOM CODE REQUEST METHODS FILTERED help text for additional steps.\nRewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK|DEBUG) [NC]\nRewriteRule ^(.*)$ - [F]\nRewriteCond %{REQUEST_METHOD} ^(HEAD) [NC]\nRewriteRule ^(.*)$ " . $bps_get_wp_root_secure . $bps_plugin_dir . "/bulletproof-security/405.php [L]", $stringReplace);			
		}

		// 11.6: New RMF R=405 Code exists: Replace the R=405 code if the host is Not Go Daddy & the R=405 code does not exist in Custom Code.
		if ( preg_match( $pattern19, $stringReplace, $matches ) && ! preg_match( '/secureserver\.net/', $hostaddress ) && ! preg_match( '/R=405/', $BPSCustomCodeOptions['bps_customcode_request_methods'] ) ) {			
			$stringReplace = preg_replace( $pattern19, "RewriteRule ^(.*)$ " . $bps_get_wp_root_secure . $bps_plugin_dir . "/bulletproof-security/405.php [L]", $stringReplace);
		}

		// 13: Add R to the dumb downed Request Methods Filtered 405 htaccess code in the Root htaccess file.
		// 13.2: Reverted: Remove R due to duplicate security log entries and pfw issues
		if ( preg_match( $pattern20, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern20, "RewriteRule ^(.*)$ " . $bps_get_wp_root_secure . $bps_plugin_dir . "/bulletproof-security/405.php [L]", $stringReplace);
		}
		*/

		// 13: Add additional https scheme conditions to 3 htaccess security rules and combine 2 rules into 1 rule.
		if ( preg_match( $pattern21, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern21, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)(http|https)(:/|/) [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern22, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern22, "RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(http|https):// [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern23, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern23, "RewriteCond %{QUERY_STRING} ^(.*)cPath=(http|https)://(.*)$ [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern24, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern24, "RewriteCond %{QUERY_STRING} (http|https)\: [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern1, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/#\sFORBID\sEMPTY\sREFFERER\sSPAMBOTS(.*)RewriteCond\s%{HTTP_USER_AGENT}\s\^\$\sRewriteRule\s\.\*\s\-\s\[F\]/s', '', $stringReplace);
		}

		if ( preg_match($pattern2, $stringReplace, $matches) ) {
			$stringReplace = preg_replace('/AnotherWebsite\.com\)\.\*\s*(RewriteCond\s%\{HTTP_REFERER\}\s\^\.\*'.$bps_get_domain_root.'\.\*\s*){2,}\s*RewriteRule\s\.\s\-\s\[S=1\]/s', "AnotherWebsite.com).*\nRewriteCond %{HTTP_REFERER} ^.*$bps_get_domain_root.*\nRewriteRule . - [S=1]", $stringReplace);
		}
		
		if ( !preg_match( $pattern10, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/#\sBPSQSE\sBPS\sQUERY\sSTRING\sEXPLOITS\s*#\sThe\slibwww-perl\sUser\sAgent\sis\sforbidden/', "# BEGIN BPSQSE BPS QUERY STRING EXPLOITS\n# The libwww-perl User Agent is forbidden", $stringReplace);
		}		
		
		if ( preg_match( $pattern10a, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10a, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern10b, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10b, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern10c, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10c, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern11, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]\=http:\/\/\s\[OR\]/s', "RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern12, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]\=\(\\\.\\\.\/\/\?\)\+\s\[OR\]/s', "RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [NC,OR]", $stringReplace);
		}

		if ( preg_match($pattern13, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%\{QUERY_STRING\}\s\(\\\.\\\.\/\|\\\.\\\.\)\s\[OR\]/s', "RewriteCond %{QUERY_STRING} (\.\./|%2e%2e%2f|%2e%2e/|\.\.%2f|%2e\.%2f|%2e\./|\.%2e%2f|\.%2e/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern6, $stringReplace, $matches ) ) {
			$stringReplace = str_replace("RewriteCond %{QUERY_STRING} ^.*(\[|\]|\(|\)|<|>|%3c|%3e|%5b|%5d).* [NC,OR]", "RewriteCond %{QUERY_STRING} ^.*(\(|\)|<|>|%3c|%3e).* [NC,OR]", $stringReplace);
			$stringReplace = str_replace("RewriteCond %{QUERY_STRING} ^.*(\x00|\x04|\x08|\x0d|\x1b|\x20|\x3c|\x3e|\x5b|\x5d|\x7f).* [NC,OR]", "RewriteCond %{QUERY_STRING} ^.*(\x00|\x04|\x08|\x0d|\x1b|\x20|\x3c|\x3e|\x7f).* [NC,OR]", $stringReplace);		
		}
		
		if ( preg_match( $pattern7, $stringReplace, $matches ) ) {
$stringReplace = preg_replace('/RewriteCond %{QUERY_STRING} \^\.\*(.*)[5](.*)[5](.*)\)/', 'RewriteCond %{QUERY_STRING} ^.*(\x00|\x04|\x08|\x0d|\x1b|\x20|\x3c|\x3e|\x7f)', $stringReplace);
		}

		if ( preg_match( $pattern14, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%{QUERY_STRING}\s\(\\\.\/\|\\\.\.\/\|\\\.\.\.\/\)\+\(motd\|etc\|bin\)\s\[NC,OR\]/s', "RewriteCond %{QUERY_STRING} (\.{1,}/)+(motd|etc|bin) [NC,OR]", $stringReplace);
		}

		if ( !preg_match( $pattern4, $stringReplace, $matches ) ) {
			$stringReplace = str_replace("RewriteCond %{QUERY_STRING} union([^a]*a)+ll([^s]*s)+elect [NC,OR]", "RewriteCond %{QUERY_STRING} union([^a]*a)+ll([^s]*s)+elect [NC,OR]\nRewriteCond %{QUERY_STRING} \-[sdcr].*(allow_url_include|allow_url_fopen|safe_mode|disable_functions|auto_prepend_file) [NC,OR]", $stringReplace);
		}

		if ( ! is_multisite() && !preg_match( $pattern9, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%{QUERY_STRING}\s\(sp_executesql\)\s\[NC\]\s*(.*)\s*RewriteCond\s%{REQUEST_FILENAME}\s!-f\s*RewriteCond\s%{REQUEST_FILENAME}\s!-d\s*RewriteRule\s\.(.*)\/index\.php\s\[L\]/', "RewriteCond %{QUERY_STRING} (sp_executesql) [NC]\nRewriteRule ^(.*)$ - [F,L]\n# END BPSQSE BPS QUERY STRING EXPLOITS\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . ".$bps_get_wp_root_secure."index.php [L]\n# WP REWRITE LOOP END", $stringReplace);
		}

		if ( preg_match( $pattern_amod, $stringReplace, $matches ) && $BPSCustomCodeOptions['bps_customcode_deny_files'] == '' && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' ) {
			
			$stringReplace = preg_replace( $pattern_amod, "# DENY BROWSER ACCESS TO THESE FILES\n# Use BPS Custom Code to modify/edit/change this code and to save it permanently.\n# wp-config.php, bb-config.php, php.ini, php5.ini, readme.html\n# To be able to view these files from a Browser, replace 127.0.0.1 with your actual\n# current IP address. Comment out: #Require all denied and Uncomment: Require ip 127.0.0.1\n# Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1\n# Note: The BPS System Info page displays which modules are loaded on your server.\n\n<FilesMatch \"^(wp-config\.php|php\.ini|php5\.ini|readme\.html|bb-config\.php)\">\n<IfModule mod_authz_core.c>\nRequire all denied\n#Require ip 127.0.0.1\n</IfModule>\n\n<IfModule !mod_authz_core.c>\n<IfModule mod_access_compat.c>\nOrder Allow,Deny\nDeny from all\n#Allow from 127.0.0.1\n</IfModule>\n</IfModule>\n</FilesMatch>", $stringReplace);
		
		} elseif ( preg_match( $pattern_amod, $stringReplace, $matches ) && $BPSCustomCodeOptions['bps_customcode_deny_files'] == '' && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' ) {
			
			$stringReplace = preg_replace( $pattern_amod, "# DENY BROWSER ACCESS TO THESE FILES\n# Use BPS Custom Code to modify/edit/change this code and to save it permanently.\n# wp-config.php, bb-config.php, php.ini, php5.ini, readme.html\n# To be able to view these files from a Browser, replace 127.0.0.1 with your actual\n# current IP address. Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1\n# Note: The BPS System Info page displays which modules are loaded on your server.\n\n<FilesMatch \"^(wp-config\.php|php\.ini|php5\.ini|readme\.html|bb-config\.php)\">\nOrder Allow,Deny\nDeny from all\n#Allow from 127.0.0.1\n</FilesMatch>", $stringReplace);	
		}

		// 11.4: POST Request Attack Protection code correction|addition
		// 11.5: Condition added to allow commenting out wp-admin URI whitelist rule		
		if ( preg_match( $pattern15, $stringReplace, $matches ) && ! preg_match( $pattern16, $stringReplace, $matches ) && ! preg_match( $pattern17, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace('/RewriteCond\s%\{REQUEST_METHOD\}\sPOST\s\[NC\]/s', "RewriteCond %{REQUEST_METHOD} POST [NC]\n# NEVER COMMENT OUT THIS LINE OF CODE BELOW FOR ANY REASON\nRewriteCond %{REQUEST_URI} !^.*/wp-admin/ [NC]\n# Whitelist the WordPress Theme Customizer\nRewriteCond %{HTTP_REFERER} !^.*/wp-admin/customize.php", $stringReplace);
		}

		// Clean up - replace 3 and 4 multiple newlines with 1 newline
		if ( preg_match('/(\n\n\n|\n\n\n\n)/', $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace("/(\n\n\n|\n\n\n\n)/", "\n", $stringReplace);
		}
		// remove duplicate referer lines
		if ( preg_match( $pattern8, $stringReplace, $matches ) ) {
$stringReplace = preg_replace("/\[NC\]\s*RewriteCond\s%{HTTP_REFERER}\s\^\.\*(.*)\.\*\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*(.*)\s*RewriteRule\s\.\s\-\s\[S=1\]/", "[NC]\nRewriteCond %{HTTP_REFERER} ^.*$bps_get_domain_root.*\nRewriteRule . - [S=1]", $stringReplace);
		}
		
			file_put_contents($filename, $stringReplace);
		
		if ( @$permsRootHtaccess == '0644' && @substr( $sapi_type, 0, 6 ) != 'apache' && $options2['bps_root_htaccess_autolock'] == 'On' ) {			
			@chmod($filename, 0404);
		}

			@copy( $filename, $htaccessARRoot );

		if ( getBPSInstallTimeTXT() == getBPSRootHtaccessLasModTime_minutes() || getBPSInstallTime_plusone() == getBPSRootHtaccessLasModTime_minutes() ) {
			
			$bps_root_upgrade = 'upgrade';
			
			$pos = strpos( $check_string, 'IMPORTANT!!! DO NOT DELETE!!! - B E G I N Wordpress' );
			
			if ( $pos === false ) {
 		
				$updateText = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__("The BPS Pro Automatic htaccess File Update Completed Successfully!", 'bulletproof-security').'</font></div>';
				//print($updateText);	
			}			
		} // end up upgrade processing			
		break;		
	case strpos( $check_string, "BULLETPROOF PRO $bpspro_version" ) && strpos( $check_string, "BPSQSE" ):	
		
			$RBM = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'" title="'.esc_attr( 'Root Folder BulletProof Mode' ).'" style="text-decoration:none;">'.__('RBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>';
			$RBM_str = str_replace( "BULLETPROOF PRO $bpspro_version SECURE .HTACCESS", "BPS Pro $bpspro_version $RBM", $section );
			
			echo '<div id="bps-status-display" style="font-weight:bold;float:left;margin:0px 0px 10px 0px;">'.$RBM_str.'</div>';
			
			//echo '<div id="bps-status-display" style="float:left;"><strong>'.$RBM_str.'</strong>'.$RBM.'</div>';
			
			// echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		
		break;
	default:
		
		if ( $bps_root_upgrade != 'upgrade' ) {		
			$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! Your site does not appear to be protected by BulletProof Security', 'bulletproof-security').'</font><br>'.__('Go to the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and click the Root Folder BulletProof Mode Activate button.', 'bulletproof-security').'</div>';
			echo $text;
		}
}}}}}}

// S-Monitor Display - wp-admin htaccess - BPS Status and Alerts in BPS - bpsOn
function bps_security_status_wpadmin_bps_only() {
$options = get_option('bulletproof_security_options_monitor');

	if ( current_user_can('manage_options') && isset($options['bps_security_status']) && $options['bps_security_status'] == 'bpsOn' ) {
		
	global $bpspro_version, $bpspro_last_version, $aitpro_bullet;

	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

	$BPS_wpadmin_Options = get_option('bulletproof_security_options_htaccess_res');
	$GDMW_options = get_option('bulletproof_security_options_GDMW');		

	if ( $BPS_wpadmin_Options['bps_wpadmin_restriction'] == 'disabled' || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) {
		return;
	}

	$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
	$filename = ABSPATH . 'wp-admin/.htaccess';

	if ( file_exists($filename) ) {
	$permsHtaccess = @substr(sprintf('%o', fileperms($filename)), -4);
	$check_string = @file_get_contents($filename);
	$section = @file_get_contents($filename, NULL, NULL, 3, 50);
	$htaccessARwpadmin = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-admin/wpadmin.htaccess';
	$bps_wpadmin_upgrade = '';

	$pattern10a = '/RewriteCond\s%\{THE_REQUEST\}\s(.*)\?(.*)\sHTTP\/\s\[NC,OR\]\s*RewriteCond\s%\{THE_REQUEST\}\s(.*)\*(.*)\sHTTP\/\s\[NC,OR\]/';	
	$pattern10b = '/RewriteCond\s%\{THE_REQUEST\}\s.*\?\+\(%20\{1,\}.*\s*RewriteCond\s%\{THE_REQUEST\}\s.*\+\(.*\*\|%2a.*\s\[NC,OR\]/';	
	$pattern10c = '/RewriteCond\s%\{THE_REQUEST\}\s\(\\\\?.*%2a\)\+\(%20\+\|\\\\s\+.*HTTP\(:\/.*\[NC,OR\]/';
	$pattern1 = '/(\[|\]|\(|\)|<|>)/s';
	$pattern_amod = '/#\sWPADMIN\sDENY\sBROWSER\sACCESS\sTO\sFILES(.*\s*){13,16}#\sEND\sBPS\sWPADMIN\sDENY\sACCESS\sTO\sFILES/';	
	$pattern21 = '/RewriteCond\s%\{THE_REQUEST\}\s\(\\\?.*%2a\)\+\(%20.*HTTP\(:\/.*\[NC,OR\]/';
	$pattern22 = '/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]=http:\/\/\s\[NC,OR\]/';
	$pattern23 = '/RewriteCond\s%\{QUERY_STRING\}\s\^\(\.\*\)cPath=http:\/\/\(\.\*\)\$\s\[NC,OR\]/';
	$pattern24 = '/RewriteCond\s%\{QUERY_STRING\}\shttp\\\:\s\[NC,OR\](.*\s*){1}.*RewriteCond\s%\{QUERY_STRING\}\shttps\\\:\s\[NC,OR\]/';
	$pattern25 = '/#\sREQUEST\sMETHODS\sFILTERED(.*\s*){1}RewriteEngine\sOn(.*\s*){1}RewriteCond(.*\s*){1}RewriteRule\s\^\(\.\*\)\$\s\-\s\[F\]/';
	$pattern26 = '/RewriteCond\s%\{REQUEST_URI\}\s\(press-this\\\.php\)\s\[NC\]/';
	}
	
	if ( ! file_exists($filename) && $HFiles_options['bps_htaccess_files'] != 'disabled' ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! An htaccess file was NOT found in your wp-admin folder. Go to the  ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and click the wp-admin Folder BulletProof Mode Activate button.', 'bulletproof-security').'</font></div>';
		echo $text;
	
	} else {
	
	if ( file_exists($filename) ) {

switch ( $bpspro_version ) {
    case $bpspro_last_version:
		if ( strpos( $check_string, "BULLETPROOF PRO $bpspro_last_version" ) && strpos( $check_string, "BPSQSE-check" ) ) {
			// echo or print for testing
		}
		break;
    case ! strpos( $check_string, "BULLETPROOF" ):

		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! Your wp-admin folder may not be protected by BulletProof Security', 'bulletproof-security').'</font><br>'.__('The BPS version: BULLETPROOF PRO x.x WP-ADMIN SECURE .HTACCESS line of code was not found at the top of your wp-admin htaccess file.', 'bulletproof-security').'<br>'.__('The BPS version line of code MUST be at the very top of your wp-admin htaccess file.', 'bulletproof-security').'<br>'.__('Go to the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and Activate wp-admin Folder BulletProof Mode.', 'bulletproof-security').'</div>';
		echo $text;

		break;
	case ! strpos( $check_string, "BULLETPROOF PRO $bpspro_version" ) && strpos( $check_string, "BPSQSE-check" ):
				
			// mod_authz_core forward/backward compatibility: create new htaccess files if needed
			bpsPro_apache_mod_directive_check();
			$CC_Options_wpadmin = get_option('bulletproof_security_options_customcode_WPA');
			$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');	
			
			if ( @substr( $sapi_type, 0, 6 ) != 'apache' || @$permsHtaccess != '0666' || @$permsHtaccess != '0777') { // Windows IIS, XAMPP, etc
				@chmod($filename, 0644);
			}
			
			$stringReplace = @file_get_contents($filename);
			$stringReplace = preg_replace('/BULLETPROOF PRO(.*)WP-ADMIN SECURE .HTACCESS/s', "BULLETPROOF PRO $bpspro_version WP-ADMIN SECURE .HTACCESS", $stringReplace);

		if ( preg_match( $pattern_amod, $stringReplace, $matches ) && $CC_Options_wpadmin['bps_customcode_deny_files_wpa'] == '' && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' ) {
			
			$stringReplace = preg_replace( $pattern_amod, "# WPADMIN DENY BROWSER ACCESS TO FILES\n# Deny Browser access to /wp-admin/install.php\n# Use BPS Custom Code to modify/edit/change this code and to save it permanently.\n# To be able to view the install.php file from a Browser, replace 127.0.0.1 with your actual\n# current IP address. Comment out: #Require all denied and Uncomment: Require ip 127.0.0.1\n# Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1\n# Note: The BPS System Info page displays which modules are loaded on your server.\n\n# BEGIN BPS WPADMIN DENY ACCESS TO FILES\n<FilesMatch \"^(install\.php)\">\n<IfModule mod_authz_core.c>\nRequire all denied\n#Require ip 127.0.0.1\n</IfModule>\n\n<IfModule !mod_authz_core.c>\n<IfModule mod_access_compat.c>\nOrder Allow,Deny\nDeny from all\n#Allow from 127.0.0.1\n</IfModule>\n</IfModule>\n</FilesMatch>\n# END BPS WPADMIN DENY ACCESS TO FILES", $stringReplace);
		
		} elseif ( preg_match( $pattern_amod, $stringReplace, $matches ) && $CC_Options_wpadmin['bps_customcode_deny_files_wpa'] == '' && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' ) {
			
			$stringReplace = preg_replace( $pattern_amod, "# WPADMIN DENY BROWSER ACCESS TO FILES\n# Deny Browser access to /wp-admin/install.php\n# Use BPS Custom Code to modify/edit/change this code and to save it permanently.\n# To be able to view the install.php file from a Browser, replace 127.0.0.1 with your actual\n# current IP address. Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1\n# Note: The BPS System Info page displays which modules are loaded on your server.\n\n# BEGIN BPS WPADMIN DENY ACCESS TO FILES\n<FilesMatch \"^(install\.php)\">\nOrder Allow,Deny\nDeny from all\n#Allow from 127.0.0.1\n</FilesMatch>\n# END BPS WPADMIN DENY ACCESS TO FILES", $stringReplace);	
		}

		if ( preg_match( $pattern26, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern26, "RewriteCond %{REQUEST_URI} (press-this\.php|widgets\.php) [NC]", $stringReplace);
		}

		if ( preg_match( $pattern25, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern25, "# BPS REWRITE ENGINE\nRewriteEngine On", $stringReplace);
		}

		if ( preg_match( $pattern10a, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10a, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern10b, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10b, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern10c, $stringReplace, $matches ) ) {
			$stringReplace = preg_replace( $pattern10c, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)HTTP(:/|/) [NC,OR]", $stringReplace);
		}

		// 13: Add additional https scheme conditions to 3 htaccess security rules and combine 2 rules into 1 rule.
		if ( preg_match( $pattern21, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern21, "RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)(http|https)(:/|/) [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern22, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern22, "RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(http|https):// [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern23, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern23, "RewriteCond %{QUERY_STRING} ^(.*)cPath=(http|https)://(.*)$ [NC,OR]", $stringReplace);	
		}

		if ( preg_match( $pattern24, $stringReplace, $matches ) ) {			
			$stringReplace = preg_replace( $pattern24, "RewriteCond %{QUERY_STRING} (http|https)\: [NC,OR]", $stringReplace);
		}

		if ( preg_match( $pattern1, $stringReplace, $matches ) ) {
			$stringReplace = str_replace("RewriteCond %{QUERY_STRING} ^.*(\[|\]|\(|\)|<|>).* [NC,OR]", "RewriteCond %{QUERY_STRING} ^.*(\(|\)|<|>).* [NC,OR]", $stringReplace);		
		}

			file_put_contents($filename, $stringReplace);
			@copy($filename, $htaccessARwpadmin);	
		
		if ( getBPSInstallTimeTXT() == getBPSwpadminHtaccessLasModTime_minutes() || getBPSInstallTime_plusone() == getBPSwpadminHtaccessLasModTime_minutes() ) {
			//print("Testing wp-admin auto-update");	
			$bps_wpadmin_upgrade = 'upgrade';
		} // end upgrade processing	
		break;		
	case strpos( $check_string, "BULLETPROOF PRO $bpspro_version" ) && strpos( $check_string, "BPSQSE-check" ):
		
			$WBM = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#RBM-Status' ).'" title="'.esc_attr( 'wp-admin Folder BulletProof Mode' ).'" style="text-decoration:none;">'.__('WBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>';
			$WBM_str = str_replace( "BULLETPROOF PRO $bpspro_version WP-ADMIN SECURE .HTACCESS", "$WBM", $section );			
			
			echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'.$WBM_str;
			
			if ( $options['bps_autorestore_status'] == 'bpsOn' || $options['bps_dbm_status'] == 'bpsOn' || $options['bps_dbb_status'] == 'bpsOn' || $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {

				echo '</div>';	

			} else {
				
				echo '</div><div style="clear:both;"></div>';		
			}		
		
		break;
	default:
		
		if ( $bps_wpadmin_upgrade != 'upgrade' ) {		
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('BPS Pro Alert! A valid BPS Pro htaccess file was NOT found in your wp-admin folder', 'bulletproof-security').'</font><br>'.__('BulletProof Mode for the wp-admin folder should also be activated when you have BulletProof Mode activated for the Root folder', 'bulletproof-security').'<br>'.__('Go to the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Security Modes page', 'bulletproof-security').'</a>'.__(' and click the wp-admin Folder BulletProof Mode Activate button.', 'bulletproof-security').'</div>';
		echo $text;
		}
	}
	}
	}
	}
	}
}

// S-Monitor - AutoRestore Status display - BPS pages ONLY
function bps_ARCM_admin_notice_status_bps() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_autorestore_status']) && $options['bps_autorestore_status'] == 'bpsOn' ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		echo bpsProARCMStatus();

		if ( $options['bps_mscan_status_display'] == 'bpsOn' || $options['bps_dbm_status'] == 'bpsOn' || $options['bps_dbb_status'] == 'bpsOn' || $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
				
			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}	
	}
	}
}

// S-Monitor - MScan Status display - BPS pages ONLY
function bps_MScan_admin_notice_status_bps() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_mscan_status_display']) && $options['bps_mscan_status_display'] == 'bpsOn' ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		echo bpsProMScanStatus();

		if ( $options['bps_dbm_status'] == 'bpsOn' || $options['bps_dbb_status'] == 'bpsOn' || $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
				
			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}	
	}
	}
}

// S-Monitor - DB Monitor Status display - BPS pages ONLY
function bps_DBM_admin_notice_status_bps() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_dbm_status']) && $options['bps_dbm_status'] == 'bpsOn' ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {
	
		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		echo bpsProDBMStatus();
			
		if ( $options['bps_dbb_status'] == 'bpsOn' || $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
				
			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}	
	}
	}
}

// S-Monitor - DB Backup Status display - BPS pages ONLY
function bps_DBB_admin_notice_status_bps() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_dbb_status']) && $options['bps_dbb_status'] == 'bpsOn' ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {
	
		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		echo bpsProDBBStatus();
		
		if ( $options['bps_plugin_firewall_status'] == 'bpsOn' || $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
				
			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}
	}
	}
}

// S-Monitor - Plugin Firewall Status display - BPS pages ONLY
function bps_PFWAP_admin_notice_status_bps() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_plugin_firewall_status']) && $options['bps_plugin_firewall_status'] == 'bpsOn' ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {
	
		echo '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">';
		echo bpsProPFWAPStatus();
			
		if ( $options['bps_UAEG_status'] == 'bpsOn' || $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {

			echo '</div>';	

		} else {
				
			echo '</div><div style="clear:both;"></div>';		
		}	
	}
	}
}

// S-Monitor - Uploads Anti-Exploit Guard Status display - BPS pages ONLY
function bps_UAEG_admin_notice_status_bps() {
	
	if ( current_user_can('manage_options') ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

	global $aitpro_bullet;
	$options = get_option('bulletproof_security_options_monitor');

	// new installations of BPS - First Install / Launch S-Monitor Notification is already displayed - no need to also display a notification for this
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_UAEG_status']) ) { 
		return;
	}
	
	if ( $options['bps_UAEG_status'] == 'Off' ) {
		return;
	}

	if ( $options['bps_UAEG_status'] == 'bpsOn') {

		if ( $options['bps_login_security_status'] == 'bpsOn' || $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
			
			$status_DDiv = '</div>';

		} else {
			
			$status_DDiv = '</div><div style="clear:both;"></div>';			
		}

	$bps_Uploads_Dir = wp_upload_dir();	
	$UploadsHtaccess = $bps_Uploads_Dir['basedir'] . '/.htaccess'; // for both single and Multisite is the standard /uploads folder	

	if ( file_exists($UploadsHtaccess) ) {
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#UAEG-Menu-Link' ).'" title="'.esc_attr( 'Uploads Anti-Exploit Guard' ).'" style="text-decoration:none;">'.__('UAEG', 'bulletproof-security').'</a>: <font color="green">'.__('On', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	
	} else {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#UAEG-Menu-Link' ).'" title="'.esc_attr( 'Uploads Anti-Exploit Guard' ).'" style="text-decoration:none;">'.__('UAEG', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	}	
	}
	}
	}
}

// S-Monitor - Login Security Status display - BPS pages ONLY
function bps_Login_Security_admin_notice_status_bps() {
global $aitpro_bullet;
	
	if ( current_user_can('manage_options') ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

	$options = get_option('bulletproof_security_options_monitor');
	$BPSoptions = get_option('bulletproof_security_options_login_security');	

	// new installations of BPS - First Install / Launch S-Monitor Notification is already displayed - no need to also display a notification for this
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_login_security_status']) ) { 
		return;
	}
	// this is already handled by the WP Dashboard alert
	if ( $options['bps_first_launch'] && ! $options['bps_login_security_status'] ) { 
		return;
	}
	
	if ( $options['bps_login_security_status'] == 'Off' && $BPSoptions['bps_login_security_OnOff'] == 'Off' ) {
		return;
	}

		if ( $options['bps_jtc_antispam_status'] == 'bpsOn' || $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
			
			$status_DDiv = '</div>';

		} else {
			
			$status_DDiv = '</div><div style="clear:both;"></div>';			
		}

	if ( $options['bps_login_security_status'] == 'bpsOn' ) {

	if ( $BPSoptions['bps_login_security_OnOff'] == 'On' ) {
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php' ).'" title="'.esc_attr( 'Login Security & Monitoring' ).'" style="text-decoration:none;">'.__('LSM', 'bulletproof-security').'</a>: <font color="green">'.__('On', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	}

	if ( $BPSoptions['bps_login_security_OnOff'] == 'Off' || $BPSoptions['bps_login_security_OnOff'] == 'pwreset' ) {
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php' ).'" title="'.esc_attr( 'Login Security & Monitoring' ).'" style="text-decoration:none;">'.__('LSM', 'bulletproof-security').'</a>: <font color="#fb0101">'.__('Off', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	}
	}
	}
	}
}

// S-Monitor - JTC Anti-Spam Status display WP Dashboard - BPS Pages ONLY
function bps_jtc_antispam_admin_notice_status_bps() {
global $aitpro_bullet;
	
	if ( current_user_can('manage_options') ) {
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

	$options = get_option('bulletproof_security_options_monitor');
	$BPSoptionsJTC = get_option('bulletproof_security_options_login_security_jtc');

	// new installations of BPS - First Install / Launch S-Monitor Notification is already displayed - do not display an additional notification
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_jtc_antispam_status']) ) { 
		return;
	}

	if ( $options['bps_jtc_antispam_status'] == 'Off' ) {
		return;
	}

		if ( $options['bps_isl_status'] == 'bpsOn' || $options['bps_ace_status'] == 'bpsOn' ) {
			
			$status_DDiv = '</div>';

		} else {
			
			$status_DDiv = '</div><div style="clear:both;"></div>';			
		}

	if ( $options['bps_jtc_antispam_status'] == 'bpsOn' ) {

	if ( $BPSoptionsJTC['bps_jtc_login_form'] == '1' || $BPSoptionsJTC['bps_jtc_register_form'] == '1' || $BPSoptionsJTC['bps_jtc_lostpassword_form'] == '1' || $BPSoptionsJTC['bps_jtc_comment_form'] == '1' || $BPSoptionsJTC['bps_jtc_mu_register_form'] == '1' || $BPSoptionsJTC['bps_jtc_buddypress_register_form'] == '1' || $BPSoptionsJTC['bps_jtc_buddypress_sidebar_form'] == '1' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-2' ).'" title="'.esc_attr( 'JTC Anti-Spam|Anti-Hacker' ).'" style="text-decoration:none;">'.__('JTC', 'bulletproof-security').'</a>: <font color="green">'.__('On', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	} 

	if ( $BPSoptionsJTC['bps_jtc_login_form'] != '1' && $BPSoptionsJTC['bps_jtc_register_form'] != '1' && $BPSoptionsJTC['bps_jtc_lostpassword_form'] != '1' && $BPSoptionsJTC['bps_jtc_comment_form'] != '1' && $BPSoptionsJTC['bps_jtc_mu_register_form'] != '1' && $BPSoptionsJTC['bps_jtc_buddypress_register_form'] != '1' && $BPSoptionsJTC['bps_jtc_buddypress_sidebar_form'] != '1' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">' . $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-2' ).'" title="'.esc_attr( 'JTC Anti-Spam|Anti-Hacker' ).'" style="text-decoration:none;">'.__('JTC', 'bulletproof-security').'</a>: <font color="#fb0101">'.__('Off', 'bulletproof-security').'</font>'.$status_DDiv;
		echo $text;
	}
	}
	}
	}
}

// S-Monitor - Idle Session Logout ISL Status display WP Dashboard - BPS Pages ONLY
function bpsPro_isl_notice_status_bps() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet;

	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

		$options = get_option('bulletproof_security_options_monitor');
		$BPSoptionsISL = get_option('bulletproof_security_options_idle_session');

	// new installations of BPS - First Install / Launch S-Monitor Notification is already displayed - do not display an additional notification
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_isl_status']) ) { 
		return;
	}

	if ( $options['bps_isl_status'] == 'Off' ) {
		return;
	}

		if ( $options['bps_ace_status'] == 'bpsOn' ) {
			
			$status_DDiv = '</div>';

		} else {
			
			$status_DDiv = '</div><div style="clear:both;"></div>';			
		}

	if ( $options['bps_isl_status'] == 'bpsOn' ) {
	
		if ( ! $BPSoptionsISL['bps_isl'] ) {
			// <div style="margin:-5px 0px 10px 0px;font-size:13px;font-weight:bold;">
			$text = '<br><div style="clear:both;background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:2px 5px;margin:0px 0px 4px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Idle Session Logout' ).'">'.__('ISL', 'bulletproof-security').'</a>: <font color="#fb0101">'.__('Settings have not been saved yet. ISL is not turned On.', 'bulletproof-security').'</font></div>';
			echo $text;
		}

	if ( $BPSoptionsISL['bps_isl'] == 'On' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'. $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Idle Session Logout' ).'" style="text-decoration:none;">'.__('ISL', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	} 

	if ( $BPSoptionsISL['bps_isl'] == 'Off' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'. $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Idle Session Logout' ).'" style="text-decoration:none;">'.__('ISL', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	}
	}
	}
	}
}

// S-Monitor - Auth Cookie Expiration ACE Status display WP Dashboard - BPS Pages ONLY
// Notes: When additional new status display options are added to the Dashboard Status Display the div conditions code starting from WBM
// needs to be updated with new options. RBM does not have this div condition.
// ACE is currently the last DSD option.
function bpsPro_ace_notice_status_bps() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet;

	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' ) {

		$options = get_option('bulletproof_security_options_monitor');
		$BPSoptionsACE = get_option('bulletproof_security_options_auth_cookie');

	// new installations of BPS - First Install / Launch S-Monitor Notification is already displayed - do not display an additional notification
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_ace_status']) ) { 
		return;
	}

	if ( $options['bps_ace_status'] == 'Off' ) {
		return;
	}

	// Important! See Notes above			
	$status_DDiv = '</div><div style="clear:both;"></div>';			

	if ( $options['bps_ace_status'] == 'bpsOn' ) {
	
		if ( ! $BPSoptionsACE['bps_ace'] ) {
			$text = '<br><div style="clear:both;background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:2px 5px;margin:0px 0px 4px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Idle Session Logout' ).'">'.__('ACE', 'bulletproof-security').'</a>: <font color="#fb0101">'.__('Settings have not been saved yet. ACE is not turned On.', 'bulletproof-security').'</font></div>';
			echo $text;
		}

	if ( $BPSoptionsACE['bps_ace'] == 'On' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'. $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Auth Cookie Expiration' ).'" style="text-decoration:none;">'.__('ACE', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	} 

	if ( $BPSoptionsACE['bps_ace'] == 'Off' ) {
		
		$text = '<div id="bps-status-display" style="background-color:#eeeeee;font-weight:bold;float:left;margin:0px 0px 10px 0px;">'. $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Auth Cookie Expiration' ).'" style="text-decoration:none;">'.__('ACE', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	}
	}
	}
	}
}

// S-Monitor - ARQ inpage alerts - BPS Only
// 13.3: added
function bps_smonitor_ARQ_alerts_bps() {
	
	if ( current_user_can('manage_options') ) {
	
		$Smonitor_options = get_option('bulletproof_security_options_monitor');

		if ( isset($Smonitor_options['bps_autorestore_alerts']) && $Smonitor_options['bps_autorestore_alerts'] == 'bpsOn' ) {	
			$options = get_option('bulletproof_security_options_ARCM_log');	
	
			if ( strcmp( bps_getARCMLogLastMod_wp_secs(), $options['bps_arcm_log_date_mod'] ) != 0 && $options['bps_arcm_log_date_mod'] != '' && strcmp( bps_getARCMLogLastMod_wp(), getBPSInstallTime() ) == 0 ) {

				$gmt_offset = get_option( 'gmt_offset' ) * 3600;
				$filename = WP_CONTENT_DIR . '/bps-backup/logs/autorestore_log.txt';

				touch( $filename, strtotime( $options['bps_arcm_log_date_mod'] ) - $gmt_offset );
			}
	
			$db_timestamp_plus_one = strtotime( $options['bps_arcm_log_date_mod'] ) + 3600;
			$db_timestamp_minus_one = strtotime( $options['bps_arcm_log_date_mod'] ) - 3600;	
	
			// probably not needed: $options['bps_arcm_log_date_mod'] != '' && 
			if ( strcmp( bps_getARCMLogLastMod_wp_secs(), $options['bps_arcm_log_date_mod'] ) != 0 && $db_timestamp_plus_one != strtotime( bps_getARCMLogLastMod_wp_secs() ) && $db_timestamp_minus_one != strtotime( bps_getARCMLogLastMod_wp_secs() ) ) {
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('AutoRestore|Quarantine Alert', 'bulletproof-security').'</font><br>'.__('A file has been quarantined. ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/quarantine/quarantine.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to Quarantine to view the quarantined file.', 'bulletproof-security').'<br>'.__('To clear/reset this alert click the Reset Last Modified Time in DB button on the Quarantine Log tab page.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
	}
}

// S-Monitor - Login Security Last modified check - BPS Only
function bps_smonitor_LoginSecurityResetModTimeDiff_bps() {

	if ( current_user_can('manage_options') ) {
	
		$options = get_option('bulletproof_security_options_monitor');

	if ( isset($options['bps_login_security_status']) && $options['bps_login_security_status'] == 'bpsOn' ) {
	
		$LSAlertsoptions = get_option('bulletproof_security_options_login_alerts');
		$filename = WP_CONTENT_DIR . '/bps-backup/master-backups/Login-Security-Alert-Reset.txt'; 	
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;	
	
	if ( strcmp( bps_getLoginSecurityResetFileLastMod_secs(), $LSAlertsoptions['bps_login_security_db_mod_time'] ) != 0 && $LSAlertsoptions['bps_login_security_db_mod_time'] != '' && strcmp( bps_getLoginSecurityResetFileLastMod_minutes(), getBPSInstallTime() ) == 0 ) {
	
		touch( $filename, strtotime( $LSAlertsoptions['bps_login_security_db_mod_time'] ) - $gmt_offset );
	}
	
	$db_timestamp_plus_one = strtotime( $LSAlertsoptions['bps_login_security_db_mod_time'] ) + 3600;
	$db_timestamp_minus_one = strtotime( $LSAlertsoptions['bps_login_security_db_mod_time'] ) - 3600;	
	
	if ( strcmp( bps_getLoginSecurityResetFileLastMod_secs(), $LSAlertsoptions['bps_login_security_db_mod_time'] ) != 0  && $db_timestamp_plus_one != strtotime( bps_getLoginSecurityResetFileLastMod_secs() ) && $db_timestamp_minus_one != strtotime( bps_getLoginSecurityResetFileLastMod_secs() ) ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Login Security Alert', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Login Security page.', 'bulletproof-security').'<br>'.__('To reset/clear Login Security Alerts click the Reset|Clear Login Security Alerts button on the Login Security page.', 'bulletproof-security').'</div>';
		echo $text;
	}
	}
	}
}

// S-Monitor - Folder Lock Reset Last modified check - BPS Only
function bps_smonitor_FolderLockResetModTimeDiff_bps() {

	if ( current_user_can('manage_options') ) {
	
	$options = get_option('bulletproof_security_options_monitor');

	if ( $options['bps_flock_FL_alerts'] == 'bpsOn' ) {
	
	$FLAlertsoptions = get_option('bulletproof_security_options_flock_FL_alerts');
	$filename = WP_CONTENT_DIR . '/bps-backup/master-backups/Folder-Lock-Alert-Reset.txt'; 	
	$gmt_offset = get_option( 'gmt_offset' ) * 3600;	
					
	if ( strcmp( bps_getFolderLockResetFileLastMod_secs(), $FLAlertsoptions['bps_folderlock_db_mod_time'] ) != 0 && $FLAlertsoptions['bps_folderlock_db_mod_time'] != '' && strcmp( bps_getFolderLockResetFileLastMod_minutes(), getBPSInstallTime() ) == 0 ) {
	
		touch( $filename, strtotime( $FLAlertsoptions['bps_folderlock_db_mod_time'] ) - $gmt_offset );
	}
	
	$db_timestamp_plus_one = strtotime( $FLAlertsoptions['bps_folderlock_db_mod_time'] ) + 3600;
	$db_timestamp_minus_one = strtotime( $FLAlertsoptions['bps_folderlock_db_mod_time'] ) - 3600;	
	
	if ( strcmp( bps_getFolderLockResetFileLastMod_secs(), $FLAlertsoptions['bps_folderlock_db_mod_time'] ) != 0  && $db_timestamp_plus_one != strtotime( bps_getFolderLockResetFileLastMod_secs() ) && $db_timestamp_minus_one != strtotime( bps_getFolderLockResetFileLastMod_secs() ) ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('F-Lock Folder Lock Alert', 'bulletproof-security').'</font><br>'.__('A Hosting Account Root Folder has been locked.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php#bps-tabs-2' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the F-Lock Folder Lock page. Click the Folder Lock Help Info Read Me button for help information.', 'bulletproof-security').'<br>'.__('To reset/clear Folder Lock Alerts click the Reset|Clear Folder Lock Alerts button on the Folder Lock page.', 'bulletproof-security').'</div>';
		echo $text;
	}
	}
	}
}

// S-Monitor - PHP Error Log new errors - String comparison of DB Last Modified Time and Actual File Last Modified Time - BPS Only
function bps_smonitor_ELogModTimeDiff_bps() {
	
	if ( current_user_can('manage_options') ) {
	
	$options = get_option('bulletproof_security_options_monitor');	
	
	if ( isset($options['bps_PHP_ELog_error']) && $options['bps_PHP_ELog_error'] == 'bpsOn' ) {
	
	$ELog_mod_time = get_option('bulletproof_security_options_elog');
	$gmt_offset = get_option( 'gmt_offset' ) * 3600;
	$ELog_location = get_option('bulletproof_security_options2');
	$filename = $ELog_location['bps_error_log_location'];	
	
	if ( strcmp( bps_getPhpELogLastMod_smonitor(), $ELog_mod_time['bps_error_log_date_mod'] ) != 0 && $ELog_mod_time['bps_error_log_date_mod'] != '' && strcmp( bps_getPhpELogLastMod_minutes(), getBPSInstallTime() ) == 0 ) {

		touch( $ELog_location['bps_error_log_location'], strtotime( $ELog_mod_time['bps_error_log_date_mod'] ) - $gmt_offset );
	}
	
	$db_timestamp_plus_one = strtotime( $ELog_mod_time['bps_error_log_date_mod'] ) + 3600;
	$db_timestamp_minus_one = strtotime( $ELog_mod_time['bps_error_log_date_mod'] ) - 3600;	
	
	if ( strcmp( bps_getPhpELogLastMod_smonitor(), $ELog_mod_time['bps_error_log_date_mod'] ) != 0  && $db_timestamp_plus_one != strtotime( bps_getPhpELogLastMod_smonitor() ) && $db_timestamp_minus_one != strtotime( bps_getPhpELogLastMod_smonitor() ) ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('A PHP Error has been logged in your PHP Error Log', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-5' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To go to the P-Security PHP Error Log page.', 'bulletproof-security').'<br>'.__('To remove/clear this Alert click on the Reset Last Modified Time in DB button.', 'bulletproof-security').'</div>';
		echo $text;
	}
	}
	}
}

// S-Monitor - Security Log new errors - String comparison of DB Last Modified Time and Actual File Last Modified Time - BPS Only
function bps_smonitor_SecurityLogModTimeDiff_bps() {

	if ( current_user_can('manage_options') ) {
	
	$options = get_option('bulletproof_security_options_monitor');	
	
	if ( isset($options['bps_SecLog_entry']) && $options['bps_SecLog_entry'] == 'bpsOn' ) {
	
	$SecLog_mod_date = get_option('bulletproof_security_options_Security_log');
	$filename = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';	
	$gmt_offset = get_option( 'gmt_offset' ) * 3600;
	
	if ( strcmp( bps_getSecurityLogLastMod_secs(), $SecLog_mod_date['bps_security_log_date_mod'] ) != 0 && $SecLog_mod_date['bps_security_log_date_mod'] != '' && strcmp( bps_getSecurityLogLastMod_minutes(), getBPSInstallTime() ) == 0 ) {

		touch( $filename, strtotime( $SecLog_mod_date['bps_security_log_date_mod'] ) - $gmt_offset );	
	}
	
	$db_timestamp_plus_one = strtotime( $SecLog_mod_date['bps_security_log_date_mod'] ) + 3600;
	$db_timestamp_minus_one = strtotime( $SecLog_mod_date['bps_security_log_date_mod'] ) - 3600;	
	
	if ( strcmp( bps_getSecurityLogLastMod_secs(), $SecLog_mod_date['bps_security_log_date_mod'] ) != 0 && $db_timestamp_plus_one != strtotime( bps_getSecurityLogLastMod_secs() ) && $db_timestamp_minus_one != strtotime( bps_getSecurityLogLastMod_secs() ) ) {
		$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Security Log Alert', 'bulletproof-security').'</font><br>'.__('A New Security Log Entry Has Been Logged. ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/security-log/security-log.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Security Log.', 'bulletproof-security').'<br>'.__('To remove/clear this alert click the Reset Last Modified Time in DB button on the Security Log page.', 'bulletproof-security').'<br>'.__('To turn Off Security Log Dashboard Alerts ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/monitor/monitor.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the S-Monitor page.', 'bulletproof-security').'</div>';
		
		echo $text;
	}
	}
	}
}

// S-Monitor - PHP Error Log Path/Location Check - Check if the php error log path is valid - BPS Only
// ini_set Options Checks & auto-update wp-config.php & add the 3 new ini_set options.
function bps_smonitor_phpini_bps() {

	if ( current_user_can('manage_options') ) {
	
		$options = get_option('bulletproof_security_options_monitor');	
		$options3 = get_option('bulletproof_security_options2');	
		$ElogPathSet = ! isset($options3['bps_error_log_location']) ? '' : $options3['bps_error_log_location'];	
	
		if ( isset($options['bps_PHP_ELogLoc_set']) && $options['bps_PHP_ELogLoc_set'] == 'bpsOn' && $ElogPathSet != '' ) { 
		
			$wpconfig_file = ABSPATH . 'wp-config.php';
			
			if ( ! file_exists($wpconfig_file) ) {
				$wpconfig_file_moved = __('The wp-config.php file has been moved to another hosting account folder. ', 'bulletproof-security');
			} else {
				$wpconfig_file_moved = '';
			
				$subject = file_get_contents($wpconfig_file);
				$pattern = '/\/\*\* BEGIN BPS Pro ini_set Settings \*\*\/(.*?)\/\*\* END BPS Pro ini_set Settings \*\*\//s';
				
				if ( ! preg_match($pattern, $subject ) ) {
					$ini_set_code_missing = __('The BPS ini_set Options code does not exist in the wp-config.php file.', 'bulletproof-security');
				} else {
					$ini_set_code_missing = '';
				}
			}
			
			$ini_get_error_log = ini_get('error_log');
			
			if ( $ini_get_error_log == '' ) {
				$ElogPathServer = 'blank/none';
			} else {
				$ElogPathServer = ini_get('error_log');
			}
			
			if ( $ElogPathServer == 'blank/none' && $wpconfig_file_moved == '' && $ini_set_code_missing == '' ) {
				$host_config_problem = __('Web host PHP server configuration problem.', 'bulletproof-security');
			} else {
				$host_config_problem = '';
			}

			$ElogPathServerXampp = addslashes( ini_get('error_log') );
			$sapi_type = php_sapi_name();	
			
			// Linux
			if ( substr($sapi_type, 0, 6) != 'apache' ) {

				if ( strcmp($ElogPathServer, $ElogPathSet) != 0 ) {
					$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</font><br>'.__('The "PHP Error Log Location Set To" value does not match the "Error Log Path Seen by Server" value.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-5' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the PHP Error Log page.', 'bulletproof-security').'<br>'.__('Copy the "Error Log Path Seen by Server" value: ', 'bulletproof-security').'<font color="blue">'.$ElogPathServer.'</font>'.__(' into the "PHP Error Log Location Set To" text box and click the Set Error Log Location button to fix this unless you see "blank/none" for the value.', 'bulletproof-security').'<br>'.__('If you see "blank/none" for the value click this forum link: ', 'bulletproof-security').'<a href="https://forum.ait-pro.com/forums/topic/php-error-log-path-does-not-match-error-log-path-seen-by-server-blank-none/" target="_blank" title="Link opens in a new Browser window">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</a>'.__(' for how to fix this problem.', 'bulletproof-security').'<br><font color="#fb0101">'.__('Cause of the problem: ', 'bulletproof-security').'</font>'.$wpconfig_file_moved.$ini_set_code_missing.$host_config_problem.'</div>';
					echo $text;
				}
			
			} else {
				
				// XAMPP, MAMP, WAMP, etc.
				if ( strcmp($ElogPathServerXampp, $ElogPathSet) != 0 ) { // 0 is equal - != 0 means that the paths do not match
					$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</font><br>'.__('The "PHP Error Log Location Set To" value does not match the "Error Log Path Seen by Server" value.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-5' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the PHP Error Log page.', 'bulletproof-security').'<br>'.__('Copy the "Error Log Path Seen by Server" value: ', 'bulletproof-security').'<font color="blue">'.$ElogPathServer.'</font>'.__(' into the "PHP Error Log Location Set To" text box and click the Set Error Log Location button to fix this unless you see "blank/none" for the value.', 'bulletproof-security').'<br>'.__('If you see "blank/none" for the value click this forum link: ', 'bulletproof-security').'<a href="https://forum.ait-pro.com/forums/topic/php-error-log-path-does-not-match-error-log-path-seen-by-server-blank-none/" target="_blank" title="Link opens in a new Browser window">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</a>'.__(' for how to fix this problem.', 'bulletproof-security').'<br><font color="#fb0101">'.__('Cause of the problem: ', 'bulletproof-security').'</font>'.$wpconfig_file_moved.$ini_set_code_missing.$host_config_problem.'</div>';
					echo $text;
				}				
			}
		}

		if ( isset($options['bps_phpini_created']) && $options['bps_phpini_created'] == 'bpsOn' ) { 
		
			$ini_set_options = get_option('bulletproof_security_options_iniSet');	
	
			if ( ! isset($ini_set_options['bps_iniSet_ErrorReporting']) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('ini_set Options Need To Be Saved & The PHP Error Log Path|Location Needs To Be Set', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-2' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the P-Security ini_set Options page. Enter a php error log path in the ini_set PHP Error Log Location Set To: text box (see the Recommended Setting/path to the right of this text box) and click the Save|Enable Options button. Click the ini_set Options Read Me Help button if you need additional help info.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
	}
}

// F-Lock - Check if F-Lock options saved - F-Lock Lock / Unlock File Status & actual file permissions 404 or 400 - BPS Only
function bps_smonitor_flock_bps() {
	
	if ( current_user_can('manage_options') ) {
	
		$fl_override_options = get_option('bulletproof_security_options_flock_eol');
		
		if ( isset($fl_override_options['bps_file_lock_override']) && $fl_override_options['bps_file_lock_override'] == 'Off' ) {
			return;
		}

		$options = get_option('bulletproof_security_options_monitor');	
		
		if ( isset($options['bps_flock_status']) && $options['bps_flock_status'] == 'Off' ) { 
			return;
		}
	
		if ( ! get_option('bulletproof_security_options_flock' ) ) {
			if ( isset($options['bps_flock_status']) && $options['bps_flock_status'] == 'bpsOn' ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">'.__('BPS Pro F-Lock Notification', 'bulletproof-security').'<br>'.__('F-Lock options have not been saved yet.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the F-Lock page to choose and save your File Lock|Unlock options.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
		
		if ( isset($options['bps_flock_status']) && $options['bps_flock_status'] == 'bpsOn' ) {
			
			if ( isset($_POST['bpsFlockSubmit']) && @$_POST['bpsFlockSubmit'] == true ) {
				return;
			}
		
			clearstatcache();
		
			$fileRH = ABSPATH . '.htaccess';
			$fileWPC = ABSPATH . 'wp-config.php';
			$fileRI = ABSPATH . 'index.php';
			$fileBH = ABSPATH . 'wp-blog-header.php';
			$fileDRH = $_SERVER['DOCUMENT_ROOT'] . '/.htaccess';
			$fileDRI = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
			$fileHGWIOD = dirname(ABSPATH) . '/.htaccess';
			$fileIGWIOD = dirname(ABSPATH) . '/index.php';
	
			if ( file_exists($fileRH) ) {
				$permsRH = @substr(sprintf('%o', fileperms($fileRH)), -4);
			}
			if ( file_exists($fileWPC) ) {
				$permsWPC = @substr(sprintf('%o', fileperms($fileWPC)), -4);
			}
			if ( file_exists($fileRI) ) {		
				$permsRI = @substr(sprintf('%o', fileperms($fileRI)), -4);
			}
			if ( file_exists($fileBH) ) {			
				$permsBH = @substr(sprintf('%o', fileperms($fileBH)), -4);
			}
			if ( file_exists($fileDRH) ) {
				$permsDRH = @substr(sprintf('%o', fileperms($fileDRH)), -4);
			}
			if ( file_exists($fileDRI) ) {
				$permsDRI = @substr(sprintf('%o', fileperms($fileDRI)), -4);
			}
			if ( file_exists($fileHGWIOD) ) {
				$permsHGWIOD = @substr(sprintf('%o', fileperms($fileHGWIOD)), -4);
			}
			if ( file_exists($fileIGWIOD) ) {
				$permsIGWIOD = @substr(sprintf('%o', fileperms($fileIGWIOD)), -4);
			}
	
			$options2 = get_option('bulletproof_security_options_flock'); 
			$GDMW_options = get_option('bulletproof_security_options_GDMW');	
			
			if ( $options2['bps_lock_root_htaccess'] == 'off' || !$options2['bps_lock_root_htaccess'] ) { 
				echo '';
			}	
			elseif ( $options2['bps_lock_root_htaccess'] == 'no' || $permsRH != '0404' && file_exists($fileRH) ) {
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your Root htaccess File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your Root htaccess file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_wpconfig'] == 'off' || !$options2['bps_lock_wpconfig'] ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_wpconfig'] == 'no'  || $permsWPC != '0400' && file_exists($fileWPC) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your wp-config.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your wp-config.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php'] == 'off' || !$options2['bps_lock_index_php'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_index_php'] == 'no' || $permsRI != '0400' ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your WP Root index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your WP Root index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_wpblog_header'] == 'off' || !$options2['bps_lock_wpblog_header'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_wpblog_header'] == 'no' || $permsBH != '0400' ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your wp-blog-header.php File is not Locked', 'bulletproof-security').'</font><br><strong><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your wp-blog-header.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_root_htaccess_dr'] == 'off' || !$options2['bps_lock_root_htaccess_dr'] ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_root_htaccess_dr'] == 'no' || $permsDRH != '0404' && file_exists($fileDRH) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your DR Root htaccess File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your DR Root htaccess file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php_dr'] == 'off' || !$options2['bps_lock_index_php_dr'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_index_php_dr'] == 'no' || $permsDRI != '0400' && file_exists($fileDRI) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your DR WP index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your DR WP index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_root_htaccess_gwiod'] == 'off' || !$options2['bps_lock_root_htaccess_gwiod'] ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_root_htaccess_gwiod'] == 'no' || $permsHGWIOD != '0404' && file_exists($fileHGWIOD) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your GWIOD Root htaccess File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your GWIOD Root htaccess file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php_gwiod'] == 'off' || !$options2['bps_lock_index_php_gwiod'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_index_php_gwiod'] == 'no' || $permsIGWIOD != '0400' && file_exists($fileIGWIOD) ) { 
				$text = '<div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;padding:0px 5px;margin:-7px 0px 10px 0px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your GWIOD WP index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your GWIOD WP index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
	}
}

// Plugin Firewall Whitelist checks for valid whitelist rules/paths/scripts
// 12.5: pattern5: removed /plugins/ from the RegEx whitelist rule error check
function bpsPFWWhitelistRulesCheck() {

	if ( current_user_can('manage_options') ) {

	$options = get_option('bulletproof_security_options_pfirewall'); 
	$pattern1 = '/(\/(.*)\s{2}\/|\/(.*)\s{3}\/|\/(.*)\s{4}\/|\/(.*)\s{5}\/|\/(.*),\/|\n|\r)/';		
	$pattern2 = '/(\bver=\b|\bpage=\b|\bsrc=\b|\bwww\b|\bhttp\b|\bhttps\b|\bhref\b|\b\.com\b|\b\.net\b|\b\.org\b\b\.biz\b|\b\.info\b|\b\.gov\b|\b\.edu\b)/';
	$pattern3 = '/[\%\"\'\&\;\<\>]/';
	$pattern4 = '/(\/bulletproof-security\/admin\/js\/\(\.\*\)\.js|\/bulletproof-security\/)/';
	//$pattern5 = '/(\/themes\/|\/plugins\/|\/wp-content\/|\/wp-includes\/|\/uploads\/)/';
	$pattern5 = '/(\/wp-content\/|\/wp-includes\/)/';
	$bps_pfw_whitelist = ! isset($options['bps_pfw_whitelist']) ? '' : $options['bps_pfw_whitelist'];

	$error = '0';

	if ( preg_match( $pattern1, $bps_pfw_whitelist, $matches ) ) {
		echo '<div id="pfw-inpage-messages" style="border:2px solid black;padding:5px;margin-bottom:5px;max-width:100%;background-color:#dfecf2;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">';
		$text = '<font color="#fb0101"><strong>'.__('Error: Your Whitelist rules either have additional/extra whitespaces between whitelist rules, line breaks/new lines between<br>or after your whitelist rules or no space after the comma between your plugin scripts/paths/rules.', 'bulletproof-security').'</font><br>'.__('Click on the Plugin Firewall Whitelist Tools accordion tab and click the Save Whitelist Options button to see if this will automatically fix the problem.<br>If the error is still occurring then correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area.', 'bulletproof-security').'<br>'.__('Edit your Whitelist rules to correct the error and click the Save Whitelist Options button and activate the Plugin Firewall again.', 'bulletproof-security').'<br>'.__('Valid plugin Whitelist rules MUST use ONLY this Format: /plugin-folder-name/plugin-script.js, /plugin-folder-name/(.*).js.<br>Plugin paths/scripts are separated by a comma and a single space. Your whitelist rules should be one continuous single line of scripts/paths/rules without any line breaks/new lines.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</div>';
	$error = '1';
	}
	if ( preg_match( $pattern2, $bps_pfw_whitelist, $matches ) ) {
		echo '<div id="pfw-inpage-messages" style="border:2px solid black;padding:5px;margin-bottom:5px;max-width:100%;background-color:#dfecf2;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">';
		$text = '<font color="#fb0101"><strong>'.__('Error: One or more of your Whitelist rules are not valid', 'bulletproof-security').'</font><br>'.__('Click on the Plugin Firewall Whitelist Tools accordion tab and correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area.', 'bulletproof-security').'<br>'.__('Edit your Whitelist rules and correct whitelist rules that contain any of these invalid things:', 'bulletproof-security').'<br>'.__('ver=, page=, src=, www, http, https, href, .com, .net, .org, .biz, .info, .gov, .edu and', 'bulletproof-security').'<br>'.__('click the Save Whitelist Options button and activate the Plugin Firewall again.', 'bulletproof-security').'<br>'.__('Valid plugin Whitelist rules MUST use ONLY this Format: /plugin-folder-name/plugin-script.js, /plugin-folder-name/(.*).js. Plugin paths/scripts are separated by a comma and a single space.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</div>';
	$error = '2';
	}
	if ( preg_match( $pattern3, $bps_pfw_whitelist, $matches ) ) {
		echo '<div id="pfw-inpage-messages" style="border:2px solid black;padding:5px;margin-bottom:5px;max-width:100%;background-color:#dfecf2;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">';
		$text = '<font color="#fb0101"><strong>'.__('Error: One or more of your Whitelist rules contain these invalid characters: %, ", \', &, <, > or ;', 'bulletproof-security').'</font><br>'.__('Click on the Plugin Firewall Whitelist Tools accordion tab and correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area.', 'bulletproof-security').'<br>'.__('Edit your Whitelist rules to correct the error and click the Save Whitelist Options button and activate the Plugin Firewall again.', 'bulletproof-security').'<br>'.__('Valid plugin Whitelist rules MUST use ONLY this Format: /plugin-folder-name/plugin-script.js, /plugin-folder-name/(.*).js. Plugin paths/scripts are separated by a comma and a single space.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</div>';
	$error = '3';
	}
	if ( preg_match( $pattern4, $bps_pfw_whitelist, $matches ) ) {
		echo '<div id="pfw-inpage-messages" style="border:2px solid black;padding:5px;margin-bottom:5px;max-width:100%;background-color:#dfecf2;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">';
		$text = '<font color="#fb0101"><strong>'.__('Error: Your Whitelist rules have a /bulletproof-security/admin/js/ script whitelisted', 'bulletproof-security').'</font><br>'.__('The bulletproof-security plugin js scripts should NOT be whitelisted.', 'bulletproof-security').__('Click on the Plugin Firewall Whitelist Tools accordion tab and correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area.', 'bulletproof-security').'<br>'.__('Delete the bulletproof-security js script(s) and click the Save Whitelist Options button and activate the Plugin Firewall again.', 'bulletproof-security').'<br>'.__('Valid plugin Whitelist rules MUST use ONLY this Format: /plugin-folder-name/plugin-script.js, /plugin-folder-name/(.*).js. Plugin paths/scripts are separated by a comma and a single space.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</div>';
	$error = '4';
	}
	if ( preg_match( $pattern5, $bps_pfw_whitelist, $matches ) ) {
		echo '<div id="pfw-inpage-messages" style="border:2px solid black;padding:5px;margin-bottom:5px;max-width:100%;background-color:#dfecf2;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">';
		$text = '<font color="#fb0101"><strong>'.__('Error: One or more of your Whitelist rules contain these invalid paths: /wp-content/ or /wp-includes/', 'bulletproof-security').'</font><br>'.__('Click on the Plugin Firewall Whitelist Tools accordion tab and correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area.', 'bulletproof-security').'<br>'.__('Edit your Whitelist rules to correct the error and click the Save Whitelist Options button and activate the Plugin Firewall again.', 'bulletproof-security').'<br>'.__('Valid plugin Whitelist rules MUST use ONLY this Format: /plugin-folder-name/plugin-script.js, /plugin-folder-name/(.*).js. Plugin paths/scripts are separated by a comma and a single space.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</div>';
	$error = '5';
	}
	if ( $error != '0' ) {
		echo '<div id="message" class="updated" style="background-color:#dfecf2;border:1px solid #999;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><p>';
		$text = '<font color="#fb0101"><strong>'.__('BPS Alert! Plugin Firewall Invalid Whitelist Rules', 'bulletproof-security').'</font><br>'.__('One or more of your Plugin Firewall Whitelist rules are not valid. ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" style="text-decoration:underline;">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Plugin Firewall Tools section. A detailed error message will be displayed to you with what needs to be corrected. Click on the Plugin Firewall Whitelist Tools accordion tab and correct/fix any invalid plugin whitelist rules in the Plugins Script|File Whitelist Text Area. The Plugin Firewall has been automatically deactivated/turned Off until this issue is corrected so that this issue does not cause a problem for your website.', 'bulletproof-security').'</strong><br>';
		echo $text;
		echo '</p></div>';			
	}
}
}

// 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. 
// B-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: new htaccess files created if needed.
// bpsPro_apache_mod_create_htaccess_files() executed in this function which creates new htaccess files if needed.
// 11.1: fallback to mod_access_compat. see 11.8
// 11.5: 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.
// 11.8: 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.
// 15.1: Using IfModule conditions for all tests. No longer checking for No IfModule conditions. All htaccess code now contains IfModule condtions.
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
			// 2: 200: mod_access_compat Module is NOT loaded.
			$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
			// 3: 200: mod_authz_core Module is NOT loaded.
			$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' );
			// 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' );
			// 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, $url3, $url4, $url5, $url6, $url9, $url12, $url13 );
	
			echo '<strong><span class="sysinfo-label-text">'.__('Apache Modules|Directives|Backward Compatibility(Yes|No)|IfModule(Yes|No): ', 'bulletproof-security').'</span></strong><br>';

			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 ) { // 9
						$status_code9 = $response['response']['code'];
					}

					if ( $key == 6 ) { // 12
						$status_code12 = $response['response']['code'];
					}

					if ( $key == 7 ) { // 13
						$status_code13 = $response['response']['code'];
					}

				} else {
		
					$text = '<font color="#fb0101"><strong>'.__('ERROR: wp_remote_get() function is blocked or unable to get the URL path', 'bulletproof-security').'</strong></font><br>';
					echo $text;;
				}
			}
			
			// Fubar: Server does not have necessary Modules loaded to use htaccess files
			// if $status_code2, 3 and 4 are not 403 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 ( 403 != $status_code2 && 403 != $status_code3 && 403 != $status_code4 || 500 == $status_code9 ) {
				
				$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
				if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
					$apache_ifmodule = 'Yes';
				} else {
					$apache_ifmodule = 'fubar';
				}
				
				$text = '<font color="#fb0101"><strong>'.$status_code2.':'.$status_code3.':'.$status_code4.':'.$status_code9.':</strong></font> '.__('mod_access_compat and mod_authz_core or mod_rewrite are not Loaded', 'bulletproof-security').'<br>';
				echo $text;
			
			} else {
				*/
				
				// mod_access_compat loaded, Order, Allow, Deny directives are supported
				if ( 403 == $status_code2 ) {

					$apache_ifmodule = 'Yes';
		
					$text = '<font color="green"><strong>'.$status_code2.':</strong></font> '.__('mod_access_compat is Loaded|Order, Allow, Deny directives are supported|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;				
			
				// mod_access_compat is not loaded|available.
				} elseif ( 403 != $status_code2 ) {
				
					$apache_ifmodule = 'Yes';

					$text = '<font color="#2ea2cc"><strong>'.$status_code2.':</strong></font> '.__('mod_access_compat is not Loaded|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;
				}

				// mod_authz_core loaded, IfModule condition working, Order, Allow, Deny directives are supported
				// 3 normal mod_authz_core test| 4 is mod_access_compat	BC
				if ( 403 == $status_code3 && 403 == $status_code4 ) {
				
					$text = '<font color="green"><strong>'.$status_code3.':</strong></font> '.__('mod_authz_core is Loaded|Order, Allow, Deny directives are supported|BC: Yes|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;
				
				} elseif ( 403 == $status_code3 && 403 != $status_code4 ) {
			
					$text = '<font color="green"><strong>'.$status_code3.':</strong></font> '.__('mod_authz_core is Loaded|Order, Allow, Deny directives are not supported|BC: No|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;		
			
				} elseif ( 403 != $status_code3 && 403 != $status_code4 ) {
				
					$text = '<font color="#2ea2cc"><strong>'.$status_code3.':</strong></font> '.__('mod_authz_core is not Loaded|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;	
				}

				// mod_authz_host loaded, IfModule condition working, Order, Allow, Deny directives are supported
				// 5 normal mod_authz_core test| 6 is mod_access_compat	BC			
				if ( 403 == $status_code5 && 403 == $status_code6 ) {
				
					$text = '<font color="green"><strong>'.$status_code5.':</strong></font> '.__('mod_authz_host is Loaded|Order, Allow, Deny directives are supported|BC: Yes|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;
				
				} elseif ( 403 == $status_code5 && 403 != $status_code6 ) {
			
					$text = '<font color="green"><strong>'.$status_code5.':</strong></font> '.__('mod_authz_host is Loaded|Order, Allow, Deny directives are not supported|BC: No|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;		
			
				} elseif ( 403 != $status_code5 && 403 != $status_code6 ) {
				
					$text = '<font color="#2ea2cc"><strong>'.$status_code6.':</strong></font> '.__('mod_authz_host is not Loaded|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;	
				}

				// 11.8: mod_rewrite Module loaded.
				if ( 301 == $status_code9 || 302 == $status_code9 || 200 == $status_code9 || 404 == $status_code9 || 403 == $status_code9 ) {
				
					$text = '<font color="green"><strong>'.$status_code9.':</strong></font> '.__('mod_rewrite Module is Loaded|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;
			
				} else {
				
					$text = '<font color="#2ea2cc"><strong>'.$status_code9.':</strong></font> '.__('mod_rewrite Inconclusive: Status is not 200, 301, 302, 403 or 404', 'bulletproof-security').'<br>';
					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);
				}			
			}

			## 15.3: BugFix
			## 15.9: BugFix: htaccess files enabled if disabled using the disable htaccess files Setup Wizard option
			$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
			
			$htaccess_files_disabled_enabled = isset($HFiles_options['bps_htaccess_files']) ? $HFiles_options['bps_htaccess_files'] : '';

			if ( $apache_ifmodule == 'Yes' && $htaccess_files_disabled_enabled != 'disabled' ) {
			
				$htaccess_files_Options = array(
				'bps_htaccess_files' 	=> 'enabled'
				);

				foreach( $htaccess_files_Options as $key => $value ) {
					update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
				}			
			}

			// 13.4.1: mod_security or mod_security2 Module loaded.
			if ( 403 == $status_code12 || 403 == $status_code13 ) {
				
				if ( 403 == $status_code12 ) {
					$text = '<font color="#2ea2cc"><strong>'.$status_code12.':</strong></font> '.__('mod_security Module is Loaded|Enabled|IfModule: Yes', 'bulletproof-security').'<br>';
					echo $text;
				} elseif ( 403 == $status_code13 ) {
					$text = '<font color="#2ea2cc"><strong>'.$status_code13.':</strong></font> '.__('mod_security2 Module is Loaded|Enabled|IfModule: Yes', 'bulletproof-security').'<br>';
					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 = '<font color="green"><strong>'.$status_code12.':</strong></font> '.__('mod_security Module is not Loaded|Enabled|IfModule: Yes', 'bulletproof-security').'<br>';
				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
		// 13.4.1: Add new BPS Mod Security DB option here. Will be used in a Mod Security Dismiss Notice. 
		} else {

			// 2: 403: mod_access_compat Module IS loaded. "Deny from all". Allows "Order, Deny, Allow" directives
			// 2: 200: mod_access_compat Module is NOT loaded.
			$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
			// 3: 200: mod_authz_core Module is NOT loaded.
			$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' );
			// 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' );
			// 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, $url3, $url4, $url9, $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 ) { // 3
							$status_code3 = $response['response']['code'];
						}

						if ( $key == 2 ) { // 4
							$status_code4 = $response['response']['code'];
						}

						if ( $key == 3 ) { // 9
							$status_code9 = $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_code2, 3 and 4 are not 403 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 ( 403 != $status_code2 && 403 != $status_code3 && 403 != $status_code4 || 500 == $status_code9 ) {

					$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
					if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
						$apache_ifmodule = 'Yes';
					} 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 ) {

						$apache_ifmodule = 'Yes';
			
					} else { 
		
						$apache_ifmodule = 'Yes';
					}
				//} // 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);
					}			
				}

				## 15.3: BugFix
				## 15.9: BugFix: htaccess files enabled if disabled using the disable htaccess files Setup Wizard option
				$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
				$htaccess_files_disabled_enabled = isset($HFiles_options['bps_htaccess_files']) ? $HFiles_options['bps_htaccess_files'] : '';

				if ( $apache_ifmodule == 'Yes' && $htaccess_files_disabled_enabled != 'disabled' ) {
				
					$htaccess_files_Options = array(
					'bps_htaccess_files' 	=> 'enabled'
					);

					foreach( $htaccess_files_Options as $key => $value ) {
						update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
					}			
				}				

				// 13.4.1: 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');
				$bps_apache_mod_time = isset($Apache_Mod_options['bps_apache_mod_time']) ? $Apache_Mod_options['bps_apache_mod_time'] : '';		

				// Note: if the db option does not exist yet it is created: time now is greater than nothing
				if ( time() < $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 ) { // 3
								$status_code3 = $response['response']['code'];
							}
	
							if ( $key == 2 ) { // 4
								$status_code4 = $response['response']['code'];
							}
	
							if ( $key == 3 ) { // 9
								$status_code9 = $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_code2, 3 and 4 are not 403 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 ( 403 != $status_code2 && 403 != $status_code3 && 403 != $status_code4 || 500 == $status_code9 ) {
				
						$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
						if ( $HFiles_options['bps_htaccess_files'] == 'enabled' ) {
							$apache_ifmodule = 'Yes';
						} 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 ) {

							$apache_ifmodule = 'Yes';
			
						} else { 
		
							$apache_ifmodule = 'Yes';
						}
					//} // 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);
						}			
					}

					## 15.3: BugFix
					## 15.9: BugFix: htaccess files enabled if disabled using the disable htaccess files Setup Wizard option
					$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
					
					$htaccess_files_disabled_enabled = isset($HFiles_options['bps_htaccess_files']) ? $HFiles_options['bps_htaccess_files'] : '';
		
					if ( $apache_ifmodule == 'Yes' && $htaccess_files_disabled_enabled != 'disabled' ) {
					
						$htaccess_files_Options = array(
						'bps_htaccess_files' 	=> 'enabled'
						);
	
						foreach( $htaccess_files_Options as $key => $value ) {
							update_option('bulletproof_security_options_htaccess_files', $htaccess_files_Options);
						}			
					}

					// 13.4.1: 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
// 21 htaccess files total
// 11.8: Fubar condition added for servers that do not have either mod_access_compat and mod_authz_core or mod_rewrite Loaded.
// 11.8: BugFix|AutoFix: delete the /xternal/.htaccess file.
// 12: new condition added for Zip File Download Fix (Incapsula, Proxy, Other Cause). core, login and wizard htaccess files are not created if == On
// 13.3: MScan htaccess file added
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/activation/.htaccess';	
		$core2 = $bpsPro_pf  . 'admin/autorestore/.htaccess';
		$core3 = $bpsPro_pf  . 'admin/core/.htaccess';
		$core4 = $bpsPro_pf  . 'admin/db-backup-security/.htaccess';
		$core5 = $bpsPro_pf  . 'admin/db-monitor/.htaccess';
		$core6 = $bpsPro_pf  . 'admin/htaccess/.htaccess';
		$core7 = $bpsPro_pf  . 'admin/install/.htaccess';
		$core8 = $bpsPro_pf  . 'admin/lock/.htaccess';
		$core9 = $bpsPro_pf  . 'admin/login/.htaccess';
		$core10 = $bpsPro_pf . 'admin/maintenance/.htaccess';
		$core11 = $bpsPro_pf . 'admin/monitor/.htaccess';	
		$core12 = $bpsPro_pf . 'admin/php/.htaccess';	
		$core13 = $bpsPro_pf . 'admin/quarantine/.htaccess';	
		$core14 = $bpsPro_pf . 'admin/security-log/.htaccess';
		$core15 = $bpsPro_pf . 'admin/system-info/.htaccess';
		$core16 = $bpsPro_pf . 'admin/theme-skin/.htaccess';	
		$core17 = $bpsPro_pf . 'admin/tools/.htaccess';
		$core18 = $bpsPro_pf . 'admin/wizard/.htaccess';	
		$core19 = $bpsPro_pf . 'admin/xternal/.htaccess';
		$core20 = $bpsPro_pf . 'admin/mscan/.htaccess';	

		$Zip_download_Options = get_option('bulletproof_security_options_zip_fix');

		if ( isset( $Zip_download_Options['bps_zip_download_fix'] ) && $Zip_download_Options['bps_zip_download_fix'] == 'On' ) {
			$files = array( $bps_backup, $bps_master_backups, $core1, $core2, $core4, $core5, $core6, $core7, $core8, $core10, $core11, $core12, $core13, $core14, $core15, $core16, $core17, $core20 );
		} else {
			$files = array( $bps_backup, $bps_master_backups, $core1, $core2, $core3, $core4, $core5, $core6, $core7, $core8, $core9, $core10, $core11, $core12, $core13, $core14, $core15, $core16, $core17, $core18, $core20 );		
		}
	
		$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
		$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
		// 11.8: htaccess Files Enabled|Disabled Override
		// If someone manually chooses Disable htaccess files then htaccess files will not be created.
		if ( isset( $HFiles_options['bps_htaccess_files'] ) && $HFiles_options['bps_htaccess_files'] != 'disabled' ) {

			foreach ( $files as $file ) {

				if ( ! file_exists($file) ) {
					
					if ( isset($Apache_Mod_options['bps_apache_mod_ifmodule']) && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' ) {
						@copy($denyall_ifmodule_htaccess, $file);
					} elseif ( isset($Apache_Mod_options['bps_apache_mod_ifmodule']) && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' ) {
						@copy($denyall_htaccess, $file);
					}
				}

				if ( file_exists($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);
					}
				}
			}
		}

		if ( file_exists($core19) ) {
			unlink($core19);
		}
	}
}

// Parse phpinfo() and return the PHP memory_limit Local Value
function bpsPro_phpinfo_memory_limit_array() {
    
 	$disable_functions = explode( ',', ini_get('disable_functions') );	
   	
	if ( function_exists('phpinfo') && ! in_array( 'phpinfo', $disable_functions ) ) {
		
		ob_start();
		phpinfo();
		$info_arr = array();
		$info_lines = explode( "\n", strip_tags( ob_get_clean(), "<tr><td><h2>" ) );
		$cat = "General";
		
		foreach( $info_lines as $line ) {
	
			preg_match( "~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
			
			if ( preg_match( "~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val ) ) {
				$info_arr[$cat][$val[1]] = $val[2];
			
			} elseif ( preg_match( "~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val ) ) {
				$info_arr[$cat][$val[1]] = array( "local" => $val[2], "master" => $val[3] );
			}
		}
		
		$bps_php_memory_limit = $info_arr['Core']['memory_limit']['local'];
		
		$bps_php_memory_limit_options = array( 'bps_php_memory_limit' => $bps_php_memory_limit );
	
		foreach( $bps_php_memory_limit_options as $key => $value ) {
			update_option('bulletproof_security_options_php_memory_limit', $bps_php_memory_limit_options);
		}

		return $info_arr['Core']['memory_limit']['local'];
	
	} else {
		
		$bps_php_memory_limit = 'Unable to get the PHP memory_limit value from the server. Either the phpinfo() function does not exist or it has been disabled in your server php.ini or .user.ini file. The ini_set Options memory limit setting will be set to 256M automatically by the Setup Wizard to prevent problems or errors with the BPS Pro Setup.';
		
		$bps_php_memory_limit_options = array( 'bps_php_memory_limit' => $bps_php_memory_limit );
	
		foreach( $bps_php_memory_limit_options as $key => $value ) {
			update_option('bulletproof_security_options_php_memory_limit', $bps_php_memory_limit_options);
		}
	}
}
?>