<?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();
}
	
// Form: ARQ Exclude wp-content folders
// Save DB options, copy new class.php file & do string replacements in the class.php file filter code
// ARQ is turned Off and then turned back On if form values are valid.
if ( isset( $_POST['Submit-ARQ-wpcontent-Exclude'] ) && current_user_can('manage_options') ) {
	check_admin_referer( 'bulletproof_security_arq_wpcontent_exclude' );
	
	$ExcludePaths = array( $_POST['bpsexclude_input_1'], $_POST['bpsexclude_input_2'], $_POST['bpsexclude_input_3'], $_POST['bpsexclude_input_4'], $_POST['bpsexclude_input_5'], $_POST['bpsexclude_input_6'], $_POST['bpsexclude_input_7'], $_POST['bpsexclude_input_8'], $_POST['bpsexclude_input_9'], $_POST['bpsexclude_input_10'], $_POST['bpsexclude_input_11'], $_POST['bpsexclude_input_12'], $_POST['bpsexclude_input_13'], $_POST['bpsexclude_input_14'], $_POST['bpsexclude_input_15'], $_POST['bpsexclude_input_16'], $_POST['bpsexclude_input_17'], $_POST['bpsexclude_input_18'], $_POST['bpsexclude_input_19'], $_POST['bpsexclude_input_20'] );

	$wpce_error = 0;
	
	foreach ( $ExcludePaths as $ExcludePath ) {
		$pos = strpos( $ExcludePath, $bps_wpcontent_dir );
		
		if ( $pos !== false ) {
			$wpce_error = 1;
			
			echo $bps_topDiv;
			$text = '<strong><font color="#fb0101">'.__('Error: Incorrect Folder Exclude rule.', 'bulletproof-security').'</font><br>'.__('The Folder Exclude rule: ', 'bulletproof-security').$ExcludePath.__(' has ', 'bulletproof-security').$bps_wpcontent_dir.__(' in the folder exclude rule path. Click the Read Me help button to see examples of valid folder exclude paths.', 'bulletproof-security').'</strong><br>';
			echo $text;
			echo $bps_bottomDiv;
		}
	
		if ( ! is_dir( WP_CONTENT_DIR .'/'. $ExcludePath ) ) {	
			$wpce_error = 1;
			
			echo $bps_topDiv;
			$text = '<strong><font color="#fb0101">'.__('Error: Incorrect Folder Exclude rule.', 'bulletproof-security').'</font><br>'.__('The Folder Exclude rule: ', 'bulletproof-security').$ExcludePath.__(' is not a valid folder name/path or the folder does not exist under the wp-content folder. Click the Read Me help button to see examples of valid folder exclude rules/paths.', 'bulletproof-security').'</strong><br>';
			echo $text;
			echo $bps_bottomDiv;
		}
	}
	
	if ( $wpce_error != 1 ) {

	$ARQ_wpce_Options = array(
	'bpsexclude_input_1'  		=> esc_html($_POST['bpsexclude_input_1']), 
	'bpsexclude_input_2'  		=> esc_html($_POST['bpsexclude_input_2']), 
	'bpsexclude_input_3'  		=> esc_html($_POST['bpsexclude_input_3']), 
	'bpsexclude_input_4'  		=> esc_html($_POST['bpsexclude_input_4']), 
	'bpsexclude_input_5'  		=> esc_html($_POST['bpsexclude_input_5']), 
	'bpsexclude_input_6' 		=> esc_html($_POST['bpsexclude_input_6']), 
	'bpsexclude_input_7'  		=> esc_html($_POST['bpsexclude_input_7']), 
	'bpsexclude_input_8'  		=> esc_html($_POST['bpsexclude_input_8']), 
	'bpsexclude_input_9'  		=> esc_html($_POST['bpsexclude_input_9']), 
	'bpsexclude_input_10' 		=> esc_html($_POST['bpsexclude_input_10']), 
	'bpsexclude_input_11' 		=> esc_html($_POST['bpsexclude_input_11']), 
	'bpsexclude_input_12' 		=> esc_html($_POST['bpsexclude_input_12']), 
	'bpsexclude_input_13' 		=> esc_html($_POST['bpsexclude_input_13']), 
	'bpsexclude_input_14' 		=> esc_html($_POST['bpsexclude_input_14']), 
	'bpsexclude_input_15' 		=> esc_html($_POST['bpsexclude_input_15']), 
	'bpsexclude_input_16'		=> esc_html($_POST['bpsexclude_input_16']), 
	'bpsexclude_input_17' 		=> esc_html($_POST['bpsexclude_input_17']), 
	'bpsexclude_input_18' 		=> esc_html($_POST['bpsexclude_input_18']), 
	'bpsexclude_input_19' 		=> esc_html($_POST['bpsexclude_input_19']), 
	'bpsexclude_input_20' 		=> esc_html($_POST['bpsexclude_input_20']), 
	'bpsexclude_input_1_label'  => $_POST['bpsexclude_input_1_label'], 
	'bpsexclude_input_2_label'  => $_POST['bpsexclude_input_2_label'], 
	'bpsexclude_input_3_label'  => $_POST['bpsexclude_input_3_label'], 
	'bpsexclude_input_4_label'  => $_POST['bpsexclude_input_4_label'], 
	'bpsexclude_input_5_label'  => $_POST['bpsexclude_input_5_label'], 
	'bpsexclude_input_6_label'  => $_POST['bpsexclude_input_6_label'], 
	'bpsexclude_input_7_label'  => $_POST['bpsexclude_input_7_label'], 
	'bpsexclude_input_8_label'  => $_POST['bpsexclude_input_8_label'], 
	'bpsexclude_input_9_label'  => $_POST['bpsexclude_input_9_label'], 
	'bpsexclude_input_10_label' => $_POST['bpsexclude_input_10_label'], 
	'bpsexclude_input_11_label' => $_POST['bpsexclude_input_11_label'], 
	'bpsexclude_input_12_label' => $_POST['bpsexclude_input_12_label'], 
	'bpsexclude_input_13_label' => $_POST['bpsexclude_input_13_label'], 
	'bpsexclude_input_14_label' => $_POST['bpsexclude_input_14_label'], 
	'bpsexclude_input_15_label' => $_POST['bpsexclude_input_15_label'], 
	'bpsexclude_input_16_label' => $_POST['bpsexclude_input_16_label'], 
	'bpsexclude_input_17_label' => $_POST['bpsexclude_input_17_label'], 
	'bpsexclude_input_18_label' => $_POST['bpsexclude_input_18_label'], 
	'bpsexclude_input_19_label' => $_POST['bpsexclude_input_19_label'], 
	'bpsexclude_input_20_label' => $_POST['bpsexclude_input_20_label'] 
	);
	
	foreach( $ARQ_wpce_Options as $key => $value ) {
		update_option('bulletproof_security_options_exclude_folder', $ARQ_wpce_Options);
	}	
	
	$bpsClassFile = WP_PLUGIN_DIR . '/bulletproof-security/includes/class.php';
	$bpsClassFileBAK = WP_PLUGIN_DIR . '/bulletproof-security/includes/class-BAK.php';	
	$bpsClassFileARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/includes/class.php';		
	$bpsClassFileARQBAK = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/includes/class-BAK.php';
	$bpsClassFileARQMB = WP_CONTENT_DIR . '/bps-backup/master-backups/class.php';
			
	$ARQoptions = get_option('bulletproof_security_options_ARCM');	
	
	$ARQoptions1 = ! $ARQoptions['bps_autorestore_cron_frequency'] ? '2' : $ARQoptions['bps_autorestore_cron_frequency'];	
	$ARQoptions2 = 'Off';
	$ARQoptions3 = ! $ARQoptions['bps_autorestore_cron_override'] ? 'Off' : $ARQoptions['bps_autorestore_cron_override'];
	$ARQoptions4 = ! $ARQoptions['bps_autorestore_cron_filecheck'] ? 'On' : $ARQoptions['bps_autorestore_cron_filecheck'];
	$ARQoptions5 = ! $ARQoptions['bps_autorestore_cron_forced'] ? '1' : $ARQoptions['bps_autorestore_cron_forced'];
	$ARQoptions6 = ! $ARQoptions['bps_autorestore_cron_end'] ? '' : $ARQoptions['bps_autorestore_cron_end'];

	$ARQ_WPCE_Options = array(
	'bps_autorestore_cron_frequency' 	=> $ARQoptions1, 
	'bps_autorestore_cron' 				=> $ARQoptions2, 
	'bps_autorestore_cron_override' 	=> $ARQoptions3, 
	'bps_autorestore_cron_filecheck' 	=> $ARQoptions4, 
	'bps_autorestore_cron_forced' 		=> $ARQoptions5, 
	'bps_autorestore_cron_end' 			=> $ARQoptions6
	);

	foreach( $ARQ_WPCE_Options as $key => $value ) {
		update_option('bulletproof_security_options_ARCM', $ARQ_WPCE_Options);
	}

	if ( file_exists($bpsClassFile) ) {
	
		if ( ! copy($bpsClassFileBAK, $bpsClassFile) ) {
		
			echo $bps_topDiv;
			$text = '<font color="#fb0101"><strong>'.__('Error: Failed to copy the ', 'bulletproof-security').$bpsClassFileBAK.__(' file to ', 'bulletproof-security').$bpsClassFile.'</strong></font><br>';
			echo $text;
			echo $bps_bottomDiv;
   	
		} else {
			
			@copy($bpsClassFileBAK, $bpsClassFileARQBAK);
			@copy($bpsClassFile, $bpsClassFileARQ);
			@copy($bpsClassFile, $bpsClassFileARQMB);
				
			$options = get_option('bulletproof_security_options_exclude_folder');				
			$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) ) {

				echo $bps_topDiv;
				$text = '<font color="#fb0101"><strong>'.__('Error: Failed to create the ARQ wp-content Exclude Filters in the class.php file: ', 'bulletproof-security').$bpsClassFile.__(' Your ARQ wp-content folder exclude rules were not created succesfully. Re-run the BPS Setup Wizards again. Go the BPS Pro forum website: forum.ait-pro.com, create a new forum topic and post this error message for assistance.', 'bulletproof-security').'</strong></font><br>';
				echo $text;
				echo $bps_bottomDiv;
   	
			} else {
	
				@copy($bpsClassFile, $bpsClassFileARQ);
				@copy($bpsClassFile, $bpsClassFileARQMB);
		
				echo $bps_topDiv;
				$text = '<font color="green"><strong>'.__('Your wp-content Folder Exclude Rules have been updated successfully!', 'bulletproof-security').'<br>'.__('AutoRestore is automatically turned Off when adding or removing wp-content folder exclude rules as a safety precaution.', 'bulletproof-security').'<br>'.__('Before turning AutoRestore back On do these steps below: (You can click the Save Folder Exclude Rules button again to see these steps again)', 'bulletproof-security').'<br>'.__('1. Click the AutoRestore|Quarantine tab page and scroll down to the AutoRestore|Quarantine Controls & Backup Status section.', 'bulletproof-security').'<br>'.__('2. Click the wp-content Files Backup Files button to backup wp-content files again.', 'bulletproof-security').'<br>'.__('3. Turn AutoRestore On.', 'bulletproof-security').'</strong></font>';
				echo $text;
				echo $bps_bottomDiv;			
			}	
		}	
	}
	}	
}

?>