PluginProbe
WebTotem Security / 2.1.1
WebTotem Security v2.1.1
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 / routes.php

routes.php in WebTotem Security 2.1.1, at routes.php

430 lines 17.6 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 add_action('admin_menu', 'wtsec_add_menu_link');
4 add_action('wp_ajax_change_status', 'wtsec_ajax_changeStatus');
5 add_action('admin_post_change_status', 'wtsec_changeStatus');
6 add_action('wp_ajax_cmd', 'wtsec_cmd_ajax');
7 add_action('admin_post_login_form', 'wtsec_login_form');
8 add_action('admin_post_ajax_cmd', 'wtsec_cmd_ajax');
9
10 function wtsec_add_menu_link()
11 {
12 add_menu_page(
13 WTSEC_PAGE_TITLE,
14 WTSEC_MENU_TITLE,
15 'manage_options',
16 wtsec_getRoute('dashboard'),
17 'wtsec_index_page',
18 '',
19 '1'
20 );
21 $parent = wtsec_getRoute('dashboard');
22 if (WTSEC_LIBRARY_App::authorized()) {
23 $capability = 'manage_options';
24 foreach (wtsec_pages() as $page => $arguments) {
25 add_submenu_page($parent, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), $arguments['function']);
26 }
27 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
28 add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
29 } else {
30 $capability = 'manage_options';
31 foreach (wtsec_pages() as $page => $arguments) {
32 add_submenu_page(null, $arguments['page_title'], $arguments['menu_title'], $capability, wtsec_getRoute($page), function () {
33 wp_safe_redirect(wtsec_getUrl('login'));
34 });
35 }
36 add_submenu_page($parent, WTSEC_LIBRARY_Localization::lmsg('sign_in'), WTSEC_LIBRARY_Localization::lmsg('sign_in'), 'manage_options', wtsec_getRoute('login'), 'wtsec_login');
37 add_submenu_page(null, WTSEC_LIBRARY_Localization::lmsg('logout'), WTSEC_LIBRARY_Localization::lmsg('logout'), 'manage_options', wtsec_getRoute('logout'), 'wtsec_logout');
38 }
39 }
40
41 function wtsec_index_page()
42 {
43 $host = WTSEC_LIBRARY_WT::getOwnSite();
44 $services = [];
45 if (!empty($host)) {
46 $checks = WTSEC_LIBRARY_WT::getAllChecks($host['id']);
47 foreach ($checks as $service => $site) {
48 if (empty($site) || !is_array($site)) {
49 continue;
50 }
51 switch ($service) {
52 case "availability":
53 $services["wa"] = [
54 // "pause" => wtsec_getStatusStartPauseIcon($site['config']['isActive'], $site['config']['id'], $host['id']),
55 "pause" => "",
56 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
57 "response_time" => ceil($site['responseTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
58 "availability" => $site['percent'] . '%',
59 "availability_percent" => $site['percent'],
60 "downtime" => ceil($site['downTime'] / 1000000) . ' ' . WTSEC_LIBRARY_Localization::lmsg('ms'),
61 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.availability')
62 ];
63 break;
64 case "ssl":
65 if ((int)$site['expiryDate'] === 0) {
66 $days_left = 0;
67 } else {
68 $earlier = new DateTime();
69 $later = new DateTime($site['expiryDate']);
70 $days_left = $later->diff($earlier)->format("%a");
71 }
72 $services["ssl"] = [
73 "pause" => "",
74 "information" => wtsec_getInformation($service, $site['status']),
75 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
76 "days_left" => $days_left,
77 "issue_date" => $site['issueDate'],
78 "expiry_date" => $site['expiryDate'],
79 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.ssl')
80 ];
81 break;
82 case "domain":
83 if ((int)$site['expiredDate'] === 0) {
84 $days_left = 0;
85 } else {
86 $earlier = new DateTime();
87 $later = new DateTime($site['expiredDate']);
88 $days_left = $later->diff($earlier)->format("%a");
89 }
90
91 $services["dec"] = [
92 "pause" => "",
93 "registrar" => $site['registrar'],
94 "owner" => $site['owner'],
95 "information" => wtsec_getInformation($service, $site['status']),
96 "email" => $site['email'],
97 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
98 "days_left" => $days_left,
99 "created" => $site['createdDate'],
100 "expiry_date" => $site['expiredDate'],
101 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.domain')
102 ];
103 break;
104 case "reputation":
105 $count = 0;
106 if ($site['status'] != "clean") {
107 foreach ($site['virusList'] as &$list) {
108 if (!empty($list['viruses'])) {
109 $count++;
110 }
111 }
112 }
113 $services["av"] = [
114 "pause" => "",
115 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
116 "time_of_the_last_test" => $site['lastTest']['time'],
117 "blacklists_entries" => $count,
118 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.reputation')
119 ];
120 break;
121 case "maliciousScript":
122 $services["cms"] = [
123 "pause" => "",
124 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
125 "time_of_the_last_test" => $site['lastTest']['time'],
126 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.malicious')
127 ];
128 break;
129 case "deface":
130 $services["dc"] = [
131 "pause" => "",
132 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
133 "time_of_the_last_test" => $site['lastTest']['time'],
134 "number" => $site['count'],
135 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.deface')
136 ];
137 break;
138 case "ports":
139 $services["ps"] = [
140 "pause" => "",
141 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
142 "ip" => $site['ip'],
143 "time_of_the_last_test" => $site['lastTest']['time'],
144 "number" => count($site['tcp']),
145 "tcp" => !empty($site['tcp']) ? implode(",", $site['tcp']) : '',
146 "udp" => "",
147 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.port')
148 ];
149 break;
150 case "firewall":
151 $service = "WAF";
152 $_service = strtolower($service);
153 $domain = $host['hostname'];
154 $uid = $host['id'];
155 $chart = generateChart($site['chart']);
156 $status = wtsec_checkStatus($uid, $service);
157 $services["waf"] = [
158 "pause" => "",
159 "site_address" => $domain,
160 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
161 "time_of_the_last_check" => $site['lastTest']['time'],
162 "attacks" => $chart['count_attacks'],
163 "blocking" => $chart['count_blocks'],
164 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.firewall'),
165 "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
166 "chart" => json_encode($chart['chart'], true)
167 ];
168 break;
169 case "antivirus":
170 $service = "AV";
171 $_service = strtolower($service);
172 $domain = $host['hostname'];
173 $uid = $host['id'];
174 $status = wtsec_checkStatus($uid, $service);
175 $services["vc"] = [
176 "pause" => "",
177 "site_address" => $domain,
178 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
179 "signatures" => (int)$site['stats']['infected'],
180 "changes" => (int)$site['stats']['changed'],
181 "list" => $site['stats']["infected"],
182 "actions" => wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
183 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
184 ];
185 break;
186 }
187 }
188 }
189 wtsec_layout("dashboard", $services);
190 }
191
192 function generateChart($charts)
193 {
194 $count_attacks = 0;
195 $count_blocks = 0;
196 $d = date("d");
197 $m = date("m");
198 $c = [];
199 $first_day = $d - 6;
200 if ($first_day < 1) {
201 $lastmonth = (int)date('d', strtotime('last day of previous month'));
202 $lastmonth_day = $lastmonth;
203 $lastmonth_month = (int)date('m', strtotime('last day of previous month'));
204 $lastmonth = $lastmonth - ($first_day * -1);
205 for ($i = $lastmonth; $i <= $lastmonth_day; $i++) {
206 $c[$i] = [
207 'day' => "{$i}/$lastmonth_month",
208 'count' => 0,
209 ];
210 }
211 $first_day = 1;
212 }
213 for ($i = $first_day; $i <= $d; $i++) {
214 $c[$i] = [
215 'day' => "{$i}/$m",
216 'count' => 0,
217 ];
218 }
219 foreach ($charts as $chart) {
220 $d = (int)date("d", strtotime($chart['time']));
221 $c[$d]['count'] = $chart['blocked'];
222 $count_attacks += $chart['attacks'];
223 $count_blocks += $chart['blocked'];
224 }
225
226 //unset keys, because the js parser sorting by key in integer
227 $result = [];
228 foreach ($c as $d) {
229 $result[] = $d;
230 }
231 return ['chart' => $result, 'count_attacks' => $count_attacks, 'count_blocks' => $count_blocks];
232 }
233
234 function wtsec_getInformation($service, $status)
235 {
236 $information = [
237 "ssl" => [
238 WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
239 WTSEC_LIBRARY_Localization::lmsg("statuses.invalid"),
240 WTSEC_LIBRARY_Localization::lmsg("statuses.expired"),
241 WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
242 "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.missing"),
243 ],
244 "domain" => [
245 WTSEC_LIBRARY_Localization::lmsg("statuses.ok"),
246 WTSEC_LIBRARY_Localization::lmsg("statuses.expires"),
247 "unknown_status" => WTSEC_LIBRARY_Localization::lmsg("statuses.error"),
248 ]
249 ];
250 return isset($information[$service][$status]) ? $information[$service][$status] : $information[$service]["unknown_status"];
251 }
252
253 function wtsec_getStatusStartPauseIcon($status, $config_id, $host_id)
254 {
255 $icon = '';
256 switch ($status) {
257 case "1":
258 $icon = '<div class="v-pause ww-icon ww-icon--pause" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
259 break;
260 case "0":
261 $icon = '<div class="v-pause ww-icon ww-icon--play" style="border:none" data-config_id="' . $config_id . '" data-host_id="' . $host_id . '"></div>';
262 break;
263 }
264 return $icon;
265 }
266
267 function wtsec_options_page()
268 {
269 $host = WTSEC_LIBRARY_WT::getOwnSite();
270 $result = WTSEC_LIBRARY_WT::getOptions($host['id']);
271 $options = [];
272 if (isset($result['data']['userHost']['services'])) {
273 foreach ($result['data']['userHost']['services'] as $service) {
274 $configs = $service['configs'][0];
275 $options[$service['name']] = ['config_id' => $configs['id'], 'is_active' => $configs['isActive']];
276 }
277 }
278 $options['host_id'] = $host['id'];
279 wtsec_layout("options", $options);
280 }
281
282 function wtsec_services_page()
283 {
284 wtsec_layout("services");
285 }
286
287 function wtsec_antivirus_page()
288 {
289 $host = WTSEC_LIBRARY_WT::getOwnSite();
290 $services = [];
291 if (!empty($host)) {
292 $site = WTSEC_LIBRARY_WT::getAntivirus($host['id']);
293 if (isset($site['data']['auth']['viewer']['sites']['one']['antivirus']['log'])) {
294 $site = $site['data']['auth']['viewer']['sites']['one']['antivirus'];
295 $service = "AV";
296 $_service = strtolower($service);
297 $domain = $host['hostname'];
298 $uid = $host['id'];
299 $status = wtsec_checkStatus($uid, $service);
300 $services["vc"] = [
301 "pause" => "",
302 "site_address" => $domain,
303 "status" => WTSEC_LIBRARY_WT::getStatusIcon($site['status']),
304 "signatures" => $site['stats']['infected'],
305 "changes" => $site['stats']['changed'],
306 "list" => $site["log"]['edges'],
307 "actions" => $buttons = wtsec_generateButtons($uid, $_service, $service, $status, WTSEC_SITE_URL),
308 "description" => WTSEC_LIBRARY_Localization::lmsg('descriptions.antivirus')
309 ];
310 }
311 }
312 wtsec_layout("antivirus", $services);
313 }
314
315 function wtsec_login_form()
316 {
317 if (wtsec_request()->method === "POST") {
318 $result = WTSEC_LIBRARY_WT::auth(wtsec_request()->key);
319 if (isset($result['data']['guest']['apiKeys']['auth']['token']['value'])) {
320 WTSEC_LIBRARY_Session::setNotification("success", WTSEC_LIBRARY_Localization::lmsg('successfully_activated'));
321 $token = $result['data']['guest']['apiKeys']['auth']['token']['value'];
322 WTSEC_LIBRARY_App::login($token);
323 wtsec_app()->set("api_key", wtsec_request()->key);
324 wp_safe_redirect(wtsec_getUrl('dashboard'));
325 exit;
326 } else {
327 WTSEC_LIBRARY_Session::setNotification("error", WTSEC_LIBRARY_Localization::lmsg("form.incorrect"));
328 }
329 }
330 wp_safe_redirect(wtsec_getUrl('login'));
331 }
332
333 function wtsec_cmd_ajax()
334 {
335 $service = strtoupper(wtsec_request()->service);
336 $_service = strtolower(wtsec_request()->service);
337 $uid = wtsec_request()->uid;
338 $cmd = wtsec_request()->cmd;
339 $status = wtsec_checkStatus($uid, $service);
340 global $wp_filesystem;
341 if (mb_stripos($cmd, "install") === false) {
342 wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
343 wp_safe_redirect(wp_get_referer());
344 } else {
345 $redirect = wtsec_getUrl("dashboard");
346 $form_url = wp_nonce_url(admin_url('admin-post.php?cmd=' . $cmd . '&action=ajax_cmd&service=' . $service . '&uid=' . $uid), "ajax_cmd");
347 if (wtsec_filesystem_init($form_url, '', false, false)) {
348 wtsec_cmd($wp_filesystem, $cmd, $service, $_service, $uid, $status, WTSEC_SITE_URL);
349 wp_safe_redirect($redirect);
350 }
351 }
352 }
353
354 function wtsec_login()
355 {
356 wtsec_layout("login");
357 }
358
359 function wtsec_logout()
360 {
361 WTSEC_LIBRARY_App::logout();
362 }
363
364
365 function wtsec_layout($template, $arguments = [], $faq = "faq")
366 {
367 $body = WTSEC_PLUGIN_PATH . "includes/" . $template . ".php";
368 $faq = WTSEC_PLUGIN_PATH . "includes/" . $faq . ".php";
369 require_once WTSEC_PLUGIN_PATH . "includes/layout.php";
370 }
371
372
373 function wtsec_ajax_changeStatus()
374 {
375 if (wtsec_request()->method === "POST") {
376 $host_id = wtsec_request()->host_id;
377 $config_id = wtsec_request()->config_id;
378 $result = WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
379 echo json_encode($result);
380 }
381 wp_die();
382 }
383
384 function wtsec_changeStatus()
385 {
386 if (wtsec_request()->method === "POST") {
387 $host_id = wtsec_request()->host_id;
388 $config_id = wtsec_request()->config_id;
389 WTSEC_LIBRARY_WT::changeStatus($config_id, $host_id);
390 }
391 wp_safe_redirect(wp_get_referer());
392 }
393
394 function wtsec_page($page)
395 {
396 return wtsec_pages()[$page];
397 }
398
399 function wtsec_getUrl($page)
400 {
401 return admin_url('admin.php?page=' . WTSEC_PAGE_PREFIX . $page);
402 }
403
404 function wtsec_getRoute($page)
405 {
406 return WTSEC_PAGE_PREFIX . $page;
407 }
408
409 function wtsec_pages()
410 {
411 return [
412 // "options" => [
413 // "page_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
414 // "menu_title" => WTSEC_LIBRARY_Localization::lmsg('options'),
415 // "function" => "wtsec_options_page",
416 // ],
417 "services" => [
418 "page_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
419 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('services'),
420 "function" => "wtsec_services_page",
421 ],
422 "vc" => [
423 "page_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
424 "menu_title" => WTSEC_LIBRARY_Localization::lmsg('remote_antivirus'),
425 "function" => "wtsec_antivirus_page",
426 "vc_action" => "vc-action",
427 "vc_function" => "wtsec_vc_function"
428 ],
429 ];
430 }