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

/****************************************/
# BEGIN Folder Lock Scan
/****************************************/
// Drop the existing Folder Lock DB Table, Create a new DB Table, insert new DB Rows.
// Include wp-admin, wp-content and wp-includes folders if they are in the Hosting Root folder.
// Not using the orig_perms db column at this point, maybe later on. See DW file code.
function bpsPro_SWizard_flock_folder_scan() {

	if ( current_user_can('manage_options') ) {

		global $wpdb, $bps_wpcontent_dir, $bps_topDiv, $bps_bottomDiv;	
	
		$source = $_SERVER['DOCUMENT_ROOT'];
		$FLtable_name = $wpdb->prefix . "bpspro_folder_lock";
		$wpdb_collate = $wpdb->collate;
	
		if ( $wpdb->query("DROP TABLE IF EXISTS $FLtable_name") ) {	
	
			if ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $FLtable_name ) ) != $FLtable_name ) {	
	
			$sql = "CREATE TABLE $FLtable_name (
			id bigint(20) NOT NULL auto_increment,
			folder_name text NOT NULL,
			status varchar(60) NOT NULL default '',
			curr_perms varchar(4) NOT NULL default '',
			orig_perms varchar(4) NOT NULL default '',
			path text NOT NULL,
			last_mod varchar(10) NOT NULL default '',
			ulock_time varchar(10) NOT NULL default '',
			hlock_time datetime NOT NULL default '0000-00-00 00:00:00',
			UNIQUE KEY id (id)
			)
			COLLATE {$wpdb_collate};";
	
			require_once ABSPATH . 'wp-admin/includes/upgrade.php';
			dbDelta($sql);
			}
		}
	
		if ( is_dir($source) ) {
			
			$iterator = new DirectoryIterator($source);	
	
			foreach ( $iterator as $files ) {
				
				try {
					if ( $files->isDir() && ! $files->isDot() ) {
	
						// test this on a testing site that only has the default wp folders and no other hosting account folders
						if ( empty( $files ) ) {
					
						} else {
	
							// maybe filter these later if there is a problem: if ( $files != $bps_wpcontent_dir && $files != 'wp-admin' && $files != 'wp-includes' ) {
							if ( $insert_rows = $wpdb->insert( $FLtable_name, array( 'folder_name' => $files->getFilename(), 'status' => 'Not Locked', 'curr_perms' => substr(sprintf('%o', $files->getPerms()), -4), 'path' => $files->getPathname(), 'last_mod' => $files->getMTime(), 'ulock_time' => time(), 'hlock_time' => current_time('mysql') ) ) ) {
					
							}
						}
					}
				} catch (RuntimeException $e) {}
			}
		}
	}
}

/****************************************/
# END Folder Lock Scan
/****************************************/

?>