PluginProbe
WebTotem Security / 2.4.9
WebTotem Security v2.4.9
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 / lib / Interface.php

Interface.php in WebTotem Security 2.4.9, at lib/Interface.php

219 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
4 if (!headers_sent()) {
5 header('HTTP/1.1 403 Forbidden');
6 }
7 die("Protected By WebTotem!");
8 }
9
10 /**
11 * Plugin initializer.
12 *
13 */
14 class WebTotemInterface extends WebTotem {
15
16 /**
17 * Execute pre-checks before every page.
18 *
19 * @return void
20 */
21 public static function startupChecks() {
22 $_page = WebTotemRequest::get('page');
23 if(strpos($_page, 'wtotem') === 0){
24
25 if(!WebTotemOption::isActivated()){
26 // Checking the old version of options.
27 WebTotemOption::checkOldOptions();
28 }
29
30 WebTotemOption::multisiteCheck();
31
32 if(!WebTotemOption::isActivated() and $_page !== 'wtotem_activation') {
33 // If the plugin is not activated by the API key, then redirect to the activation page.
34 wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_activation') );
35 exit;
36 }
37 elseif (WebTotemOption::isActivated() and ($_page === 'wtotem_activation' or $_page === 'wtotem')){
38 // If the plugin is activated by the API key, then redirect to the main page.
39 if(self::isMultiSite() and is_super_admin()){
40 // Main page is all sites page.
41 wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_all_sites') );
42 } else {
43 // Main page is dashboard page.
44 wp_safe_redirect( WebTotem::adminURL('admin.php?page=wtotem_dashboard') );
45 }
46 exit;
47 }
48 elseif(WebTotemOption::isActivated()) {
49 // Checking whether agents are installed, if they are not installed, then install.
50 self::checkAgents();
51 }
52 }
53
54 $sapi = @php_sapi_name();
55 if( ! current_user_can( 'publish_posts' ) and $sapi != "cli" ) {
56 if ($waf = WebTotemOption::getOption(("waf_installed_file"))) {
57 $include_waf_file = ABSPATH . '/_include_' . $waf;
58
59 if (is_file($include_waf_file) && is_readable($include_waf_file)) {
60 include_once $include_waf_file;
61 }
62 }
63 }
64 }
65
66 /**
67 * Checking whether agents are installed, if they are not installed, then install.
68 */
69 private static function checkAgents(){
70
71 $api_key = WebTotemOption::getOption('api_key');
72
73 // Check if the plugin version has changed.
74 WebTotemAgentManager::checkVersion();
75
76 if(!$api_key){
77 $api_key = WebTotemOption::getOption('api_key');
78 }
79
80 $host = WebTotemAPI::siteInfo();
81
82 if ($api_key && array_key_exists('id', $host)) {
83
84 // Install Agent Manager if it was not previously installed.
85 $am_installed = WebTotemAgentManager::checkInstalledService('am');
86 if (!$am_installed['option_status'] || !$am_installed['file_status']) {
87
88 $am_was_installed = WebTotemAgentManager::amInstall();
89
90 if (!$am_was_installed) {
91 WebTotemOption::setOptions(['am_installed' => FALSE]);
92 }
93 }
94
95 }
96 }
97
98 /**
99 * When adding a new site, add it to the WebTotem platform.
100 */
101 public static function addNewSite($new_site){
102 $domain = untrailingslashit($new_site->domain . $new_site->path);
103 WebTotemOption::setNotification( 'info', __('A new website has been added: ', 'wtotem') . $domain);
104 WebTotemAPI::addMultiSiteNewSites([$domain]);
105 }
106
107 /**
108 * Verify the nonce of the previous page after a form submission.
109 *
110 * @return bool True if the nonce is valid, false otherwise.
111 */
112 public static function checkNonce() {
113 if (!empty($_POST)) {
114 $name = 'wtotem_page_nonce';
115 $value = WebTotemRequest::post($name);
116
117 if (!$value || !wp_verify_nonce($value, $name)) {
118 WebTotemOption::setNotification('error', __('The WordPress CSRF check failed. The submitted form is missing an important unique code. Go back and try again.', 'wtotem'));
119 return false;
120 }
121 }
122
123 return true;
124 }
125
126 /**
127 * A safe way to add JavaScript and css files to a WordPress-managed page
128 *
129 * @return void
130 */
131 public static function enqueueScripts() {
132 $_page = WebTotemRequest::get('page');
133 if(strpos($_page, 'wtotem') === 0){
134 // Adding CSS files.
135 wp_register_style(
136 'wtotem_flatpickr',
137 WEBTOTEM_URL . '/includes/css/flatpickr.min.css',
138 array(),
139 WebTotem::fileVersion('includes/css/flatpickr.min.css')
140 );
141 wp_enqueue_style('wtotem_flatpickr');
142
143 wp_register_style(
144 'wtotem_main_css',
145 WEBTOTEM_URL . '/includes/css/main.css',
146 array(),
147 WebTotem::fileVersion('includes/css/main.css')
148 );
149 wp_enqueue_style('wtotem_main_css');
150
151 // Adding JS files.
152 wp_register_script(
153 'wtotem_amplitude',
154 WEBTOTEM_URL . '/includes/js/amplitude.js',
155 array( 'jquery' ),
156 WebTotem::fileVersion('includes/js/amplitude.js'),
157 false
158 );
159 wp_enqueue_script('wtotem_amplitude');
160
161 wp_register_script(
162 'wtotem_d3',
163 WEBTOTEM_URL . '/includes/js/d3.v4.js',
164 array( 'jquery' ),
165 WebTotem::fileVersion('includes/js/d3.v4.js'),
166 true
167 );
168 wp_enqueue_script('wtotem_d3');
169
170 wp_register_script(
171 'wtotem_chart',
172 WEBTOTEM_URL . '/includes/js/chart.js',
173 array( 'jquery', 'wtotem_d3', 'wtotem_jsdelivr'),
174 WebTotem::fileVersion('includes/js/chart.js'),
175 true
176 );
177 wp_enqueue_script('wtotem_chart');
178
179 wp_register_script(
180 'wtotem_flatpickr_js',
181 WEBTOTEM_URL . '/includes/js/flatpickr.js',
182 array( 'jquery', 'wp-i18n' ),
183 WebTotem::fileVersion('includes/js/flatpickr.js'),
184 true
185 );
186 wp_enqueue_script('wtotem_flatpickr_js');
187 wp_set_script_translations( 'wtotem_flatpickr_js', 'wtotem' );
188
189 wp_register_script(
190 'wtotem_jsdelivr',
191 WEBTOTEM_URL . '/includes/js/jsdelivr_chart.js',
192 array( 'jquery' ),
193 WebTotem::fileVersion('includes/js/jsdelivr_chart.js'),
194 true
195 );
196 wp_enqueue_script('wtotem_jsdelivr');
197
198 wp_register_script(
199 'wtotem_progress_bar',
200 WEBTOTEM_URL . '/includes/js/progress_bar.js',
201 array(),
202 WebTotem::fileVersion('includes/js/progress_bar.js'),
203 true
204 );
205 wp_enqueue_script('wtotem_progress_bar');
206
207 wp_register_script(
208 'wtotem_main',
209 WEBTOTEM_URL . '/includes/js/main.js',
210 array( 'jquery' ),
211 WebTotem::fileVersion('includes/js/main.js'),
212 true
213 );
214 wp_enqueue_script('wtotem_main');
215 }
216 }
217
218 }
219