PluginProbe
WebTotem Security / 2.4.3
WebTotem Security v2.4.3
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.3, at lib/Interface.php

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