PluginProbe
WebTotem Security / 2.3.21
WebTotem Security v2.3.21
3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 2.2.4 All 109 releases
wt-security / wt-security.php

wt-security.php in WebTotem Security 2.3.21, at wt-security.php

232 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.21
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_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/');
18 if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) {
19 define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
20 define("WTOTEMSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
21 } else {
22 define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
23 define("WTOTEMSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
24 }
25 define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__));
26 define("WTSEC_PLUGIN_BASENAME", plugin_basename( __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( '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
70 add_action('admin_init', 'wtsec_admin_init');
71 add_action('wp_loaded', 'wtsec_init');
72
73 add_action( 'authenticate', 'wtsec_login_check' );
74
75 function wtsec_init()
76 {
77 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
78 require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
79
80 // WAF include (Если не админка и статус waf = "start", "uninstalled")
81 // && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])
82 if (!is_admin()) {
83 if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) {
84 $path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf;
85 if (is_file($path_to_waf) && is_readable($path_to_waf)) {
86 include_once $path_to_waf;
87 }
88 }
89 }
90
91 if (is_admin()) {
92 require_once WTSEC_PLUGIN_PATH . 'library/WT.php';
93 require_once WTSEC_PLUGIN_PATH . 'library/Localization.php';
94 require_once WTSEC_PLUGIN_PATH . 'library/Idn.php';
95 require_once WTSEC_PLUGIN_PATH . 'library/Session.php';
96 require_once WTSEC_PLUGIN_PATH . 'routes.php';
97 require_once WTSEC_PLUGIN_PATH . 'services.php';
98 require_once WTSEC_PLUGIN_PATH . 'helpers.php';
99
100 function wtsec_request()
101 {
102 return new WTSEC_LIBRARY_Request();
103 }
104 function wtsec_app()
105 {
106 return new WTSEC_LIBRARY_App();
107 }
108 function wtsec_filesystem_init($form_url, $method, $context, $fields = null)
109 {
110 global $wp_filesystem;
111 if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) {
112 return false;
113 }
114 if (!WP_Filesystem($creds)) {
115 request_filesystem_credentials($form_url, $method, true, $context);
116 return false;
117 }
118 return true;
119 }
120 function wtsec_locale($lmsg, $args = [])
121 {
122 return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args);
123 }
124 function wtsec_getImagePath($image)
125 {
126 return plugins_url('/htdocs/img/' . $image, __FILE__);
127 }
128 function wtsec_SIS($arr, $key, $form = null)
129 {
130 $key = explode(".", $key);
131 foreach ($key as $_key) {
132 if (!isset($arr[$_key])) {
133 $arr = "";
134 break;
135 }
136 $arr = $arr[$_key];
137 }
138 return !empty($form) ? str_replace("$" . $key, $arr, $form) : $arr;
139 }
140 }
141 }
142
143 function wtsec_admin_init()
144 {
145 $rand = '?rand='.rand();
146 if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) {
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 );
158 wp_enqueue_script('subscriber');
159 wp_enqueue_script('print');
160 wp_enqueue_script('d3-v4');
161 wp_enqueue_script('jsdelivr');
162 wp_enqueue_script('chart');
163 wp_enqueue_script('circle-progress');
164 wp_enqueue_script('line-progress');
165 wp_enqueue_script('range-plugin');
166 wp_enqueue_script('flatpickr');
167 wp_enqueue_script('filter-calendar');
168 wp_enqueue_script('main');
169 wp_enqueue_script('ajax');
170
171 wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
172 wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
173 wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__));
174 wp_enqueue_style('flatpickr-css');
175 wp_enqueue_style('font');
176 wp_enqueue_style('print-css');
177 wp_enqueue_style('main');
178
179 $page = wtsec_request()->page;
180 if ($page === wtsec_getRoute("login")) {
181 if (WTSEC_LIBRARY_App::authorized()) {
182 wp_safe_redirect(wtsec_getUrl('dashboard'));
183 }
184 } elseif ($page === wtsec_getRoute("logout")) {
185 WTSEC_LIBRARY_App::logout();
186 if (!WTSEC_LIBRARY_App::authorized()) {
187 wp_safe_redirect(wtsec_getUrl('login'));
188 }
189 } elseif ($page === wtsec_getRoute("activate")) {
190 if (WTSEC_LIBRARY_App::authorized()) {
191 wp_safe_redirect(wtsec_getUrl('sites'));
192 }
193 } else {
194 if (!WTSEC_LIBRARY_App::authorized()) {
195 wp_safe_redirect(wtsec_getUrl('login'));
196 }
197 }
198 }
199 }
200
201 function wtsec_login_check() {
202 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
203 require_once WTSEC_PLUGIN_PATH . 'library/Localization.php';
204 $app = new WTSEC_LIBRARY_App;
205
206 function wtsec_locale($lmsg, $args = [])
207 {
208 return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args);
209 }
210
211 $app->wtsec_login_check();
212 }
213
214
215 add_action('init', 'wtsec_StartSession', 1);
216 add_action('wp_logout', 'wtsec_EndSession');
217 add_action('wp_login', 'wtsec_EndSession');
218
219
220 function wtsec_StartSession() {
221 if(!session_id()) {
222 session_start();
223 }
224 }
225
226 function wtsec_EndSession() {
227 session_destroy ();
228 }
229
230
231
232