| 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.3.7 |
| 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.3"); |
| 30 |
|
| 31 |
$curLang = substr(get_bloginfo('language'), 0,2); |
| 32 |
$language = (in_array($curLang,['ru','en','pl'])) ? $curLang : 'en' ; |
| 33 |
define("WTSEC_LANGUAGE", $language); |
| 34 |
|
| 35 |
|
| 36 |
add_action('admin_init', 'wtsec_admin_init'); |
| 37 |
add_action('wp_loaded', 'wtsec_init'); |
| 38 |
|
| 39 |
add_action( 'authenticate', 'wtsec_login_check' ); |
| 40 |
|
| 41 |
function wtsec_init() |
| 42 |
{ |
| 43 |
require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 44 |
require_once WTSEC_PLUGIN_PATH . 'library/Request.php'; |
| 45 |
|
| 46 |
// WAF include (Если не админка и статус waf = "start", "uninstalled") |
| 47 |
// && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"]) |
| 48 |
if (!is_admin()) { |
| 49 |
if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) { |
| 50 |
$path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf; |
| 51 |
if (is_file($path_to_waf) && is_readable($path_to_waf)) { |
| 52 |
include_once $path_to_waf; |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
if (is_admin()) { |
| 58 |
require_once WTSEC_PLUGIN_PATH . 'library/WT.php'; |
| 59 |
require_once WTSEC_PLUGIN_PATH . 'library/Localization.php'; |
| 60 |
require_once WTSEC_PLUGIN_PATH . 'library/Idn.php'; |
| 61 |
require_once WTSEC_PLUGIN_PATH . 'library/Session.php'; |
| 62 |
require_once WTSEC_PLUGIN_PATH . 'routes.php'; |
| 63 |
require_once WTSEC_PLUGIN_PATH . 'services.php'; |
| 64 |
require_once WTSEC_PLUGIN_PATH . 'helpers.php'; |
| 65 |
|
| 66 |
function wtsec_request() |
| 67 |
{ |
| 68 |
return new WTSEC_LIBRARY_Request(); |
| 69 |
} |
| 70 |
function wtsec_app() |
| 71 |
{ |
| 72 |
return new WTSEC_LIBRARY_App(); |
| 73 |
} |
| 74 |
function wtsec_filesystem_init($form_url, $method, $context, $fields = null) |
| 75 |
{ |
| 76 |
global $wp_filesystem; |
| 77 |
if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
if (!WP_Filesystem($creds)) { |
| 81 |
request_filesystem_credentials($form_url, $method, true, $context); |
| 82 |
return false; |
| 83 |
} |
| 84 |
return true; |
| 85 |
} |
| 86 |
function wtsec_locale($lmsg, $args = []) |
| 87 |
{ |
| 88 |
return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args); |
| 89 |
} |
| 90 |
function wtsec_getImagePath($image) |
| 91 |
{ |
| 92 |
return plugins_url('/htdocs/img/' . $image, __FILE__); |
| 93 |
} |
| 94 |
function wtsec_SIS($arr, $key, $form = null) |
| 95 |
{ |
| 96 |
$key = explode(".", $key); |
| 97 |
foreach ($key as $_key) { |
| 98 |
if (!isset($arr[$_key])) { |
| 99 |
$arr = ""; |
| 100 |
break; |
| 101 |
} |
| 102 |
$arr = $arr[$_key]; |
| 103 |
} |
| 104 |
return !empty($form) ? str_replace("$" . $key, $arr, $form) : $arr; |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
function wtsec_admin_init() |
| 110 |
{ |
| 111 |
$rand = '?rand='.rand(); |
| 112 |
if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) { |
| 113 |
wp_enqueue_script('subscriber', plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true); |
| 114 |
wp_enqueue_script('d3-v4', plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true); |
| 115 |
wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true); |
| 116 |
wp_enqueue_script('chart', plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true); |
| 117 |
wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true); |
| 118 |
wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true); |
| 119 |
wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true); |
| 120 |
wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true); |
| 121 |
wp_enqueue_script('line-progress', plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true); |
| 122 |
wp_enqueue_script('main', plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true); |
| 123 |
wp_enqueue_script('ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'jquery' ),false, true ); |
| 124 |
wp_enqueue_script('subscriber'); |
| 125 |
wp_enqueue_script('print'); |
| 126 |
wp_enqueue_script('d3-v4'); |
| 127 |
wp_enqueue_script('jsdelivr'); |
| 128 |
wp_enqueue_script('chart'); |
| 129 |
wp_enqueue_script('circle-progress'); |
| 130 |
wp_enqueue_script('line-progress'); |
| 131 |
wp_enqueue_script('range-plugin'); |
| 132 |
wp_enqueue_script('flatpickr'); |
| 133 |
wp_enqueue_script('filter-calendar'); |
| 134 |
wp_enqueue_script('main'); |
| 135 |
wp_enqueue_script('ajax'); |
| 136 |
|
| 137 |
wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css'); |
| 138 |
wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap'); |
| 139 |
wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__)); |
| 140 |
wp_enqueue_style('flatpickr-css'); |
| 141 |
wp_enqueue_style('font'); |
| 142 |
wp_enqueue_style('print-css'); |
| 143 |
wp_enqueue_style('main'); |
| 144 |
|
| 145 |
$page = wtsec_request()->page; |
| 146 |
if ($page === wtsec_getRoute("login")) { |
| 147 |
if (WTSEC_LIBRARY_App::authorized()) { |
| 148 |
wp_safe_redirect(wtsec_getUrl('dashboard')); |
| 149 |
} |
| 150 |
} elseif ($page === wtsec_getRoute("logout")) { |
| 151 |
WTSEC_LIBRARY_App::logout(); |
| 152 |
if (!WTSEC_LIBRARY_App::authorized()) { |
| 153 |
wp_safe_redirect(wtsec_getUrl('login')); |
| 154 |
} |
| 155 |
} elseif ($page === wtsec_getRoute("activate")) { |
| 156 |
if (WTSEC_LIBRARY_App::authorized()) { |
| 157 |
wp_safe_redirect(wtsec_getUrl('sites')); |
| 158 |
} |
| 159 |
} else { |
| 160 |
if (!WTSEC_LIBRARY_App::authorized()) { |
| 161 |
wp_safe_redirect(wtsec_getUrl('login')); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
function wtsec_login_check() { |
| 168 |
require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 169 |
require_once WTSEC_PLUGIN_PATH . 'library/Localization.php'; |
| 170 |
$app = new WTSEC_LIBRARY_App; |
| 171 |
|
| 172 |
function wtsec_locale($lmsg, $args = []) |
| 173 |
{ |
| 174 |
return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args); |
| 175 |
} |
| 176 |
|
| 177 |
$app->wtsec_login_check(); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
add_action('init', 'wtsec_StartSession', 1); |
| 182 |
add_action('wp_logout', 'wtsec_EndSession'); |
| 183 |
add_action('wp_login', 'wtsec_EndSession'); |
| 184 |
|
| 185 |
function wtsec_StartSession() { |
| 186 |
if(!session_id()) { |
| 187 |
session_start(); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
function wtsec_EndSession() { |
| 192 |
require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 193 |
session_destroy (); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|