<?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();
}

// BPS Pro Software Anti-Piracy Check
// WARNING! Tampering with this code will cause BPS Pro to stop functioning.
// This code only does 1 thing - It checks that your copy of BPS Pro is not pirated and is legitimately licensed.
function bpsPro_AP_Check($D8) {
	if ( is_admin() && current_user_can('manage_options') ) {
		$D1 = '0784623491';
		$D2 = '1789456307';
		$D7 = '42756C6C657450726F6F66 5365637572697479 50726F';
		$i = '8'; 		
		if ((ord($D7[$i]) >= $D2[$i])) {
			@$D8 = chr((ord($D2[$i])-ord($D1[$i]))%256);
		}
	}
}

// First Launch Admin Notice / BPS Pro Activation & Setup Wizard Notification
function bps_first_launch_admin_notice_act() {

	if ( is_admin() && current_user_can('manage_options') ) {
	
	global $blog_id;
	if ( is_multisite() && $blog_id != 1 ) {	
		return;
	}

	$options = get_option('bulletproof_security_options_activation');

	if ( ! get_option('bulletproof_security_options_activation') || strlen($options['bps_pro_activation']) == 17 ) {
		
		if ( esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/activation/activation.php' ) {
		
			$text = '<div id="bps-inpage-message" 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);">'.__('BPS Pro Activation Notification', 'bulletproof-security').'<br>'.__('Please Activate BPS Pro first before doing anything else. BPS Pro will not function correctly until Activation has been completed. ', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/activation/activation.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Activation page.', 'bulletproof-security').'</div>';
			echo $text;
		}
	
	} else {

		if ( esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/activation/activation.php' && strlen($options['delete_paypal_email']) < 18 && strlen($options['bps_pro_activation']) != 17 ) {
		
			$text = '<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="#fb0101">'.__('BPS Pro Activation Error', 'bulletproof-security').'</font><br>'.__('The BPS Pro plugin pages will display blank until Activation has been completed successfully.', 'bulletproof-security').'<br>'.__('Did you enter and save your Activation Key? Did you accidentally enter your Download-Request Key in the Activation Key text box by mistake?', 'bulletproof-security').'<br>'.__('Please follow the 3 step Activation process on the BPS Pro Activation page. The Activation steps are numbered to match the text boxes.', 'bulletproof-security').'<br>'.__('Click the Read Me help button on the Activation page for additional troubleshooting help information.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/activation/activation.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Activation page.', 'bulletproof-security').'</div>';
			echo $text;		
		}
	}
	
	if ( isset($options['delete_paypal_email']) && strlen($options['delete_paypal_email']) > 18) {
	
		$PreInstallOptions = get_option('bulletproof_security_options_preinstallation'); 
		$Smonitor_options = get_option('bulletproof_security_options_monitor');
		$Upgrade_notice_options = get_option('bulletproof_security_options_upgrade_notice');
		$new_install_activation_message = ! isset($PreInstallOptions['bps_wizard_preinstallation']) ? '' : $PreInstallOptions['bps_wizard_preinstallation']; 
		$bps_upgrade_notification_wizard = ! isset($Upgrade_notice_options['bps_upgrade_notification_wizard']) ? '' : $Upgrade_notice_options['bps_upgrade_notification_wizard'];
		
		if ( $new_install_activation_message != 'yes' && ! isset($Smonitor_options['bps_first_launch']) ) {
			$text = '<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);">'.__('BPS Pro Setup Wizard Notification', 'bulletproof-security').'<br>'.__('BPS Pro has been Activated successfully. ', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the BPS Pro Setup Wizard page.', 'bulletproof-security').'<br>'.__('Click the Pre-Installation Wizard button first and then click the Setup Wizard button.', 'bulletproof-security').'</div>';
			echo $text;
		}
	
		// only for very old BPS Pro versions being upgraded to a new version with the Setup Wizard
		if ( $new_install_activation_message != 'yes' && isset($Smonitor_options['bps_first_launch']) && $bps_upgrade_notification_wizard != 'yes') {
			$text = '<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);">'.__('New BPS Pro Setup Wizard Notification', 'bulletproof-security').'<br>'.__('BPS Pro setup can now be done in less than 1 minute with only 2 clicks using the new BPS Pro Setup Wizard.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/whatsnew/whatsnew.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the BPS Pro Whats New page to read more about the new BPS Pro Setup Wizard.', 'bulletproof-security').'</div>';
			echo $text;

			$bps_option_upgrade_notice = 'bulletproof_security_options_upgrade_notice';
			$bps_new_value_upgrade_wizard = 'yes';
			$BPS_Options_upgrade_notice = array( 'bps_upgrade_notification_wizard' => $bps_new_value_upgrade_wizard );

			if ( ! get_option( $bps_option_upgrade_notice ) ) {	
				foreach( $BPS_Options_upgrade_notice as $key => $value ) {			
					update_option('bulletproof_security_options_upgrade_notice', $BPS_Options_upgrade_notice);
				}
		
			} else {
				foreach( $BPS_Options_upgrade_notice as $key => $value ) {			
					update_option('bulletproof_security_options_upgrade_notice', $BPS_Options_upgrade_notice);
				}
			}	
		}	
	} // end if ( strlen($options['delete_paypal_email']) > 18) { = A BPS Pro Activation Key has been entered
	}
}
add_action('admin_notices', 'bps_first_launch_admin_notice_act');

/***************************************/
// Installation/Upgrade Time Checks
/***************************************/

// Get the Current / Last Modifed Date of the bulletproof-security.php File - Minutes check
// used in both the php error log check and autorestore log check - touch minus 1 hour comes into play
function getBPSInstallTime() {
$filename = WP_PLUGIN_DIR . '/bulletproof-security/bulletproof-security.php';

	if ( file_exists($filename) ) {
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$last_modified_install = date("F d Y H:i", filemtime($filename) + $gmt_offset );
	return $last_modified_install;
	}
}

// Get the Current / Last Modifed Date of the readme.txt File - Minutes check
// used for checking and displaying .htaccess AutoUpdate notice
function getBPSInstallTimeTXT() {
$filename = WP_PLUGIN_DIR . '/bulletproof-security/readme.txt';

	if ( file_exists($filename) ) {
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$last_modified_install = date("F d Y H:i", filemtime($filename) + $gmt_offset );
	return $last_modified_install;
	}
}

// Get the Current / Last Modifed Date of the readme.txt File + one minute buffer - Minutes check
function getBPSInstallTime_plusone() {
$filename = WP_PLUGIN_DIR . '/bulletproof-security/readme.txt';

	if ( file_exists($filename) ) {
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$last_modified_install = date("F d Y H:i", filemtime($filename) + $gmt_offset + (60 * 1));
	return $last_modified_install;
	}
}

// Get the Current / Last Modifed Date of the Root .htaccess File - Minutes check
function getBPSRootHtaccessLasModTime_minutes() {
$filename = ABSPATH . '.htaccess';

	if ( file_exists($filename) ) {
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$last_modified_install = date("F d Y H:i", filemtime($filename) + $gmt_offset );
	return $last_modified_install;
	}
}

// Get the Current / Last Modifed Date of the wp-admin .htaccess File - Minutes check
function getBPSwpadminHtaccessLasModTime_minutes() {
$filename = ABSPATH . 'wp-admin/.htaccess';

	if ( file_exists($filename) ) {
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$last_modified_install = date("F d Y H:i", filemtime($filename) + $gmt_offset );
	return $last_modified_install;
	}
}

// Recreate the User Agent filters in the 403.php file on BPS upgrade
function bpsPro_autoupdate_useragent_filters() {		
global $wpdb;

	$bps403File = WP_PLUGIN_DIR . '/bulletproof-security/403.php';	

	if ( ! file_exists($bps403File) ) {
		return;
	}
	
	$blankFile = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
	$userAgentMaster = WP_CONTENT_DIR . '/bps-backup/master-backups/UserAgentMaster.txt';	

	if ( file_exists($blankFile) ) {
		copy($blankFile, $userAgentMaster);
	}

	$table_name = $wpdb->prefix . "bpspro_seclog_ignore";
	$bps403FileARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/403.php';
	$ARQdir = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/';
	$search = '';	

	$getSecLogTable = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $table_name WHERE user_agent_bot LIKE %s", "%$search%") );
	$UserAgentRules = array();
		
	if ( $wpdb->num_rows != 0 ) {

		foreach ( $getSecLogTable as $row ) {
			$UserAgentRules[] = "(.*)".$row->user_agent_bot."(.*)|";
			file_put_contents($userAgentMaster, $UserAgentRules);
		}
	
	$UserAgentRulesT = file_get_contents($userAgentMaster);
	$stringReplace = file_get_contents($bps403File);

	$stringReplace = preg_replace('/# BEGIN USERAGENT FILTER(.*)# END USERAGENT FILTER/s', "# BEGIN USERAGENT FILTER\nif ( @!preg_match('/".trim($UserAgentRulesT, "|")."/', \$_SERVER['HTTP_USER_AGENT']) ) {\n# END USERAGENT FILTER", $stringReplace);
		
	file_put_contents($bps403File, $stringReplace);
		
	if ( is_dir($ARQdir) ) {
		copy($bps403File, $bps403FileARQ);
	}
	}
}

// Update/Add/Save any new DB options/features during the BPS Pro upgrades
// bpsPro_new_version_db_options_files_autoupdate() is in general-functions.php
function bpsPro_new_feature_autoupdate() {
	bpsPro_new_version_db_options_files_autoupdate();	
}

// BPS Dashboard Status Display Admin notices
function bpsPro_dashboard_status_display_admin_notices() {
	
	if ( preg_match( '/page=stories-dashboard/', esc_html($_SERVER['QUERY_STRING']) ) || preg_match( '/page=backwpupbackups/', esc_html( $_SERVER['QUERY_STRING'] ) ) || preg_match( '/post_type=ai1ec_event/', esc_html( $_SERVER['QUERY_STRING'] ) ) ) {
		return;
	}

	if ( current_user_can('manage_options') ) { 
		bps_status_WP_Dashboard();
		bpsPro_install_upgrade_Touch();
		bps_status_wpadmin_WP_Dashboard();
		bps_ARCM_admin_notice_status_wp();
		bps_MScan_admin_notice_status_wp();
		bps_DBM_admin_notice_status_wp();
		bps_DBB_admin_notice_status_wp();
		bps_PFWAP_admin_notice_status_wp();
		bps_UAEG_admin_notice_status_wp();
		bps_Login_Security_admin_notice_status_wp();
		bps_jtc_antispam_admin_notice_status_wp();
		bpsPro_isl_notice_status_wp();
		bpsPro_ace_notice_status_wp();
		bps_email_logging_alerts_wp();
	}
}

add_action('admin_notices', 'bpsPro_dashboard_status_display_admin_notices');

// S-Monitor Display - Root htaccess - BPS Status and Alerts in WP Dashboard - wpOn
// IMPORTANT Note: preg_match must be enclosed otherwise the conditions fail
// also a nice bonus is that this forces the string replace on a new line.
// The Default BPS Processing Spinner is a lightweight CSS Spinner - no js
// The Alternate BPS Processing Spinner uses CSS and javascript
function bps_status_WP_Dashboard() {

	$options = get_option('bulletproof_security_options_monitor');	
	
	if ( current_user_can('manage_options') && isset($options['bps_security_status']) && $options['bps_security_status'] == 'wpOn' ) {
	
		global $bpspro_version, $bpspro_last_version, $wp_version, $wpdb, $aitpro_bullet, $pagenow;

	// Only performs these checks if a POST Form is submitted. See elseif conditions below for exclusions.
	if ( esc_html($_SERVER['REQUEST_METHOD']) == 'POST' ) {
		
		$wp_admin_url = admin_url();
		
		if ( 'update-core.php' != $pagenow ) {
		?>
        
        <div id="url-hash"></div>

		<script type="text/javascript">
        /* <![CDATA[ */
        var bpsPage = "<?php echo $wp_admin_url . 'admin.php?' . $_SERVER['QUERY_STRING']; ?>"
        var hash = window.location.hash;
        
        document.getElementById("url-hash").innerHTML = '<div id="bps-status-display" style="float:left;margin:6px 0px 0px 2px;padding:3px 5px 3px 5px;background-color:#e8e8e8;border:1px solid gray;"><a href="' + bpsPage + hash + '" style="text-decoration:none;font-weight:bold;">Reload BPS Pro Status Display</a></div>';
        /* ]]> */
        </script>
        
		<?php
		}

		if ( isset($_POST['submit-bps-spinner']) && @$_POST['submit-bps-spinner'] == true || isset($_POST['Submit-Setup-Wizard-Preinstallation']) && @$_POST['Submit-Setup-Wizard-Preinstallation'] == true || isset($_POST['Submit-Setup-Wizard']) && @$_POST['Submit-Setup-Wizard'] == true || isset($_POST['Submit-DBB-Run-Job']) && @$_POST['Submit-DBB-Run-Job'] == true || isset($_POST['Submit-DB-Table-Prefix']) && @$_POST['Submit-DB-Table-Prefix'] == true || isset($_POST['Submit-DB-Prefix-Table-Refresh']) && @$_POST['Submit-DB-Prefix-Table-Refresh'] == true || isset($_POST['Submit-ARCM-RootNR']) && @$_POST['Submit-ARCM-RootNR'] == true || isset($_POST['Submit-ARCM-Wpadmin']) && @$_POST['Submit-ARCM-Wpadmin'] == true || isset($_POST['Submit-ARCM-Wpincludes']) && @$_POST['Submit-ARCM-Wpincludes'] == true || isset($_POST['Submit-ARCM-Wpcontent']) && @$_POST['Submit-ARCM-Wpcontent'] == true || isset($_POST['Submit-ARCM-Root-Delete']) && @$_POST['Submit-ARCM-Root-Delete'] == true || isset($_POST['Submit-ARCM-Wpadmin-Delete']) && @$_POST['Submit-ARCM-Wpadmin-Delete'] == true || isset($_POST['Submit-ARCM-Wpincludes-Delete']) && @$_POST['Submit-ARCM-Wpincludes-Delete'] == true || isset($_POST['Submit-ARCM-Wpcontent-Delete']) && @$_POST['Submit-ARCM-Wpcontent-Delete'] == true || isset($_POST['Submit-ARCM-Root-Restore']) && @$_POST['Submit-ARCM-Root-Restore'] == true || isset($_POST['Submit-ARCM-Wpadmin-Restore']) && @$_POST['Submit-ARCM-Wpadmin-Restore'] == true || isset($_POST['Submit-ARCM-Wpincludes-Restore']) && @$_POST['Submit-ARCM-Wpincludes-Restore'] == true || isset($_POST['Submit-ARCM-Wpcontent-Restore']) && @$_POST['Submit-ARCM-Wpcontent-Restore'] == true || isset($_POST['Submit-ARCM-Root-Show-Backup']) && @$_POST['Submit-ARCM-Root-Show-Backup'] == true || isset($_POST['Submit-ARCM-Wpadmin-Show-Backup']) && @$_POST['Submit-ARCM-Wpadmin-Show-Backup'] == true || isset($_POST['Submit-ARCM-Wpincludes-Show-Backup']) && @$_POST['Submit-ARCM-Wpincludes-Show-Backup'] == true || isset($_POST['Submit-ARCM-Wpcontent-Show-Backup']) && @$_POST['Submit-ARCM-Wpcontent-Show-Backup'] == true || isset($_POST['Submit-ARCM-Root-Show-Website']) && @$_POST['Submit-ARCM-Root-Show-Website'] == true || isset($_POST['Submit-ARCM-Wpadmin-Show-Website']) && @$_POST['Submit-ARCM-Wpadmin-Show-Website'] == true || isset($_POST['Submit-ARCM-Wpincludes-Show-Website']) && @$_POST['Submit-ARCM-Wpincludes-Show-Website'] == true || isset($_POST['Submit-ARCM-Wpcontent-Show-Website']) && @$_POST['Submit-ARCM-Wpcontent-Show-Website'] == true || isset($_POST['Submit-Quarantine-Search-Radio']) && @$_POST['Submit-Quarantine-Search-Radio'] == true || isset($_POST['Submit-ARQ-Quarantine-Radio']) && @$_POST['Submit-ARQ-Quarantine-Radio'] == true || isset($_POST['submit-bps-zip-install']) && @$_POST['submit-bps-zip-install'] == true || isset($_POST['Submit-DBD-Diff-Tool']) && @$_POST['Submit-DBD-Diff-Tool'] == true || isset($_POST['Submit-DBD-Diff-Large']) && @$_POST['Submit-DBD-Diff-Large'] == true || isset($_POST['Submit-diagnostic-check1']) && @$_POST['Submit-diagnostic-check1'] == true || isset($_POST['Submit-diagnostic-check2']) && @$_POST['Submit-diagnostic-check2'] == true || isset($_POST['bpsStringFinder']) && @$_POST['bpsStringFinder'] == true || isset($_POST['bpsStringReplacer']) && @$_POST['bpsStringReplacer'] == true || isset($_POST['bpsStringReplacerFP']) && @$_POST['bpsStringReplacerFP'] == true || isset($_POST['bpsDBStringFinder9']) && @$_POST['bpsDBStringFinder9'] == true || isset($_POST['bpsMulti-Scan-All-Pages-Submit']) && @$_POST['bpsMulti-Scan-All-Pages-Submit'] == true || isset($_POST['bpsMulti-Scan-Plugins-Submit']) && @$_POST['bpsMulti-Scan-Plugins-Submit'] == true || isset($_POST['bpsMulti-Scan-Submit']) && @$_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="background:#fff;border:4px solid black;">';
   			echo '<img id="bps-img-spinner" src="'.plugins_url('/bulletproof-security/admin/images/bps-spinner.gif').'" style="float:left;margin:0px 20px 0px 0px;" />'; 
			echo '<div id="bps-spinner-text-btn" style="padding:20px 0px 26px 0px;font-size:14px;">Processing...<br><button style="margin:10px 0px 0px 10px;" onclick="javascript:history.go(-1)">Cancel</button></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
		echo '</div>';
		}  
		}
	
	} 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:5px;">'.__('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>';
	} elseif ( 'about.php' == $pagenow  || 'upload.php' == $pagenow || 'update-core.php' == $pagenow || esc_html($_SERVER['QUERY_STRING']) == 'page=theseoframework-extensions' ) {
		
		return;
	
	} 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);
	$check_string = @file_get_contents($filename);
	$section = @file_get_contents($filename, NULL, NULL, 3, 46);	
	$sapi_type = php_sapi_name();	
	$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="float:left;"><strong>'.__('BPS Pro ', 'bulletproof-security').$bpspro_version.'</strong></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: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="#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 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="#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();
			// 9.1, 12.8, 12.9:  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 [R,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);
		}
		
		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="float:left;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><br><br>';
				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", $section );
			
			// just for screenshots for now - maybe make this permanent? 
			//echo '<div id="bps-status-display-container" style="max-width:1400px;">';
			echo '<div id="bps-status-display" style="float:left;"><strong>'.$RBM_str.'</strong>'.$RBM.'</div>';
		
		break;
	default:
		
	if ( $bps_root_upgrade != 'upgrade' ) {
	
		$text = '<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="#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;
	}
}}}}}}

// 14: Changed the BPS version check in the root htaccess file to a Dismiss Notice
add_action('admin_init', 'bps_root_version_check_nag_ignore');

function bps_root_version_check_nag_ignore() {
global $current_user;
$user_id = $current_user->ID;
        
	if ( isset($_GET['bps_root_version_check_nag_ignore']) && '0' == $_GET['bps_root_version_check_nag_ignore'] ) {
		add_user_meta($user_id, 'bps_ignore_root_version_check_notice', 'true', true);
	}
}

/** IMPORTANT function that touches the bulletproof-security.php file on new installs & upgrades  **/
// Compare timestamp for /admin/bps_php_error.log & bulletproof-security.php
// If they match: Touch bulletproof-security.php - 1 hour
function bpsPro_install_upgrade_Touch() {

	if ( current_user_can('manage_options') ) {
	
		$ELog_mod_time = get_option('bulletproof_security_options_elog');

	if ( isset($ELog_mod_time['bps_error_log_date_mod']) && $ELog_mod_time['bps_error_log_date_mod'] != '' && strcmp( bps_getPhpELogLastMod_minutes(), getBPSInstallTime() ) == 0 ) {	

		$bulletproofSecurityPhp = WP_PLUGIN_DIR . '/bulletproof-security/bulletproof-security.php';	
		$timeMinusOneHour = time() - 3600;

		// cleanup for the old dot in the php error log timestamp
		if ( preg_match( '/\./', $ELog_mod_time['bps_error_log_date_mod'], $matches ) ) {
			$BPS_Options = array( 'bps_error_log_date_mod' => str_replace( '.', "", $ELog_mod_time['bps_error_log_date_mod'] ) );
			update_option('bulletproof_security_options_elog', $BPS_Options);
		}
		
		touch($bulletproofSecurityPhp, $timeMinusOneHour);
	}
	}
}

// BPS Pro 9.1/9.2/12.8/12.9: Synchronize DB timestamps to GMT. Only needs to happen once.
function bpsPro_sync_time_gmt() {
$GMT_time = get_option('bulletproof_security_options_GMT');

	if ( ! isset($GMT_time['bps_gmt_timestamp']) || isset($GMT_time['bps_gmt_timestamp']) && $GMT_time['bps_gmt_timestamp'] != 'GMT2' || isset($GMT_time['bps_gmt_timestamp']) && $GMT_time['bps_gmt_timestamp'] != 'GMT3' ) {
	
	$ARQ_db_options = array( 'bps_arcm_log_date_mod' => bps_getARCMLogLastMod_wp_secs() );
	update_option('bulletproof_security_options_ARCM_log', $ARQ_db_options);
	
	$php_db_options = array( 'bps_error_log_date_mod' => bps_getPhpELogLastMod_smonitor() );
	update_option('bulletproof_security_options_elog', $php_db_options);	

	$LSM_db_options = array( 'bps_login_security_db_mod_time' => bps_getLoginSecurityResetFileLastMod_secs() );
	update_option('bulletproof_security_options_login_alerts', $LSM_db_options);	

	$SecLog_db_options = array( 'bps_security_log_date_mod' => bps_getSecurityLogLastMod_secs() );
	update_option('bulletproof_security_options_Security_log', $SecLog_db_options);	

	$DBM_db_options = array( 'bps_dbm_log_date_mod' => bpsPro_DBM_LogLastMod_wp_secs() );
	update_option('bulletproof_security_options_DBM_log', $DBM_db_options);	

	$DBB_db_options = array( 'bps_dbb_log_date_mod' => bpsPro_DBB_LogLastMod_wp_secs() );
	update_option('bulletproof_security_options_DBB_log', $DBB_db_options);	
	
	$FL_db_options = array( 'bps_folderlock_db_mod_time' => bps_getFolderLockResetFileLastMod_secs() );
	update_option('bulletproof_security_options_flock_FL_alerts', $FL_db_options);

	$MScan_db_options = array( 'bps_mscan_log_date_mod' => bpsPro_MScan_LogLastMod_wp_secs() );
	update_option('bulletproof_security_options_MScan_log', $MScan_db_options);	

	$GMT_Options = array( 'bps_gmt_timestamp' => 'GMT3' );	
	
		foreach( $GMT_Options as $key => $value ) {
			update_option('bulletproof_security_options_GMT', $GMT_Options);
		}	
	}
}

// S-Monitor Display - wp-admin htaccess - BPS Status and Alerts in WP Dashboard - wpOn
function bps_status_wpadmin_WP_Dashboard() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_security_status']) && $options['bps_security_status'] == 'wpOn' ) {
		
	global $bpspro_version, $bpspro_last_version, $aitpro_bullet, $pagenow;

	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow || esc_html($_SERVER['QUERY_STRING']) == 'page=theseoframework-extensions' ) {
		return;
	}
	
	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 ( isset( $BPS_wpadmin_Options['bps_wpadmin_restriction'] ) && $BPS_wpadmin_Options['bps_wpadmin_restriction'] == 'disabled' || isset( $GDMW_options['bps_gdmw_hosting'] ) && $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);
	// BPS Pro 11: changed to 49. change back to 50 for 11.1
	$section = @file_get_contents($filename, NULL, NULL, 3, 49);
	$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: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="#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 = '<br><div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;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="#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');			
			$sapi_type = php_sapi_name();
			
			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="float:left;">'.$WBM_str;
		
			if ( $options['bps_autorestore_status'] == 'wpOn' || $options['bps_dbm_status'] == 'wpOn' || $options['bps_dbb_status'] == 'wpOn' || $options['bps_plugin_firewall_status'] == 'wpOn' || $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {

				echo '</div>';	

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

		break;
	default:
		
	if ( $bps_wpadmin_upgrade != 'upgrade' ) {
	
		$text = '<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="#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 WP Dashboard - wpOn
function bps_ARCM_admin_notice_status_wp() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_autorestore_status']) && $options['bps_autorestore_status'] == 'wpOn' ) {
		
	global $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}
	
	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {

		echo '<div id="bps-status-display" style="float:left;">';
		bpsProARCMStatus();		
		
		if ( $options['bps_mscan_status_display'] == 'wpOn' || $options['bps_dbm_status'] == 'wpOn' || $options['bps_dbb_status'] == 'wpOn' || $options['bps_plugin_firewall_status'] == 'wpOn' || $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
			
			echo '</div>';

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

		}
	}
	}
}

// AutoRestore/Quarantine Dashboard Status: display - for both wpOn and bpsOn
function bpsProARCMStatus() {
global $aitpro_bullet;

	if ( current_user_can('manage_options') ) {
	
		if ( ! get_option('bulletproof_security_options_ARCM' ) ) {
			$text = '<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'">'.__('ARQ', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('AutoRestore|Quarantine Options have not been created yet. The BPS Pro Setup Wizard needs to be run.', 'bulletproof-security').'</strong></font>';
			echo $text;
		} 
		
		$options = get_option('bulletproof_security_options_ARCM');	
		
		if ( $options['bps_autorestore_cron_override'] == 'On' ) {	
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="blue"><strong>'.__('Override On ', 'bulletproof-security').'</strong></font>';
			echo $text;
			return;
		}
	
		$ARQ_Status = get_option('bulletproof_security_options_ARQ_status');
	
?>

<style>
<!--
div.arq-tooltip {display:inline-block;position:relative;}
div.arq-tooltip:hover {z-index:10;}
div.arq-tooltip img:hover {z-index:10;}
div.arq-tooltip span {display:none;position:absolute;bottom:0;left:0;right:0;}
div.arq-tooltip:hover span {width:500px;height:60px;display:block;position:absolute;top:30px;left:5px;right:0;color:#000;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);}
-->
</style>

<?php	
	// Note: The CSS Style must be inline since BPS CSS stylesheets are only loaded on BPS plugin pages
	$bps_question_mark_arq = '<div class="arq-tooltip"><img src="'.plugins_url('/bulletproof-security/admin/images/question-mark.png').'" style="position:relative;top:3px;right:1px;" /><span>ARQ is pending automatic Turn On in 1 minute - No action is required by you. If the ARQ "<font color="blue">Pending</font>" status is still displayed after 3 minutes then go to the BPS Pro Setup Wizard page and run the Setup Wizard again.</span></div>';

	// Important: Do not remove this unless I decide to change what is displayed. 
	// ie still show ARQ as On and not Pending even though ARQ is really Off for a 1-3 minutes until all ARQ Automation processing is completed.
	if ( isset($ARQ_Status['bps_arq_status']) && $ARQ_Status['bps_arq_status'] == 'On' ) {	
		$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="blue"><strong>'.__('Pending ', 'bulletproof-security').$bps_question_mark_arq.'</strong></font>';
		echo '<div style="margin-top:-2px;">';
		echo $text;
		echo '</div>';
		return;
	}

		if ( $options['bps_autorestore_cron'] == 'Off' ) {
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off ', 'bulletproof-security').'</strong></font>';
			echo $text;
	
		} else {
		
			if ( $options['bps_autorestore_cron'] == 'On' ) {
			
				$gmt_offset = get_option( 'gmt_offset' ) * 3600;
				$bpsCronCheck = wp_get_schedule( 'bpsPro_AutoRestore_check' );
				$ARQ_cron_time = wp_next_scheduled( 'bpsPro_AutoRestore_check' );
				$arq_next_check = date_i18n( get_option('time_format'), $ARQ_cron_time + $gmt_offset );
		
				if ( $bpsCronCheck == 'minutes_1' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 1 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_2' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 2 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_3' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 3 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_4' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 4 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_5' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 5 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_10' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 10 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_15' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 15 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_30' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 30 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_60' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/autorestore/autorestore.php' ).'" title="'.esc_attr( 'AutoRestore|Quarantine' ).'" style="text-decoration:none;">'.__('ARQ', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 60 Min : ', 'bulletproof-security').$arq_next_check.'</strong></font>';
					echo $text;
				}
			}
		}
	}
}

// S-Monitor MScan Status display WP Dashboard - wpOn
function bps_MScan_admin_notice_status_wp() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_mscan_status_display']) && $options['bps_mscan_status_display'] == 'wpOn' ) {
		
		global $pagenow;
		if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
			return;
		}
		
		if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {
	
			echo '<div id="bps-status-display" style="float:left;">';
			bpsProMScanStatus();		
			
			if ( $options['bps_dbm_status'] == 'wpOn' || $options['bps_dbb_status'] == 'wpOn' || $options['bps_plugin_firewall_status'] == 'wpOn' || $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
				
				echo '</div>';
	
			} else {
				
				echo '</div><div style="clear:both;"></div>';			
	
			}
		}
	}
}

// MScan Dashboard Status: display - for both wpOn and bpsOn
// Displays the question mark hover icon if a scan has not been run or the Delete Scan Status Tool has been used.
// Displays last scan timestamp when scheduled scans are Off > MSCAN: August 3, 2017 8:45 am
// Displays next scheduled cron job when scheduled scan frequency is used > MSCAN: On : 60 Min : 9:30 am
// DB values to check:  bps_mscan_last_scan_timestamp and bps_mscan_status
function bpsProMScanStatus() {

	if ( current_user_can('manage_options') ) {
		global $aitpro_bullet;
		$MScan_status = get_option('bulletproof_security_options_MScan_status');
		?>
		
		<style>
		<!--
		div.mscan-tooltip {display:inline-block;position:relative;}
		div.mscan-tooltip:hover {z-index:10;}
		div.mscan-tooltip img:hover {z-index:10;}
		div.mscan-tooltip span {display:none;position:absolute;bottom:0;left:0;right:0;}
		div.mscan-tooltip:hover span {width:500px;height:60px;display:block;position:absolute;top:30px;left:5px;right:0;color:#000;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);}
		-->
		</style>
		
		<?php	
		// Note: The CSS Style must be inline since BPS CSS stylesheets are only loaded on BPS plugin pages
		$bps_question_mark_mscan = '<div class="mscan-tooltip"><img src="'.plugins_url('/bulletproof-security/admin/images/question-mark.png').'" style="position:relative;top:3px;right:1px;" /><span>An MScan scan has not been run yet.</span></div>';
	
		if ( ! isset($MScan_status['bps_mscan_status']) || ! isset($MScan_status['bps_mscan_last_scan_timestamp']) ) {	
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: '.$bps_question_mark_mscan;
			echo '<div style="margin-top:-2px;">';
			echo $text;
			echo '</div>';
			return;
		}
	
		$MScan_options = get_option('bulletproof_security_options_MScan');
	
		if ( $MScan_options['mscan_scan_frequency'] == 'Off' ) {
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.$MScan_status['bps_mscan_last_scan_timestamp'].'</strong></font>';
			echo $text;
	
		} else {
		
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$bpsCronCheck = wp_get_schedule( 'bpsPro_MScan_check' );
			$MScan_cron_time = wp_next_scheduled( 'bpsPro_MScan_check' );
			$mscan_next_check = date_i18n( get_option('time_format'), $MScan_cron_time + $gmt_offset );
	
			if ( $bpsCronCheck == 'minutes_60' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 60 Min : ', 'bulletproof-security').$mscan_next_check.'</strong></font>';
				echo $text;
			}

			if ( $bpsCronCheck == 'hours_3' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 3 Hrs : ', 'bulletproof-security').$mscan_next_check.'</strong></font>';
				echo $text;
			}
			if ( $bpsCronCheck == 'hours_6' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 6 Hrs : ', 'bulletproof-security').$mscan_next_check.'</strong></font>';
				echo $text;
			}
			if ( $bpsCronCheck == 'hours_12' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 12 Hrs : ', 'bulletproof-security').$mscan_next_check.'</strong></font>';
				echo $text;
			}
			if ( $bpsCronCheck == 'hours_24' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/mscan/mscan.php' ).'" title="'.esc_attr( 'MScan Malware Scanner' ).'" style="text-decoration:none;">'.__('MSCAN', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 24 Hrs : ', 'bulletproof-security').$mscan_next_check.'</strong></font>';
				echo $text;
			}
		}
	}
}

// S-Monitor - DB Monitor Status display WP Dashboard - wpOn
function bps_DBM_admin_notice_status_wp() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_dbm_status']) && $options['bps_dbm_status'] == 'wpOn' ) {
		
		global $pagenow;
		if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
			return;
		}
	
		if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {		
			
			echo '<div id="bps-status-display" style="float:left;">';
			bpsProDBMStatus();
			
			if ( $options['bps_dbb_status'] == 'wpOn' || $options['bps_plugin_firewall_status'] == 'wpOn' || $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
				
				echo '</div>';
	
			} else {
				
				echo '</div><div style="clear:both;"></div>';			
			}
		}
	}
}

// S-Monitor - DB Monitor Status display WP Dashboard - for both wpOn and bpsOn
function bpsProDBMStatus() {
	
	if ( current_user_can('manage_options') ) {
	
		global $aitpro_bullet;
		$options = get_option('bulletproof_security_options_db_monitor');
	
		if ( $options['bps_db_monitor_cron'] == 'Off' ) {
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off ', 'bulletproof-security').'</strong></font>';
			echo $text;
	
		} else {
		
			if ( $options['bps_db_monitor_cron'] == 'On' ) {
			
				$gmt_offset = get_option( 'gmt_offset' ) * 3600;
				$bpsCronCheck = wp_get_schedule( 'bpsPro_DBM_check' );
				$DBM_cron_time = wp_next_scheduled( 'bpsPro_DBM_check' );
				$dbm_next_check = date_i18n( get_option('time_format'), $DBM_cron_time + $gmt_offset );
		
				if ( $bpsCronCheck == 'minutes_1' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 1 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_5' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 5 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_10' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 10 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_15' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 15 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_30' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 30 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_60' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-monitor/db-monitor.php' ).'" title="'.esc_attr( 'Database Monitor' ).'" style="text-decoration:none;">'.__('DBM', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On : 60 Min : ', 'bulletproof-security').$dbm_next_check.'</strong></font>';
					echo $text;
				}
			}
		}
	}
}

// S-Monitor - DB Backup Status display WP Dashboard - wpOn
function bps_DBB_admin_notice_status_wp() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_dbb_status']) && $options['bps_dbb_status'] == 'wpOn' ) {
		
		global $pagenow;
		if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
			return;
		}
	
		if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {		
			
			echo '<div id="bps-status-display" style="float:left;">';
			bpsProDBBStatus();
			
			if ( $options['bps_plugin_firewall_status'] == 'wpOn' || $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
				
				echo '</div>';
	
			} else {
				
				echo '</div><div style="clear:both;"></div>';			
			}
		}
	}
}

// S-Monitor - DB Backup Status display WP Dashboard - for both wpOn and bpsOn
// First time installations and upgrades the DB option bps_db_backup_status_display has value "No DB Backups"
// When a Backup Job is created for the first time the value is "Backup Job Created" - one time/one-shot option
// All S-Monitor DB Backup options & DB Backup options are automatically created and saved for new installations and upgrades
function bpsProDBBStatus() {

	if ( current_user_can('manage_options') ) {
	
		global $aitpro_bullet;
		$options = get_option('bulletproof_security_options_monitor');
	
		if ( $options['bps_dbb_status'] == 'Off' ) {
			return;
		}
		
		$DBBoptions = get_option('bulletproof_security_options_db_backup');	
		
		?>

		<style>
		<!--
		div.dbb-status-tooltip {display:inline-block;position:relative;}
		div.dbb-status-tooltip:hover {z-index:10;}
		div.dbb-status-tooltip img:hover {z-index:10;}
		div.dbb-status-tooltip span {display:none;position:absolute;bottom:0;left:0;right:0;}
		div.dbb-status-tooltip:hover span {width:500px;height:60px;display:block;position:absolute;top:30px;left:5px;right:0;color:#000;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);}
		-->
		</style>

		<?php
		$bps_qm_dbb1 = '<div class="dbb-status-tooltip"><img src="'.plugins_url('/bulletproof-security/admin/images/question-mark.png').'" style="position:relative;top:3px;right:1px;" /><span>A BPS DB Backup has not been performed yet. To run a DB Backup go to the BPS DB Backup page, create a Backup Job and run the Backup Job or you can just ignore this hover tooltip and not perform a DB Backup.</span></div>';
			
		$bps_qm_dbb2 = '<div class="dbb-status-tooltip"><img src="'.plugins_url('/bulletproof-security/admin/images/question-mark.png').'" style="position:relative;top:3px;right:1px;" /><span>A BPS DB Backup Job has been created. To run a DB Backup go to the BPS DB Backup page and run the Backup Job or you can just ignore this hover tooltip and not perform a DB Backup.</span></div>';

		if ( $DBBoptions['bps_db_backup_status_display'] == 'No DB Backups' || $DBBoptions['bps_db_backup_status_display'] == '' ) {
			
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-backup-security/db-backup-security.php' ).'" title="'.esc_attr( 'Database Backup' ).'" style="text-decoration:none;">'.__('DBB', 'bulletproof-security').'</a>: '.$bps_qm_dbb1;
			echo '<div style="margin-top:-2px;">';
			echo $text;
			echo '</div>';

		} elseif ( $DBBoptions['bps_db_backup_status_display'] == 'Backup Job Created' ) {
			
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-backup-security/db-backup-security.php' ).'" title="'.esc_attr( 'Database Backup' ).'" style="text-decoration:none;">'.__('DBB', 'bulletproof-security').'</a>: '.$bps_qm_dbb2;
			echo '<div style="margin-top:-2px;">';
			echo $text;
			echo '</div>';	
		
		} else {
			
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/db-backup-security/db-backup-security.php' ).'" title="'.esc_attr( 'Database Backup' ).'" style="text-decoration:none;">'.__('DBB', 'bulletproof-security').'</a>: <font color="green"><strong>'.$DBBoptions['bps_db_backup_status_display'].'</strong></font>';
			echo $text;
		}
	}
}

// S-Monitor - Plugin Firewall Status display WP Dashboard - wpOn
function bps_PFWAP_admin_notice_status_wp() {
$options = get_option('bulletproof_security_options_monitor');
	
	if ( current_user_can('manage_options') && isset($options['bps_plugin_firewall_status']) && $options['bps_plugin_firewall_status'] == 'wpOn' ) {
		
	global $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {		
		
		echo '<div id="bps-status-display" style="float:left;">';
		bpsProPFWAPStatus();
		
		if ( $options['bps_UAEG_status'] == 'wpOn' || $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
			
			echo '</div>';

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

// S-Monitor - Plugin Firewall Status display WP Dashboard - for both wpOn and bpsOn
function bpsProPFWAPStatus() {

	if ( current_user_can('manage_options') ) {
	
		global $aitpro_bullet;
		$PluginsHtaccess = WP_PLUGIN_DIR . '/.htaccess';

		if ( ! file_exists($PluginsHtaccess) ) {		
			$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('Off', 'bulletproof-security').'</strong></font>';
			echo $text;

		} else {

			$pfwap_options = get_option('bulletproof_security_options_pfw_autopilot');

			if ( $pfwap_options['bps_pfw_autopilot_cron'] == 'Off' ) {
				$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>';
				echo $text;

			} else {
	
				if ( $pfwap_options['bps_pfw_autopilot_cron'] == 'On' ) {
		
					$gmt_offset = get_option( 'gmt_offset' ) * 3600;
					$bpsCronCheck = wp_get_schedule( 'bpsPro_PFWAP_check' );
					$PFWAP_cron_time = wp_next_scheduled( 'bpsPro_PFWAP_check' );
					$pfwap_next_check = date_i18n( get_option('time_format'), $PFWAP_cron_time + $gmt_offset );
					$PFWTM_options = get_option('bulletproof_security_options_pfw_test_mode');
					$PFW_OnOff = get_option('bulletproof_security_options_pfw');
				
				if ( isset($PFWTM_options['bps_pfw_test_mode']) && $PFWTM_options['bps_pfw_test_mode'] == 'On' && isset($PFW_OnOff['bps_pfw_on_off']) && $PFW_OnOff['bps_pfw_on_off'] != 'Off' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="blue"><strong>'.__('Test Mode : 1 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;					
				}		

				// This condition is a little confusing, but the plugin firewall htaccess file actually exists so PFW is On.
				if ( isset($PFW_OnOff['bps_pfw_on_off']) && $PFW_OnOff['bps_pfw_on_off'] == 'Off' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('On', 'bulletproof-security').'</strong></font>';
					echo $text;					
				}

				if ( $bpsCronCheck == 'minutes_1' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 1 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_5' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 5 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_10' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 10 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_15' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 15 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_30' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 30 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				if ( $bpsCronCheck == 'minutes_60' ) {
					$text = $aitpro_bullet . '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#PFWScan-Menu-Link' ).'" title="'.esc_attr( 'Plugin Firewall' ).'" style="text-decoration:none;">'.__('PFW', 'bulletproof-security').'</a>: <font color="green"><strong>'.__('AutoPilot : 60 Min : ', 'bulletproof-security').$pfwap_next_check.'</strong></font>';
					echo $text;
				}
				}
			}
		}
	}
}

// S-Monitor - Uploads Anti-Exploit Guard Status display WP Dashboard - wpOn
function bps_UAEG_admin_notice_status_wp() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet, $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

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

		$options = get_option('bulletproof_security_options_monitor');

	if ( isset($options['bps_UAEG_status']) && $options['bps_UAEG_status'] == 'Off' ) {
		return;
	}
	
	// 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;
	}
	// upgrade installations of BPS
	if ( $options['bps_first_launch'] && !$options['bps_UAEG_status'] ) {
		$text = '<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php#UAEG-Menu-Link' ).'" title="'.esc_attr( 'Uploads Anti-Exploit Guard' ).'">'.__('UAEG', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('S-Monitor Uploads Anti-Exploit Guard Status Option Has Not Been Selected and Saved Yet', 'bulletproof-security').' </strong></font><strong><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/monitor/monitor.php' ).'">'.__('Click Here', 'bulletproof-security').'</a></strong>';
		echo $text;
	}
	
	if ( $options['bps_UAEG_status'] == 'wpOn' ) {

		if ( $options['bps_login_security_status'] == 'wpOn' || $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
			
			$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="float:left;">'. $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"><strong>'.__('On', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	} else {
		$text = '<div id="bps-status-display" style="float:left;">'. $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').'</strong></font>'.$status_DDiv;
		echo $text;
	}	
	}
	}
	}
}

// S-Monitor - Login Security Status display WP Dashboard - wpOn
function bps_Login_Security_admin_notice_status_wp() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet, $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

	if ( esc_html($_SERVER['REQUEST_METHOD']) != 'POST' && esc_html($_SERVER['QUERY_STRING']) != 'page=bulletproof-security/admin/system-info/system-info.php' && esc_html($_SERVER['QUERY_STRING']) != 'page=theseoframework-extensions' ) {
	
		$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 - do not display an additional notification
	if ( ! isset($options['bps_first_launch']) && ! isset($options['bps_login_security_status']) ) { 
		return;
	}

	if ( $options['bps_login_security_status'] == 'Off' && $BPSoptions['bps_login_security_OnOff'] == 'Off' ) {
		return;
	}

	// upgrade installations of BPS
	if ( $options['bps_first_launch'] && ! $options['bps_login_security_status'] ) {
		$text = '<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php' ).'" title="'.esc_attr( 'Login Security & Monitoring' ).'">'.__('LSM', 'bulletproof-security').'</a>: <font color="#fb0101"><strong>'.__('S-Monitor Login Security Status Option Has Not Been Selected and Saved Yet', 'bulletproof-security').' </strong></font><strong><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/monitor/monitor.php' ).'">'.__('Click Here', 'bulletproof-security').'</a></strong>';
		echo $text;
	}
	
		if ( $options['bps_jtc_antispam_status'] == 'wpOn' || $options['bps_isl_status'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
			
			$status_DDiv = '</div>';

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

	if ( ! $options['bps_login_security_status'] && $BPSoptions['bps_login_security_OnOff'] == 'On' ) {
		$text = '<div id="bps-status-display" style="float:left;">'. $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"><strong>'.__('On', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	}

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

	if ( $BPSoptions['bps_login_security_OnOff'] == 'On' ) {
		$text = '<div id="bps-status-display" style="float:left;">'. $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"><strong>'.__('On', 'bulletproof-security').'</strong></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="float:left;">'. $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"><strong>'.__('Off', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	}
	}
	
	// upgrade new feature notification - needs to be here to display correctly
	if ( isset($options['bps_first_launch']) && ! isset($BPSoptions['bps_login_security_OnOff']) ) {
		
		if ( ! preg_match( '/page=bulletproof-security\/admin\/wizard\//', esc_html( $_SERVER['REQUEST_URI'] ) ) ) {	
		
		$text = '<br><div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;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);">'.__('Login Security Settings Need To Be Saved', 'bulletproof-security').'<br>'.__('Run the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'">'.__('Pre-Installation Wizard and Setup Wizard', 'bulletproof-security').'</a>'.__(' or...', 'bulletproof-security').'<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 and click the Save Options button and the Reset|Clear Login Security Alerts button.', 'bulletproof-security').'<br>'.__('Click the Login Security & Monitoring  Read Me Help button for additional help info.', 'bulletproof-security').'</div>';
		echo $text;
		}
	}	
	}
	}
}

// S-Monitor - JTC Anti-Spam Status display WP Dashboard - wpOn
function bps_jtc_antispam_admin_notice_status_wp() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet, $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

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

		$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'] == 'wpOn' || $options['bps_ace_status'] == 'wpOn' ) {
			
			$status_DDiv = '</div>';

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

	if ( $options['bps_jtc_antispam_status'] == 'wpOn' ) {
	
	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="float:left;">'. $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"><strong>'.__('On', 'bulletproof-security').'</strong></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="float:left;">'. $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"><strong>'.__('Off', 'bulletproof-security').'</strong></font>'.$status_DDiv;
		echo $text;
	}
	}
	}
	}
}

// S-Monitor - Idle Session Logout ISL Status display WP Dashboard - wpOn
function bpsPro_isl_notice_status_wp() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet, $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

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

		$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'] == 'wpOn' ) {
			
			$status_DDiv = '</div>';

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

	if ( $options['bps_isl_status'] == 'wpOn' ) {
	
		if ( ! $BPSoptionsISL['bps_isl'] ) {
			$text = '<br><div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;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);"><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="float:left;">'. $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="float:left;">'. $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 - wpOn
// Notes: When additional new status display options are added to the Dashboard Status Display the div conditions code starting from WBM
// need 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_wp() {
	
	if ( current_user_can('manage_options') ) {
	
	global $aitpro_bullet, $pagenow;
	if ( $pagenow == 'about.php' || $pagenow == 'upload.php' || 'update-core.php' == $pagenow ) {
		return;
	}

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

		$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
	// for screenshots only - maybe make this permanent?
	//$status_DDiv = '</div></div><div style="clear:both;"></div>';		
	$status_DDiv = '</div><div style="clear:both;"></div>';			

	if ( $options['bps_ace_status'] == 'wpOn' ) {
	
		if ( ! $BPSoptionsACE['bps_ace'] ) {
			$text = '<br><div id="bps-inpage-message" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:bold;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);"><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php#bps-tabs-3' ).'" title="'.esc_attr( 'Auth Cookie Expiration' ).'">'.__('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="float:left;">'. $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="float:left;">'. $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 Email Alerts and Log File options check here  //
// when a new option or feature is added it needs to be    //
// below Dashboard Status displays above. BPS Pro 9.0 is   //
// an exception - major version Dismiss notice function is //
// created in hud-dismiss-functions.php                    //
/**********************************************************/

// S-Monitor - Email Alerting & Log File Options
function bps_email_logging_alerts_wp() {

	if ( current_user_can('manage_options') ) {
	
		$options = get_option('bulletproof_security_options_monitor');
 
	if ( ! isset($options['bps_first_launch']) ) { 
		return;
	}
	
	if ( $options['bps_first_launch'] == 'wpOn' || $options['bps_first_launch'] == 'bpsOn' || $options['bps_first_launch'] == 'Off' ) { 	
	
		$options_email = get_option('bulletproof_security_options_email'); 	
	
	if ( ! isset($options_email['bps_security_log_size']) || ! isset($options_email['bps_login_security_email']) ) {
		
		if ( ! preg_match( '/page=bulletproof-security\/admin\/wizard\//', 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: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);">'.__('Email Alerting & Log File Options Need to be saved/resaved', 'bulletproof-security').'<br>'.__('Run the ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'">'.__('Pre-Installation Wizard and Setup Wizard', 'bulletproof-security').'</a>'.__(' or...', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/monitor/monitor.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the S-Monitor Monitoring and Alerting page and click the Save Options button for Email Alerting & Log File options.', 'bulletproof-security').'<br>'.__('View the Email Alerting & Log File Options Read Me Help button for additional help info or to find out what new features or options have been added.', 'bulletproof-security').'</div>';
		echo $text;	
		}
	}
	}
	}
}

// Installation Check - Check important Core files for installation errors/problems and log them in /master-backups/bps-install-log.txt
function bpsPro_Core_Files_Check() {

	if ( is_admin() && current_user_can('manage_options') ) {

	$bpsPro_blankTXT = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
	$bpsPro_install_log = WP_CONTENT_DIR . '/bps-backup/master-backups/bps-install-log.txt';
	$bpsPro_pf = WP_PLUGIN_DIR . '/bulletproof-security/';
	$bpsPro_Core1 = $bpsPro_pf . 'admin/core/core.php';
	$bpsPro_Core2 = $bpsPro_pf . 'admin/php/php-options.php';	
	$bpsPro_Core3 = $bpsPro_pf . 'admin/monitor/monitor.php';	
	$bpsPro_Core4 = $bpsPro_pf . 'admin/db-monitor/db-monitor.php';	
	$bpsPro_Core5 = $bpsPro_pf . 'admin/install/installation.php';	
	$bpsPro_Core6 = $bpsPro_pf . 'admin/login/login.php';	
	$bpsPro_Core7 = $bpsPro_pf . 'admin/activation/activation.php';	
	$bpsPro_Core8 = $bpsPro_pf . 'admin/lock/flock.php';	
	$bpsPro_Core9 = $bpsPro_pf . 'admin/autorestore/autorestore.php';	
	$bpsPro_Core10 = $bpsPro_pf . 'admin/quarantine/quarantine.php';	
	$bpsPro_Core11 = $bpsPro_pf . 'admin/security-log/security-log.php';
	$bpsPro_Core12 = $bpsPro_pf . 'admin/whatsnew/whatsnew.php';	
	$bpsPro_Core13 = $bpsPro_pf . 'admin/wizard/wizard.php';	
	$bpsPro_Core14 = $bpsPro_pf . 'includes/functions.php';
	$bpsPro_Core15 = $bpsPro_pf . 'admin/mscan/mscan.php';	
	
	$files = array( $bpsPro_Core1, $bpsPro_Core2, $bpsPro_Core3, $bpsPro_Core4, $bpsPro_Core5, $bpsPro_Core6, $bpsPro_Core7, $bpsPro_Core8, $bpsPro_Core9, $bpsPro_Core10, $bpsPro_Core11, $bpsPro_Core12, $bpsPro_Core13, $bpsPro_Core14, $bpsPro_Core15 );
	
	$last_modified_installf = date("F d Y H:i", filemtime($bpsPro_Core14));
	
	foreach ( $files as $file ) {
		if ( file_exists($file) ) {
			$last_modified_install = date("F d Y H:i", filemtime($file));
			$last_modified_install1 = date("F d Y H:i", filemtime($file) + (60 * 1));

		if ( $last_modified_install != $last_modified_installf && $last_modified_install1 != $last_modified_installf ) {
			$get_code_line = @file_get_contents($file);
			$get_code_line = preg_replace('/\)\s{/', '{', $get_code_line);
			$log_entry = "Installation Problem with file: ".str_replace($bpsPro_pf, '', $file)."\n\n";
		
		if ( @copy($bpsPro_blankTXT, $bpsPro_install_log) ) {
			@file_put_contents($file, $get_code_line);
			@file_put_contents($bpsPro_install_log, $log_entry);
		}
		}
		}
		}
	}
}

// Get WordPress Root Installation Folder 
function bps_wp_get_root_folder() {

	if ( is_admin() && current_user_can('manage_options') ) {
		$site_root = parse_url(get_option('siteurl'));
	if ( isset( $site_root['path'] ) )
		$site_root = trailingslashit($site_root['path']);
	else
		$site_root = '/';
	return $site_root;
	}
}

// Get Domain Root without prefix
function bpsGetDomainRoot() {

	if ( is_admin() && current_user_can('manage_options') ) {
	if ( isset( $_SERVER['SERVER_NAME'] ) ) {

		$ServerName = str_replace( 'www.', "", esc_html( $_SERVER['SERVER_NAME'] ) );
		return $ServerName;		
	
	} else {
		$ServerName = str_replace( 'www.', "", esc_html( $_SERVER['HTTP_HOST'] ) );
		return $ServerName;	
	}
	}
}

// Get Server IP address - Plugin Firewall & Setup Wizard & Ping Website Pro-Tool
function bps_get_server_ip_address() {
	
	if ( is_admin() && current_user_can('manage_options') ) {
		
		if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
			$ip = esc_html( $_SERVER['SERVER_ADDR'] );
			return $ip;
		} elseif ( isset( $_SERVER['HTTP_HOST'] ) ) {
			$ip = esc_html( gethostbyname( $_SERVER['HTTP_HOST'] ) );
			return $ip;
		} else { 
			$ip = @dns_get_record( bpsGetDomainRoot(), DNS_ALL );
			return $ip[0]['ip'];	
		}
	}
}

// Get Real IP address - USE EXTREME CAUTION!!!
// The client IP address is used in the Plugin Firewall.
// X-Forwarded-For: client, proxy1, proxy2
function bpsPro_get_proxy_real_ip_address() {

	if ( is_admin() && current_user_can('manage_options') ) {
	
		if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
			$ip = esc_html( $_SERVER['HTTP_CLIENT_IP'] );
			
			if ( ! is_array($ip) ) {
				
				if ( preg_match( '/(\d+\.){3}\d+/', $ip, $matches ) ) {

					return $matches[0];	
				
				} elseif ( preg_match( '/([:\d\w]+\.(\d+\.){2}\d+|[:\d\w]+)/', $ip, $matches ) ) {
				
					return $matches[0];	
		
				} else {
					
					return $ip;
				}
			
			} else {
				
				return current($ip);				
			}
		
		} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
			$ip = esc_html( $_SERVER['HTTP_X_FORWARDED_FOR'] );
			
			if ( ! is_array($ip) ) {
				
				if ( preg_match( '/(\d+\.){3}\d+/', $ip, $matches ) ) {

					return $matches[0];	
				
				} elseif ( preg_match( '/([:\d\w]+\.(\d+\.){2}\d+|[:\d\w]+)/', $ip, $matches ) ) {
				
					return $matches[0];	
		
				} else {
					
					return $ip;
				}
			
			} else {
				
				return current($ip);				
			}
		
		} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
			$ip = esc_html( $_SERVER['REMOTE_ADDR'] );
			return $ip;
		}
	}
}	

// Check if Server is Up/Down - send empty test string - ONLY display error if Server is Down
$old_bpspro_url = 'https://www.ait-pro.com/';
$bpspro_url = 'https://api.ait-pro.com/';
function bps_cuser_errors() {

if ( is_admin() && current_user_can('manage_options') ) {

	global $bpspro_url, $blog_id, $bpsTestA, $bpsTestB;
	$options = get_option('bulletproof_security_options_activation');
	$test_array = array('test_connection' => $options['delete_paypal_email'],);
	$test_string = bps_test_array('delete_paypal_email', $test_array);
	$check_server_response = wp_remote_post($bpspro_url, $test_string);
	
	if ( is_multisite() && $blog_id != 1 ) {	
		return;
	}
	if ( ! get_option('bulletproof_security_options_activation') ) {
		exit;
	}
	if ( ! is_wp_error($check_server_response) && ($check_server_response['response']['code'] == 200) && @!file_exists(str_rot13($bpsTestA) ) ) {
		if ( file_exists($bpsTestA) && file_exists($bpsTestB) ) {
			@copy(str_rot13($bpsTestA), str_rot13($bpsTestB));
		}
	}
	if ( ! is_wp_error($check_server_response) && ($check_server_response['response']['code'] != 200) ) {
		$text = '<font color="#fb0101"><strong>'.__('Error: The Server appears to be down. Please send an email to info@ait-pro.com', 'bulletproof-security').'</strong></font>';
		echo @$test;
		exit;
	}
}
}

// Test array
function bps_test_array($test, $test_string) {
	return array('body' => array('action' => $test, 'request' => serialize($test_string)), 'user-agent' => get_bloginfo('url'));	
}

// BPS Pro Upgrade Check - twice daily cron check with 82800 / 23hours time limit condition = 1 email per every 23 hours
function bpsPro_update_checks() {
global $bpspro_version;
$Emailoptions = get_option('bulletproof_security_options_email');		

	if ( isset($Emailoptions['bps_upgrade_email']) && $Emailoptions['bps_upgrade_email'] != 'yes' ) {
		return;
	}
	
	$UpgradeEmailTimeOptions = get_option('bulletproof_security_options_upgrade_email');
	//$timeNow = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );
	$timeNowMinus23Hours = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) - 82800 ); // 82800 - testing 1800
	
	if ( isset($Emailoptions['bps_upgrade_email']) && $Emailoptions['bps_upgrade_email'] == 'yes' && isset($UpgradeEmailTimeOptions['bps_upgrade_check_email']) && $timeNowMinus23Hours >= $UpgradeEmailTimeOptions['bps_upgrade_check_email'] || ! isset($UpgradeEmailTimeOptions['bps_upgrade_check_email'] ) ) {
	
	$url = 'https://www.ait-pro.com/vcheck/?bps_version=$bps_version';
	$response = wp_remote_get( $url, array( 'timeout' => 120, 'httpversion' => '1.1' ) );

	if ( ! is_wp_error( $response ) && 200 == $response['response']['code'] ) {
		
		$vcheckVersion = var_export($response['body'], true);
		$vcheckVersion = trim( $vcheckVersion, "' \t\n\r");
	}
	
	if ( version_compare( $bpspro_version, $vcheckVersion, '>=' ) ) {
		return;

	} else {

	$bps_email = $Emailoptions['bps_send_email_to'];
	$bps_email_from = $Emailoptions['bps_send_email_from'];
	$bps_email_cc = $Emailoptions['bps_send_email_cc'];
	$bps_email_bcc = $Emailoptions['bps_send_email_bcc'];
	
	$path = '/wp-admin/plugins.php';
	$whats_new_link = 'https://forum.ait-pro.com/forums/topic/bulletproof-security-pro-version-release-dates/';
	$justUrl = get_site_url(null, $path, null);
	$timeNow = time();
	$gmt_offset = get_option( 'gmt_offset' ) * 3600;
	$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);

	$headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: ' . $bps_email_from, 'Cc: ' . $bps_email_cc, 'Bcc: ' . $bps_email_bcc );
	$mail_Subject = " BPS Pro Upgrade Notification - $timestamp ";

	$mail_message = '<p><font color="blue"><strong>A new version of BPS Pro is available.</strong></font></p>';
	$mail_message .= '<p>You can install BPS Pro upgrades from within your WP Dashboard just like any other plugin update using the update now link on the WordPress Plugins page. If you are not seeing a BPS Pro update/upgrade notification on the WordPress Plugins page then try clicking the Plugins menu link 3 times (forces a plugin API update check on page reload). You can also try refreshing your Browser on the WordPress Plugins page (two or more times) to see if the BPS Pro plugin update/notification is displayed. If you are still not seeing an upgrade notice then click the BulletProof Security Pro Manual Upgrade Check link on the WordPress Plugins page and run the Plugin Update Check Pro-Tool, go to your WordPress Plugins page and refresh your Browser. If you still do not see the new BPS Pro version then clear your Browser cache and Refresh your Browser again. If you still do not see the new BPS Pro version update/upgrade then click this link: https://forum.ait-pro.com/forums/topic/wp-mu-plugin-update/#post-22887 for other possible reasons or you can use the Alternative BPS Pro upgrade method below.</p>';
	$mail_message .= '<p><strong>Alternative Zip Upload/Upgrade Installation Method:</strong> BPS Pro has a built-in Upload Zip Installer to install BPS Pro upgrade zip files. Download the bulletproof-security.zip file from the AITpro.com Secure Download Area: https://www.ait-pro.com/wp-admin/. Under the BPS Pro Setup Main menu, click the Upload Zip Install submenu link. Click the Choose File button, navigate to where you downloaded the bulletproof-security.zip file on your computer (Note: the zip file MUST be named bulletproof-security.zip) and click the Install Zip Now button.</p>';
	$mail_message .= '<p><strong>Site: </strong>'.$justUrl.'</p>';
	$mail_message .= '<p><strong>BPS Pro Whats New|Changelog: </strong>'.$whats_new_link.'</p>';
	
	if ( wp_mail( $bps_email, $mail_Subject, $mail_message, $headers ) ) {
		
		$bps_UE_option = 'bulletproof_security_options_upgrade_email';
		$bps_UE_value = current_time( 'mysql' );
		$BPS_UE_Options = array( 'bps_upgrade_check_email' => $bps_UE_value );

		if ( ! get_option( $bps_UE_option ) ) {	
			update_option('bulletproof_security_options_upgrade_email', $BPS_UE_Options);
		} else {
			update_option('bulletproof_security_options_upgrade_email', $BPS_UE_Options);
		}	
	}
	}
	}
}

add_action('bpsPro_update_check', 'bpsPro_update_checks');

/********************************************/
/* Cron Checks & Schedules                  */
/********************************************/

// Twice Daily Cron check for new BPS versions - function bpsPro_schedule_update_checks() must match schedules 
// The time restriction condition only allows checks/emails each 23hours
function bpsPro_add_weekly_cron( $schedules ) {
	$schedules['twicedaily'] = array('interval' => 43200, 'display' => __('Twice Daily'));
	return $schedules;
}
add_filter('cron_schedules', 'bpsPro_add_weekly_cron');

function bpsPro_schedule_update_checks() {
	$bpsCronCheck = wp_get_schedule('bpsPro_update_check');
	
	if ( $bpsCronCheck == 'weekly' || $bpsCronCheck == 'daily' || $bpsCronCheck == 'hourly' ) {
		wp_clear_scheduled_hook('bpsPro_update_check');
	}

	if ( ! wp_next_scheduled('bpsPro_update_check') ) {
		wp_schedule_event(time(), 'twicedaily', 'bpsPro_update_check');
	}
}

// comment out to kill action and uncomment clear scheduled hook
add_action('init', 'bpsPro_schedule_update_checks');

// Displays a warning that BPS Pro should not be upgraded on the WordPress Updates page
// This is a Fallback function in case all the other methods of removing BPS Pro from the update-core.php page fail.
function bpsPro_prevent_update_notice() {

	if ( current_user_can( 'update_core' ) ) {
	
		global $pagenow;
		$plugins = get_plugin_updates();

		if ( 'update-core.php' == $pagenow && ! empty( $plugins ) ) {
		
			foreach ( (array) $plugins as $plugin_file => $plugin_data) {
			 	if ( $plugin_data->Name == 'BulletProof Security Pro' ) {
		
					$text = '<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="#fb0101">'.__('WARNING!!! DO NOT upgrade the BulletProof Security Pro plugin on this WordPress Updates page', 'bulletproof-security').'</font><br>'.__('Upgrade the BulletProof Security Pro plugin on the WordPress Plugins page ONLY by clicking the update now link', 'bulletproof-security').'<br><a href="plugins.php">'.__('WordPress Plugins page link', 'bulletproof-security').'</a></div>';
					echo $text;
				}
			}
		}
	}
}

add_action('admin_notices', 'bpsPro_prevent_update_notice');

// BPS Pro Upgrades & Setup Wizard - Create ARQ Exclude rule for /wp-includes/version.php 
function bps_wp_versionphp_exclude_rule() {

	if ( current_user_can('manage_options') ) {

	global $wpdb;
	$versionphp = ABSPATH . 'wp-includes/version.php';	
	$versionphpDB = 'version.php';
	$Etable_name = $wpdb->prefix . "bpspro_arq_exclude";
	$getExcludeRows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $Etable_name WHERE arq_exclude_source LIKE %s", "%$versionphpDB%") );	
		
		foreach ( $getExcludeRows as $row ) {
			if ( $row->arq_exclude_source == $versionphp ) {		
				return;
			}
		}

		if ( file_exists($versionphp) ) {	
			$Excludeversionphp = $wpdb->insert( $Etable_name, array( 'time' => current_time('mysql'), 'arq_exclude_source' => $versionphp ) );
		}
	}
}

// BPS Pro Upgrades & Setup Wizard - Create an ARQ single file Exclude rule for /mu-plugins/bps-pro-mu-tools.php 
function bpsPro_mu_tools_exclude_rule() {

	if ( current_user_can('manage_options') ) {

	global $wpdb;
	$BPS_MU_tools = WP_CONTENT_DIR . '/mu-plugins/bps-pro-mu-tools.php';	
	$BPS_MU_tools_DB = 'bps-pro-mu-tools.php';
	$Etable_name = $wpdb->prefix . "bpspro_arq_exclude";
	$getExcludeRows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $Etable_name WHERE arq_exclude_source LIKE %s", "%$BPS_MU_tools_DB%") );	
		
		foreach ( $getExcludeRows as $row ) {
			if ( $row->arq_exclude_source == $BPS_MU_tools ) {		
				return;
			}
		}

		if ( file_exists($BPS_MU_tools) ) {	
			$Exclude_BPS_MU_tools = $wpdb->insert( $Etable_name, array( 'time' => current_time('mysql'), 'arq_exclude_source' => $BPS_MU_tools ) );
		}
	}
}

// 15.1: Remove (unset) the WP Site Health "A scheduled event is late" error message for any BPS Cron jobs.
function bpsPro_filter_scheduled_events( $tests ) {

	if ( ! class_exists( 'WP_Site_Health' ) ) {
		require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
	}

	$get_test_scheduled_events = new WP_Site_Health();
	$test_description = $get_test_scheduled_events->get_test_scheduled_events();
	$pattern = '/(bpsPro_DBB_check|bpsPro_php_elog_check|bpsPro_update_check|bpsPro_email_log_files|bpsPro_PFWAP_check|bpsPro_DBM_check|bpsPro_security_log_check|bpsPro_AutoRestore_check|bpsPro_ARQ_OBFD|bpsPro_FolderLock_check|bpsPro_ARQ_Off_check|bpsPro_HPF_check|bpsPro_AFS_check|bpsPro_MScan_check)/';
	
	if ( preg_match( $pattern, $test_description['description'] ) ) {
		
		unset( $tests['direct']['scheduled_events'] );
	}
	
	return $tests;
}

add_filter( 'site_status_tests', 'bpsPro_filter_scheduled_events' );

?>