PluginProbe
WebTotem Security / 2.3.26
WebTotem Security v2.3.26
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.26, at wt-security.php

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