| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | /* |
| 4 | 4 | Plugin Name: WT Security |
| 5 | 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 | 6 | Author: WT Security |
| 7 | -Version: 2.2.2 | |
| 7 | +Version: 2.3.24 | |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | define("WTSEC_PAGE_TITLE", 'Dashboard'); |
| 11 | 11 | define("WTSEC_MENU_TITLE", 'WT Security'); |
| @@ -13,9 +13,8 @@ | ||
| 13 | 13 | define("WTSEC_PLUGIN_NAME", 'wt-security'); |
| 14 | 14 | define("WTSEC_PLUGIN_PREFIX", 'wtsec_'); |
| 15 | 15 | define("WTSEC_PAGE_PREFIX", WTSEC_PLUGIN_NAME . '-'); |
| 16 | 16 | define("WTSEC_FILE_URL", "https://api.wtotem.com/agent"); |
| 17 | -define("WTSEC_ROOT", WP_PLUGIN_DIR . '/'); | |
| 18 | 17 | define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/'); |
| 19 | 18 | if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) { |
| 20 | 19 | define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR); |
| 21 | 20 | define("WTOTEMSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR); |
| @@ -23,15 +22,57 @@ | ||
| 23 | 22 | define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/'); |
| 24 | 23 | define("WTOTEMSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/'); |
| 25 | 24 | } |
| 26 | 25 | define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__)); |
| 27 | -define("WTSEC_SITE_URL", str_replace(['http://', 'https://', 'www.', '//', '://'], '', get_site_url())); | |
| 26 | +define("WTSEC_PLUGIN_BASENAME", plugin_basename( __FILE__)); | |
| 27 | +define("WTSEC_SITE_URL", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url())); | |
| 28 | 28 | |
| 29 | -define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.2"); | |
| 29 | +define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.3"); | |
| 30 | 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( 'deactivated_plugin', 'wtsec_DeactivatedPlugin', 1 ); | |
| 37 | + | |
| 38 | +// Clear database, delete am(agents) after plugin deactivate | |
| 39 | +function wtsec_DeactivatedPlugin($plugin){ | |
| 40 | + | |
| 41 | + if($plugin == WTSEC_PLUGIN_BASENAME) { | |
| 42 | + | |
| 43 | + define("WTSEC_DEACTIVATED", true); | |
| 44 | + require_once WTSEC_PLUGIN_PATH . 'library/App.php'; | |
| 45 | + $app = new WTSEC_LIBRARY_App; | |
| 46 | + if(wtsec_DeleteAm()){ | |
| 47 | + $app::clearDB(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + } | |
| 51 | +} | |
| 52 | + | |
| 53 | +add_action( 'upgrader_process_complete', 'wtsec_generate_file', 10, 2 ); | |
| 54 | + | |
| 55 | +// Create file generate.php after plugin update | |
| 56 | +function wtsec_generate_file( $upgrader_object, $options ) { | |
| 57 | + | |
| 58 | + if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) { | |
| 59 | + foreach( $options['plugins'] as $plugin ) { | |
| 60 | + if( $plugin == WTSEC_PLUGIN_BASENAME ) { | |
| 61 | + require_once WTSEC_PLUGIN_PATH . 'library/App.php'; | |
| 62 | + $fileName = WTSEC_LIBRARY_App::getOption('am_installed_file'); | |
| 63 | + | |
| 64 | + wtsec_addCheckFile($fileName); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 68 | +} | |
| 69 | + | |
| 31 | 70 | add_action('admin_init', 'wtsec_admin_init'); |
| 32 | 71 | add_action('wp_loaded', 'wtsec_init'); |
| 33 | 72 | |
| 73 | +add_filter( 'authenticate', 'wtsec_login_check', 30, 3 ); | |
| 74 | + | |
| 34 | 75 | function wtsec_init() |
| 35 | 76 | { |
| 36 | 77 | require_once WTSEC_PLUGIN_PATH . 'library/App.php'; |
| 37 | 78 | require_once WTSEC_PLUGIN_PATH . 'library/Request.php'; |
| @@ -100,29 +141,25 @@ | ||
| 100 | 141 | } |
| 101 | 142 | |
| 102 | 143 | function wtsec_admin_init() |
| 103 | 144 | { |
| 145 | + $rand = '?rand='.rand(); | |
| 104 | 146 | if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) { |
| 105 | - wp_enqueue_script('subscriber', plugins_url('/htdocs/js/subscriber.js', __FILE__), [], false, true); | |
| 106 | - wp_enqueue_script('plug', plugins_url('/htdocs/js/d3.v5.min.js', __FILE__), [], false, true); | |
| 107 | - wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true); | |
| 108 | - wp_enqueue_script('d3-v3', plugins_url('/htdocs/js/d3.v4.js', __FILE__), array( 'jquery' ), false, true); | |
| 109 | - wp_enqueue_script('d3-scale', plugins_url('/htdocs/js/d3-scale-chromatic.v1.min.js', __FILE__), array( 'jquery' ), false, true); | |
| 110 | - wp_enqueue_script('d3-geo', plugins_url('/htdocs/js/d3-geo-projection.v2.min.js', __FILE__), array( 'jquery' ), false, true); | |
| 111 | - wp_enqueue_script('chart', plugins_url('/htdocs/js/Chart.js', __FILE__), [], false, true); | |
| 112 | - wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/circle-progress.js', __FILE__), [], false, true); | |
| 113 | - wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/rangePlugin.js', __FILE__), array( 'jquery' ), false, true); | |
| 114 | - wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/flatpickr.js', __FILE__), array( 'jquery' ), false, true); | |
| 115 | - wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/filterCalendar.js', __FILE__), array( 'jquery' ), false, true); | |
| 116 | - wp_enqueue_script('line-progress', plugins_url('/htdocs/js/line-progress.js', __FILE__), [], false, true); | |
| 117 | - wp_enqueue_script('main', plugins_url('/htdocs/js/main.js', __FILE__), [], false, true); | |
| 118 | - wp_enqueue_script('ajax', plugins_url( '/htdocs/js/ajax.js', __FILE__ ), array( 'jquery' ),false, true ); | |
| 147 | + wp_enqueue_script('subscriber', plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true); | |
| 148 | + wp_enqueue_script('d3-v4', plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true); | |
| 149 | + wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true); | |
| 150 | + wp_enqueue_script('chart', plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true); | |
| 151 | + wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true); | |
| 152 | + wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true); | |
| 153 | + wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true); | |
| 154 | + wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true); | |
| 155 | + wp_enqueue_script('line-progress', plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true); | |
| 156 | + wp_enqueue_script('main', plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true); | |
| 157 | + wp_enqueue_script('ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'jquery' ),false, true ); | |
| 119 | 158 | wp_enqueue_script('subscriber'); |
| 120 | - wp_enqueue_script('plug'); | |
| 159 | + wp_enqueue_script('print'); | |
| 160 | + wp_enqueue_script('d3-v4'); | |
| 121 | 161 | wp_enqueue_script('jsdelivr'); |
| 122 | - wp_enqueue_script('d3-v3'); | |
| 123 | - wp_enqueue_script('d3-scale'); | |
| 124 | - wp_enqueue_script('d3-geo'); | |
| 125 | 162 | wp_enqueue_script('chart'); |
| 126 | 163 | wp_enqueue_script('circle-progress'); |
| 127 | 164 | wp_enqueue_script('line-progress'); |
| 128 | 165 | wp_enqueue_script('range-plugin'); |
| @@ -132,17 +169,12 @@ | ||
| 132 | 169 | wp_enqueue_script('ajax'); |
| 133 | 170 | |
| 134 | 171 | wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css'); |
| 135 | 172 | wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap'); |
| 136 | - wp_register_style('normalize', plugins_url('/htdocs/css/normalize.css', __FILE__)); | |
| 137 | - wp_register_style('options', plugins_url('/htdocs/css/options.css', __FILE__)); | |
| 138 | - wp_register_style('header', plugins_url('/htdocs/css/header.css', __FILE__)); | |
| 139 | - wp_register_style('main', plugins_url('/htdocs/css/main.css', __FILE__)); | |
| 173 | + wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__)); | |
| 140 | 174 | wp_enqueue_style('flatpickr-css'); |
| 141 | 175 | wp_enqueue_style('font'); |
| 142 | - wp_enqueue_style('normalize'); | |
| 143 | - wp_enqueue_style('header'); | |
| 144 | - wp_enqueue_style('options'); | |
| 176 | + wp_enqueue_style('print-css'); | |
| 145 | 177 | wp_enqueue_style('main'); |
| 146 | 178 | |
| 147 | 179 | $page = wtsec_request()->page; |
| 148 | 180 | if ($page === wtsec_getRoute("login")) { |
| @@ -165,18 +197,12 @@ | ||
| 165 | 197 | } |
| 166 | 198 | } |
| 167 | 199 | } |
| 168 | 200 | |
| 169 | - | |
| 170 | -add_action('init', 'wtsec_StartSession', 1); | |
| 171 | -add_action('wp_logout', 'wtsec_EndSession'); | |
| 172 | -add_action('wp_login', 'wtsec_EndSession'); | |
| 173 | - | |
| 174 | -function wtsec_StartSession() { | |
| 175 | - if(!session_id()) { | |
| 176 | - session_start(); | |
| 201 | +function wtsec_login_check($user, $username, $password) { | |
| 202 | + require_once WTSEC_PLUGIN_PATH . 'library/App.php'; | |
| 203 | + $app = new WTSEC_LIBRARY_App; | |
| 204 | + if($app::getOption('authorized')){ | |
| 205 | + return $app->wtsec_login_check($user, $username, $password); | |
| 177 | 206 | } |
| 178 | -} | |
| 179 | - | |
| 180 | -function wtsec_EndSession() { | |
| 181 | - session_destroy (); | |
| 207 | + return $user; | |
| 182 | 208 | } |