<?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 ( ! current_user_can('manage_options') ) { 
		header('Status: 403 Forbidden');
		header('HTTP/1.1 403 Forbidden');
		exit();
}
	
// Pre-Installation Wizard - save these S-Monitor db values so that the Setup Wizard Spinner and BPS Pro Status Display display on first time installations
// The Setup Wizard converts PW db values to new wpOn or On|Off default values
function bpsPro_SetupWizard_smonitor_db_values() {

	$bps_option_name6 = 'bulletproof_security_options_monitor';

	$BPS_Options6 = array(
	'bps_first_launch' 				=> 'Off', 
	'bps_security_status' 			=> 'wpOn', 
	'bps_SecLog_entry' 				=> 'PW', 
	'bps_autorestore_status' 		=> 'PW', 
	'bps_autorestore_alerts' 		=> 'PW', 
	'bps_plugin_firewall_status' 	=> 'PW', 
	'bps_UAEG_status' 				=> 'PW', 
	'bps_login_security_status' 	=> 'PW', 
	'bps_flock_status' 				=> 'PW', 
	'bps_HUD_alerts' 				=> 'PW', 
	'bps_PHP_ELogLoc_set' 			=> 'PW', 
	'bps_PHP_ELog_error' 			=> 'PW', 
	'bps_phpini_created' 			=> 'PW', 
	'bps_login_security_alerts' 	=> 'PW', 
	'bps_jtc_antispam_status' 		=> 'PW', 
	'bps_dbm_status' 				=> 'PW', 
	'bps_dbm_alerts' 				=> 'Off', 
	'bps_dbb_status' 				=> 'PW', 
	'bps_flock_FL_alerts' 			=> 'PW', 
	'bps_isl_status' 				=> 'Off', 		
	'bps_ace_status' 				=> 'Off', 
	'bps_mscan_status_display' 		=> 'PW' 
	);

	if ( ! get_option( $bps_option_name6 ) ) {	
		
		foreach( $BPS_Options6 as $key => $value ) {
			update_option('bulletproof_security_options_monitor', $BPS_Options6);
		}
	
	} else {

		$BPS_SM_Options = get_option('bulletproof_security_options_monitor');

		$BPS_Options_SM = array(
		'bps_first_launch' 				=> $BPS_SM_Options['bps_first_launch'], 
		'bps_security_status' 			=> $BPS_SM_Options['bps_security_status'], 
		'bps_SecLog_entry' 				=> $BPS_SM_Options['bps_SecLog_entry'], 
		'bps_autorestore_status' 		=> $BPS_SM_Options['bps_autorestore_status'], 
		'bps_autorestore_alerts' 		=> $BPS_SM_Options['bps_autorestore_alerts'], 
		'bps_plugin_firewall_status' 	=> $BPS_SM_Options['bps_plugin_firewall_status'], 
		'bps_UAEG_status' 				=> $BPS_SM_Options['bps_UAEG_status'], 
		'bps_login_security_status' 	=> $BPS_SM_Options['bps_login_security_status'], 
		'bps_flock_status' 				=> $BPS_SM_Options['bps_flock_status'], 
		'bps_HUD_alerts' 				=> $BPS_SM_Options['bps_HUD_alerts'], 
		'bps_PHP_ELogLoc_set' 			=> $BPS_SM_Options['bps_PHP_ELogLoc_set'], 
		'bps_PHP_ELog_error' 			=> $BPS_SM_Options['bps_PHP_ELog_error'], 
		'bps_phpini_created' 			=> $BPS_SM_Options['bps_phpini_created'], 
		'bps_login_security_alerts' 	=> $BPS_SM_Options['bps_login_security_alerts'], 
		'bps_jtc_antispam_status' 		=> $BPS_SM_Options['bps_jtc_antispam_status'], 
		'bps_dbm_status' 				=> $BPS_SM_Options['bps_dbm_status'], 
		'bps_dbm_alerts' 				=> $BPS_SM_Options['bps_dbm_alerts'], 
		'bps_dbb_status' 				=> $BPS_SM_Options['bps_dbb_status'], 
		'bps_flock_FL_alerts' 			=> $BPS_SM_Options['bps_flock_FL_alerts'], 
		'bps_isl_status' 				=> $BPS_SM_Options['bps_isl_status'], 		
		'bps_ace_status' 				=> $BPS_SM_Options['bps_ace_status'], 
		'bps_mscan_status_display' 		=> $BPS_SM_Options['bps_mscan_status_display'] 
		);

		foreach( $BPS_Options_SM as $key => $value ) {
			update_option('bulletproof_security_options_monitor', $BPS_Options_SM);
		}
	}
}

function bpsPro_network_domain_check_wizard() {
	global $wpdb;
	if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
		return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
	return false;
}

function bpsPro_get_clean_basedomain_wizard() {
	if ( $existing_domain = bpsPro_network_domain_check_wizard() )
		return $existing_domain;
	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
	if ( $slash = strpos( $domain, '/' ) )
		$domain = substr( $domain, 0, $slash );
	return $domain;
}

// Pre-installation Setup Wizard - Create Secure Root .htaccess file
function bpsSetupWizardCreateRootHtaccess() {
global $bpspro_version;
// secure.htaccess fwrite content for all WP site types
$bps_get_domain_root = bpsGetDomainRoot();
$bps_get_wp_root_default = bps_wp_get_root_folder();
// Replace ABSPATH = wp-content/plugins
$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
// Replace ABSPATH = wp-content
$bps_wpcontent_dir = str_replace( ABSPATH, '', WP_CONTENT_DIR );
// Replace ABSPATH = wp-content/uploads
$wp_upload_dir = wp_upload_dir();
$bps_uploads_dir = str_replace( ABSPATH, '', $wp_upload_dir['basedir'] );
	
	if ( is_multisite() ) {
	
	$hostname          = bpsPro_get_clean_basedomain_wizard();
	$slashed_home      = trailingslashit( get_option( 'home' ) );
	$base              = parse_url( $slashed_home, PHP_URL_PATH );
	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
	$abspath_fix       = str_replace( '\\', '/', ABSPATH );
	$home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
	$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
	$rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
	$subdomain_install = is_subdomain_install();
	$subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
	$subdir_replacement_01 = $subdomain_install ? '' : '$1';
	$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
		
		$ms_files_rewriting = '';
		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
			$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}wp-includes/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
		}
	}

$BPSCustomCodeOptions = get_option('bulletproof_security_options_customcode');
$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
$bps_get_wp_root_secure = bps_wp_get_root_folder();
$bps_auto_write_secure_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/secure.htaccess';
$bps_auto_write_secure_file_root = ABSPATH . '.htaccess';
$bps_auto_write_secure_file_rootARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/root-files/auto_.htaccess';
$bps_auto_write_secure_fileARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/admin/htaccess/secure.htaccess';

$bpsSuccessMessageSec = '<font color="green"><strong>'.__('Pass! secure.htaccess Root Master file htaccess creation.', 'bulletproof-security').'<br>'.__('Pass! Root Folder BulletProof Mode activation.', 'bulletproof-security').'</strong></font><br>';

$bpsFailMessageSec = '<font color="#fb0101"><strong>'.__('Error: Your BulletProof Security Root Master htaccess file cannot be created.', 'bulletproof-security').'</strong></font><br><strong>'.__('If your Server configuration is DSO you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security').' <a href="https://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window">'.__('DSO Setup Steps', 'bulletproof-security').'</a></strong><br>';

if ( ! is_multisite() && $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'] != '' ) {        
$bpsBeginWP = "# CUSTOM CODE WP REWRITE LOOP START\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'], ENT_QUOTES ) . "\n\n";
} else {
$bpsBeginWP = "# WP REWRITE LOOP START
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase $bps_get_wp_root_default
RewriteRule ^index\.php$ - [L]\n";
}

// Network/Multisite all site types and versions
if ( is_multisite() ) {
if ( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'] != '' ) {    
$bpsMUSDirTop = "# CUSTOM CODE WP REWRITE LOOP START\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'], ENT_QUOTES ) . "\n\n";
} else {
$bpsMUSDirTop = "# WP REWRITE LOOP START
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase $bps_get_wp_root_default
RewriteRule ^index\.php$ - [L]\n
{$ms_files_rewriting}
# add a trailing slash to /wp-admin
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]\n\n";
}

// Network/Multisite all site types and versions
if ( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_end'] != '' ) {    
$bpsMUSDirBottom = "# CUSTOM CODE WP REWRITE LOOP END\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_end'], ENT_QUOTES ) . "\n\n";
} else {
$bpsMUSDirBottom = "RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
RewriteRule . index.php [L]
# WP REWRITE LOOP END\n";
}
}

$bps_secure_content_top = "#   BULLETPROOF PRO $bpspro_version SECURE .HTACCESS          \n\n";

if ( $BPSCustomCodeOptions['bps_customcode_one'] != '' ) {
$bps_secure_phpini_cache = "# CUSTOM CODE TOP PHP/PHP.INI HANDLER/CACHE CODE\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_one'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_phpini_cache = "# PHP/PHP.INI HANDLER/CACHE CODE
# Use BPS Custom Code to add php/php.ini Handler and Cache htaccess code and to save it permanently.
# Most Hosts do not have/use/require php/php.ini Handler htaccess code\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_server_signature'] != '' ) {
$bps_server_signature = "# CUSTOM CODE TURN OFF YOUR SERVER SIGNATURE\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_server_signature'], ENT_QUOTES ) . "\n\n";
} else {
$bps_server_signature = "# TURN OFF YOUR SERVER SIGNATURE
# Suppresses the footer line server version number and ServerName of the serving virtual host
ServerSignature Off\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_directory_index'] != '' ) {        
$bps_secure_directory_list_index = "# CUSTOM CODE DIRECTORY LISTING/DIRECTORY INDEX\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_directory_index'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_directory_list_index = "# DO NOT SHOW DIRECTORY LISTING
# Disallow mod_autoindex from displaying a directory listing
# If a 500 Internal Server Error occurs when activating Root BulletProof Mode 
# copy the entire DO NOT SHOW DIRECTORY LISTING and DIRECTORY INDEX sections of code 
# and paste it into BPS Custom Code and comment out Options -Indexes 
# by adding a # sign in front of it.
# Example: #Options -Indexes
Options -Indexes\n
# DIRECTORY INDEX FORCE INDEX.PHP
# Use index.php as default directory index file. index.html will be ignored.
# If a 500 Internal Server Error occurs when activating Root BulletProof Mode 
# copy the entire DO NOT SHOW DIRECTORY LISTING and DIRECTORY INDEX sections of code 
# and paste it into BPS Custom Code and comment out DirectoryIndex 
# by adding a # sign in front of it.
# Example: #DirectoryIndex index.php index.html /index.php
DirectoryIndex index.php index.html /index.php\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_server_protocol'] != '' ) {        
$bps_secure_brute_force_login = "# CUSTOM CODE BRUTE FORCE LOGIN PAGE PROTECTION\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_server_protocol'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_brute_force_login = "# BRUTE FORCE LOGIN PAGE PROTECTION
# PLACEHOLDER ONLY
# Use BPS Custom Code to add Brute Force Login protection code and to save it permanently.
# See this link: https://forum.ait-pro.com/forums/topic/protect-login-page-from-brute-force-login-attacks/
# for more information.\n\n";
}

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

if ( $BPSCustomCodeOptions['bps_customcode_deny_dot_folders'] != '' ) {        
$bps_secure_dot_server_files = "# CUSTOM CODE DENY ACCESS TO PROTECTED SERVER FILES AND FOLDERS\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_deny_dot_folders'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_dot_server_files = "# DENY ACCESS TO PROTECTED SERVER FILES AND FOLDERS
# Use BPS Custom Code to modify/edit/change this code and to save it permanently.
# Files and folders starting with a dot: .htaccess, .htpasswd, .errordocs, .logs
RedirectMatch 403 \.(htaccess|htpasswd|errordocs|logs)$\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_admin_includes'] != '' ) {        
$bps_secure_content_wpadmin = "# CUSTOM CODE WP-ADMIN/INCLUDES\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_admin_includes'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_content_wpadmin = "# WP-ADMIN/INCLUDES
# Use BPS Custom Code to remove this code permanently.
RewriteEngine On
RewriteBase $bps_get_wp_root_secure
RewriteRule ^wp-admin/includes/ - [F]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F]
RewriteRule ^wp-includes/theme-compat/ - [F]\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_request_methods'] != '' ) {        
$bps_secure_request_methods = "\n# CUSTOM CODE REQUEST METHODS FILTERED\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_request_methods'], ENT_QUOTES)."\n\n";
} else {
$bps_secure_request_methods = "\n# REQUEST METHODS FILTERED
# If you want to allow HEAD Requests use BPS Custom Code and copy 
# this entire REQUEST METHODS FILTERED section of code to this BPS Custom Code 
# text box: CUSTOM CODE REQUEST METHODS FILTERED.
# See the CUSTOM CODE REQUEST METHODS FILTERED help text for additional steps.
RewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK|DEBUG) [NC]
RewriteRule ^(.*)$ - [F]
RewriteCond %{REQUEST_METHOD} ^(HEAD) [NC]
RewriteRule ^(.*)$ " . $bps_get_wp_root_secure . $bps_plugin_dir . "/bulletproof-security/405.php [L]\n\n";
}

$bps_secure_begin_plugins_skip_rules_text = "# PLUGINS/THEMES AND VARIOUS EXPLOIT FILTER SKIP RULES
# To add plugin/theme skip/bypass rules use BPS Custom Code.
# The [S] flag is used to skip following rules. Skip rule [S=12] will skip 12 following RewriteRules.
# The skip rules MUST be in descending consecutive number order: 12, 11, 10, 9...
# If you delete a skip rule, change the other skip rule numbers accordingly.
# Examples: If RewriteRule [S=5] is deleted than change [S=6] to [S=5], [S=7] to [S=6], etc.
# If you add a new skip rule above skip rule 12 it will be skip rule 13: [S=13]\n\n";

// Plugin/Theme skip/bypass rules
$bps_secure_plugins_themes_skip_rules = '';
if ( $BPSCustomCodeOptions['bps_customcode_two'] != '' ) {
$bps_secure_plugins_themes_skip_rules = "# CUSTOM CODE PLUGIN/THEME SKIP/BYPASS RULES\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_two'], ENT_QUOTES ) . "\n\n";
}

$bps_secure_default_skip_rules = "# Adminer MySQL management tool data populate
RewriteCond %{REQUEST_URI} ^" . $bps_get_wp_root_secure . $bps_plugin_dir . "/adminer/ [NC]
RewriteRule . - [S=12]
# Comment Spam Pack MU Plugin - CAPTCHA images not displaying 
RewriteCond %{REQUEST_URI} ^". $bps_get_wp_root_secure . $bps_wpcontent_dir . "/mu-plugins/custom-anti-spam/ [NC]
RewriteRule . - [S=11]
# Peters Custom Anti-Spam display CAPTCHA Image
RewriteCond %{REQUEST_URI} ^" . $bps_get_wp_root_secure . $bps_plugin_dir . "/peters-custom-anti-spam-image/ [NC] 
RewriteRule . - [S=10]
# Status Updater plugin fb connect
RewriteCond %{REQUEST_URI} ^" . $bps_get_wp_root_secure . $bps_plugin_dir . "/fb-status-updater/ [NC] 
RewriteRule . - [S=9]
# Stream Video Player - Adding FLV Videos Blocked
RewriteCond %{REQUEST_URI} ^" . $bps_get_wp_root_secure . $bps_plugin_dir . "/stream-video-player/ [NC]
RewriteRule . - [S=8]
# XCloner 404 or 403 error when updating settings
RewriteCond %{REQUEST_URI} ^" . $bps_get_wp_root_secure . $bps_plugin_dir . "/xcloner-backup-and-restore/ [NC]
RewriteRule . - [S=7]
# BuddyPress Logout Redirect
RewriteCond %{QUERY_STRING} action=logout&redirect_to=http%3A%2F%2F(.*) [NC]
RewriteRule . - [S=6]
# redirect_to=
RewriteCond %{QUERY_STRING} redirect_to=(.*) [NC]
RewriteRule . - [S=5]
# Login Plugins Password Reset And Redirect 1
RewriteCond %{QUERY_STRING} action=resetpass&key=(.*) [NC]
RewriteRule . - [S=4]
# Login Plugins Password Reset And Redirect 2
RewriteCond %{QUERY_STRING} action=rp&key=(.*) [NC]
RewriteRule . - [S=3]\n\n";

if ( $BPSCustomCodeOptions['bps_customcode_timthumb_misc'] != '' ) {        
$bps_secure_timthumb_misc = "# CUSTOM CODE TIMTHUMB FORBID RFI and MISC FILE SKIP/BYPASS RULE\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_timthumb_misc'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_timthumb_misc = "# TIMTHUMB FORBID RFI and MISC FILE SKIP/BYPASS RULE
# Use BPS Custom Code to modify/edit/change this code and to save it permanently.
# Remote File Inclusion (RFI) security rules
# Note: Only whitelist your additional domains or files if needed - do not whitelist hacker domains or files
RewriteCond %{QUERY_STRING} ^.*(http|https|ftp)(%3A|:)(%2F|/)(%2F|/)(w){0,3}.?(blogger|picasa|blogspot|tsunami|petapolitik|photobucket|imgur|imageshack|wordpress\.com|img\.youtube|tinypic\.com|upload\.wikimedia|kkc|start-thegame).*$ [NC,OR]
RewriteCond %{THE_REQUEST} ^.*(http|https|ftp)(%3A|:)(%2F|/)(%2F|/)(w){0,3}.?(blogger|picasa|blogspot|tsunami|petapolitik|photobucket|imgur|imageshack|wordpress\.com|img\.youtube|tinypic\.com|upload\.wikimedia|kkc|start-thegame).*$ [NC]
RewriteRule .* index.php [F]
# 
# Example: Whitelist additional misc files: (example\.php|another-file\.php|phpthumb\.php|thumb\.php|thumbs\.php)
RewriteCond %{REQUEST_URI} (timthumb\.php|phpthumb\.php|thumb\.php|thumbs\.php) [NC]
# Example: Whitelist additional website domains: RewriteCond %{HTTP_REFERER} ^.*(YourWebsite.com|AnotherWebsite.com).*
RewriteCond %{HTTP_REFERER} ^.*" . $bps_get_domain_root . ".*
RewriteRule . - [S=1]\n\n";
}

if ( $BPSCustomCodeOptions['bps_customcode_bpsqse'] != '' ) {        
$bps_secure_BPSQSE = "# CUSTOM CODE BPSQSE BPS QUERY STRING EXPLOITS\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_bpsqse'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_BPSQSE = "# BEGIN BPSQSE BPS QUERY STRING EXPLOITS
# The libwww-perl User Agent is forbidden - Many bad bots use libwww-perl modules, but some good bots use it too.
# Good sites such as W3C use it for their W3C-LinkChecker. 
# Use BPS Custom Code to add or remove user agents temporarily or permanently from the 
# User Agent filters directly below or to modify/edit/change any of the other security code rules below.
RewriteCond %{HTTP_USER_AGENT} (havij|libwww-perl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (%0A|%0D|%27|%3C|%3E|%00) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (;|<|>|'|".'"'."|\)|\(|%0A|%0D|%22|%27|%28|%3C|%3E|%00).*(libwww-perl|wget|python|nikto|curl|scan|java|winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner) [NC,OR]
RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\s+|%20+\\\\s+|\\\\s+%20+|\\\\s+%20+\\\\s+)(http|https)(:/|/) [NC,OR]
RewriteCond %{THE_REQUEST} etc/passwd [NC,OR]
RewriteCond %{THE_REQUEST} cgi-bin [NC,OR]
RewriteCond %{THE_REQUEST} (%0A|%0D|\\"."\\"."r|\\"."\\"."n) [NC,OR]
RewriteCond %{REQUEST_URI} owssvr\.dll [NC,OR]
RewriteCond %{HTTP_REFERER} (%0A|%0D|%27|%3C|%3E|%00) [NC,OR]
RewriteCond %{HTTP_REFERER} \.opendirviewer\. [NC,OR]
RewriteCond %{HTTP_REFERER} users\.skynet\.be.* [NC,OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(http|https):// [NC,OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [NC,OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC,OR]
RewriteCond %{QUERY_STRING} \=PHP[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} [NC,OR]
RewriteCond %{QUERY_STRING} (\.\./|%2e%2e%2f|%2e%2e/|\.\.%2f|%2e\.%2f|%2e\./|\.%2e%2f|\.%2e/) [NC,OR]
RewriteCond %{QUERY_STRING} ftp\: [NC,OR]
RewriteCond %{QUERY_STRING} (http|https)\: [NC,OR] 
RewriteCond %{QUERY_STRING} \=\|w\| [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)/self/(.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)cPath=(http|https)://(.*)$ [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*embed.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^e]*e)+mbed.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*object.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^o]*o)+bject.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (\<|%3C).*iframe.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^i]*i)+frame.*(>|%3E) [NC,OR] 
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [NC,OR]
RewriteCond %{QUERY_STRING} base64_(en|de)code[^(]*\([^)]*\) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} ^.*(\(|\)|<|>|%3c|%3e).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(\\x00|\\x04|\\x08|\\x0d|\\x1b|\\x20|\\x3c|\\x3e|\\x7f).* [NC,OR]
RewriteCond %{QUERY_STRING} (NULL|OUTFILE|LOAD_FILE) [OR]
RewriteCond %{QUERY_STRING} (\.{1,}/)+(motd|etc|bin) [NC,OR]
RewriteCond %{QUERY_STRING} (localhost|loopback|127\.0\.0\.1) [NC,OR]
RewriteCond %{QUERY_STRING} (<|>|'|%0A|%0D|%27|%3C|%3E|%00) [NC,OR]
RewriteCond %{QUERY_STRING} concat[^\(]*\( [NC,OR]
RewriteCond %{QUERY_STRING} union([^s]*s)+elect [NC,OR]
RewriteCond %{QUERY_STRING} union([^a]*a)+ll([^s]*s)+elect [NC,OR]
RewriteCond %{QUERY_STRING} \-[sdcr].*(allow_url_include|allow_url_fopen|safe_mode|disable_functions|auto_prepend_file) [NC,OR]
RewriteCond %{QUERY_STRING} (;|<|>|'|".'"'."|\)|%0A|%0D|%22|%27|%3C|%3E|%00).*(/\*|union|select|insert|drop|delete|update|cast|create|char|convert|alter|declare|order|script|set|md5|benchmark|encode) [NC,OR]
RewriteCond %{QUERY_STRING} (sp_executesql) [NC]
RewriteRule ^(.*)$ - [F]
# END BPSQSE BPS QUERY STRING EXPLOITS\n";
}

$bps_secure_wp_rewrite_loop_end = "RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . " . $bps_get_wp_root_secure . "index.php [L]
# WP REWRITE LOOP END\n";

if ( $BPSCustomCodeOptions['bps_customcode_deny_files'] != '' ) {        
$bps_secure_deny_browser_access = "\n# CUSTOM CODE DENY BROWSER ACCESS TO THESE FILES\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_deny_files'], ENT_QUOTES ) . "\n\n";

} else {

	if ( $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' ) {	
	
		$bps_secure_deny_browser_access = "\n# DENY BROWSER ACCESS TO THESE FILES 
# Use BPS Custom Code to modify/edit/change this code and to save it permanently.
# wp-config.php, bb-config.php, php.ini, php5.ini, readme.html
# To be able to view these files from a Browser, replace 127.0.0.1 with your actual 
# current IP address. Comment out: #Require all denied and Uncomment: Require ip 127.0.0.1
# Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1 
# Note: The BPS System Info page displays which modules are loaded on your server. 

<FilesMatch \"^(wp-config\.php|php\.ini|php5\.ini|readme\.html|bb-config\.php)\">
<IfModule mod_authz_core.c>
Require all denied
#Require ip 127.0.0.1
</IfModule>

<IfModule !mod_authz_core.c>
<IfModule mod_access_compat.c>
Order Allow,Deny
Deny from all
#Allow from 127.0.0.1
</IfModule>
</IfModule>
</FilesMatch>\n\n";
	
	} else {
		
		$bps_secure_deny_browser_access = "\n# DENY BROWSER ACCESS TO THESE FILES 
# Use BPS Custom Code to modify/edit/change this code and to save it permanently.
# wp-config.php, bb-config.php, php.ini, php5.ini, readme.html
# To be able to view these files from a Browser, replace 127.0.0.1 with your actual 
# current IP address. Comment out: #Deny from all and Uncomment: Allow from 127.0.0.1 
# Note: The BPS System Info page displays which modules are loaded on your server. 

<FilesMatch \"^(wp-config\.php|php\.ini|php5\.ini|readme\.html|bb-config\.php)\">
Order Allow,Deny
Deny from all
#Allow from 127.0.0.1
</FilesMatch>\n\n";		
	}
}

// CUSTOM CODE BOTTOM
$bps_secure_bottom_misc_code = '';
if ( $BPSCustomCodeOptions['bps_customcode_three'] != '' ) {
$bps_secure_bottom_misc_code = "# CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_three'], ENT_QUOTES ) . "\n\n";
} else {
$bps_secure_bottom_misc_code = "# HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE
# PLACEHOLDER ONLY
# Use BPS Custom Code to add custom code and save it permanently here.\n";
}
	
	$lock = '';

	if ( file_exists($bps_auto_write_secure_file_root) ) {
		$permsRootHtaccess = @substr(sprintf('%o', fileperms($bps_auto_write_secure_file_root)), -4);
	
		if ( @$permsRootHtaccess == '0404') {
			$lock = '0404';			
		}		
	
		$sapi_type = php_sapi_name();
		
		if ( @substr($sapi_type, 0, 6) != 'apache' && @$permsRootHtaccess != '0666' || @$permsRootHtaccess != '0777') { 
			@chmod($bps_auto_write_secure_file_root, 0644);
		}
	}
	
// Single/Standard WordPress site type: Create secure.htaccess Master File
if ( ! is_multisite() ) {

	$stringReplace = file_get_contents($bps_auto_write_secure_file);

	if ( file_exists($bps_auto_write_secure_file) ) {
		$stringReplace = $bps_secure_content_top.$bps_secure_phpini_cache.$bps_server_signature.$bps_secure_directory_list_index.$bps_secure_brute_force_login.$bps_secure_error_logging.$bps_secure_dot_server_files.$bps_secure_content_wpadmin.$bpsBeginWP.$bps_secure_request_methods.$bps_secure_begin_plugins_skip_rules_text.$bps_secure_plugins_themes_skip_rules.$bps_secure_default_skip_rules.$bps_secure_timthumb_misc.$bps_secure_BPSQSE.$bps_secure_wp_rewrite_loop_end.$bps_secure_deny_browser_access.$bps_secure_bottom_misc_code;		
		
		if ( file_put_contents( $bps_auto_write_secure_file, $stringReplace ) ) {
			@copy($bps_auto_write_secure_file, $bps_auto_write_secure_file_root);
			if ( is_dir( WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/admin/htaccess' ) ) {
			@copy($bps_auto_write_secure_file, $bps_auto_write_secure_fileARQ);
			}
    		
			echo $bpsSuccessMessageSec;
		
		} else {
		
    		echo $bpsFailMessageSec;
		}
	}

	if ( @$lock == '0404') {	
		@chmod($bps_auto_write_secure_file_root, 0404);
	}
}

// Network site type: Create secure.htaccess Master File
if ( is_multisite() && is_super_admin() ) { 

		$stringReplace = file_get_contents($bps_auto_write_secure_file);

	if ( file_exists($bps_auto_write_secure_file) ) {
		$stringReplace = $bps_secure_content_top.$bps_secure_phpini_cache.$bps_server_signature.$bps_secure_directory_list_index.$bps_secure_brute_force_login.$bps_secure_error_logging.$bps_secure_dot_server_files.$bpsMUSDirTop.$bps_secure_request_methods.$bps_secure_begin_plugins_skip_rules_text.$bps_secure_plugins_themes_skip_rules.$bps_secure_default_skip_rules.$bps_secure_timthumb_misc.$bps_secure_BPSQSE.$bpsMUSDirBottom.$bps_secure_deny_browser_access.$bps_secure_bottom_misc_code;		
		
		if ( file_put_contents( $bps_auto_write_secure_file, $stringReplace ) ) {
			@copy($bps_auto_write_secure_file, $bps_auto_write_secure_file_root);
			@copy($bps_auto_write_secure_file, $bps_auto_write_secure_fileARQ);
    		
			echo $bpsSuccessMessageSec;
		
		} else {
		
    		echo $bpsFailMessageSec;
		}
	}
	
	if ( @$lock == '0404') {	
		@chmod($bps_auto_write_secure_file_root, 0404);
	}
}
}

// Pre-installation Setup Wizard - Create wp-admin htaccess file
function bpsSetupWizardCreateWpadminHtaccess() {
$options = get_option('bulletproof_security_options_customcode_WPA');  

$bpsSuccessMessageSec = '<font color="green"><strong>'.__('Pass! wp-admin BulletProof Mode activation.', 'bulletproof-security').'</strong></font><br>';
$bpsFailMessageSec = '<br><font color="#fb0101"><strong>'.__('Error: wp-admin BulletProof Mode cannot be activated.', 'bulletproof-security').'</strong></font><br><strong>'.__('If your Server configuration is DSO you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security').' <a href="https://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window">'.__('DSO Setup Steps', 'bulletproof-security').'</a></strong><br>';

	$BPS_wpadmin_Options = get_option('bulletproof_security_options_htaccess_res');
	$GDMW_options = get_option('bulletproof_security_options_GDMW');	
	
	if ( $BPS_wpadmin_Options['bps_wpadmin_restriction'] == 'disabled' || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) {
		$text = '<font color="blue"><strong>'.__('Go Daddy Managed WordPress Hosting option is set to Yes or Enable|Disable wp-admin BulletProof Mode option is set to disabled. GDMW hosting does not allow wp-admin htaccess files.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	return;
	}

	$wpadminMasterHtaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';
	$wpadminActiveHtaccess = ABSPATH . 'wp-admin/.htaccess';
	$wpadminARQHtaccess = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-admin/wpadmin.htaccess';
	if ( file_exists($wpadminActiveHtaccess) ) {
		$permsHtaccess = @substr(sprintf('%o', fileperms($wpadminActiveHtaccess)), -4);
	}
	$sapi_type = php_sapi_name();
	$bpsString1 = "# CCWTOP";
	$bpsString2 = "# CCWPF";
	$bpsString3 = '/#\sBEGIN\sBPS\sWPADMIN\sDENY\sACCESS\sTO\sFILES(.*)#\sEND\sBPS\sWPADMIN\sDENY\sACCESS\sTO\sFILES/s';
	$bpsString4 = '/#\sBEGIN\sBPSQSE-check\sBPS\sQUERY\sSTRING\sEXPLOITS\sAND\sFILTERS(.*)#\sEND\sBPSQSE-check\sBPS\sQUERY\sSTRING\sEXPLOITS\sAND\sFILTERS/s';
	$bpsReplace1 = htmlspecialchars_decode($options['bps_customcode_one_wpa'], ENT_QUOTES);
	$bpsReplace2 = htmlspecialchars_decode($options['bps_customcode_two_wpa'], ENT_QUOTES);
	$bpsReplace3 = htmlspecialchars_decode($options['bps_customcode_deny_files_wpa'], ENT_QUOTES);	
	$bpsReplace4 = htmlspecialchars_decode($options['bps_customcode_bpsqse_wpa'], ENT_QUOTES);	
	
	if ( file_exists($wpadminActiveHtaccess) ) {	
		if ( @substr($sapi_type, 0, 6) != 'apache' || @$permsHtaccess != '0666' || @$permsHtaccess != '0777') { // Windows IIS, XAMPP, etc
			@chmod($wpadminActiveHtaccess, 0644);
		}
	}

	if ( @copy($wpadminMasterHtaccess, $wpadminActiveHtaccess) ) {
		echo $bpsSuccessMessageSec;
	} else {
		echo $bpsFailMessageSec;	
	}
	
	if ( file_exists($wpadminActiveHtaccess) ) {
		
		$bpsBaseContent = @file_get_contents($wpadminActiveHtaccess);
		
		if ( $options['bps_customcode_deny_files_wpa'] != '') {        
			$bpsBaseContent = preg_replace('/#\sBEGIN\sBPS\sWPADMIN\sDENY\sACCESS\sTO\sFILES(.*)#\sEND\sBPS\sWPADMIN\sDENY\sACCESS\sTO\sFILES/s', $bpsReplace3, $bpsBaseContent);
		}
		
		if ( $options['bps_customcode_bpsqse_wpa'] != '') {        
			$bpsBaseContent = preg_replace('/#\sBEGIN\sBPSQSE-check\sBPS\sQUERY\sSTRING\sEXPLOITS\sAND\sFILTERS(.*)#\sEND\sBPSQSE-check\sBPS\sQUERY\sSTRING\sEXPLOITS\sAND\sFILTERS/s', $bpsReplace4, $bpsBaseContent);
		}
		
		$bpsBaseContent = str_replace($bpsString1, $bpsReplace1, $bpsBaseContent);
		$bpsBaseContent = str_replace($bpsString2, $bpsReplace2, $bpsBaseContent);
		@file_put_contents($wpadminActiveHtaccess, $bpsBaseContent);
		
		if ( file_exists($wpadminActiveHtaccess) ) {
			
			if ( is_dir( WP_CONTENT_DIR . '/bps-backup/autorestore/wp-admin' ) ) {
				@copy($wpadminActiveHtaccess, $wpadminARQHtaccess);
			}
		}
	}
}

// Pre-installation Setup Wizard - Create the default.htaccess htaccess file
function bpsSetupWizardCreateDefaultHtaccess() {
global $bpspro_version;

$bps_get_wp_root_default = bps_wp_get_root_folder();
	
	if ( is_multisite() ) {
	
	$hostname          = bpsPro_get_clean_basedomain_wizard();
	$slashed_home      = trailingslashit( get_option( 'home' ) );
	$base              = parse_url( $slashed_home, PHP_URL_PATH );
	$document_root_fix = str_replace( '\\', '/', realpath( $_SERVER['DOCUMENT_ROOT'] ) );
	$abspath_fix       = str_replace( '\\', '/', ABSPATH );
	$home_path         = 0 === strpos( $abspath_fix, $document_root_fix ) ? $document_root_fix . $base : get_home_path();
	$wp_siteurl_subdir = preg_replace( '#^' . preg_quote( $home_path, '#' ) . '#', '', $abspath_fix );
	$rewrite_base      = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
	$subdomain_install = is_subdomain_install();
	$subdir_match          = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
	$subdir_replacement_01 = $subdomain_install ? '' : '$1';
	$subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
		
		$ms_files_rewriting = '';
		if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
			$ms_files_rewriting = "\n# uploaded files\nRewriteRule ^";
			$ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}wp-includes/ms-files.php?file={$subdir_replacement_12} [L]" . "\n";
		}
	}

$BPSCustomCodeOptions = get_option('bulletproof_security_options_customcode');

$bpsSuccessMessageSec = '<font color="green"><strong>'.__('Pass! The default.htaccess Master htaccess file was created successfully.', 'bulletproof-security').'</strong></font><br>';

$bpsFailMessageSec = '<font color="#fb0101"><strong>'.__('Error: The default.htaccess Master htaccess file cannot be created.', 'bulletproof-security').'</strong></font><br><strong>'.__('If your Server configuration is DSO you must first make some one-time manual changes to your website before running the Setup Wizard. Please click this Forum Link for instructions: ', 'bulletproof-security').' <a href="https://forum.ait-pro.com/forums/topic/dso-setup-steps/" target="_blank" title="Link opens in a new Browser window">'.__('DSO Setup Steps', 'bulletproof-security').'</a></strong><br>';

$bps_default_content_top = "#   BULLETPROOF PRO DEFAULT .HTACCESS      \n
# WARNING!!! THE default.htaccess FILE DOES NOT PROTECT YOUR WEBSITE AGAINST HACKERS
# This is a standard generic htaccess file that does NOT provide any website security
# The DEFAULT .HTACCESS file should be used for testing and troubleshooting purposes only\n
# BEGIN BPS WordPress\n";

$bps_default_content_bottom = "<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase $bps_get_wp_root_default
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . " . $bps_get_wp_root_default . "index.php [L]
</IfModule>\n
# END BPS WordPress";

$bpsMUEndWP = "# END BPS WordPress";

// Network/Multisite all site types and versions
if ( is_multisite() ) {
if ( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'] != '' ) {    
$bpsMUSDirTop = "# CUSTOM CODE WP REWRITE LOOP START\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_start'], ENT_QUOTES ) . "\n\n";
} else {
$bpsMUSDirTop = "# WP REWRITE LOOP START
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase $bps_get_wp_root_default
RewriteRule ^index\.php$ - [L]\n
{$ms_files_rewriting}
# add a trailing slash to /wp-admin
RewriteRule ^{$subdir_match}wp-admin$ {$subdir_replacement_01}wp-admin/ [R=301,L]\n\n";
}

// Network/Multisite all site types and versions
if ( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_end'] != '' ) {    
$bpsMUSDirBottom = "# CUSTOM CODE WP REWRITE LOOP END\n" . htmlspecialchars_decode( $BPSCustomCodeOptions['bps_customcode_wp_rewrite_end'], ENT_QUOTES ) . "\n\n";
} else {
$bpsMUSDirBottom = "RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L]
RewriteRule ^{$subdir_match}(.*\.php)$ {$rewrite_base}$subdir_replacement_12 [L]
RewriteRule . index.php [L]
# WP REWRITE LOOP END\n";
}
}

	$bps_auto_write_default_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/default.htaccess';
	$bps_auto_write_default_fileARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/admin/htaccess/default.htaccess';

	// Single/Standard WordPress site type: Create default.htaccess Master File
	if ( ! is_multisite() ) {

		$stringReplace = file_get_contents($bps_auto_write_default_file);

	if ( file_exists($bps_auto_write_default_file) ) {
		$stringReplace = $bps_default_content_top.$bps_default_content_bottom;
		
		if ( file_put_contents( $bps_auto_write_default_file, $stringReplace ) ) {
			if ( is_dir( WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/admin/htaccess' ) ) {
			@copy($bps_auto_write_default_file, $bps_auto_write_default_fileARQ);
			}
    		
			echo $bpsSuccessMessageSec;
		
		} else {
		
    		echo $bpsFailMessageSec;
		}
	}
	}

	// Network site type: Create default.htaccess Master File
	if ( is_multisite() && is_super_admin() ) {

		$stringReplace = file_get_contents($bps_auto_write_default_file);

	if ( file_exists($bps_auto_write_default_file) ) {
		$stringReplace = $bps_default_content_top.$bpsMUSDirTop.$bpsMUSDirBottom.$bpsMUEndWP;
		
		if ( file_put_contents( $bps_auto_write_default_file, $stringReplace ) ) {
    		@copy($bps_auto_write_default_file, $bps_auto_write_default_fileARQ);
			
			echo $bpsSuccessMessageSec;
		
		} else {
		
    		echo $bpsFailMessageSec;
		}
	}
	}
}

// Pre-installation Wizard - Check if php.ini handler code exists in root .htaccess file, but not in Custom Code.
// The bpsSetupWizardCreateRootHtaccess() function will ensure that Custom Code DB options already exist if a php.ini handler is found in the root .htaccess file
// This additional insurance check is needed in cases where users re-run the wizard at a later time & for making error/troubleshooting simpler
// Note: If bps_customcode_one has existing code, it is updated with the new php.ini handler code. 
// If no CC db options exist yet then all CC db options are saved with blank values.
function bpsSetupWizardPhpiniHandlerCheck() {
$options = get_option('bulletproof_security_options_customcode');	
$file = ABSPATH . '.htaccess';
$file_contents = @file_get_contents($file);
$successTextBegin = '<font color="green"><strong>';
$successTextEnd = '</strong></font><br>';
$failTextBegin = '<font color="#fb0101"><strong>';
$failTextEnd = '</strong></font><br>';	

	if ( file_exists($file) ) {		

		preg_match_all('/AddHandler|SetEnv PHPRC|suPHP_ConfigPath|Action application/', $file_contents, $matches);
		preg_match_all('/AddHandler|SetEnv PHPRC|suPHP_ConfigPath|Action application/', $options['bps_customcode_one'], $DBmatches);
		
		if ( ! $matches[0] ) {
			echo $successTextBegin.__('Pass! PHP/php.ini handler htaccess code check: Not in use, required or needed for your website/Server', 'bulletproof-security').$successTextEnd;
		return;
		}
	
		if ( $matches[0] && $DBmatches[0] ) {
			echo $successTextBegin.__('Pass! PHP/php.ini handler htaccess code was found in your root .htaccess file AND in BPS Pro Custom Code', 'bulletproof-security').$successTextEnd;
		}
		
		if ( $matches[0] && ! $DBmatches[0] ) {
			
			preg_match_all('/(([#\s]{1,}|)(AddHandler|SetEnv PHPRC|suPHP_ConfigPath|Action application).*\s*){1,}/', $file_contents, $h_matches );			
			
			foreach ( $h_matches[0] as $Key => $Value ) {

				$BPS_CC_Options = array( 'bps_customcode_one' => '# PHP/php.ini handler htaccess code' . "\n" . trim( $Value, " \n\r" ) . "\n\n" . $options['bps_customcode_one'] );	

				foreach( $BPS_CC_Options as $key => $value ) {
					update_option('bulletproof_security_options_customcode', $BPS_CC_Options);
				}
			}
				echo $successTextBegin.__('Pass! PHP/php.ini handler root htaccess code added/created in BPS Pro Custom Code', 'bulletproof-security').$successTextEnd;
		}
	}
}

// Pre-installation Setup Wizard - cURL Scanner checks - cURL Extension is Loaded & disable_functions directive checks
function bpsSetupWizardcURLCheck() {
	if (current_user_can('manage_options')) {
	
	if ( ! extension_loaded('curl') ) {
		$text = '<br><strong><font color="#fb0101">'.__('The cURL Extension is Not Loaded/Installed on your website/Server.', 'bulletproof-security').'</font><br>'.__('The scanner uses cURL to scan your website for plugin scripts/files to add to the Firewall Whitelist. You will either have to add plugin script/file names manually or Load/add/install the cURL extension on your Server.', 'bulletproof-security').'</strong><br>';
		echo $text;
	} else {
		$text = '<strong><font color="green">'.__('Pass! The cURL Extension is Loaded/Installed on your website/Server.', 'bulletproof-security').'</font></strong><br>';
		echo $text;	
	}
 	
	$disabled = explode(',', ini_get('disable_functions'));	
   	
	if ( in_array('curl_init', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_init function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_init function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}

	if ( in_array('curl_multi_init', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_multi_init function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_multi_init function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}

	if ( in_array('curl_exec', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_exec function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_exec function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}

	if ( in_array('curl_multi_exec', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_multi_exec function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_multi_exec function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}

	if ( in_array('curl_setopt', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_setopt function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_setopt function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}
	
	if ( in_array('curl_multi_getcontent', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_multi_getcontent function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_multi_getcontent function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}

	if ( in_array('curl_multi_add_handle', $disabled) ) {	
    	$text = '<br><strong><font color="#fb0101">'.__('The curl_multi_add_handle function is disabled in the disable_functions directive in your php.ini file. The cURL scanner cannot scan your website.', 'bulletproof-security').'</font><br>'.__('You will either need to remove the curl_multi_add_handle function from the disable_functions directive in your php.ini file or add plugin scripts/paths manually to your Plugin Firewall Whitelist Text Area. See the Plugin Firewall Read Me help button for instructions on how to add plugin scripts/paths manually.', 'bulletproof-security').'</strong><br>';
		echo $text;
	}
	}
}

// Pre-installation Setup Wizard - wp-content Exclude folders $FILTERS from file type checks for automatic ARQ Exclude rule creation
class BPSWPCSourceExcludeRecursiveFilterIterator extends RecursiveFilterIterator {

	public static $FILTERS = array('plugins', 'mu-plugins', 'themes', 'upgrade', 'uploads', 'blogs.dir', 'bps-backup', 'cache', 'w3tc');
	
	public function accept() {
		return !in_array( $this->getSubPathName(), self::$FILTERS, true );
	}
}

// Pre-installation Setup Wizard - Create ARQ Exclude DB options/rules for plugins, mu-plugins & other folders that contain backups, other media types or files over 5MB
// Prevent root /wp-content folder rule - do not check /mu-plugins folder if it exists & create a mu-plugins folder exclude rule - excluded in Class filter
function bpsSetupWizardARQExcludeDB() {
$fileTypesMedia = array('png', 'jpg', 'jpeg', 'gif', 'bmp', 'swf', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'pps', 'ppsx', 'odt', 'xls', 'xlsx', 'mp3', 'm4a', 'ogg', 'wav', 'mp4', 'm4v', 'mov', 'wmv', 'avi', 'mpg', 'mpeg', 'mpe', 'ogv', '3gp', '3g2', 'ttf', 'ttc', 'woff', 'flv');

$fileTypesBackupCache = array('gz', '7z', 'htm', 'html', 'html5', 'xhtml', 'shtm', 'shtml', 'mht', 'mhtml', 'sql', 'zip', 'rar', 'ini', 'csv', 'xml', 'tar', 'tgz', 'bz2');

//$fileSize = array();
$filePath = array();
$path = WP_CONTENT_DIR;
$dirItr = new RecursiveDirectoryIterator($path);
$filterItr = new BPSWPCSourceExcludeRecursiveFilterIterator($dirItr);
$objects = new RecursiveIteratorIterator($filterItr, RecursiveIteratorIterator::SELF_FIRST); 

	foreach ( $objects as $files ) {
		if ( $files->isFile() ) {
		
			$path_parts = pathinfo($files);
			$path_parts_ext = $path_parts['extension'];
		
			if ( filesize($files) > 5242880 ) {
				//$fileSize[] = $files->getSize();
				$filePath[] = $files->getPathname();
			}
			
			if ( in_array($path_parts_ext, $fileTypesMedia) || in_array($path_parts_ext, $fileTypesBackupCache ) ) {

				$filePath[] = $files->getPathname();
			}
		}	
	}

	$path_parts_base = array();

	foreach ( $filePath as $baseFolder ) {
		
		$path_parts = pathinfo($baseFolder);
		
		if ( is_dir( WP_CONTENT_DIR .'/'. basename($path_parts['dirname']) ) ) {
			$path_parts_base[] = basename($path_parts['dirname']);
		}

		if ( is_dir( WP_CONTENT_DIR .'/'. basename(dirname(dirname($path_parts['dirname']))) )) {
			$path_parts_base[] .= basename(dirname(dirname($path_parts['dirname'])));
		}

		if ( is_dir( WP_CONTENT_DIR .'/'. basename(dirname(dirname(dirname($path_parts['dirname'])))) )) {
			$path_parts_base[] .= basename(dirname(dirname(dirname($path_parts['dirname']))));
		}

		if ( is_dir( WP_CONTENT_DIR .'/'. basename(dirname(dirname(dirname(dirname($path_parts['dirname']))))) )) {
			$path_parts_base[] .= basename(dirname(dirname(dirname(dirname($path_parts['dirname'])))));
		}

		if ( is_dir( WP_CONTENT_DIR .'/'. basename(dirname(dirname(dirname(dirname(dirname($path_parts['dirname'])))))) )) {
			$path_parts_base[] .= basename(dirname(dirname(dirname(dirname(dirname($path_parts['dirname']))))));
		}
	}

/*	
	//Testing/Troubleshooting
	echo '<pre>';
	print_r($path_parts_base);
	echo '</pre>';
*/

	$ARQ_wpcontent_folder_exclude_options = get_option('bulletproof_security_options_exclude_folder');
	$mu_plugins_dir_path = WP_CONTENT_DIR . '/mu-plugins';

	// Create an ARQ exclude rule for the plugins folder by default. 
	// If someone removes the plugins exclude rule then do not recreate it again since they want ARQ to check the plugins folder.
	if ( ! is_array($ARQ_wpcontent_folder_exclude_options) ) {
		$plugins_dir = array( 'plugins' );
	} elseif ( is_array($ARQ_wpcontent_folder_exclude_options) && in_array( 'plugins', $ARQ_wpcontent_folder_exclude_options ) ) {
		$plugins_dir = array( 'plugins' );
	} else {
		$plugins_dir = array();
	}

	// If the mu-plugins folder exists then create an ARQ exclude rule by default. 
	// If someone removes the mu-plugins exclude rule then do not recreate it again since they want ARQ to check the mu-plugins folder.
	if ( is_dir($mu_plugins_dir_path) ) {

		if ( ! is_array($ARQ_wpcontent_folder_exclude_options) ) {
			$mu_plugins_dir = array( 'mu-plugins' );
		} elseif ( is_array($ARQ_wpcontent_folder_exclude_options) && in_array( 'mu-plugins', $ARQ_wpcontent_folder_exclude_options ) ) {
			$mu_plugins_dir = array( 'mu-plugins' );
		} else {
			$mu_plugins_dir = array();
		}
	} else {
		$mu_plugins_dir = array();
	}

	// Exclude Turdfence folders if they exist: wfcache and wflogs. We wouldn't want sissy boy to cry.
	$turdfence_dir_path1 = WP_CONTENT_DIR . '/wfcache';
	$turdfence_dir_path2 = WP_CONTENT_DIR . '/wflogs';	

	if ( is_dir($turdfence_dir_path1) ) {
		$turdfence_dir1 = array( 'wfcache' );
	} else {
		$turdfence_dir1 = array();
	}
	if ( is_dir($turdfence_dir_path2) ) {
		$turdfence_dir2 = array( 'wflogs' );
	} else {
		$turdfence_dir2 = array();
	}

	## 13.4.1: Exclude the WP languages folder if it exists
	$wp_languages_dir = WP_CONTENT_DIR . '/languages';
	
	if ( is_dir($wp_languages_dir) ) {
		$wp_languages_dir = array( 'languages' );
	} else {
		$wp_languages_dir = array();
	}

	## 15: Exclude the Divi et-cache folder if it exists
	$et_cache_dir = WP_CONTENT_DIR . '/et-cache';
	
	if ( is_dir($et_cache_dir) ) {
		$et_cache_dir = array( 'et-cache' );
	} else {
		$et_cache_dir = array();
	}	

	## 15: Exclude the litespeed cache folder if it exists
	$litespeed_cache_dir = WP_CONTENT_DIR . '/litespeed';
	
	if ( is_dir($litespeed_cache_dir) ) {
		$litespeed_cache_dir = array( 'litespeed' );
	} else {
		$litespeed_cache_dir = array();
	}	

	## 15: Exclude the EWWW Image Optimizer ewww folder if it exists
	$ewww_cache_dir = WP_CONTENT_DIR . '/ewww';
	
	if ( is_dir($ewww_cache_dir) ) {
		$ewww_cache_dir = array( 'ewww' );
	} else {
		$ewww_cache_dir = array();
	}

	## 15: Exclude the updraft folder if it exists
	$updraft_dir = WP_CONTENT_DIR . '/updraft';
	
	if ( is_dir($updraft_dir) ) {
		$updraft_dir = array( 'updraft' );
	} else {
		$updraft_dir = array();
	}

	## 15: Exclude the Shield plugin folder if it exists
	$shield_dir = WP_CONTENT_DIR . '/shield';
	
	if ( is_dir($shield_dir) ) {
		$shield_dir = array( 'shield' );
	} else {
		$shield_dir = array();
	}

	## 15: Exclude the All in one wp migration folder if it exists
	$ai1wm_backups_dir = WP_CONTENT_DIR . '/ai1wm-backups';
	
	if ( is_dir($ai1wm_backups_dir) ) {
		$ai1wm_backups_dir = array( 'ai1wm-backups' );
	} else {
		$ai1wm_backups_dir = array();
	}

	## 15: Exclude the Endurance Page Cache folder if it exists
	$epc_cache_dir = WP_CONTENT_DIR . '/endurance-page-cache';
	
	if ( is_dir($epc_cache_dir) ) {
		$epc_cache_dir = array( 'endurance-page-cache' );
	} else {
		$epc_cache_dir = array();
	}

	## 15: Exclude the Hummingbird Cache folder if it exists
	$hummingbird_cache_dir = WP_CONTENT_DIR . '/wphb-cache';
	
	if ( is_dir($hummingbird_cache_dir) ) {
		$hummingbird_cache_dir = array( 'wphb-cache' );
	} else {
		$hummingbird_cache_dir = array();
	}

	## 15.3: Exclude the Themify Cache folder if it exists
	$themify_cache_dir = WP_CONTENT_DIR . '/tf_cache';
	
	if ( is_dir($themify_cache_dir) ) {
		$themify_cache_dir = array( 'tf_cache' );
	} else {
		$themify_cache_dir = array();
	}
	
	## 15.6: Exclude the WP Rocket Config folder if it exists
	$wp_rocket_config_dir = WP_CONTENT_DIR . '/wp-rocket-config';
	
	if ( is_dir($wp_rocket_config_dir) ) {
		$wp_rocket_config_dir = array( 'wp-rocket-config' );
	} else {
		$wp_rocket_config_dir = array();
	}

	## 15.6: Exclude the PeepSo folder if it exists
	$peepso_dir = WP_CONTENT_DIR . '/peepso';
	
	if ( is_dir($peepso_dir) ) {
		$peepso_dir = array( 'peepso' );
	} else {
		$peepso_dir = array();
	}

	## 15.9: Exclude the MalCare folder if it exists
	$malcare_dir = WP_CONTENT_DIR . '/mc_data';
	
	if ( is_dir($malcare_dir) ) {
		$malcare_dir = array( 'mc_data' );
	} else {
		$malcare_dir = array();
	}

	$wp_content_filter = array( 'wp-content' );
	$uniqueDirs1 = array_unique(array_diff( $path_parts_base, $wp_content_filter ));
	$uniqueDirs = array_merge( $uniqueDirs1, $plugins_dir, $mu_plugins_dir, $turdfence_dir1, $turdfence_dir2, $wp_languages_dir, $et_cache_dir, $litespeed_cache_dir, $ewww_cache_dir, $updraft_dir, $shield_dir, $ai1wm_backups_dir, $epc_cache_dir, $hummingbird_cache_dir, $themify_cache_dir, $wp_rocket_config_dir, $peepso_dir, $malcare_dir );
	sort($uniqueDirs);

/*	//Testing/Troubleshooting
	echo '<pre>';
	print_r($uniqueDirs);
	echo '</pre>';
*/
	
	$ARQExcludeOptions = get_option('bulletproof_security_options_exclude_folder');
	$ExcludeRulesArray = array();

	if ( is_array( $ARQExcludeOptions ) ) {

		foreach ( $ARQExcludeOptions as $key => $value ) {
			if ( ! preg_match('/_label/', $key, $matches ) && $value != '' ) {
				$ExcludeRulesArray[] = $value;
			}
		}
	}
	
	$Merged = array_unique(array_merge($ExcludeRulesArray, $uniqueDirs));
	sort($Merged);

/*//Testing/Troubleshooting
	echo '<pre>';
	print_r($Merged);
	echo '</pre>';
*/

	$bpsexclude_input_1  = ! empty($Merged[0]) ? $Merged[0] : '';
	$bpsexclude_input_2  = ! empty($Merged[1]) ? $Merged[1] : '';
	$bpsexclude_input_3  = ! empty($Merged[2]) ? $Merged[2] : '';
	$bpsexclude_input_4  = ! empty($Merged[3]) ? $Merged[3] : '';
	$bpsexclude_input_5  = ! empty($Merged[4]) ? $Merged[4] : '';
	$bpsexclude_input_6  = ! empty($Merged[5]) ? $Merged[5] : '';
	$bpsexclude_input_7  = ! empty($Merged[6]) ? $Merged[6] : '';
	$bpsexclude_input_8  = ! empty($Merged[7]) ? $Merged[7] : '';
	$bpsexclude_input_9  = ! empty($Merged[8]) ? $Merged[8] : '';
	$bpsexclude_input_10 = ! empty($Merged[9]) ? $Merged[9] : '';
	$bpsexclude_input_11 = ! empty($Merged[10]) ? $Merged[10] : '';
	$bpsexclude_input_12 = ! empty($Merged[11]) ? $Merged[11] : '';
	$bpsexclude_input_13 = ! empty($Merged[12]) ? $Merged[12] : '';
	$bpsexclude_input_14 = ! empty($Merged[13]) ? $Merged[13] : '';
	$bpsexclude_input_15 = ! empty($Merged[14]) ? $Merged[14] : '';
	$bpsexclude_input_16 = ! empty($Merged[15]) ? $Merged[15] : '';
	$bpsexclude_input_17 = ! empty($Merged[16]) ? $Merged[16] : '';
	$bpsexclude_input_18 = ! empty($Merged[17]) ? $Merged[17] : '';
	$bpsexclude_input_19 = ! empty($Merged[18]) ? $Merged[18] : '';
	$bpsexclude_input_20 = ! empty($Merged[19]) ? $Merged[19] : '';

	$bpsexclude_input_1_label  = ! empty($Merged[0]) ? 'Exclude '.$Merged[0].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_2_label  = ! empty($Merged[1]) ? 'Exclude '.$Merged[1].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_3_label  = ! empty($Merged[2]) ? 'Exclude '.$Merged[2].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_4_label  = ! empty($Merged[3]) ? 'Exclude '.$Merged[3].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_5_label  = ! empty($Merged[4]) ? 'Exclude '.$Merged[4].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_6_label  = ! empty($Merged[5]) ? 'Exclude '.$Merged[5].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_7_label  = ! empty($Merged[6]) ? 'Exclude '.$Merged[6].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_8_label  = ! empty($Merged[7]) ? 'Exclude '.$Merged[7].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_9_label  = ! empty($Merged[8]) ? 'Exclude '.$Merged[8].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_10_label = ! empty($Merged[9]) ? 'Exclude '.$Merged[9].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_11_label = ! empty($Merged[10]) ? 'Exclude '.$Merged[10].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_12_label = ! empty($Merged[11]) ? 'Exclude '.$Merged[11].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_13_label = ! empty($Merged[12]) ? 'Exclude '.$Merged[12].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_14_label = ! empty($Merged[13]) ? 'Exclude '.$Merged[13].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_15_label = ! empty($Merged[14]) ? 'Exclude '.$Merged[14].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_16_label = ! empty($Merged[15]) ? 'Exclude '.$Merged[15].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_17_label = ! empty($Merged[16]) ? 'Exclude '.$Merged[16].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_18_label = ! empty($Merged[17]) ? 'Exclude '.$Merged[17].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_19_label = ! empty($Merged[18]) ? 'Exclude '.$Merged[18].' Folder' : 'Exclude  Folder';
	$bpsexclude_input_20_label = ! empty($Merged[19]) ? 'Exclude '.$Merged[19].' Folder' : 'Exclude  Folder';

	// Populate the ARQ DB Options array values
	$bps_option_name = 'bulletproof_security_options_exclude_folder';
	$BPS_Options = array(
	'bpsexclude_input_1'  		=> $bpsexclude_input_1, 
	'bpsexclude_input_2'  		=> $bpsexclude_input_2, 
	'bpsexclude_input_3'  		=> $bpsexclude_input_3, 
	'bpsexclude_input_4'  		=> $bpsexclude_input_4, 
	'bpsexclude_input_5'  		=> $bpsexclude_input_5, 
	'bpsexclude_input_6'  		=> $bpsexclude_input_6, 
	'bpsexclude_input_7'  		=> $bpsexclude_input_7, 
	'bpsexclude_input_8'  		=> $bpsexclude_input_8, 
	'bpsexclude_input_9'  		=> $bpsexclude_input_9, 
	'bpsexclude_input_10'		=> $bpsexclude_input_10, 
	'bpsexclude_input_11' 		=> $bpsexclude_input_11, 
	'bpsexclude_input_12' 		=> $bpsexclude_input_12, 
	'bpsexclude_input_13' 		=> $bpsexclude_input_13, 
	'bpsexclude_input_14' 		=> $bpsexclude_input_14, 
	'bpsexclude_input_15'		=> $bpsexclude_input_15, 
	'bpsexclude_input_16' 		=> $bpsexclude_input_16, 
	'bpsexclude_input_17' 		=> $bpsexclude_input_17, 
	'bpsexclude_input_18' 		=> $bpsexclude_input_18, 
	'bpsexclude_input_19' 		=> $bpsexclude_input_19, 
	'bpsexclude_input_20' 		=> $bpsexclude_input_20, 
	'bpsexclude_input_1_label'  => $bpsexclude_input_1_label, 
	'bpsexclude_input_2_label'  => $bpsexclude_input_2_label, 
	'bpsexclude_input_3_label'  => $bpsexclude_input_3_label, 
	'bpsexclude_input_4_label'  => $bpsexclude_input_4_label, 
	'bpsexclude_input_5_label'  => $bpsexclude_input_5_label, 
	'bpsexclude_input_6_label'  => $bpsexclude_input_6_label, 
	'bpsexclude_input_7_label'  => $bpsexclude_input_7_label, 
	'bpsexclude_input_8_label'  => $bpsexclude_input_8_label, 
	'bpsexclude_input_9_label'  => $bpsexclude_input_9_label, 
	'bpsexclude_input_10_label' => $bpsexclude_input_10_label, 
	'bpsexclude_input_11_label' => $bpsexclude_input_11_label, 
	'bpsexclude_input_12_label' => $bpsexclude_input_12_label, 
	'bpsexclude_input_13_label' => $bpsexclude_input_13_label, 
	'bpsexclude_input_14_label' => $bpsexclude_input_14_label, 
	'bpsexclude_input_15_label' => $bpsexclude_input_15_label, 
	'bpsexclude_input_16_label' => $bpsexclude_input_16_label, 
	'bpsexclude_input_17_label' => $bpsexclude_input_17_label, 
	'bpsexclude_input_18_label' => $bpsexclude_input_18_label, 
	'bpsexclude_input_19_label' => $bpsexclude_input_19_label, 
	'bpsexclude_input_20_label' => $bpsexclude_input_20_label
	);

	if ( ! get_option( $bps_option_name ) ) {
		foreach( $BPS_Options as $key => $value ) {
			update_option('bulletproof_security_options_exclude_folder', $BPS_Options);

			if ( ! preg_match('/_label/', $key, $matches ) && $value != '' ) {
				
				$text = '<strong><font color="green">'.__('AutoRestore|Quarantine ', 'bulletproof-security').$value.__(' folder Exclude Rule DB Option saved or updated Successfully!', 'bulletproof-security').'</font></strong><br>';
				echo $text;
			}		
		}
	
	} else {

		foreach( $BPS_Options as $key => $value ) {
			update_option('bulletproof_security_options_exclude_folder', $BPS_Options);

			if ( ! preg_match('/_label/', $key, $matches ) && $value != '' ) {
				
				$text = '<strong><font color="green">'.__('AutoRestore|Quarantine ', 'bulletproof-security').$value.__(' folder Exclude Rule DB Option saved or updated Successfully!', 'bulletproof-security').'</font></strong><br>';
				echo $text;
			}		
		}	
	}
}

// Pre-installation Setup Wizard - Create the ARQ exclude filters in class.php & copy class.php to the /master-backups folder
// Create a new class.php file from class-BAK.php first so that exclude rules will be created correctly
function bpsSetupWizardARQExcludeFile() {
	if (current_user_can('manage_options')) {
$options = get_option('bulletproof_security_options_exclude_folder'); 
$bpsClassFile = WP_PLUGIN_DIR . '/bulletproof-security/includes/class.php';
$bpsClassBAKFile = WP_PLUGIN_DIR . '/bulletproof-security/includes/class-BAK.php';
$bpsClassFileARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/includes/class.php';		
$bpsClassFileARQMB = WP_CONTENT_DIR . '/bps-backup/master-backups/class.php';		

	if ( file_exists($bpsClassBAKFile) ) {	
		
		if ( copy($bpsClassBAKFile, $bpsClassFile ) ) {
			
			$stringReplace = @file_get_contents($bpsClassFile);
	
		if ( $options['bpsexclude_input_1'] != '' ) {
			$stringReplace = str_replace("bps-hard-exclude001", $options['bpsexclude_input_1'], $stringReplace);
		}
		if ( $options['bpsexclude_input_2'] != '' ) {
			$stringReplace = str_replace("bps-hard-exclude002", $options['bpsexclude_input_2'], $stringReplace);
		}
		if ( $options['bpsexclude_input_3'] != '' ) {
			$stringReplace = str_replace("bps-hard-exclude003", $options['bpsexclude_input_3'], $stringReplace);
		}
		if ( $options['bpsexclude_input_4'] != '' ) {		
			$stringReplace = str_replace("bps-hard-exclude004", $options['bpsexclude_input_4'], $stringReplace);
		}
		if ( $options['bpsexclude_input_5'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude005", $options['bpsexclude_input_5'], $stringReplace);
		}
		if ( $options['bpsexclude_input_6'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude006", $options['bpsexclude_input_6'], $stringReplace);
		}
		if ( $options['bpsexclude_input_7'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude007", $options['bpsexclude_input_7'], $stringReplace);
		}
		if ( $options['bpsexclude_input_8'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude008", $options['bpsexclude_input_8'], $stringReplace);
		}
		if ( $options['bpsexclude_input_9'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude009", $options['bpsexclude_input_9'], $stringReplace);
		}
		if ( $options['bpsexclude_input_10'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude010", $options['bpsexclude_input_10'], $stringReplace);
		}
		if ( $options['bpsexclude_input_11'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude011", $options['bpsexclude_input_11'], $stringReplace);
		}
		if ( $options['bpsexclude_input_12'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude012", $options['bpsexclude_input_12'], $stringReplace);
		}
		if ( $options['bpsexclude_input_13'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude013", $options['bpsexclude_input_13'], $stringReplace);
		}
		if ( $options['bpsexclude_input_14'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude014", $options['bpsexclude_input_14'], $stringReplace);
		}
		if ( $options['bpsexclude_input_15'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude015", $options['bpsexclude_input_15'], $stringReplace);
		}
		if ( $options['bpsexclude_input_16'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude016", $options['bpsexclude_input_16'], $stringReplace);
		}
		if ( $options['bpsexclude_input_17'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude017", $options['bpsexclude_input_17'], $stringReplace);
		}
		if ( $options['bpsexclude_input_18'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude018", $options['bpsexclude_input_18'], $stringReplace);
		}
		if ( $options['bpsexclude_input_19'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude019", $options['bpsexclude_input_19'], $stringReplace);
		}
		if ( $options['bpsexclude_input_20'] != '' ) {	
			$stringReplace = str_replace("bps-hard-exclude020", $options['bpsexclude_input_20'], $stringReplace);
		}
		}

			if ( ! file_put_contents($bpsClassFile, $stringReplace) ) {
				$text = '<br><strong><font color="#fb0101">'.__('Error: Unable to write to /bulletproof-security/includes/class.php file to create ARQ Exclude Rules.', 'bulletproof-security').'</font></strong><br>';
				echo $text;	
   			} else {
				if ( is_dir( WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/includes' ) ) {
					@copy($bpsClassFile, $bpsClassFileARQ);
				}
				
				@copy($bpsClassFile, $bpsClassFileARQMB);
				
				foreach( $options as $key => $value ) {
					
					if ( ! preg_match('/_label/', $key, $matches ) && $value != '' ) {
					
						$text1 = '<strong><font color="green">'.__('AutoRestore|Quarantine ', 'bulletproof-security').$value.__(' folder Exclude Rule created or updated Successfully!', 'bulletproof-security').'</font></strong><br>';
						echo $text1;
					}
				}
				$text2 = '<strong><font color="green">'.$bpsClassFile.__(' File created or updated Successfully!', 'bulletproof-security').'<br>'.$bpsClassFileARQMB.__(' File copied to backup Successfully!', 'bulletproof-security').'<br>'.$bpsClassFileARQ.__(' File copied to ARQ backup Successfully!', 'bulletproof-security').'</font></strong><br>';
				echo $text2;	
			}	
	}
	}
}

// Pre-installation Setup Wizard - Enable|Disable htaccess Files: htaccess Files Disabled 
// Deletes all htaccess files: /bps-backup/.htaccess, /master-backups/.htaccess, Root, /wp-admin/, /plugins/, /uploads/ and all BPS Core folder htaccess files.
// ARQ: /root-files/auto_.htaccess, /wp-admin/wpadmin.htaccess and /wp-content/plugins/.htaccess
function bpsSetupWizard_delete_htaccess_files() {

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

		$bps_backup = WP_CONTENT_DIR . '/bps-backup/.htaccess';
		$bps_master_backups = WP_CONTENT_DIR . '/bps-backup/master-backups/.htaccess';
		$root_htaccess = ABSPATH . '.htaccess';		
		$root_htaccess_ARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/root-files/auto_.htaccess';
		$wpadmin_htaccess = ABSPATH . 'wp-admin/.htaccess';
		$wpadmin_htaccess_ARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-admin/wpadmin.htaccess';
		$plugins_htaccess = WP_PLUGIN_DIR . '/.htaccess';
		$plugins_htaccess_ARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/.htaccess';
		$uploads_dir = wp_upload_dir();	
		$uploads_htaccess = $uploads_dir['basedir'] . '/.htaccess';

		$bpsPro_pf = WP_PLUGIN_DIR . '/bulletproof-security/';
		$core1 = $bpsPro_pf  . 'admin/activation/.htaccess';	
		$core2 = $bpsPro_pf  . 'admin/autorestore/.htaccess';
		$core3 = $bpsPro_pf  . 'admin/core/.htaccess';
		$core4 = $bpsPro_pf  . 'admin/db-backup-security/.htaccess';
		$core5 = $bpsPro_pf  . 'admin/db-monitor/.htaccess';
		$core6 = $bpsPro_pf  . 'admin/htaccess/.htaccess';
		$core7 = $bpsPro_pf  . 'admin/install/.htaccess';
		$core8 = $bpsPro_pf  . 'admin/lock/.htaccess';
		$core9 = $bpsPro_pf  . 'admin/login/.htaccess';
		$core10 = $bpsPro_pf . 'admin/maintenance/.htaccess';
		$core11 = $bpsPro_pf . 'admin/monitor/.htaccess';	
		$core12 = $bpsPro_pf . 'admin/php/.htaccess';	
		$core13 = $bpsPro_pf . 'admin/quarantine/.htaccess';	
		$core14 = $bpsPro_pf . 'admin/security-log/.htaccess';
		$core15 = $bpsPro_pf . 'admin/system-info/.htaccess';
		$core16 = $bpsPro_pf . 'admin/theme-skin/.htaccess';	
		$core17 = $bpsPro_pf . 'admin/tools/.htaccess';
		$core18 = $bpsPro_pf . 'admin/wizard/.htaccess';	
		$core19 = $bpsPro_pf . 'admin/xternal/.htaccess';
		$core20 = $bpsPro_pf . 'admin/mscan/.htaccess';	

		$files = array( $bps_backup, $bps_master_backups, $root_htaccess, $root_htaccess_ARQ, $wpadmin_htaccess, $wpadmin_htaccess_ARQ, $plugins_htaccess, $plugins_htaccess_ARQ, $uploads_htaccess, $core1, $core2, $core3, $core4, $core5, $core6, $core7, $core8, $core9, $core10, $core11, $core12, $core13, $core14, $core15, $core16, $core17, $core18, $core19, $core20 );
	
		$HFiles_options = get_option('bulletproof_security_options_htaccess_files');
				
		if ( $HFiles_options['bps_htaccess_files'] == 'disabled' ) {

			foreach ( $files as $file ) {

				if ( file_exists($file) ) {
					unlink($file);
				}
			}
			echo '<strong><font color="blue">'.__('htaccess Files Disabled: Existing BPS htaccess files have been deleted and new BPS htaccess files will not be created. All BPS htaccess features are disabled.', 'bulletproof-security').' '.__('Click this link for help information: ', 'bulletproof-security').'</font></strong><a href="https://forum.ait-pro.com/forums/topic/htaccess-files-disabled-setup-wizard-enable-disable-htaccess-files/" target="_blank" title="htaccess Files Disabled Forum Topic">'.__('htaccess Files Disabled Forum Topic', 'bulletproof-security').'</a><br>';
		}
	}
}

function bspPro_bps_free_mu_files_cleanup() {
	
	$autoupdate_muplugins_file = WP_CONTENT_DIR . '/mu-plugins/bps-plugin-autoupdate.php';
	$bps_mu_tools_muplugins_file = WP_CONTENT_DIR . '/mu-plugins/bps-mu-tools.php';
	
	if ( file_exists($autoupdate_muplugins_file) ) {
		unlink($autoupdate_muplugins_file);
	}	
	if ( file_exists($bps_mu_tools_muplugins_file) ) {
		unlink($bps_mu_tools_muplugins_file);
	}
}

// Pre-save UI|UX DB option settings to avoid doing additional Form coding work for PHP 7.4.9 Notice errors
function bpsPro_presave_uiux_settings() {
	
	// Theme Skin
	$UITSoptions = get_option('bulletproof_security_options_theme_skin');
	$uits = ! isset($UITSoptions['bps_ui_theme_skin']) ? 'blue' : $UITSoptions['bps_ui_theme_skin'];
	$uits_options = array('bps_ui_theme_skin' => $uits);

	foreach( $uits_options as $key => $value ) {
		update_option('bulletproof_security_options_theme_skin', $uits_options);
	}

	// Processing Spinner
	$UISpinneroptions = get_option('bulletproof_security_options_spinner');
	$uips = ! isset($UISpinneroptions['bps_spinner']) ? 'On' : $UISpinneroptions['bps_spinner'];
	$uips_options = array('bps_spinner' => $uips);

	foreach( $uips_options as $key => $value ) {
		update_option('bulletproof_security_options_spinner', $uips_options);
	}

	// ScrollTop Animation
	$ScrollTopoptions = get_option('bulletproof_security_options_scrolltop');
	$uist = ! isset($ScrollTopoptions['bps_scrolltop']) ? 'On' : $ScrollTopoptions['bps_scrolltop'];
	$uist_options = array('bps_scrolltop' => $uist);

	foreach( $uist_options as $key => $value ) {
		update_option('bulletproof_security_options_scrolltop', $uist_options);
	}
	
	// WP Toolbar Functionality in BPS plugin pages		
	$UIWPToptions = get_option('bulletproof_security_options_wpt_nodes');
	$uiwpt = ! isset($UIWPToptions['bps_wpt_nodes']) ? 'allnodes' : $UIWPToptions['bps_wpt_nodes'];
	$uiwpt_options = array('bps_wpt_nodes' => $uiwpt);

	foreach( $uiwpt_options as $key => $value ) {
		update_option('bulletproof_security_options_wpt_nodes', $uiwpt_options);
	}		

	// Script|Style Loader Filter (SLF) In BPS Plugin Pages	
	$UISLFoptions = get_option('bulletproof_security_options_SLF');
	$uislf1 = ! isset($UISLFoptions['bps_slf_filter']) ? 'On' : $UISLFoptions['bps_slf_filter'];
	$uislf2 = ! isset($UISLFoptions['bps_slf_filter_new']) ? '14' : $UISLFoptions['bps_slf_filter_new'];	
	$uislf_options = array(
	'bps_slf_filter' 		=> $uislf1, 
	'bps_slf_filter_new' 	=> $uislf2
	);

	foreach( $uislf_options as $key => $value ) {
		update_option('bulletproof_security_options_SLF', $uislf_options);
	}

	// BPS UI|UX|AutoFix Debug
	$UIDebug_options = get_option('bulletproof_security_options_debug');
	$uidb = ! isset($UIDebug_options['bps_debug']) ? 'Off' : $UIDebug_options['bps_debug'];
	$uidb_options = array('bps_debug' => $uidb);

	foreach( $uidb_options as $key => $value ) {
		update_option('bulletproof_security_options_debug', $uidb_options);
	}
}

// Pre-save the Setup Wizard Options DB option settings to avoid doing additional Form coding work for PHP 7.4.9 Notice errors
function bpsPro_presave_setupwizard_option_settings() {
	
	// AutoFix
	$AutoFix_Options = get_option('bulletproof_security_options_wizard_autofix');
	$swoaf = ! isset($AutoFix_Options['bps_wizard_autofix']) ? 'On' : $AutoFix_Options['bps_wizard_autofix'];
	$SWOAF_options = array('bps_wizard_autofix' => $swoaf);

	foreach( $SWOAF_options as $key => $value ) {
		update_option('bulletproof_security_options_wizard_autofix', $SWOAF_options);
	}		
	
	// GDPR Compliance
	$GDPR_Options = get_option('bulletproof_security_options_gdpr');	
	$swgdpr = ! isset($GDPR_Options['bps_gdpr_on_off']) ? 'Off' : $GDPR_Options['bps_gdpr_on_off'];
	$SWGDPR_options = array('bps_gdpr_on_off' => $swgdpr);

	foreach( $SWGDPR_options as $key => $value ) {
		update_option('bulletproof_security_options_gdpr', $SWGDPR_options);
	}		
	
	// cURL Scan & DB Monitor
	$CURL_options = get_option('bulletproof_security_options_wizard_curl');
	$swcurl1 = ! isset($CURL_options['bps_wizard_curl_scan']) ? 'Off' : $CURL_options['bps_wizard_curl_scan'];
	$swcurl2 = ! isset($CURL_options['bps_wizard_dbm_settings']) ? 'On' : $CURL_options['bps_wizard_dbm_settings'];
	$SWCURL_options = array(
	'bps_wizard_curl_scan' 		=> $swcurl1, 
	'bps_wizard_dbm_settings' 	=> $swcurl2
	);

	foreach( $SWCURL_options as $key => $value ) {
		update_option('bulletproof_security_options_wizard_curl', $SWCURL_options);
	}		
	
	// GDMW 
	$GDMW_options = get_option('bulletproof_security_options_GDMW');
	$swgdmw = ! isset($GDMW_options['bps_gdmw_hosting']) ? 'no' : $GDMW_options['bps_gdmw_hosting'];
	$SWGDMW_options = array('bps_gdmw_hosting' => $swgdmw);

	foreach( $SWGDMW_options as $key => $value ) {
		update_option('bulletproof_security_options_GDMW', $SWGDMW_options);
	}		
	
	// Enable|Disable htaccess files
	$HFiles_options = get_option('bulletproof_security_options_htaccess_files');		
	$swhf = ! isset($HFiles_options['bps_htaccess_files']) ? 'enabled' : $HFiles_options['bps_htaccess_files'];
	$SWHF_options = array('bps_htaccess_files' => $swhf);

	foreach( $SWHF_options as $key => $value ) {
		update_option('bulletproof_security_options_htaccess_files', $SWHF_options);
	}		
				
	// Enable|Disable wp-admin BulletProof Mode
	$BPS_wpadmin_Options = get_option('bulletproof_security_options_htaccess_res');
	$swwhf = ! isset($BPS_wpadmin_Options['bps_wpadmin_restriction']) ? 'enabled' : $BPS_wpadmin_Options['bps_wpadmin_restriction'];
	$SWWHF_options = array('bps_wpadmin_restriction' => $swwhf);

	foreach( $SWWHF_options as $key => $value ) {
		update_option('bulletproof_security_options_htaccess_res', $SWWHF_options);
	}

	// Zip File Download Fix
	$Zip_download_Options = get_option('bulletproof_security_options_zip_fix');
	$swzd = ! isset($Zip_download_Options['bps_zip_download_fix']) ? 'Off' : $Zip_download_Options['bps_zip_download_fix'];
	$SWZD_options = array('bps_zip_download_fix' => $swzd);

	foreach( $SWZD_options as $key => $value ) {
		update_option('bulletproof_security_options_zip_fix', $SWZD_options);
	}		

	// Multisite Hide|Display System Info Page for Subsites
	$Mu_Sysinfo_page_options = get_option('bulletproof_security_options_mu_sysinfo');
	$swmus = ! isset($Mu_Sysinfo_page_options['bps_sysinfo_hide_display']) ? 'display' : $Mu_Sysinfo_page_options['bps_sysinfo_hide_display'];
	$SWMUS_options = array('bps_sysinfo_hide_display' => $swmus);

	foreach( $SWMUS_options as $key => $value ) {
		update_option('bulletproof_security_options_mu_sysinfo', $SWMUS_options);
	}	
}
?>