| @@ -1,125 +1,159 @@ | ||
| 1 | -<?php defined('ABSPATH') or die("Protected By WT!"); | |
| 2 | - | |
| 3 | -/* | |
| 4 | -Plugin Name: WT Security | |
| 5 | -Description: WT is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way. | |
| 6 | -Author: WT Security | |
| 7 | -Version: 2.0 | |
| 8 | -*/ | |
| 9 | - | |
| 10 | -define("WTSEC_PAGE_TITLE", 'Dashboard'); | |
| 11 | -define("WTSEC_MENU_TITLE", 'WT Security'); | |
| 12 | -define("WTSEC_PLUGIN_PATH", plugin_dir_path(__FILE__)); | |
| 13 | -define("WTSEC_PLUGIN_NAME", 'wt-security'); | |
| 14 | -define("WTSEC_PLUGIN_PREFIX", 'wtsec_'); | |
| 15 | -define("WTSEC_PAGE_PREFIX", WTSEC_PLUGIN_NAME . '-'); | |
| 16 | -define("WTSEC_FILE_URL", "https://api.wtotem.com/agent"); | |
| 17 | -define("WTSEC_ROOT", WP_PLUGIN_DIR . '/'); | |
| 18 | -define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/'); | |
| 19 | -if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) { | |
| 20 | - define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR); | |
| 21 | - define("WTOTEMSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR); | |
| 22 | -} else { | |
| 23 | - define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/'); | |
| 24 | - define("WTOTEMSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/'); | |
| 25 | -} | |
| 26 | -define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__)); | |
| 27 | -define("WTSEC_SITE_URL", str_replace(['http://', 'https://', 'www.', '//', '://'], '', get_site_url())); | |
| 28 | - | |
| 29 | -define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.0"); | |
| 30 | - | |
| 31 | -add_action('admin_init', 'wtsec_admin_init'); | |
| 32 | -add_action('wp_loaded', 'wtsec_init'); | |
| 33 | - | |
| 34 | -function wtsec_init() | |
| 35 | -{ | |
| 36 | - require_once WTSEC_PLUGIN_PATH . 'library/App.php'; | |
| 37 | - require_once WTSEC_PLUGIN_PATH . 'library/Request.php'; | |
| 38 | - if (!is_admin() && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])) { | |
| 39 | - if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) { | |
| 40 | - $path_to_waf = WTSEC_INSTALLATION_DIR . '/' . $waf; | |
| 41 | - if (is_file($path_to_waf) && is_readable($path_to_waf)) { | |
| 42 | - include $path_to_waf; | |
| 43 | - } | |
| 44 | - } | |
| 45 | - } | |
| 46 | - if (is_admin()) { | |
| 47 | - require_once WTSEC_PLUGIN_PATH . 'library/WT.php'; | |
| 48 | - require_once WTSEC_PLUGIN_PATH . 'library/Localization.php'; | |
| 49 | - require_once WTSEC_PLUGIN_PATH . 'library/Idn.php'; | |
| 50 | - require_once WTSEC_PLUGIN_PATH . 'library/Session.php'; | |
| 51 | - require_once WTSEC_PLUGIN_PATH . 'routes.php'; | |
| 52 | - require_once WTSEC_PLUGIN_PATH . 'services.php'; | |
| 53 | - function wtsec_request() | |
| 54 | - { | |
| 55 | - return new WTSEC_LIBRARY_Request(); | |
| 56 | - } | |
| 57 | - function wtsec_app() | |
| 58 | - { | |
| 59 | - return new WTSEC_LIBRARY_App(); | |
| 60 | - } | |
| 61 | - function wtsec_filesystem_init($form_url, $method, $context, $fields = null) | |
| 62 | - { | |
| 63 | - global $wp_filesystem; | |
| 64 | - if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) { | |
| 65 | - return false; | |
| 66 | - } | |
| 67 | - if (!WP_Filesystem($creds)) { | |
| 68 | - request_filesystem_credentials($form_url, $method, true, $context); | |
| 69 | - return false; | |
| 70 | - } | |
| 71 | - return true; | |
| 72 | - } | |
| 73 | - function wtsec_locale($lmsg, $args = []) | |
| 74 | - { | |
| 75 | - return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args); | |
| 76 | - } | |
| 77 | - function wtsec_getImagePath($image) | |
| 78 | - { | |
| 79 | - return plugins_url('/htdocs/images/' . $image, __FILE__); | |
| 80 | - } | |
| 81 | - function wtsec_SIS($arr, $key, $form = null) | |
| 82 | - { | |
| 83 | - $key = explode(".", $key); | |
| 84 | - foreach ($key as $_key) { | |
| 85 | - if (!isset($arr[$_key])) { | |
| 86 | - $arr = ""; | |
| 87 | - break; | |
| 88 | - } | |
| 89 | - $arr = $arr[$_key]; | |
| 90 | - } | |
| 91 | - return !empty($form) ? str_replace("$" . $key, $arr, $form) : $arr; | |
| 92 | - } | |
| 93 | - } | |
| 94 | -} | |
| 95 | - | |
| 96 | -function wtsec_admin_init() | |
| 97 | -{ | |
| 98 | - if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) { | |
| 99 | - wp_register_style("css", plugins_url('/htdocs/css/src.c37ba8ac.css', __FILE__)); | |
| 100 | - wp_enqueue_style('css'); | |
| 101 | - wp_enqueue_script('chart', plugins_url('/htdocs/js/Chart.min.js', __FILE__), [], false, true); | |
| 102 | - wp_enqueue_script('chart'); | |
| 103 | - wp_enqueue_script('app', plugins_url('/htdocs/js/src.e31bb0bc.js', __FILE__), [], false, true); | |
| 104 | - wp_enqueue_script('app'); | |
| 105 | - $page = wtsec_request()->page; | |
| 106 | - if ($page === wtsec_getRoute("login")) { | |
| 107 | - if (WTSEC_LIBRARY_App::authorized()) { | |
| 108 | - wp_safe_redirect(wtsec_getUrl('dashboard')); | |
| 109 | - } | |
| 110 | - } elseif ($page === wtsec_getRoute("logout")) { | |
| 111 | - WTSEC_LIBRARY_App::logout(); | |
| 112 | - if (!WTSEC_LIBRARY_App::authorized()) { | |
| 113 | - wp_safe_redirect(wtsec_getUrl('login')); | |
| 114 | - } | |
| 115 | - } elseif ($page === wtsec_getRoute("activate")) { | |
| 116 | - if (WTSEC_LIBRARY_App::authorized()) { | |
| 117 | - wp_safe_redirect(wtsec_getUrl('sites')); | |
| 118 | - } | |
| 119 | - } else { | |
| 120 | - if (!WTSEC_LIBRARY_App::authorized()) { | |
| 121 | - wp_safe_redirect(wtsec_getUrl('login')); | |
| 122 | - } | |
| 123 | - } | |
| 124 | - } | |
| 125 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Plugin Name: WebTotem Security | |
| 4 | + * Description: The <a href="https://wtotem.com/" target="_blank">WebTotem</a> Security plugin monitors websites and prevents website attacks with the help of special internal and external utilities. | |
| 5 | + * Author URI: https://wtotem.com/ | |
| 6 | + * Author: WebTotem | |
| 7 | + * Text Domain: wtotem | |
| 8 | + * Domain Path: /lang | |
| 9 | + * Version: 2.4.14 | |
| 10 | + * | |
| 11 | + * PHP version 7.1 | |
| 12 | + * | |
| 13 | + * @copyright 2021-2022 WebTotem | |
| 14 | + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL2 | |
| 15 | + * @link https://wordpress.org/plugins/wt-security | |
| 16 | + */ | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Main file to control the plugin. | |
| 20 | + */ | |
| 21 | +define('WEBTOTEM_INIT', true); | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Plugin dependencies. | |
| 25 | + * | |
| 26 | + * list of required WordPress functions for the plugin to work. | |
| 27 | + */ | |
| 28 | +$wtotem_dependencies = array( | |
| 29 | + 'wp', | |
| 30 | + 'wp_die', | |
| 31 | + 'add_action', | |
| 32 | + 'remove_action', | |
| 33 | + 'wp_remote_get', | |
| 34 | + 'wp_remote_post', | |
| 35 | +); | |
| 36 | + | |
| 37 | +// Stopping execution if dependencies are not met. | |
| 38 | +foreach ($wtotem_dependencies as $dependency) { | |
| 39 | + if (!function_exists($dependency)) { | |
| 40 | + // Report invalid access. | |
| 41 | + header('HTTP/1.1 403 Forbidden'); | |
| 42 | + die("Protected By WebTotem!"); | |
| 43 | + } | |
| 44 | +} | |
| 45 | + | |
| 46 | +// Stopping execution if the ABSPATH constant is not available | |
| 47 | +if (!defined('ABSPATH')) { | |
| 48 | + // Report invalid access. | |
| 49 | + header('HTTP/1.1 403 Forbidden'); | |
| 50 | + die("Protected By WebTotem!"); | |
| 51 | +} | |
| 52 | + | |
| 53 | +/** | |
| 54 | + * Current version of the plugin's code. | |
| 55 | + */ | |
| 56 | +define('WEBTOTEM_VERSION', '2.4.14'); | |
| 57 | + | |
| 58 | +/** | |
| 59 | + * The name of the folder where the plugin's files will be located. | |
| 60 | + */ | |
| 61 | +define("WEBTOTEM_PLUGIN_FOLDER", basename(dirname(__FILE__))); | |
| 62 | + | |
| 63 | +/** | |
| 64 | + * The fullpath where the plugin's files will be located. | |
| 65 | + */ | |
| 66 | +define('WEBTOTEM_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . WEBTOTEM_PLUGIN_FOLDER); | |
| 67 | + | |
| 68 | +/** | |
| 69 | + * The local URL where the plugin's files and assets are served. | |
| 70 | + */ | |
| 71 | +define('WEBTOTEM_URL', rtrim(plugin_dir_url(__FILE__), '/')); | |
| 72 | + | |
| 73 | +/** | |
| 74 | + * The domain name of the current site, without protocol and www. | |
| 75 | + */ | |
| 76 | +define("WEBTOTEM_SITE_DOMAIN", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url())); | |
| 77 | + | |
| 78 | +/** | |
| 79 | + * Unique name of the plugin through out all the code. | |
| 80 | + */ | |
| 81 | +define("WEBTOTEM", 'wtotem'); | |
| 82 | + | |
| 83 | +/* Load plugin translations */ | |
| 84 | +function wtotem_load_plugin_textdomain() { | |
| 85 | + load_plugin_textdomain('wtotem', false, basename(dirname(__FILE__)) . '/lang/'); | |
| 86 | +} | |
| 87 | +add_action('plugins_loaded', 'wtotem_load_plugin_textdomain'); | |
| 88 | + | |
| 89 | + | |
| 90 | +/* Load all classes before anything else. */ | |
| 91 | +require_once 'lib/Helper.php'; | |
| 92 | +require_once 'lib/API.php'; | |
| 93 | +require_once 'lib/DB.php'; | |
| 94 | +require_once 'lib/Cache.php'; | |
| 95 | +require_once 'lib/login/Login.php'; | |
| 96 | +require_once 'lib/Request.php'; | |
| 97 | +require_once 'lib/Interface.php'; | |
| 98 | +require_once 'lib/AgentManager.php'; | |
| 99 | +require_once 'lib/Option.php'; | |
| 100 | +require_once 'lib/Template.php'; | |
| 101 | +require_once 'lib/Country.php'; | |
| 102 | +require_once 'lib/Ajax.php'; | |
| 103 | + | |
| 104 | +/* Load page and ajax handlers */ | |
| 105 | +require_once 'src/PageHandler.php'; | |
| 106 | + | |
| 107 | +/* Load common variables and triggers */ | |
| 108 | +require_once 'src/Common.php'; | |
| 109 | + | |
| 110 | +/** | |
| 111 | + * Uninstalled the plugin | |
| 112 | + * | |
| 113 | + * @return void | |
| 114 | + */ | |
| 115 | +function wtotemUninstall() { | |
| 116 | + | |
| 117 | + if (WebTotemOption::getPluginSettings('hide_wp_version')) { | |
| 118 | + WebTotemOption::restoreReadme(); | |
| 119 | + } | |
| 120 | + | |
| 121 | + if(WebTotem::isMultiSite()){ | |
| 122 | + WebTotemOption::clearAllHosts(); | |
| 123 | + } | |
| 124 | + | |
| 125 | + /* Delete all agents files and directories */ | |
| 126 | + WebTotemAgentManager::removeAgents(); | |
| 127 | + | |
| 128 | + /* Delete settings from the database */ | |
| 129 | + WebTotemDB::uninstall(); | |
| 130 | + | |
| 131 | +} | |
| 132 | + | |
| 133 | +register_uninstall_hook(__FILE__, 'wtotemUninstall'); | |
| 134 | + | |
| 135 | +/** | |
| 136 | + * Deactivation plugin | |
| 137 | + * | |
| 138 | + * @return void | |
| 139 | + */ | |
| 140 | +function wtotemDeactivation() { | |
| 141 | + if (WebTotemOption::getPluginSettings('hide_wp_version')) { | |
| 142 | + WebTotemOption::restoreReadme(); | |
| 143 | + } | |
| 144 | +} | |
| 145 | +register_deactivation_hook( __FILE__, 'wtotemDeactivation' ); | |
| 146 | + | |
| 147 | +/** | |
| 148 | + * Deactivation plugin | |
| 149 | + * | |
| 150 | + * @return void | |
| 151 | + */ | |
| 152 | +function wtotemActivation() { | |
| 153 | + WebTotemDB::install(); | |
| 154 | + if (WebTotemOption::getPluginSettings('hide_wp_version')) { | |
| 155 | + WebTotemOption::hideReadme(); | |
| 156 | + } | |
| 157 | +} | |
| 158 | + | |
| 159 | +register_activation_hook( __FILE__, 'wtotemActivation' ); | |