<?php
/*
Plugin Name: BulletProof Security Pro
Plugin URI: https://forum.ait-pro.com/forums/forum/bulletproof-security-pro/
Description: <strong>Feature Highlights:</strong> Setup Wizard &bull; AutoRestore|Quarantine (ARQ IDPS): Real-time File Monitor (IDPS) &bull; MScan Malware Scanner &bull; Plugin Firewall (IP Firewall) &bull; JTC Anti-Spam|Anti-Hacker &bull; Uploads Anti-Exploit Guard (UAEG) &bull; .htaccess Website Security Protection (Firewalls) &bull; DB Monitor (IDS) &bull; DB Backup &bull; DB Diff Tool &bull; DB Table Prefix Changer &bull; Login Security & Monitoring &bull; Idle Session Logout (ISL) &bull; Auth Cookie Expiration (ACE) &bull; S-Monitor: Monitoring & Alerting Control Core &bull; UI Theme Skin Changer &bull; System Info: Extensive System, Server and Security Status Information &bull; DB Status & Info: Extensive Database Information &bull; Force Strong Passwords &bull; FrontEnd|BackEnd Maintenance Mode &bull; Pro-Tools: 16 mini-plugins.
Text Domain: bulletproof-security
Domain Path: /languages/
Version: 15.9
Author: AITpro Website Security
Author URI: https://forum.ait-pro.com/forums/forum/bulletproof-security-pro/
*/

#  ________         ____________      _____ ________                       ________      
#  ___  __ )____  _____  /___  /_____ __  /____  __ \______________ ______ ___  __/      
#  __  __  |_  / / /__  / __  / _  _ \_  __/__  /_/ /__  ___/_  __ \_  __ \__  /_        
#  _  /_/ / / /_/ / _  /  _  /  /  __// /_  _  ____/ _  /    / /_/ // /_/ /_  __/        
#  /_____/  \__,_/  /_/   /_/   \___/ \__/  /_/      /_/     \____/ \____/ /_/           
#  ________                             _____ _____              ________                
#  __  ___/_____ ___________  _____________(_)__  /______  __    ___  __ \______________ 
#  _____ \ _  _ \_  ___/_  / / /__  ___/__  / _  __/__  / / /    __  /_/ /__  ___/_  __ \
#  ____/ / /  __// /__  / /_/ / _  /    _  /  / /_  _  /_/ /     _  ____/ _  /    / /_/ /
#  /____/  \___/ \___/  \__,_/  /_/     /_/   \__/  _\__, /      /_/      /_/     \____/ 
#                                                   /____/                               
# 42756C6C657450726F6F66 5365637572697479 50726F 

/*	The Copyright, AITpro Software Products License Information must remain
	intact or all BulletProof Security Pro warranties, guarantees, liabilities are void.
	
	Copyright (C) Edward Alexander, AIT-pro.com. All rights reserved.

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

// BPS Pro Global variables
// 13.9: It is not a mistake or retarded to add the global keyword to global variables outside of functions per PHP.net, but yeah it does appear to be retarded. 
// WP_CLI requires that all global variables outside of functions MUST explicitly use the global keyword since WP_CLI loads WP within a function
// and cannot access the global variables within functions in BPS. Luckily this does not break BPS or WordPress in any way and PHP.net states this is technically not an error.
global $bpspro_plugin, $bpspro_abbr, $bpspro_last_version, $bpspro_version, $bpspro_edition, $bpspro_url, $bpsPro_api_url, $bps_plugin_slug, $bulletproof_security_arq_db_version, $aitpro_bullet, $bps_topDiv, $bps_bottomDiv, $bpsPro_remote_addr, $bpsPro_http_client_ip, $bpsPro_http_forwarded, $bpsPro_http_x_forwarded_for, $bpsPro_http_x_cluster_client_ip, $bps_wpcontent_dir, $bps_plugin_dir, $plugin_hashes, $theme_hashes;

define( 'BULLETPROOF_VERSION', '15.9' );
$bpspro_plugin = 'BulletProof Security Pro';
$bpspro_abbr = 'BPS Pro';
$bpspro_last_version = '15.8';
$bpspro_version = '15.9';
$bpspro_edition = 'Professional Edition';
$bpspro_url = 'https://api.ait-pro.com/';
$bpsPro_api_url = 'https://api.ait-pro.com/';
$bps_plugin_slug = basename(dirname(__FILE__));
$bulletproof_security_arq_db_version = "5.1.8";
$aitpro_bullet = '<img src="'.plugins_url('/bulletproof-security/admin/images/aitpro-bullet.png').'" style="padding:0px 3px 0px 3px;" />';
// Top div & bottom div
$bps_topDiv = '<div id="message" class="updated" style="background-color:#dfecf2;border:1px solid #999;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><p>';
$bps_bottomDiv = '</p></div>';
$bps_wpcontent_dir = str_replace( ABSPATH, '', WP_CONTENT_DIR );
$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );

// Setup Wizard Options: GDPR Compliance Global Variables
$GDPR_Options = get_option('bulletproof_security_options_gdpr');

if ( isset( $GDPR_Options['bps_gdpr_on_off'] ) && $GDPR_Options['bps_gdpr_on_off'] != 'On' ) {

	$bpsPro_remote_addr = false;
	if ( array_key_exists('REMOTE_ADDR', $_SERVER) ) {
	$bpsPro_remote_addr = $_SERVER['REMOTE_ADDR'];
	}	
	$bpsPro_http_client_ip = false;
	if ( array_key_exists('HTTP_CLIENT_IP', $_SERVER) ) {
	$bpsPro_http_client_ip = $_SERVER['HTTP_CLIENT_IP'];
	}
	$bpsPro_http_forwarded = false;
	if ( array_key_exists('HTTP_FORWARDED', $_SERVER) ) {
	$bpsPro_http_forwarded = $_SERVER['HTTP_FORWARDED'];
	}
	$bpsPro_http_x_forwarded_for = false;
	if ( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ) {
	$bpsPro_http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}			
	$bpsPro_http_x_cluster_client_ip = false;
	if ( array_key_exists('HTTP_X_CLUSTER_CLIENT_IP', $_SERVER) ) {
	$bpsPro_http_x_cluster_client_ip = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
	}		

} else {
	
	$bpsPro_remote_addr = 'GDPR Compliance On';
	$bpsPro_http_client_ip = 'GDPR Compliance On';
	$bpsPro_http_forwarded = 'GDPR Compliance On';		
	$bpsPro_http_x_forwarded_for = 'GDPR Compliance On';	
	$bpsPro_http_x_cluster_client_ip = 'GDPR Compliance On';		
}

add_action( 'init', 'bulletproof_security_load_plugin_textdomain' );

// Load i18n Language Translation
function bulletproof_security_load_plugin_textdomain() {
	load_plugin_textdomain('bulletproof-security', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
}

// BPS includes: The order is important
// Contains RecursiveFilterIterator classes used by AutoRestore
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/class.php';
// ARQ Cron & other related functions
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/arq-cron.php';
// ARQ AJAX Automation
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/arq-ajax-automation.php';
// MScan Plugin and Theme file hash variables - added to global variables above: $plugin_hashes, $theme_hashes
if ( file_exists( WP_CONTENT_DIR . '/bps-backup/plugin-hashes/plugin-hashes.php' ) ) {
require_once WP_CONTENT_DIR . '/bps-backup/plugin-hashes/plugin-hashes.php';
}
if ( file_exists( WP_CONTENT_DIR . '/bps-backup/theme-hashes/theme-hashes.php' ) ) {
require_once WP_CONTENT_DIR . '/bps-backup/theme-hashes/theme-hashes.php';
}
// MScan AJAX functions
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/mscan-ajax-functions.php';
// General functions
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/functions.php';
// S-Monitor Dashboard Alerts
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/dashboard-email-alerts.php';
// BPS HUD Dimiss functions - includes AutoFix AutoSetup checks
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/hud-autofix-setup.php';
// BPS HUD Dimiss functions - includes AutoFix AutoWhitelist checks
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/hud-autofix-whitelist.php';
// BPS HUD Dimiss functions - General Error Checks & Misc checks
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/hud-dismiss-functions.php';
// BPS inpage functions - top of BPS Pro pages - BPS Only display
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/inpage-functions.php';
// BPS Zip & Email Log File Cron functions
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/zip-email-cron-functions.php';
// BPS general functions
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/general-functions.php';
// BPS Login Security
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/login-security.php';
// BPS Force Strong Passwords
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/force-strong-passwords.php';
// BPS DB Backup & DB Monitor
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/db-security.php';
// BPS Plugin Firewall AutoPilot
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/firewall-autopilot.php';
// BPS ARQ Old Backup File Deletion
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/arq-obfd.php';
// BPS Folder Lock Cron Scan
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/folder-lock-cron.php';
// BPS Hidden Plugin Folders|Files (HPF) Cron
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/hidden-plugin-folders-cron.php';
// PHP Encryption|Decryption class using openssl_decrypt() and openssl_encrypt()
// Web hosts may see this file as malicious and block or delete it. So a file_exists check needs to be here.
$bpsPro_encrypt_decrypt_class = WP_PLUGIN_DIR . '/bulletproof-security/includes/encrypt-decrypt-class.php';
if ( file_exists ( $bpsPro_encrypt_decrypt_class ) ) {
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/encrypt-decrypt-class.php';
}
// Idle Session Logout (ISL)
$BPS_ISL_options = get_option('bulletproof_security_options_idle_session');
if ( isset( $BPS_ISL_options['bps_isl'] ) && $BPS_ISL_options['bps_isl'] == 'On' ) {
require_once WP_PLUGIN_DIR . '/bulletproof-security/includes/idle-session-logout.php';
}

// If in WP Dashboard / Admin Panels
if ( is_admin() ) {
    require_once WP_PLUGIN_DIR . '/bulletproof-security/admin/includes/admin.php';
	register_activation_hook(__FILE__, 'bulletproof_security_install');
	register_deactivation_hook(__FILE__, 'bulletproof_security_deactivation');
    register_uninstall_hook(__FILE__, 'bulletproof_security_uninstall');

	add_action( 'admin_init', 'bulletproof_security_admin_init' );
    add_action( 'admin_menu', 'bulletproof_security_admin_menu' );

	add_filter( 'http_request_args', 'bpsPro_prevent_wp_update_check', 10, 2 );

function bpsPro_prevent_wp_update_check( $r, $url ) {
global $pagenow;
	
	if ( $pagenow == 'update-core.php' && 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check/1.1/' ) || 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check/1.0/' ) ) {
		$bps_plugin = plugin_basename( __FILE__ );
		$plugins = json_decode( $r['body']['plugins'], true );

		unset( $plugins['plugins'][$bps_plugin] );
		$r['body']['plugins'] = json_encode( $plugins );
	}
	return $r;
}

// Plugin update check
add_filter('pre_set_site_transient_update_plugins', 'bps_upgrade_check_for_plugin_update');

}

function bps_upgrade_check_for_plugin_update($checked_data) {
	global $bpsPro_api_url, $bps_plugin_slug, $pagenow;

	if ( $pagenow == 'update-core.php' )
		return $checked_data;
	
	if ( empty( $checked_data->checked ) )
		return $checked_data;
	
	$request_args = array(
		'slug' 		=> $bps_plugin_slug,
		'version' 	=> $checked_data->checked[$bps_plugin_slug .'/'. $bps_plugin_slug .'.php'],
	);
	
	$request_string = bps_upgrade_prepare_request( 'basic_check', $request_args );
	
	// Start checking for an update
	$raw_response = wp_remote_post($bpsPro_api_url, $request_string);
	$response = '';	

	if ( ! is_wp_error($raw_response) && ($raw_response['response']['code'] == 200) )
		$response = @unserialize($raw_response['body']);

	if ( is_object($response) && ! empty($response) ) // Feed the update data into WP updater
		$checked_data->response[$bps_plugin_slug .'/'. $bps_plugin_slug .'.php'] = $response;
		
	return $checked_data;
}

// Plugin API call & info screen
add_filter('plugins_api', 'bps_upgrade_plugin_api_call', 10, 3);

function bps_upgrade_plugin_api_call($def, $action, $args) {
	global $bps_plugin_slug, $bpsPro_api_url, $pagenow;
	
	if ( isset( $args->slug ) && $args->slug != $bps_plugin_slug )
		return false;
	
	// 11.7.1: BugFix: API Server Call failed error message displayed on WP Add New Plugins page: plugin-install.php
	// 11.7.1 late: 4-11-2016: Clicking the View version X details link on the Plugins page I am seeing the BPS free plugin info and not my Pro info.
	// Added new preg_match condition so that the Pro info is displayed in the iFrame.
	// 12.4: BugFix: removed WP error checking code: WP_Error('plugins_api_failed'. fixes: BPS Pro: An HTTP Error occurred during the API request
	// 15.4: PHP Error occurring: Removed this condition: && ! preg_match( '/tab=plugin-information/', esc_html($_SERVER['REQUEST_URI']))
	if ( 'update-core.php' == $pagenow || 'plugin-install.php' == $pagenow )
		return false;
	
	$plugin_info = get_site_transient('update_plugins');
	$current_version = $plugin_info->checked[$bps_plugin_slug .'/'. $bps_plugin_slug .'.php'];
	$args->version = $current_version;
	$request_string = bps_upgrade_prepare_request($action, $args);
	$request = wp_remote_post($bpsPro_api_url, $request_string);
	$res = @unserialize($request['body']);
	
	return $res;
}

function bps_upgrade_prepare_request($action, $args) {
	global $wp_version, $pagenow;
	
	if ( $pagenow != 'update-core.php' )

	return array(
		'body' => array(
			'action' 		=> $action, 
			'request' 		=> serialize($args),
			'bps-url' 		=> get_bloginfo('url'),
			'bps-api-key' 	=> 'jKBeLZuVRwOQxTcy'
		),
		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
	);	
}

// "Settings" link on Plugins Options Page 
function bps_plugin_actlinks( $links, $file ) {
static $this_plugin;
	if ( ! $this_plugin ) 
		$this_plugin = plugin_basename(__FILE__);
	if ( $file == $this_plugin ) {
		$links[] = '<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'" title="'.esc_attr( 'BPS Setup Wizard' ).'">'.__('Setup Wizard', 'bulletproof-security').'</a>';
		//$links[] = '<br><a href="plugins.php?page=bulletproof-security/admin/includes/uninstall.php" title="Select an uninstall option for BPS plugin deletion">'.__('Uninstall Options', 'bulleproof-security').'</a>';
		
	}
	return $links;
}

add_filter( 'plugin_action_links', 'bps_plugin_actlinks', 10, 2 );
add_filter( 'network_admin_plugin_action_links', 'bps_plugin_actlinks', 10, 2 );

//add links on plugins page
function bps_plugin_extra_links($links, $file) {
	static $this_plugin;
	if ( ! current_user_can('install_plugins') )
		return $links;
	if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
	if ( $file == $this_plugin ) {
		$links[2] = '<a href="https://forum.ait-pro.com/forums/topic/bulletproof-security-pro-version-release-dates/" target="_blank" title="BulletProof Security Pro Version Release Dates and Whats New">' . __('Version Release Dates|Whats New', 'bulleproof-security').'</a>';
		$links[] = '<a href="https://forum.ait-pro.com/" target="_blank" title="BulletProof Security Pro Forum">' . __('Forum|Support', 'bulleproof-security').'</a>';
		$links[] = '<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/tools/tools.php#bps-tabs-15' ).'" title="'.esc_attr( 'Pro Tools Plugin Update Check tool' ).'">' . __('Manual Upgrade Check', 'bulleproof-security') . '</a>';

	}

	return $links;
}

add_filter( 'plugin_row_meta', 'bps_plugin_extra_links', 10, 2);

?>