PluginProbe
WebTotem Security / 2.3.42
WebTotem Security v2.3.42
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.42, at wt-security.php

192 lines 8.4 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.42
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
47 add_action( 'upgrader_process_complete', 'wtsec_generate_file', 10, 2 );
48
49 register_deactivation_hook( __FILE__, 'wtsec_DeactivatedPlugin' );
50
51 function wtsec_init()
52 {
53 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
54 require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
55
56 // WAF include (Если не админка и статус waf = "start", "uninstalled")
57 // && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])
58
59 $current_user = wp_get_current_user();
60 if ( !($current_user instanceof WP_User) )
61 return;
62 $roles = $current_user->roles;
63
64 if(!in_array('administrator',$roles) && !in_array('editor',$roles) && WTSEC_LIBRARY_App::getOption('authorized')){
65 if (!function_exists('wt_logs') && $waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) {
66 $path_to_waf = $_SERVER['DOCUMENT_ROOT'] . '/_include_' . $waf;
67 if (is_file($path_to_waf) && is_readable($path_to_waf)) {
68 include_once $path_to_waf;
69 }
70 }
71 }
72
73 if (is_admin()) {
74 require_once WTSEC_PLUGIN_PATH . 'library/WT.php';
75 require_once WTSEC_PLUGIN_PATH . 'library/Idn.php';
76 require_once WTSEC_PLUGIN_PATH . 'library/Session.php';
77 require_once WTSEC_PLUGIN_PATH . 'routes.php';
78 require_once WTSEC_PLUGIN_PATH . 'services.php';
79 require_once WTSEC_PLUGIN_PATH . 'helpers.php';
80
81 function wtsec_request()
82 {
83 return new WTSEC_LIBRARY_Request();
84 }
85
86 function wtsec_app()
87 {
88 return new WTSEC_LIBRARY_App();
89 }
90
91 function wtsec_filesystem_init($form_url, $method, $context, $fields = null)
92 {
93 global $wp_filesystem;
94 if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) {
95 return false;
96 }
97 if (!WP_Filesystem($creds)) {
98 request_filesystem_credentials($form_url, $method, true, $context);
99 return false;
100 }
101 return true;
102 }
103
104 function wtsec_getImagePath($image)
105 {
106 return plugins_url('/htdocs/img/' . $image, __FILE__);
107 }
108
109 }
110 }
111
112 function wtsec_admin_init()
113 {
114 if(!function_exists('wtsec_request')){
115 function wtsec_request(){
116 require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
117 return new WTSEC_LIBRARY_Request();
118 }
119 }
120
121 $rand = '?rand='.rand();
122 if (is_admin() && stripos(wtsec_request()->page, WTSEC_PLUGIN_NAME) !== false) {
123 if(WTSEC_LIBRARY_App::authorized()){
124 wp_enqueue_script('subscriber', plugins_url('/htdocs/js/wtsec_subscriber.js'.$rand, __FILE__), [], false, true);
125 wp_enqueue_script('amplitude', plugins_url('/htdocs/js/wtsec_amplitude.js', __FILE__ ), array(),false, true );
126 wp_enqueue_script('d3-v4', plugins_url('/htdocs/js/wtsec_d3.v4.js', __FILE__), array( 'jquery' ), false, true);
127 wp_enqueue_script('jsdelivr', plugins_url('/htdocs/js/wtsec_jsdelivr_chart.js', __FILE__), array( 'jquery' ), false, true);
128 wp_enqueue_script('chart', plugins_url('/htdocs/js/wtsec_Chart.js'.$rand, __FILE__), [], false, true);
129 wp_enqueue_script('circle-progress', plugins_url('/htdocs/js/wtsec_circle-progress.js', __FILE__), [], false, true);
130 wp_enqueue_script('range-plugin', plugins_url('/htdocs/js/wtsec_rangePlugin.js', __FILE__), array( 'jquery' ), false, true);
131 wp_enqueue_script('flatpickr', plugins_url('/htdocs/js/wtsec_flatpickr.js', __FILE__), array( 'jquery' ), false, true);
132 wp_enqueue_script('filter-calendar', plugins_url('/htdocs/js/wtsec_filterCalendar.js', __FILE__), array( 'jquery' ), false, true);
133 wp_enqueue_script('line-progress', plugins_url('/htdocs/js/wtsec_line-progress.js', __FILE__), [], false, true);
134 wp_enqueue_script('main', plugins_url('/htdocs/js/wtsec_main.js'.$rand, __FILE__), [], false, true);
135 wp_enqueue_script('ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), array( 'wp-i18n','jquery' ),false, true );
136 wp_enqueue_script('subscriber');
137 wp_enqueue_script('amplitude');
138 wp_enqueue_script('d3-v4');
139 wp_enqueue_script('jsdelivr');
140 wp_enqueue_script('chart');
141 wp_enqueue_script('circle-progress');
142 wp_enqueue_script('range-plugin');
143 wp_enqueue_script('flatpickr');
144 wp_enqueue_script('filter-calendar');
145 wp_enqueue_script('line-progress');
146 wp_enqueue_script('main');
147 wp_enqueue_script('ajax');
148
149 //wp_register_script( 'ajax', plugins_url( '/htdocs/js/wtsec_ajax.js'.$rand, __FILE__ ), [ 'wp-i18n', 'jquery' ], false, true );
150 wp_set_script_translations( 'ajax', 'wtotem' );
151 }
152
153 wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
154 wp_register_style('font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');
155 wp_register_style('main', plugins_url('/htdocs/css/wtsec_main.css'.$rand, __FILE__));
156 wp_enqueue_style('flatpickr-css');
157 wp_enqueue_style('font');
158 wp_enqueue_style('main');
159
160 $page = wtsec_request()->page;
161 if ($page === wtsec_getRoute("login")) {
162 if (WTSEC_LIBRARY_App::authorized()) {
163 wp_safe_redirect(wtsec_getUrl('dashboard'));
164 }
165 } elseif ($page === wtsec_getRoute("logout")) {
166 WTSEC_LIBRARY_App::setSiteOption('am_installed', false);
167 WTSEC_LIBRARY_App::logout();
168 wp_safe_redirect(wtsec_getUrl('login'));
169 } else {
170 if (!WTSEC_LIBRARY_App::authorized()) {
171 wp_safe_redirect(wtsec_getUrl('login'));
172 }
173 }
174 }
175 }
176
177 // Create file generate.php after plugin update
178 function wtsec_generate_file( $upgrader_object, $options ) {
179
180 if( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
181 foreach( $options['plugins'] as $plugin ) {
182 if( $plugin == WTSEC_PLUGIN_BASENAME ) {
183 require_once WTSEC_PLUGIN_PATH . 'library/App.php';
184 $fileName = WTSEC_LIBRARY_App::getOption('am_installed_file');
185
186 wtsec_addCheckFile($fileName);
187 }
188 }
189 }
190 }
191
192