PluginProbe
WebTotem Security / 2.3.37
WebTotem Security v2.3.37
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.37, at wt-security.php

200 lines 8.5 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: WebTotem Security
5 Description: WebTotem is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way.
6 Author: WebTotem
7 Version: 2.3.37
8 Text Domain: wtotem
9 Domain Path: /languages
10 */
11
12 __( 'WebTotem Security', 'wtotem' );
13 __( 'WebTotem is a SaaS which provides powerful tools for securing and monitoring your website in one place in easy and flexible way.', 'wtotem' );
14
15 define("WTSEC_PAGE_TITLE", 'Dashboard');
16 define("WTSEC_MENU_TITLE", 'WT Security');
17 define("WTSEC_PLUGIN_PATH", plugin_dir_path(__FILE__));
18 define("WTSEC_PLUGIN_NAME", 'wt-security');
19 define("WTSEC_PLUGIN_PREFIX", 'wtsec_');
20 define("WTSEC_PAGE_PREFIX", WTSEC_PLUGIN_NAME . '-');
21 define("WTSEC_FILE_URL", "https://api.wtotem.com/agent");
22 define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/');
23
24 if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) {
25 define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
26 } else {
27 define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
28 }
29
30 define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__));
31 define("WTSEC_PLUGIN_BASENAME", plugin_basename( __FILE__));
32 define("WTSEC_SITE_URL", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url()));
33
34 define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.3");
35
36 $curLang = substr(get_bloginfo('language'), 0,2);
37 $language = (in_array($curLang,['ru','en','pl'])) ? $curLang : 'en' ;
38 define("WTSEC_LANGUAGE", $language);
39
40 add_action( 'plugins_loaded', function(){
41 load_plugin_textdomain( 'wtotem', false, dirname( plugin_basename(__FILE__) ) . '/languages' );
42 } );
43
44 add_action('wp_loaded', 'wtsec_init');
45 add_action('admin_init', 'wtsec_admin_init');
46 add_filter( 'authenticate', 'wtsec_login_check', 30, 3 );
47
48 add_action( 'upgrader_process_complete', 'wtsec_generate_file', 10, 2 );
49
50 add_action( 'deactivated_plugin', 'wtsec_DeactivatedPlugin', 1 );
51
52 function wtsec_init()
53 {
54 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
55 require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
56
57 // WAF include (Если не админка и статус waf = "start", "uninstalled")
58 // && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])
59
60 $current_user = wp_get_current_user();
61 if ( !($current_user instanceof WP_User) )
62 return;
63 $roles = $current_user->roles;
64
65 if(!in_array('administrator',$roles) && !in_array('editor',$roles) && WTSEC_LIBRARY_App::getOption('authorized')){
66 if (!function_exists('wt_logs') && $waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) {
67 $path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf;
68 if (is_file($path_to_waf) && is_readable($path_to_waf)) {
69 include_once $path_to_waf;
70 }
71 }
72 }
73
74 if (is_admin()) {
75 require_once WTSEC_PLUGIN_PATH . 'library/WT.php';
76 require_once WTSEC_PLUGIN_PATH . 'library/Idn.php';
77 require_once WTSEC_PLUGIN_PATH . 'library/Session.php';
78 require_once WTSEC_PLUGIN_PATH . 'routes.php';
79 require_once WTSEC_PLUGIN_PATH . 'services.php';
80 require_once WTSEC_PLUGIN_PATH . 'helpers.php';
81
82 function wtsec_request()
83 {
84 return new WTSEC_LIBRARY_Request();
85 }
86
87 function wtsec_app()
88 {
89 return new WTSEC_LIBRARY_App();
90 }
91
92 function wtsec_filesystem_init($form_url, $method, $context, $fields = null)
93 {
94 global $wp_filesystem;
95 if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) {
96 return false;
97 }
98 if (!WP_Filesystem($creds)) {
99 request_filesystem_credentials($form_url, $method, true, $context);
100 return false;
101 }
102 return true;
103 }
104
105 function wtsec_getImagePath($image)
106 {
107 return plugins_url('/htdocs/img/' . $image, __FILE__);
108 }
109
110 }
111 }
112
113 function wtsec_admin_init()
114 {
115 if(!function_exists('wtsec_request')){
116 function wtsec_request(){
117 require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
118 return new WTSEC_LIBRARY_Request();
119 }
120 }
121
122 $rand = '?rand='.rand();
123 if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) {
124 if(WTSEC_LIBRARY_App::authorized()){
125 wp_enqueue_script('subscriber', plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true);
126 wp_enqueue_script('amplitude', plugins_url( '/htdocs/js/wtsec_amplitude.js', __FILE__ ), array(),false, true );
127 wp_enqueue_script('d3-v4', plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true);
128 wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true);
129 wp_enqueue_script('chart', plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true);
130 wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true);
131 wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true);
132 wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true);
133 wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true);
134 wp_enqueue_script('line-progress', plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true);
135 wp_enqueue_script('main', plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true);
136 wp_enqueue_script('ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'jquery' ),false, true );
137 wp_enqueue_script('subscriber');
138 wp_enqueue_script('amplitude');
139 wp_enqueue_script('d3-v4');
140 wp_enqueue_script('jsdelivr');
141 wp_enqueue_script('chart');
142 wp_enqueue_script('circle-progress');
143 wp_enqueue_script('range-plugin');
144 wp_enqueue_script('flatpickr');
145 wp_enqueue_script('filter-calendar');
146 wp_enqueue_script('line-progress');
147 wp_enqueue_script('main');
148 wp_enqueue_script('ajax');
149 }
150
151 wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
152 wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
153 wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__));
154 wp_enqueue_style('flatpickr-css');
155 wp_enqueue_style('font');
156 wp_enqueue_style('main');
157
158 $page = wtsec_request()->page;
159 if ($page === wtsec_getRoute("login")) {
160 if (WTSEC_LIBRARY_App::authorized()) {
161 wp_safe_redirect(wtsec_getUrl('dashboard'));
162 }
163 } elseif ($page === wtsec_getRoute("logout")) {
164 WTSEC_LIBRARY_App::setSiteOption('am_installed', false);
165 WTSEC_LIBRARY_App::logout();
166 wp_safe_redirect(wtsec_getUrl('login'));
167 } else {
168 if (!WTSEC_LIBRARY_App::authorized()) {
169 wp_safe_redirect(wtsec_getUrl('login'));
170 }
171 }
172 }
173 }
174
175
176 function wtsec_login_check($user, $username, $password) {
177 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
178 $app = new WTSEC_LIBRARY_App;
179 if($app::getOption('authorized')){
180 return $app->wtsec_login_check($user, $username, $password);
181 }
182 return $user;
183 }
184
185 // Create file generate.php after plugin update
186 function wtsec_generate_file( $upgrader_object, $options ) {
187
188 if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
189 foreach( $options['plugins'] as $plugin ) {
190 if( $plugin == WTSEC_PLUGIN_BASENAME ) {
191 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
192 $fileName = WTSEC_LIBRARY_App::getOption('am_installed_file');
193
194 wtsec_addCheckFile($fileName);
195 }
196 }
197 }
198 }
199
200