<?php

/*

Plugin Name: SecureScanPRO

Plugin URI: http://www.securescanpro.com/

Description: Check your site for <strong>security vulnerabilities</strong> and get precise suggestions for corrective actions on passwords, user accounts, file permissions, database security, version hiding, plugins, themes and other security aspects.

Author: PageOneTraffic Ltd

Version: 3.3

Author URI: http://www.pageonetraffic.co.uk/

 */

if (!function_exists('add_action')) {
	die('Please don\'t open this file directly!');
}

// constants

define('SSP_VER', '3.3');

define('SSP_DIC', plugin_dir_path(__FILE__) . 'dic.txt');

define('SSP_OPTIONS_KEY', 'ssp_results');

define('SSP_LICENSE_KEY', 'ssp_license_key');

define('SSP_MAX_USERS_ATTACK', 25);

define('SSP_MAX_EXEC_SEC', 200);

define('SSP_FIXIT_KEY', 'ssp_fixit');

global $ssp_plugfile, $update_check;

$ssp_plugfile = __FILE__;

$update_check = 'http://securescanpro.com/secureupdate/update_details.js';

require_once 'ssp-tests.php';

require_once 'ssp-core-scanner.php';

require_once 'ssp-scheduled-scanner.php';

require_once 'ssp-login.php';

require_once 'ssp-spam-ipblock.php';

require_once 'ssp-setting.php';

//Check for new updates

require 'plugin-updates/plugin-update-checker.php';

$plugin_slug = plugin_basename(dirname($ssp_plugfile));

$plugin_file = basename(($ssp_plugfile));

$MyUpdateChecker = new PluginUpdateChecker(

	$update_check,
	__FILE__,
	$plugin_slug
);

//end update check

class ssp {

	// init plugin

	public static function init() {

		// does the user have enough privilages to use the plugin?

		if (is_admin() && current_user_can('administrator')) {
			// this plugin requires WP v3.1

			if (!version_compare(get_bloginfo('version'), '3.3', '>=')) {
				add_action('admin_notices', array(__CLASS__, 'min_version_error'));

				return;
			} else {
				// add menu item to tools

				add_action('admin_menu', array(__CLASS__, 'admin_menu'));

				add_action('admin_print_styles', array(__CLASS__, 'menu_icon_css'));

				// aditional links in plugin description

				add_filter(
					'plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
					array(__CLASS__, 'plugin_action_links')
				);

				// enqueue scripts

				add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));

				// register ajax endpoints

				add_action('wp_ajax_ssp_run_tests', array(__CLASS__, 'run_tests'));

				add_action('wp_ajax_ssp_run_manual_test', array(__CLASS__, 'run_manual_test'));

				add_action('wp_ajax_ssp_verify_key', array(__CLASS__, 'verify_key'));

				add_action('wp_ajax_ssp_fixit', array(__CLASS__, 'fixit'));

				add_action('wp_ajax_ssp_undofixit', array(__CLASS__, 'undofixit'));

				// warn if tests were not run

				add_action('admin_notices', array(__CLASS__, 'run_tests_warning'));

				// warn if Wordfence is active

				add_action('admin_notices', array(__CLASS__, 'wordfence_warning'));
			} // if version
		} // if

		self::ssp_update_xml_rpc();

		self::apply_fixit();
	} // init

	static function ssp_update_xml_rpc() {

		$options = get_option(SSP_SETTING_OPTIONS_KEY);

		if (isset($options['xml_rpc_disable']) && $options['xml_rpc_disable'] == 1) {
			add_filter('xmlrpc_enabled', '__return_false');
		}
	}

	// add settings link to plugins page

	public static function plugin_action_links($links) {

		$settings_link = '<a href="admin.php?page=secure-scan-pro" title="SecureScanPRO">Scan site</a>';

		array_unshift($links, $settings_link);

		return $links;
	} // plugin_action_links

	/* Updater Functions Added by zignus.drionix of eAvenue */

	public static function check_update() {

		global $wp_version, $ssp_plugfile, $update_check;

		$plugin_folder = plugin_basename(dirname($ssp_plugfile));

		$plugin_file = basename(($ssp_plugfile));

		if (defined('WP_INSTALLING')) {
			return false;
		}

		$response = wp_remote_post($update_check);

		if (!is_wp_error($response) || wp_remote_retrieve_response_code($response) === 200) {
			$update_info = json_decode($response['body']);

			if (self::ssp_plugin_get("Version") == $update_info->version) {
				return false;
			}

			$plugin_transient = get_site_transient('update_plugins');

			$a = array(

				'slug' => $plugin_folder,

				'new_version' => $update_info->version,

				'url' => $update_info->author,

				'package' => $update_info->download_url,

			);

			$o = (object) $a;

			$plugin_transient->response[$plugin_folder . '/' . $plugin_file] = $o;

			set_site_transient('update_plugins', $plugin_transient);
		}
	}

	public function getRemote_information() {

		global $wp_version, $ssp_plugfile, $update_check;

		$request = wp_remote_post($update_check, array('body' => array('action' => 'info')));

		$plugin_folder = plugin_basename(dirname($ssp_plugfile));

		$plugin_file = basename(($ssp_plugfile));

		if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
			$a = json_decode($request['body']);

			$o = self::toWpFormat($a);

			$o->slug = $plugin_file;

			return $o;
		}

		return false;
	}

	public function toWpFormat($arr_fields) {

		$info = new StdClass;

		if (is_object($arr_fields)) {
			$info = $arr_fields;
		} elseif (is_array($arr_fields)) {
			foreach ($arr_fields as $field => $val) {
				if (!empty($val)) {
					$info->$field = $val;
				} else {
					$info->$field = null;
				}
			}
		}

		//Other fields need to be renamed and/or transformed.

		if (is_object($arr_fields)) {
			$info->download_link = $arr_fields->download_url;
		} else {
			$info->download_link = $arr_fields['download_url'];
		}

		if (!empty($info->author_homepage)) {
			$info->author = sprintf('<a href="%s">%s</a>', $info->author_homepage, $info->author);
		}

		if (is_object($arr_fields)) {
			$info->sections = (array) $arr_fields->sections;
		} elseif (is_array($arr_fields) && (count($arr_fields['sections']) > 0)) {
			$info->sections = $arr_fields['sections'];
		} else {
			$info->sections = array('description' => '');
		}

		return $info;
	}

	//Returns current plugin info.

	function ssp_plugin_get($i) {

		global $ssp_plugfile;

		if (!function_exists('get_plugins')) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}

		$plugin_folder = get_plugins('/' . plugin_basename(dirname($ssp_plugfile)));

		$plugin_file = basename(($ssp_plugfile));

		return $plugin_folder[$plugin_file][$i];
	}

	public static function ssp_updates_exclude($r, $url) {

		if (0 !== strpos($url, 'http://api.wordpress.org/plugins/update-check')) {
			return $r; // Not a plugin update request. Bail immediately.
		}

		$plugins = unserialize($r['body']['plugins']);

		unset($plugins->plugins[plugin_basename(__FILE__)]);

		unset($plugins->active[array_search(plugin_basename(__FILE__), $plugins->active)]);

		$r['body']['plugins'] = serialize($plugins);

		return $r;
	}

	public function ssp_check_updinfo($false, $action, $arg) {

		if ($args->slug != plugin_basename(__FILE__)) {
			return false;
		}

		$information = self::getRemote_information();

		return $information;
	}

/* END of Updater Mod */

	// test if plugin's page is visible

	public static function is_plugin_page() {

		$current_screen = get_current_screen();

		if ($current_screen->id == 'toplevel_page_secure-scan-pro') {
			return true;
		} else {
			return false;
		}
	} // is_plugin_page

	// enqueue CSS and JS scripts on plugin's pages

	public static function enqueue_scripts() {

		if (self::is_plugin_page()) {
			$plugin_url = plugin_dir_url(__FILE__);

			wp_enqueue_script('jquery-ui-tabs');

			wp_enqueue_script('ssp-jquery-plugins', $plugin_url . 'js/ssp-jquery-plugins.js', array(), SSP_VER, true);

			wp_enqueue_script('sn-js', $plugin_url . 'js/ssp-common.js', array(), SSP_VER, true);

			wp_enqueue_script('sn-tblsort-pager', $plugin_url . 'js/jquery.tablesorter.pager.js', array(), SSP_VER, true); //mod done by zignus.drionix of eAvenue

			wp_enqueue_script('sn-tblsort-js', $plugin_url . 'js/jquery.tablesorter.js', array(), SSP_VER, true); //mod done by zignus.drionix of eAvenue

			wp_enqueue_style('sn-tblsort-css', $plugin_url . 'css/jquery.tablesorter.css', array(), SSP_VER, true); //mod done by zignus.drionix of eAvenue

			wp_enqueue_style('sn-css', $plugin_url . 'css/ssp-style.css', array(), SSP_VER);

			//Unregistering other plugin conflict files

			wp_dequeue_style('kudani-jquery-ui-style');

			wp_dequeue_script('wpg-script');

			wp_dequeue_script('seo-spotlight-coreui');

			wp_dequeue_script('seo-spotlight-tabs');

			wp_dequeue_script('seo-spotlight-cookie');
		} // if
	} // enqueue_scripts

	// add entry to admin menu

	public static function admin_menu() {

		add_menu_page('SecureScanPRO', 'SecureScanPRO', 'administrator', 'secure-scan-pro', array(__CLASS__, 'options_page'));
	} // admin_menu

	// display warning if test were never run

	public static function run_tests_warning() {

		if (!self::check_license()) {
			return;
		}

		$tests = get_option(SSP_OPTIONS_KEY);

		if (self::is_plugin_page() && !$tests['last_run']) {
			echo '<div id="message" class="error"><p>SecureScanPRO <strong>tests were never run.</strong> Click "Run tests" to run them now and analyze your site for security vulnerabilities.</p></div>';
		} elseif (self::is_plugin_page() && (current_time('timestamp') - 30 * 24 * 60 * 60) > $tests['last_run']) {
			echo '<div id="message" class="error"><p>SecureScanPRO <strong>tests were not run for more than 30 days.</strong> It\'s advisable to run them once in a while. Click "Run tests" to run them now and analyze your site for security vulnerabilities.</p></div>';
		}
	} // run_tests_warning

	// display warning if Wordfence plugin is active

	public static function wordfence_warning() {

		if (!self::check_license()) {
			return;
		}

		if (defined('WORDFENCE_VERSION') && WORDFENCE_VERSION) {
			echo '<div id="message" class="error"><p>Please <strong>deactivate Wordfence plugin</strong> before running SecureScanPRO tests. Some tests are detected as site attacks by Wordfence and hence can\'t be performed properly. Activate Wordfence once you\'re done testing.</p></div>';
		}
	} // wordfence_warning

	// display warning if test were never run

	function min_version_error() {

		echo '<div id="message" class="error"><p>SecureScanPRO <b>requires WordPress version 3.3</b> or higher to function properly. You\'re using WordPress version ' . get_bloginfo('version') . '. Please <a href="' . admin_url('update-core.php') . '" title="Update WP core">update</a>.</p></div>';
	} // min_version_error

	public static function check_license() {

		$key = get_option(SSP_LICENSE_KEY);

		if (!$key) {
			return false;
		}

		$response = wp_remote_get('http://page1traffic.net/securesp/regck.php?r=' . $key);

		if (is_wp_error($response)) {
			return true;
		} else {
			$response = @$response['body'];

			$response = @explode(':', $response);

			if ($response[1] == 'true') {
				return true;
			} else {
				update_option(SSP_LICENSE_KEY, '');

				return false;
			}
		}

		return false;
	} // check_license

	function verify_key() {

		$key = trim(@$_POST['key']);

		$response = wp_remote_get('http://page1traffic.net/securesp/regck.php?r=' . $key);

		if (is_wp_error($response)) {
			update_option(SSP_LICENSE_KEY, '');

			die('5');
		} else {
			$response = @$response['body'];

			$response = @explode(':', $response);

			if ($response[1] == 'true') {
				update_option(SSP_LICENSE_KEY, $key);

				die('1');
			} else {
				update_option(SSP_LICENSE_KEY, '');

				die('0');
			}
		}
	} // check_license

	public static function ask_key() {

		echo '<div id="">';

		echo '<p>Please enter the license key you received with the purchase.</p>';

		echo '<input type="text" id="key" name="key" /> ';

		echo '<button class="button primary" id="verify-key">Verify license key</button>';

		echo '</div>';
	} // ask_key

	// whole options page

	public static function options_page() {

		// does the user have enough privilages to access this page?

		if (!current_user_can('administrator')) {
			wp_die('You do not have sufficient permissions to access this page.');
		}

		echo '<div class="wrap">' . get_screen_icon('sn-lock');

		echo '<h2>SecureScanPRO<span id="ssp-help"><a href="http://www.securescanpro.com/help-and-support/">Help & Support</a></span></h2>';

		if (!self::check_license()) {
			self::ask_key();

			return;
		}

		$tabs = array();

		$tabs[] = array('id' => 'sn_tests', 'class' => '', 'label' => 'Tests', 'callback' => array('self', 'tests_table'));

		$tabs[] = array('id' => 'sn_help', 'class' => 'sn_help', 'label' => 'Test details, tips &amp; help', 'callback' => array('self', 'help_table'));

		$tabs = apply_filters('sn_tabs', $tabs);

		echo '<div id="tabs">';

		echo '<ul>';

		foreach ($tabs as $tab) {
			echo '<li><a href="#' . $tab['id'] . '" class="' . $tab['class'] . '">' . $tab['label'] . '</a></li>';
		}

		echo '</ul>';

		foreach ($tabs as $tab) {
			echo '<div id="' . $tab['id'] . '">';

			call_user_func($tab['callback']);

			echo '</div>';
		}

		echo '</div>'; // tabs

		echo '</div>'; // wrap
	} // options_page

	// display tests help & info

	public static function help_table() {

		require_once 'ssp-tests-description.php';
	} // help_table

	// display tests table

	public static function tests_table() {

		// get test results from cache

		$tests = get_option(SSP_OPTIONS_KEY);

		echo '<p class="submit"><input type="submit" value=" Run tests " id="run-tests" class="button-primary" name="Submit" />&nbsp;&nbsp;';

		if ($tests['last_run']) {
			echo '<span class="sn-notice">Tests were last run on: ' . date(get_option('date_format') . ' ' . get_option('time_format'), $tests['last_run']) . '.</span>';
		}

		echo '</p>';

		echo '<p><strong>Please read!</strong> These tests only serve as suggestions! Although they cover years of best practices getting all test <i>green</i> will not guarantee your site will not get hacked. Likewise, getting them all <i>red</i> doesn\'t mean you\'ll certainly get hacked. Please read each test\'s detailed information to see if it represents a real security issue for your site. Suggestions and test results apply to public, production sites, not local, development ones. <br /> If you need an in-depth security analysis please hire a security expert.</p><br />';

		if ($tests['last_run']) {
			echo '<script language="javascript" type="application/javascript">';

			echo 'jQuery(document).ready(function() { ';

			echo 'jQuery("#security-ninja").tablesorter(); ';

			echo '}); </script>';

			echo '<table class="wp-list-table widefat" cellspacing="0" id="security-ninja">';

			echo '<thead><tr>';

			echo '<th class="sn-status" onclick=\'jQuery("#sort-div-std").hide(); jQuery("#sort-div-adv").hide();\'>Status</th>';

			echo '<th>Test description</th>';

			echo '<th>Test results</th>';

			echo '<th>&nbsp;</th>';

			echo '</tr></thead>';

			echo '<tbody>';

			if (is_array($tests['test'])) {
				// test Results

				/* sorting of Tests, those with 'Fix' will be shown first */

				$tmp_tests = array();

				foreach ($tests['test'] as $test_name => $details) {
					if (isset(ssp_tests::$security_tests[$test_name]['fixit']) && ssp_tests::$security_tests[$test_name]['fixit']) {
						//print_r($test_name); echo ","; // ssp_tests::$security_tests[$test_name]['fixit']

						$tmp_tests[$test_name] = $details;

						unset($tests['test'][$test_name]);
					}
				}

				$sorted_tests = array_merge($tmp_tests, $tests['test']);

				$secnd_header_shown = 0;

				$manual_sn_status = "";

				$manual_sn_title = "";

				$manual_sn_msg = "";

				$manual = "0";

				echo '<tr id="sort-div-std"><td colspan=4><h2>Standard</h2></td></tr>';

				foreach ($sorted_tests as $test_name => $details) {
					if ($test_name == 'bruteforce_login') {
						$manual_sn_status = self::status($details['status']);

						$manual_sn_title = $details['title'];

						$manual_sn_msg = $details['msg'];

						$manual = "1";
					} else {
						if (!$secnd_header_shown && !(isset(ssp_tests::$security_tests[$test_name]['fixit']) && ssp_tests::$security_tests[$test_name]['fixit'])) {
							echo '<tr id="sort-div-adv"><td colspan=4><h2>Advanced</h2></td></tr>';

							$secnd_header_shown = 1;
						}

						echo '<tr>

        <td class="sn-status">' . self::status($details['status']) . '</td>

        <td>' . $details['title'] . '</td>

        <td>' . $details['msg'] . '</td>';

						echo '<td class="sn-details">';

						if ($details['status'] && isset(ssp_tests::$security_tests[$test_name]['undo']) && ssp_tests::$security_tests[$test_name]['undo']) {
							echo ' <a href="#" data-test="' . $test_name . '" class="button action undofixit">Undo Fix!</a>';
						}

						if (!$details['status'] && isset(ssp_tests::$security_tests[$test_name]['fixit']) && ssp_tests::$security_tests[$test_name]['fixit']) {
							echo ' <a href="#" data-test="' . $test_name . '" class="button action fixit">Fix it!</a>';
						}

						echo '<a href="#' . $test_name . '" class="button action details">Details, tips &amp; help</a></td>

     </tr>';
					} //else
				} // foreach ($tests)

				echo '<tr id="sort-div-std"><td colspan=4><h2>Manual Test</h2></td></tr>';

				if ($manual == "1") {
					$test_name = 'bruteforce_login';

					echo '<tr>

         <td class="sn-status">' . $manual_sn_status . '</td>

         <td>' . $manual_sn_title . '</td>

         <td>' . $manual_sn_msg . '</td>';

					echo '<td class="sn-details">';

					if ($details['status'] && isset(ssp_tests::$security_tests[$test_name]['undo']) && ssp_tests::$security_tests[$test_name]['undo']) {
						echo ' <a href="#" data-test="' . $test_name . '" class="button action undofixit">Undo Fix!</a>';
					}

					if (!$details['status'] && isset(ssp_tests::$security_tests_2[$test_name]['fixit']) && ssp_tests::$security_tests_2[$test_name]['fixit']) {
						echo ' <a href="#" data-test="' . $test_name . '" class="button action fixit">Fix it!</a>';
					}

					echo ' <input id="scannow_manual" class="button action fixit" type="submit" name="Submit" value=" Scan It! ">';

					echo '<a href="#' . $test_name . '" class="button action details">Details, tips &amp; help</a></td>

       </tr>';
				} else {
					$test_name = 'bruteforce_login';

					echo '<tr>

       <td class="sn-status">' . ' <input id="scannow_manual" class="button action fixit" type="submit" name="Submit" value=" Scan It! ">' . '</td>

       <td>' . ssp_tests::$security_tests_2['bruteforce_login']['title'] . '</td>

       <td>' . "" . '</td>';

					echo '<td class="sn-details">';

					if (!$details['status'] && isset(ssp_tests::$security_tests_2[$test_name]['fixit']) && ssp_tests::$security_tests_2[$test_name]['fixit']) {
						echo ' <a href="#" data-test="' . $test_name . '" class="button action fixit">Fix it!</a>';
					}

					//  echo ' <input id="scannow_manual" class="button action fixit" type="submit" name="Submit" value=" Scan It! ">';

					echo '<a href="#' . $test_name . '" class="button action details">Details, tips &amp; help</a></td>

    </tr>';
				}
			} else {
				// no test results
				echo '<tr>

      <td colspan="4">No test results are available. Click "Run tests" to run tests now.</td>

    </tr>';
			} // if tests

			echo '</tbody>';

			echo '<tfoot><tr>';

			echo '<th class="sn-status">Status</th>';

			echo '<th>Test description</th>';

			echo '<th>Test results</th>';

			echo '<th>&nbsp;</th>';

			echo '</tr></tfoot>';

			echo '</table>';
		} // if $results
	} // tests_table

	// run all tests; via AJAX

	function run_tests($return = false) {

		@set_time_limit(SSP_MAX_EXEC_SEC);

		$tests = get_option(SSP_OPTIONS_KEY);

		$test_count = 0;

		$test_description = array('last_run' => current_time('timestamp'));

		$tests = get_option(SSP_OPTIONS_KEY);

		//this will store value of the bruteforce login

		foreach ($tests['test'] as $test_name => $details) {
			$test_name = $details['title'];

			if ($test_name == 'Check user\'s password strength with a brute-force attack.') {
				//print_r($test_name); echo ","; //ssp_tests::$security_tests[$test_name]['fixit']

				$test_description['test']['bruteforce_login']['title'] = $details['title'];

				$test_description['test']['bruteforce_login']['status'] = $details['status'];

				$test_description['test']['bruteforce_login']['msg'] = $details['msg'];

				$test_count++;
			}
		} //foreach

		foreach (ssp_tests::$security_tests as $test_name => $test) {
			if ($test_name[0] == '_') {
				continue;
			}

			//go to every function of the class ssp_tests, then go to the function of the array $security_tests

			// which was passed to  $test_name.

			$response = ssp_tests::$test_name();

			$test_description['test'][$test_name]['title'] = $test['title'];

			$test_description['test'][$test_name]['status'] = $response['status'];

			if (!isset($response['msg'])) {
				$response['msg'] = '';
			}

			if ($response['status'] == 10) {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_ok'], $response['msg']);
			} elseif ($response['status'] == 0) {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_bad'], $response['msg']);
			} else {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_warning'], $response['msg']);
			}

			$test_count++;
		} // foreach

		if ($return) {
			return $test_description;
		} else {
			update_option(SSP_OPTIONS_KEY, $test_description);

			die('1');
		}
	} // run_test

	// run manual tests; via AJAX

	function run_manual_test($return = false) {

		@set_time_limit(SSP_MAX_EXEC_SEC);

		$test_count = 0;

		$test_description = array('last_run' => current_time('timestamp'));

		$tests = get_option(SSP_OPTIONS_KEY);

		//this will store value of the bruteforce login

		foreach ($tests['test'] as $test_name => $details) {
			$test_name = $details['title'];

			if ($test_name != 'Check user\'s password strength with a brute-force attack.') {
				//print_r($test_name); echo ","; //ssp_tests::$security_tests[$test_name]['fixit']

				$arr = array_keys(ssp_tests::$security_tests);

				$result = count($arr);

				$row = ssp_tests::$security_tests;

				for ($i = 0; $i < $result; $i++) {
					if ($details['title'] == ssp_tests::$security_tests[$arr[$i]]['title']) {
						$test_description['test'][$arr[$i]]['title'] = $details['title'];

						$test_description['test'][$arr[$i]]['status'] = $details['status'];

						$test_description['test'][$arr[$i]]['msg'] = $details['msg'];
					}
				} //for
			} //if
		} //foreach

		foreach (ssp_tests::$security_tests_2 as $test_name => $test) {
			if ($test_name[0] == '_') {
				continue;
			}

			//go to every function of the class ssp_tests, then go to the function of the array $security_tests

			// which was passed to  $test_name.

			$response = ssp_tests::$test_name();

			$test_description['test'][$test_name]['title'] = $test['title'];

			$test_description['test'][$test_name]['status'] = $response['status'];

			if (!isset($response['msg'])) {
				$response['msg'] = '';
			}

			if ($response['status'] == 10) {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_ok'], $response['msg']);
			} elseif ($response['status'] == 0) {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_bad'], $response['msg']);
			} else {
				$test_description['test'][$test_name]['msg'] = sprintf($test['msg_warning'], $response['msg']);
			}
		} // foreach

		$value_to_store;

		if ($return) {
			die('1');
		} else {
			update_option(SSP_OPTIONS_KEY, $test_description);

			die('1');
		}
	} // run_test

	// convert status integer to button

	public static function status($int) {

		if ($int == 0) {
			$string = '<span class="sn-error">Bad</span>';
		} elseif ($int == 10) {
			$string = '<span class="sn-success">Good</span>';
		} else {
			$string = '<span class="sn-warning">Warning</span>';
		}

		return $string;
	} // status

	public static function menu_icon_css() {

		echo '<style type="text/css" media="screen">

          #toplevel_page_secure-scan-pro .wp-menu-image {

    background: url(' . plugin_dir_url(__FILE__) . '/images/menu-icon.png) no-repeat 5px 5px !important;}</style>';
	} // menu_icon_css

	// clean-up when deactivated

	function deactivate() {

		return;

		delete_option(SSP_OPTIONS_KEY);

		delete_option(SSP_LICENSE_KEY);

		global $wpdb;

		wp_clear_scheduled_hook(SSP_SS_CRON);

		wp_clear_scheduled_hook('ssp_check_event');

		delete_option(SSP_SS_OPTIONS_KEY);

		$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . SSP_SS_TABLE);

		delete_option(SSP_CS_OPTIONS_KEY);

		ssp_login::deactivate();
	} // deactivate

	function activate() {

		ssp_ss::activate();

		ssp_login::activate();

		/* mod added by zignus.drionix of eAvenue */

		wp_schedule_event(time(), 'hourly', 'ssp_check_event'); //twicedaily

		ssp::check_update();
	}

	function remove_version() {

		return '';
	}

	function wrong_login($msg) {

		if (stripos($msg, 'invalid username') || stripos($msg, 'The password you entered')) {
			return '<strong>ERROR:</strong> Wrong username or password.';
		}

		return $msg;
	}

	public static function apply_fixit() {

		$options = get_option(SSP_FIXIT_KEY);

		if (isset($options['wp_header_meta']) && $options['wp_header_meta']) {
			add_filter('the_generator', array(__CLASS__, 'remove_version'), 99);
		}

		if (isset($options['check_failed_login_info']) && $options['check_failed_login_info']) {
			add_filter('login_errors', array(__CLASS__, 'wrong_login'), 99);
		}

		if (isset($options['wlw_meta']) && $options['wlw_meta']) {
			remove_action('wp_head', 'wlwmanifest_link');
		}

		if (isset($options['rpc_meta']) && $options['rpc_meta']) {
			remove_action('wp_head', 'rsd_link');
		}

		if (isset($options['file_editor']) && $options['file_editor']) {
			define('DISALLOW_FILE_EDIT', true);
		}

		if ((isset($options['debug_check']) && $options['debug_check']) && !defined('WP_DEBUG')) {
			define('WP_DEBUG', false);
		}
	} // apply fixit

	function undofixit() {

		$case = $_POST['test'];

		if ($case == 'upgrade_file_check') {
			$tmp = @rename(ABSPATH . 'wp-admin/_upgrade.php', ABSPATH . 'wp-admin/upgrade.php');

			if ($tmp) {
				die('10');
			} else {
				die('0');
			}
		}
	}

	function fixit() {

		$options = get_option(SSP_FIXIT_KEY);

		switch ($_POST['test']) {
		case 'anyone_can_register':
			update_option('users_can_register', 0);

			die('10');

			break;

		case 'readme_check':
			$tmp = @rename(ABSPATH . 'readme.html', ABSPATH . '_readme.html');

			if ($tmp) {
				die('10');
			} else {
				die('0');
			}

			break;

		case 'wp_header_meta':
			$options['wp_header_meta'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'check_failed_login_info':
			$options['check_failed_login_info'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'wlw_meta':
			$options['wlw_meta'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'rpc_meta':
			$options['rpc_meta'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'file_editor':
			$options['file_editor'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'debug_check':
			$options['debug_check'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'install_file_check':
			$tmp = @rename(ABSPATH . 'wp-admin/install.php', ABSPATH . 'wp-admin/_install.php');

			if ($tmp) {
				die('10');
			} else {
				die('0');
			}

			break;

		case 'upgrade_file_check':
			$tmp = @rename(ABSPATH . 'wp-admin/upgrade.php', ABSPATH . 'wp-admin/_upgrade.php');

			if ($tmp) {
				die('10');
			} else {
				die('0');
			}

			break;

		case 'wpconfig_file_browsable':
			$rule = "\n\n# securescanpro code\n# protect wpconfig.php\n<files wp-config.php>\norder allow,deny\ndeny from all\n</files>\n# end securescanpro code";

			$fh = fopen(get_home_path() . '.htaccess', 'a');

			if (!$fh) {
				die('0');
			}

			$tmp = fwrite($fh, $rule);

			if ($tmp != strlen($rule)) {
				die('0');
			}

			fclose($fh);

			$options['wpconfig_file_browsable'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		case 'uploads_browsable':
			$rule = "\n\nOptions -Indexes\n";

			$fh = fopen(get_home_path() . '.htaccess', 'a');

			if (!$fh) {
				die('0');
			}

			$tmp = fwrite($fh, $rule);

			if ($tmp != strlen($rule)) {
				die('0');
			}

			fclose($fh);

			$options['uploads_browsable'] = true;

			update_option(SSP_FIXIT_KEY, $options);

			die('10');

			break;

		default:
			break;
		}

		die('0');
	} // fixit
} // ssp class

add_action('init', array('ssp', 'init'));

add_action('init', array('ssp_cs', 'init'));

add_action('init', array('ssp_ss', 'init'));

add_action('init', array('ssp_login', 'init'));

add_action('init', array('ssp_spam_ip_block', 'init'));

add_action('plugins_loaded', array('ssp_ss', 'plugins_loaded'));

add_action('init', array('ssp_setting', 'init'));

/* mods added by zignus.drionix */

add_filter('http_request_args', array('ssp', 'ssp_updates_exclude'), 5, 2);

add_filter('plugins_api', array('ssp', 'ssp_check_updinfo'), 10, 3);

add_action('ssp_check_event', array('ssp', 'check_update'));

register_activation_hook(__FILE__, array('ssp', 'activate'));

register_deactivation_hook(__FILE__, array('ssp', 'deactivate'));
