PluginProbe
WebTotem Security / 2.4.2
WebTotem Security v2.4.2
3.0.2 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 All 110 releases
← All changes | wt-security.php +120 -163 2.2.12.4.2 View file →
@@ -1,182 +1,139 @@
1 -<?php defined('ABSPATH') or die("Protected By WT!");
1 +<?php
2 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.2.1
8 -*/
3 +/**
4 + * Plugin Name: WebTotem Security
5 + * Description: The <a href="https://wtotem.com/" target="_blank">WebTotem</a> Security plugin monitors websites and prevents website attacks with the help of special internal and external utilities.
6 + * Author URI: https://wtotem.com/
7 + * Author: WebTotem
8 + * Text Domain: wtotem
9 + * Domain Path: /lang
10 + * Version: 2.4.2
11 + *
12 + * PHP version 7
13 + *
14 + * @copyright 2021-2022 WebTotem
15 + * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL2
16 + * @link https://wordpress.org/plugins/wt-security
17 + */
9 18
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_API_URL", "api.wtotem.com");
17 -define("WTSEC_FILE_URL", "https://".WTSEC_API_URL."/agent");
18 -define("WTSEC_ROOT", WP_PLUGIN_DIR . '/');
19 -define("WTSEC_MODULES_DIR", WTSEC_PLUGIN_PATH . 'uploads/');
20 -if (is_dir(WTSEC_MODULES_DIR) && is_writable(WTSEC_MODULES_DIR)) {
21 - define("WTSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
22 - define("WTOTEMSEC_INSTALLATION_DIR", WTSEC_MODULES_DIR);
23 -} else {
24 - define("WTSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
25 - define("WTOTEMSEC_INSTALLATION_DIR", wp_upload_dir()['basedir'] . '/');
19 +/**
20 + * Main file to control the plugin.
21 + */
22 +define('WEBTOTEM_INIT', true);
23 +
24 +/**
25 + * Plugin dependencies.
26 + *
27 + * list of required WordPress functions for the plugin to work.
28 + */
29 +$wtotem_dependencies = array(
30 + 'wp',
31 + 'wp_die',
32 + 'add_action',
33 + 'remove_action',
34 + 'wp_remote_get',
35 + 'wp_remote_post',
36 +);
37 +
38 +// Stopping execution if dependencies are not met.
39 +foreach ($wtotem_dependencies as $dependency) {
40 + if (!function_exists($dependency)) {
41 + // Report invalid access.
42 + header('HTTP/1.1 403 Forbidden');
43 + die("Protected By WebTotem!");
44 + }
26 45 }
27 -define("WTSEC_PLUGIN_URL", plugins_url("", __FILE__));
28 -define("WTSEC_SITE_URL", str_replace(['http://', 'https://', 'www.', '//', '://'], '', get_site_url()));
29 46
30 -define("WTSEC_PLUGIN_INFORMATION_VERSION", "2.2.1");
47 +// Stopping execution if the ABSPATH constant is not available
48 +if (!defined('ABSPATH')) {
49 + // Report invalid access.
50 + header('HTTP/1.1 403 Forbidden');
51 + die("Protected By WebTotem!");
52 +}
31 53
32 -add_action('admin_init', 'wtsec_admin_init');
33 -add_action('wp_loaded', 'wtsec_init');
54 +/**
55 + * Current version of the plugin's code.
56 + */
57 +define('WEBTOTEM_VERSION', '2.4.2');
34 58
35 -function wtsec_init()
36 -{
37 - require_once WTSEC_PLUGIN_PATH . 'library/App.php';
38 - require_once WTSEC_PLUGIN_PATH . 'library/Request.php';
59 +/**
60 + * The name of the folder where the plugin's files will be located.
61 + */
62 +define("WEBTOTEM_PLUGIN_FOLDER", basename(dirname(__FILE__)));
39 63
40 - // WAF include (Если не админка и статус waf = "start", "uninstalled")
41 - if (!is_admin() && in_array(WTSEC_LIBRARY_App::getOption('waf_status'), ["start", "uninstalled"])) {
42 - if ($waf = WTSEC_LIBRARY_App::getOption(("waf_installed_file"))) {
43 - $path_to_waf = WTSEC_INSTALLATION_DIR . '/_include_' . $waf;
44 - if (is_file($path_to_waf) && is_readable($path_to_waf)) {
45 - include_once $path_to_waf;
46 - }
47 - }
48 - }
64 +/**
65 + * The fullpath where the plugin's files will be located.
66 + */
67 +define('WEBTOTEM_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . WEBTOTEM_PLUGIN_FOLDER);
49 68
50 - if (is_admin()) {
51 - require_once WTSEC_PLUGIN_PATH . 'library/WT.php';
52 - require_once WTSEC_PLUGIN_PATH . 'library/Localization.php';
53 - require_once WTSEC_PLUGIN_PATH . 'library/Idn.php';
54 - require_once WTSEC_PLUGIN_PATH . 'library/Session.php';
55 - require_once WTSEC_PLUGIN_PATH . 'routes.php';
56 - require_once WTSEC_PLUGIN_PATH . 'services.php';
57 - require_once WTSEC_PLUGIN_PATH . 'helpers.php';
69 +/**
70 + * The local URL where the plugin's files and assets are served.
71 + */
72 +define('WEBTOTEM_URL', rtrim(plugin_dir_url(__FILE__), '/'));
58 73
59 - function wtsec_request()
60 - {
61 - return new WTSEC_LIBRARY_Request();
62 - }
63 - function wtsec_app()
64 - {
65 - return new WTSEC_LIBRARY_App();
66 - }
67 - function wtsec_filesystem_init($form_url, $method, $context, $fields = null)
68 - {
69 - global $wp_filesystem;
70 - if (!$creds = request_filesystem_credentials($form_url, $method, false, $context, $fields)) {
71 - return false;
72 - }
73 - if (!WP_Filesystem($creds)) {
74 - request_filesystem_credentials($form_url, $method, true, $context);
75 - return false;
76 - }
77 - return true;
78 - }
79 - function wtsec_locale($lmsg, $args = [])
80 - {
81 - return WTSEC_LIBRARY_Localization::lmsg($lmsg, $args);
82 - }
83 - function wtsec_getImagePath($image)
84 - {
85 - return plugins_url('/htdocs/img/' . $image, __FILE__);
86 - }
87 - function wtsec_SIS($arr, $key, $form = null)
88 - {
89 - $key = explode(".", $key);
90 - foreach ($key as $_key) {
91 - if (!isset($arr[$_key])) {
92 - $arr = "";
93 - break;
94 - }
95 - $arr = $arr[$_key];
96 - }
97 - return !empty($form) ? str_replace("$" . $key, $arr, $form) : $arr;
98 - }
99 - }
74 +/**
75 + * The domain name of the current site, without protocol and www.
76 + */
77 +define("WEBTOTEM_SITE_DOMAIN", str_replace(['http://', 'https://', '//', '://', 'www.'], '', get_site_url()));
78 +
79 +/**
80 + * Remote URL where the public WebTotem API service is running.
81 + */
82 +if (!defined('WEBTOTEM_API_URL')) {
83 + define('WEBTOTEM_API_URL', 'https://api.wtotem.com/graphql');
100 84 }
101 85
102 -function wtsec_admin_init()
86 +/**
87 + * Unique name of the plugin through out all the code.
88 + */
89 +define("WEBTOTEM", 'wtotem');
90 +
91 +/* Load plugin translations */
92 +function wtotem_load_plugin_textdomain()
103 93 {
104 - 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 );
119 - wp_enqueue_script('subscriber');
120 - wp_enqueue_script('plug');
121 - wp_enqueue_script('jsdelivr');
122 - wp_enqueue_script('d3-v3');
123 - wp_enqueue_script('d3-scale');
124 - wp_enqueue_script('d3-geo');
125 - wp_enqueue_script('chart');
126 - wp_enqueue_script('circle-progress');
127 - wp_enqueue_script('line-progress');
128 - wp_enqueue_script('range-plugin');
129 - wp_enqueue_script('flatpickr');
130 - wp_enqueue_script('filter-calendar');
131 - wp_enqueue_script('main');
132 - wp_enqueue_script('ajax');
94 + load_plugin_textdomain('wtotem', false, basename(dirname(__FILE__)) . '/lang/');
95 +}
96 +add_action('plugins_loaded', 'wtotem_load_plugin_textdomain');
133 97
134 - wp_register_style('flatpickr-css', 'https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css');
135 - 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__));
140 - wp_enqueue_style('flatpickr-css');
141 - wp_enqueue_style('font');
142 - wp_enqueue_style('normalize');
143 - wp_enqueue_style('header');
144 - wp_enqueue_style('options');
145 - wp_enqueue_style('main');
98 +$composer_autoload = __DIR__ . '/vendor/autoload.php';
99 +if ( file_exists( $composer_autoload ) ) {
100 + require_once $composer_autoload;
101 +}
146 102
147 - $page = wtsec_request()->page;
148 - if ($page === wtsec_getRoute("login")) {
149 - if (WTSEC_LIBRARY_App::authorized()) {
150 - wp_safe_redirect(wtsec_getUrl('dashboard'));
151 - }
152 - } elseif ($page === wtsec_getRoute("logout")) {
153 - WTSEC_LIBRARY_App::logout();
154 - if (!WTSEC_LIBRARY_App::authorized()) {
155 - wp_safe_redirect(wtsec_getUrl('login'));
156 - }
157 - } elseif ($page === wtsec_getRoute("activate")) {
158 - if (WTSEC_LIBRARY_App::authorized()) {
159 - wp_safe_redirect(wtsec_getUrl('sites'));
160 - }
161 - } else {
162 - if (!WTSEC_LIBRARY_App::authorized()) {
163 - wp_safe_redirect(wtsec_getUrl('login'));
164 - }
165 - }
166 - }
167 -}
103 +/* Load all classes before anything else. */
104 +require_once 'lib/Helper.php';
105 +require_once 'lib/API.php';
106 +require_once 'lib/Interface.php';
107 +require_once 'lib/AgentManager.php';
108 +require_once 'lib/Option.php';
109 +require_once 'lib/Request.php';
110 +require_once 'lib/Template.php';
111 +require_once 'lib/Country.php';
112 +require_once 'lib/Ajax.php';
168 113
114 +/* Load page and ajax handlers */
115 +require_once 'src/PageHandler.php';
169 116
170 -add_action('init', 'wtsec_StartSession', 1);
171 -add_action('wp_logout', 'wtsec_EndSession');
172 -add_action('wp_login', 'wtsec_EndSession');
117 +/* Load common variables and triggers */
118 +require_once 'src/Common.php';
173 119
174 -function wtsec_StartSession() {
175 - if(!session_id()) {
176 - session_start();
177 - }
120 +/**
121 + * Uninstalled the plugin
122 + *
123 + * @return void
124 + */
125 +function wtotemUninstall() {
126 +
127 + /* Delete settings from the database */
128 + $options = WebTotemOption::getAllOptions();
129 + WebTotemOption::clearOptions($options);
130 + if(WebTotem::isMultiSite()){
131 + WebTotemOption::clearAllHosts();
132 + }
133 +
134 + /* Delete all agents files and directories */
135 + WebTotemAgentManager::removeAgents();
136 +
178 137 }
179 138
180 -function wtsec_EndSession() {
181 - session_destroy ();
182 -}
139 +register_uninstall_hook(__FILE__, 'wtotemUninstall');