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 | src/PageHandler.php +758 -1009 3.0.12.4.2 View file →
@@ -1,1009 +1,758 @@
1 -<?php
2 -
3 -/**
4 - * Load page and ajax handlers
5 - */
6 -
7 -if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
8 - if (!headers_sent()) {
9 - header('HTTP/1.1 403 Forbidden');
10 - }
11 - die("Protected By WebTotem!");
12 -}
13 -
14 -/**
15 - * Handles all the AJAX plugin's requests.
16 - *
17 - * @return void
18 - */
19 -function wtotem_ajax_callback()
20 -{
21 -
22 - if (WebTotemRequest::get('ajax_action') != NULL) {
23 - WebTotemAjax::wtotem_scan();
24 - }
25 -
26 - $composer_autoload = WEBTOTEM_PLUGIN_PATH . '/vendor/autoload.php';
27 - if (file_exists($composer_autoload)) {
28 - require_once $composer_autoload;
29 - }
30 -
31 - if (WebTotemRequest::post('ajax_action') != NULL) {
32 - WebTotemAjax::authenticate();
33 - }
34 -
35 - if (WebTotemRequest::post('ajax_action') != NULL && WebTotemInterface::checkNonce()) {
36 -
37 - WebTotemAjax::activation();
38 - WebTotemAjax::agentsInstallation();
39 - WebTotemAjax::reinstallAgents();
40 - WebTotemAjax::chart();
41 - WebTotemAjax::logs();
42 - WebTotemAjax::wafDateFilter();
43 - WebTotemAjax::ignorePorts();
44 - WebTotemAjax::pagination();
45 - WebTotemAjax::antivirus();
46 - WebTotemAjax::changeThemeMode();
47 - WebTotemAjax::userTimeZone();
48 - WebTotemAjax::quarantine();
49 - WebTotemAjax::reports();
50 - WebTotemAjax::cashUpdate();
51 - WebTotemAjax::settings();
52 - WebTotemAjax::remove();
53 - WebTotemAjax::logout();
54 - WebTotemAjax::popup();
55 -// WebTotemAjax::multisite();
56 - WebTotemAjax::twoFactorAuth();
57 - WebTotemAjax::force_check();
58 - WebTotemAjax::user_feedback();
59 -
60 - // CVE list actions
61 -// WebTotemAjax::update_plugin();
62 -// WebTotemAjax::after_plugin_update();
63 - }
64 -
65 - wp_send_json([
66 - 'success' => false,
67 - 'error' => 'invalid ajax request',
68 - 'notifications' => WebTotemAjax::notifications(),
69 - ], 200);
70 -}
71 -
72 -/**
73 - * Handles all the AJAX plugin's public requests.
74 - *
75 - * @return void
76 - */
77 -function wtotem_public_ajax_callback()
78 -{
79 -
80 - if (WebTotemRequest::post('ajax_action') != NULL) {
81 - WebTotemAjax::authenticate();
82 - }
83 -
84 - wp_send_json([
85 - 'success' => false,
86 - 'error' => 'invalid ajax request',
87 - ], 200);
88 -
89 -}
90 -
91 -/**
92 - * Error page.
93 - *
94 - * @return void
95 - */
96 -function wtotem_error_page($data = [])
97 -{
98 - $composer_autoload = WEBTOTEM_PLUGIN_PATH . '/vendor/autoload.php';
99 - if (file_exists($composer_autoload)) {
100 - require_once $composer_autoload;
101 - }
102 -
103 - $template = new WebTotemTemplate();
104 - $parse = parse_url(WebTotemOption::getOption('api_url'));
105 - $domain = str_ireplace('api.', '', $parse['host']);
106 -
107 - if ($data['errors'] == 'PASSWORD_EXPIRED') {
108 -
109 - $build[] = [
110 - 'variables' => [
111 - 'message' => __('Your password has expired. You need to update it in cabinet.', 'wtotem'),
112 - 'is_cabinet_link' => true,
113 - 'cabinet_link' => 'https://' . $domain . '/cabinet/sign-in',
114 - ],
115 - 'template' => 'error',
116 - ];
117 - } elseif ($data['errors'] == 'TARIFF_EXPIRED') {
118 -
119 - $build[] = [
120 - 'variables' => [
121 - 'message' => __('Your subscription plan has expired. Please renew it in your account dashboard.', 'wtotem'),
122 - 'is_cabinet_link' => true,
123 - 'cabinet_link' => 'https://' . $domain . '/cabinet/pricing',
124 - ],
125 - 'template' => 'error',
126 - ];
127 - } else {
128 - $build[] = [
129 - 'variables' => [
130 - 'message' => __('Try reinstalling the agents or changing the API key', 'wtotem'),
131 - 'is_bnt' => true,
132 - ],
133 - 'template' => 'error',
134 - ];
135 - }
136 -
137 - $page_content = $template->arrayRender($build);
138 - echo $template->baseTemplate($page_content);
139 -}
140 -
141 -/**
142 - * Activation page.
143 - *
144 - * @return void
145 - */
146 -function wtotem_activation_page()
147 -{
148 - $build[] = [
149 - 'variables' => [
150 - 'notifications' => WebTotem::getNotifications(),
151 - 'current_year' => date('Y'),
152 - 'page' => 'activation',
153 - ],
154 - 'template' => 'activation'
155 - ];
156 -
157 - $template = new WebTotemTemplate();
158 - echo $template->arrayRender($build);
159 -}
160 -
161 -
162 -/**
163 - * All sites page.
164 - *
165 - * @return void
166 - */
167 -function wtotem_all_sites_page()
168 -{
169 - $allSites = WebTotemAPI::getSites(1, 1000000);
170 -
171 - // Reset session data.
172 - WebTotemOption::setSessionOptions([
173 - 'sites_cursor' => $allSites['pageInfo']['endCursor'],
174 - ]);
175 -
176 - $build[] = [
177 - 'variables' => [
178 - 'notifications' => WebTotem::getNotifications(),
179 - 'current_year' => date('Y'),
180 - 'sites' => WebTotem::allSitesData($allSites),
181 - 'theme_mode' => WebTotem::getThemeMode()
182 - ],
183 - 'template' => 'multisite'
184 - ];
185 -
186 - $template = new WebTotemTemplate();
187 - $page_content = $template->arrayRender($build);
188 - echo $template->baseTemplate($page_content);
189 -}
190 -
191 -/**
192 - * Dashboard, main page.
193 - *
194 - * @return void
195 - */
196 -function wtotem_dashboard_page()
197 -{
198 -
199 - if (WebTotemRequest::get('hid')) {
200 - $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
201 - } else {
202 - $host = WebTotemAPI::siteInfo();
203 - }
204 -
205 - $template = new WebTotemTemplate();
206 - if (!isset($host['id']) or !$host['id']) {
207 - wtotem_error_page();
208 - exit();
209 - }
210 -
211 - // Get monitoring data from WebTotem API.
212 - if ($cacheData = WebTotemCache::getdata('getMonitoringData', $host['id'])) {
213 - $data = $cacheData['data'];
214 - } else {
215 - $data = WebTotemAPI::getMonitoringData($host['id']);
216 - WebTotemCache::setData(['getMonitoringData' => $data], $host['id']);
217 - }
218 -
219 - if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) {
220 - $firewall_data = $cacheData['data'];
221 - } else {
222 - $firewall_data = WebTotemAPI::getFirewall(10, 1, 7);
223 - WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']);
224 - }
225 -
226 - if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) {
227 - $firewall_chart_data = $cacheData['data'];
228 - } else {
229 - $firewall_chart_data = WebTotemAPI::getFirewallStatistics();
230 - WebTotemCache::setData(['getFirewallStatistics' => $firewall_chart_data], $host['id']);
231 - }
232 -
233 - if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) {
234 - $agents_statuses_api = $cacheData['data'];
235 - } else {
236 - $agents_statuses_api = WebTotemAPI::getAgentsStatusesFromAPI();
237 - WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses_api], $host['id']);
238 - }
239 -
240 -
241 - if (empty($data)) {
242 - wtotem_error_page();
243 - exit();
244 - }
245 -
246 - // MultiSite page header (site name)
247 -// if (WebTotem::isMultiSite() and is_super_admin()) {
248 -// // Submenu block.
249 -// $pages['dashboard'] = 'wtotem_page-header__link_active';
250 -//
251 -// $build[] = [
252 -// 'variables' => [
253 -// 'is_active' => $pages,
254 -// 'site_name' => $host['name'],
255 -// 'hid' => $host['id'],
256 -// ],
257 -// 'template' => 'multisite_submenu',
258 -// ];
259 -// }
260 -
261 - // Reset session data.
262 - WebTotemOption::setSessionOptions([
263 - 'firewall_period' => NULL,
264 - 'ram_period' => NULL,
265 - 'cpu_period' => NULL,
266 - ]);
267 -
268 - // Scoring block.
269 -// $service_data = $data['scoring']['result'];
270 -// $total_score = round($data['scoring']['score']);
271 -// $score_grading = WebTotem::scoreGrading($total_score);
272 -// $build[] = [
273 -// 'variables' => [
274 -// "host_id" => $host['id'],
275 -// "total_score" => $total_score . "%",
276 -// "tested_on" => WebTotem::dateFormatter($data['scoring']['lastTest']['time']),
277 -// "server_ip" => $service_data['ip'] ?: ' - ',
278 -// "location" => WebTotem::getCountryName($service_data['country']) ?: ' - ',
279 -// "is_higher_than" => $service_data['isHigherThan'] . '%',
280 -// "grade" => $score_grading['grade'],
281 -// "color" => $score_grading['color'],
282 -// ],
283 -// 'template' => 'score',
284 -// ];
285 -
286 - // Agents installing process.
287 -
288 - $agents_data = [
289 - 'av' => $agents_statuses_api['av'] ?? '',
290 - 'waf' => $agents_statuses_api['waf'] ?? '',
291 - ];
292 -
293 - $agents_statuses = WebTotem::getAgentsStatuses($agents_data);
294 -
295 - if (!$agents_statuses['option_statuses']['av'] or !$agents_statuses['option_statuses']['waf']) {
296 -
297 - $status = [
298 - 'av' => $agents_statuses['process_statuses']['av'] == 'available',
299 - 'waf' => $agents_statuses['process_statuses']['waf'] == 'available',
300 - ];
301 -
302 - WebTotemOption::setOptions([
303 - 'av_installed' => $status['av'],
304 - 'waf_installed' => $status['waf'],
305 - ]);
306 -
307 - $build[] = [
308 - 'variables' => [
309 - "process_status" => $agents_statuses['process_statuses'],
310 - ],
311 - 'template' => 'agents',
312 - ];
313 - }
314 -
315 -
316 -
317 - // Monitoring header.
318 - $build[] = [
319 - 'variables' => [
320 - "title" => __('Monitoring', 'wtotem'),
321 - ],
322 - 'template' => 'section_header',
323 - ];
324 -
325 - $ssl = false;
326 - if ($data['module_ssl']) {
327 - $ssl = [
328 - 'status' => WebTotem::getStatusData($data['module_ssl']['info']['status']),
329 - 'cert_name' => $data['module_ssl']['result']['certificate_name'],
330 - 'days_left' => $data['module_ssl']['result']['days_left'],
331 - 'issue_date' => WebTotem::dateFormatter($data['module_ssl']['result']['issue_date']),
332 - 'expiry_date' => WebTotem::dateFormatter($data['module_ssl']['result']['expiry_date']),
333 - ];
334 - }
335 -
336 - $domain = [
337 - 'status' => WebTotem::getStatusData($data['module_location']['info']['status']),
338 - "redirect_link" => $data['module_location']['result']['redirect_link'],
339 - "is_created_at" => (bool)$data['module_location']['result']['checked_at'],
340 - "created_at" => WebTotem::dateFormatter($data['module_location']['result']['checked_at']),
341 - "is_taken" => $data['module_location']['result']['is_taken'],
342 - "ips" => $data['module_location']['result']['locations'],
343 - "protection" => $data['module_location']['result']['protection'],
344 - ];
345 -
346 - // Monitoring blocks.
347 - $build[] = [
348 - 'variables' => [
349 - "host_id" => $host['id'],
350 - "ssl" => $ssl,
351 - "domain_module" => $domain,
352 - 'reputation' => [
353 - "status" => WebTotem::getStatusData($data['module_reputation']['info']['status'] ?? ''),
354 -// "blacklists_entries" => WebTotem::blacklistsEntries(
355 -// $data['reputation']['status'] ?? '',
356 -// $data['reputation']['antivirus'] ?? []),
357 - "info" => WebTotem::getReputationInfo($data['reputation']['result']['status'] ?? ''),
358 - "last_test" => WebTotem::dateFormatter($data['reputation']['result']['checked_at'] ?? ''),
359 - ],
360 -
361 - 'availability' => [
362 - 'chart' => json_encode($data['module_availability']['result']['stats_by_day']),
363 - 'status' => WebTotem::getStatusData($data['module_availability']['info']['status'])
364 - ],
365 - ],
366 - 'template' => 'monitoring',
367 - ];
368 -
369 - $build[] = [
370 - 'variables' => [
371 - "ports" => [
372 - "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []),
373 - "ignorePorts" => [],
374 - ],
375 - ],
376 - 'template' => 'ports_form',
377 - ];
378 -
379 - // Scanning header.
380 - $build[] = [
381 - 'variables' => [
382 - "title" => __('Scanning', 'wtotem'),
383 - ],
384 - 'template' => 'section_header',
385 - ];
386 -
387 -
388 - // Scanning blocks.
389 - $build[] = [
390 - 'variables' => [
391 - "ports" => [
392 - 'status' => WebTotem::getStatusData($data['module_port_scanner']['info']['status'] ?? 'clean'),
393 - "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []),
394 - "ignore_ports" => [],
395 - "last_test" => WebTotem::dateFormatter($data['module_port_scanner']['result']['checked_at'] ?? false),
396 - ],
397 - "open_path" => [
398 - 'status' => WebTotem::getStatusData($data['module_open_paths']['info']['status'] ),
399 - "last_test" => WebTotem::dateFormatter($data['module_open_paths']['result']['checked_at'] ?? false),
400 - "paths" => $data['module_open_paths']['result']['open_paths'] ?? [],
401 - ],
402 - ],
403 - 'template' => 'scanning',
404 - ];
405 -
406 -
407 - // Firewall header.
408 - $build[] = [
409 - 'variables' => [
410 - "title" => __('Firewall activity', 'wtotem'),
411 - ],
412 - 'template' => 'section_header',
413 - ];
414 -
415 - $is_period_available = WebTotem::isPeriodAvailable();
416 -
417 - // Firewall stats.
418 - $chart = WebTotem::generateWafChart($firewall_chart_data['signatures_statistic'] ?? []);
419 - $build[] = [
420 - 'variables' => [
421 - "is_waf_training" => WebTotem::isWafTraining(),
422 - "is_period_available" => $is_period_available,
423 - "most_attacks" => WebTotem::getMostAttacksData($firewall_chart_data['countries_statistics'] ?? []),
424 - ],
425 - 'template' => 'firewall_stats',
426 - ];
427 -
428 - // Firewall filter form
429 - $build[] = [
430 - 'variables' => [
431 - "is_period_available" => $is_period_available,
432 - ],
433 - 'template' => 'waf_filter_form',
434 - ];
435 -
436 - // Firewall blocks.
437 - $build[] = [
438 - 'variables' => [
439 - "chart" => $chart['chart'],
440 - "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []),
441 - 'host_name' => $host['name'],
442 - ],
443 - 'template' => 'firewall',
444 - ];
445 -
446 - $page_content = $template->arrayRender($build);
447 - echo $template->baseTemplate($page_content);
448 -
449 -}
450 -
451 -/** Open paths page.
452 - *
453 - * @return void
454 - */
455 -function wtotem_open_paths_page()
456 -{
457 - if (WebTotemRequest::get('hid')) {
458 - $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
459 - } else {
460 - $host = WebTotemAPI::siteInfo();
461 - }
462 -
463 - $template = new WebTotemTemplate();
464 - if (!isset($host['id']) or !$host['id']) {
465 - wtotem_error_page();
466 - exit();
467 - }
468 -
469 - // Get data from WebTotem API.
470 - if ($cacheData = WebTotemCache::getdata('getOpenPaths', $host['id'])) {
471 - $open_path = $cacheData['data'];
472 - } else {
473 - $data = WebTotemAPI::getMonitoringData($host['id']);
474 - $open_path = $data['module_open_paths']['result']['open_paths'];
475 - WebTotemCache::setData(['getOpenPaths' => $open_path], $host['id']);
476 - }
477 -
478 - $build[] = [
479 - 'variables' => [
480 - "paths" => $open_path ?? [],
481 - ],
482 - 'template' => 'open_paths_page',
483 - ];
484 -
485 - $page_content = $template->arrayRender($build);
486 - echo $template->baseTemplate($page_content);
487 -
488 -}
489 -
490 -/** Firewall page.
491 - *
492 - * @return void
493 - */
494 -function wtotem_firewall_page()
495 -{
496 - if (WebTotemRequest::get('hid')) {
497 - $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
498 - } else {
499 - $host = WebTotemAPI::siteInfo();
500 - }
501 -
502 - $template = new WebTotemTemplate();
503 - if (!isset($host['id']) or !$host['id']) {
504 - wtotem_error_page();
505 - exit();
506 - }
507 -
508 - // Get data from WebTotem API.
509 - if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) {
510 - $data = $cacheData['data'];
511 - } else {
512 - $data = WebTotemAPI::getFirewallStatistics();
513 - WebTotemCache::setData(['getFirewallStatistics' => $data], $host['id']);
514 - }
515 - if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) {
516 - $firewall_data = $cacheData['data'];
517 - } else {
518 - $firewall_data = WebTotemAPI::getFirewall(10, 1, 7);
519 - WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']);
520 - }
521 -
522 - if (empty($data)) {
523 - wtotem_error_page();
524 - exit();
525 - }
526 -
527 -
528 - // MultiSite page header (site name)
529 -// if (WebTotem::isMultiSite() and is_super_admin()) {
530 -// // Submenu block.
531 -// $pages['firewall'] = 'wtotem_page-header__link_active';
532 -//
533 -// $build[] = [
534 -// 'variables' => [
535 -// 'is_active' => $pages,
536 -// 'site_name' => $host['name'],
537 -// 'hid' => $host['id'],
538 -// ],
539 -// 'template' => 'multisite_submenu',
540 -// ];
541 -// }
542 -
543 - // Firewall header.
544 - $build[] = [
545 - 'variables' => [
546 - "title" => __('Firewall activity', 'wtotem'),
547 - ],
548 - 'template' => 'section_header',
549 - ];
550 -
551 - // Attacks map blocks.
552 - // Get world_map json data
553 - $world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json';
554 - $map_data = WebTotem::generateAttacksMapChart($data['countries_statistics'] ?? []);
555 - $is_period_available = WebTotem::isPeriodAvailable();
556 -
557 - $build[] = [
558 - 'variables' => [
559 - "is_period_available" => $is_period_available,
560 - "attacks_map" => $map_data,
561 - "world_map_json" => $world_map_json,
562 - ],
563 - 'template' => 'attacks_map',
564 - ];
565 -
566 - // Firewall stats.
567 - $chart = WebTotem::generateWafChart($data['signatures_statistic'] ?? []);
568 -
569 - $build[] = [
570 - 'variables' => [
571 - "is_waf_training" => WebTotem::isWafTraining(),
572 - "is_period_available" => $is_period_available,
573 - "most_attacks" => WebTotem::getMostAttacksData($data['countries_statistics'] ?? []),
574 -// "all_attacks" => $firewall_statistics_data['weekly_blocked_attacks'],
575 -// "blocking" => $chart['count_blocks'],
576 -// "not_blocking" => (int)$chart['count_attacks'] - (int)$chart['count_blocks'],
577 - ],
578 - 'template' => 'firewall_stats',
579 - ];
580 -
581 - // Firewall filter form
582 - $build[] = [
583 - 'variables' => [
584 - "is_period_available" => $is_period_available,
585 - ],
586 - 'template' => 'waf_filter_form',
587 - ];
588 -
589 - // Firewall blocks.
590 - $build[] = [
591 - 'variables' => [
592 - 'page' => 'firewall',
593 - "chart" => $chart['chart'],
594 - "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []),
595 - 'host_name' => $host['name'],
596 - "firewall_logs_pagination" => WebTotem::paginationBuild(10, $firewall_data['total']),
597 - ],
598 - 'template' => 'firewall',
599 - ];
600 -
601 - $page_content = $template->arrayRender($build);
602 - echo $template->baseTemplate($page_content);
603 -
604 -}
605 -
606 -/**
607 - * Antivirus page.
608 - *
609 - * @return void
610 - */
611 -function wtotem_antivirus_page()
612 -{
613 - $host = WebTotemAPI::siteInfo();
614 -
615 - $template = new WebTotemTemplate();
616 - if (!isset($host['id']) or !$host['id']) {
617 - wtotem_error_page();
618 - exit();
619 - }
620 -
621 -// if (WebTotem::isMultiSite() and !is_super_admin()) {
622 -// echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
623 -// exit();
624 -// }
625 -
626 - // Get data from WebTotem API.
627 - if ($cacheData = WebTotemCache::getdata('getAntivirusHistory', $host['id'])) {
628 - $antivirus_history_data = $cacheData['data'];
629 - } else {
630 - $antivirus_history_data = WebTotemAPI::getAntivirusHistory();
631 - WebTotemCache::setData(['getAntivirusHistory' => $antivirus_history_data], $host['id']);
632 - }
633 -
634 - if ($cacheData = WebTotemCache::getdata('getAntivirusCurrentDetails', $host['id'])) {
635 - $infected_files = $cacheData['data'];
636 - } else {
637 - $infected_files = WebTotemAPI::getAntivirusCurrentDetails();
638 - WebTotemCache::setData(['getAntivirusCurrentDetails' => $infected_files], $host['id']);
639 - }
640 -
641 - if ($cacheData = WebTotemCache::getdata('getQuarantineList', $host['id'])) {
642 - $quarantine_files = $cacheData['data'];
643 - } else {
644 - $quarantine_files = WebTotemAPI::getQuarantineList();
645 - WebTotemCache::setData(['getQuarantineList' => $quarantine_files], $host['id']);
646 - }
647 -
648 -
649 - if (empty($antivirus_history_data)) {
650 - wtotem_error_page();
651 - exit();
652 - }
653 -
654 - // Reset session data.
655 - WebTotemOption::setSessionOptions([
656 - 'antivirus_event' => NULL,
657 - 'antivirus_permissions' => NULL,
658 - 'antivirus_current_page' => 1,
659 - ]);
660 -
661 - // MultiSite page header (site name)
662 -// if (WebTotem::isMultiSite() and is_super_admin()) {
663 -// // Submenu block.
664 -// $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
665 -// $pages['antivirus'] = 'wtotem_page-header__link_active';
666 -//
667 -// $build[] = [
668 -// 'variables' => [
669 -// 'is_active' => $pages,
670 -// 'site_name' => $host_['name'],
671 -// 'hid' => $host_['id'],
672 -// ],
673 -// 'template' => 'multisite_submenu',
674 -// ];
675 -// }
676 -
677 - // Antivirus header.
678 - $build[] = [
679 - 'variables' => [
680 - "title" => __('Antivirus', 'wtotem'),
681 - ],
682 - 'template' => 'section_header',
683 - ];
684 -
685 - // Antivirus stats blocks.
686 - $build[] = [
687 - 'variables' => [
688 - 'ws_url' => 'wss://app.wtotem.com/api/v1/ws',
689 - 'access_token' => WebTotemOption::getAuthToken(),
690 - 'config_id' => WebTotemOption::getOption('config_id'),
691 - 'page' => 'antivirus',
692 - ],
693 - 'template' => 'antivirus_stats',
694 - ];
695 -
696 - // Quarantine and infected files logs blocks.
697 -
698 -
699 - $build[] = [
700 - 'variables' => [
701 - "infected_files" => WebTotem::getInfectedFilesData($infected_files['current_infected_files'] ?? []),
702 - "infected_files_pagination" => WebTotem::paginationBuild(5, (int)$infected_files['total']),
703 - 'infected_files_total' => (int)$infected_files['total'],
704 - "quarantine_files" => WebTotem::getQuarantineListData($quarantine_files['quarantine_files'] ?? []),
705 - "quarantine_files_pagination" => WebTotem::paginationBuild(5, (int)$quarantine_files['total']),
706 - 'quarantine_files_total' => (int)$quarantine_files['total'],
707 - ],
708 - 'template' => 'quarantine',
709 - ];
710 -
711 - // History blocks.
712 - $build[] = [
713 - 'variables' => [
714 - "logs" => WebTotem::getAntivirusLogsData($antivirus_history_data['history']),
715 - "antivirus_history_pagination" => WebTotem::paginationBuild(10, (int)$antivirus_history_data['total']),
716 - ],
717 - 'template' => 'antivirus_history',
718 - ];
719 -
720 - $page_content = $template->arrayRender($build);
721 - echo $template->baseTemplate($page_content);
722 -}
723 -
724 -/**
725 - * Settings page
726 - *
727 - * @return void
728 - */
729 -function wtotem_settings_page()
730 -{
731 - $host = WebTotemAPI::siteInfo();
732 -
733 - $template = new WebTotemTemplate();
734 - if (!isset($host['id']) or !$host['id']) {
735 - wtotem_error_page();
736 - exit();
737 - }
738 -
739 -// if (WebTotem::isMultiSite() and !is_super_admin()) {
740 -// echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
741 -// exit();
742 -// }
743 -
744 - // Get data from WebTotem API.
745 -
746 - if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) {
747 - $agents_statuses = $cacheData['data'];
748 - } else {
749 - $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI();
750 - WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses], $host['id']);
751 - }
752 -
753 - if ($cacheData = WebTotemCache::getdata('getFirewallSettings', $host['id'])) {
754 - $waf_settings = $cacheData['data'];
755 - } else {
756 - $waf_settings = WebTotemAPI::getFirewallSettings();
757 - WebTotemCache::setData(['getFirewallSettings' => $waf_settings], $host['id']);
758 - }
759 -
760 - if ($cacheData = WebTotemCache::getdata('getIpLists_whitelist', $host['id'])) {
761 - $ip_whiteList = $cacheData['data'];
762 - } else {
763 - $ip_whiteList = WebTotemAPI::getIpLists('whitelist');
764 - WebTotemCache::setData(['getIpLists_whitelist' => $ip_whiteList], $host['id']);
765 - }
766 - if ($cacheData = WebTotemCache::getdata('getIpLists_blacklist', $host['id'])) {
767 - $ip_blackList = $cacheData['data'];
768 - } else {
769 - $ip_blackList = WebTotemAPI::getIpLists();
770 - WebTotemCache::setData(['getIpLists_blacklist' => $ip_blackList], $host['id']);
771 - }
772 - if ($cacheData = WebTotemCache::getdata('getIpLists_checklist', $host['id'])) {
773 - $ip_checklist = $cacheData['data'];
774 - } else {
775 - $ip_checklist = WebTotemAPI::getIpLists('checklist');
776 - WebTotemCache::setData(['getIpLists_checklist' => $ip_checklist], $host['id']);
777 - }
778 -
779 - if (empty($agents_statuses) ) {
780 - wtotem_error_page();
781 - exit();
782 - }
783 -
784 - // MultiSite page header (site name)
785 -// if (WebTotem::isMultiSite() and is_super_admin()) {
786 -// // Submenu block.
787 -//
788 -// $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
789 -// $pages['settings'] = 'wtotem_page-header__link_active';
790 -//
791 -// $build[] = [
792 -// 'variables' => [
793 -// 'is_active' => $pages,
794 -// 'site_name' => $host_['name'],
795 -// 'hid' => $host_['id'],
796 -// ],
797 -// 'template' => 'multisite_submenu',
798 -// ];
799 -// }
800 -
801 -
802 - // Settings form.
803 - $build[] = [
804 - 'variables' => [
805 - 'deny_list' => WebTotem::getIpList($ip_blackList, 'ip_deny'),
806 - 'allow_list' => WebTotem::getIpList($ip_whiteList, 'ip_allow'),
807 - 'url_list' => WebTotem::getIpList($ip_checklist, 'allow_url'),
808 - 'av_status' => WebTotem::getStatusData($agents_statuses['av']),
809 - 'waf_status' => WebTotem::getStatusData($agents_statuses['waf']),
810 - 'waf_settings' => WebTotem::getWafSettingData($waf_settings),
811 - 'plugin_settings' => WebTotem::getPluginSettingsData(),
812 - 'two_factor' => WebTotemLogin::getTwoFactorData(),
813 - ],
814 -
815 - 'template' => 'settings_form',
816 - ];
817 -
818 - $page_content = $template->arrayRender($build);
819 - echo $template->baseTemplate($page_content);
820 -}
821 -
822 -/**
823 - * Reports page.
824 - *
825 - * @return void
826 - */
827 -function wtotem_reports_page()
828 -{
829 - if (WebTotemRequest::get('hid')) {
830 - $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
831 - } else {
832 - $host = WebTotemAPI::siteInfo();
833 - }
834 -
835 - $template = new WebTotemTemplate();
836 - if (!isset($host['id']) or !$host['id']) {
837 - wtotem_error_page();
838 - exit();
839 - }
840 -
841 - // Get data from WebTotem API.
842 - if ($cacheData = WebTotemCache::getdata('getAllReports', $host['id'])) {
843 - $data = $cacheData['data'];
844 - } else {
845 - $data = WebTotemAPI::getAllReports($host['id']);
846 - WebTotemCache::setData(['getAllReports' => $data], $host['id']);
847 - }
848 -
849 - if (empty($data)) {
850 - wtotem_error_page();
851 - exit();
852 - }
853 -
854 - WebTotemOption::setSessionOptions([
855 - 'reports_cursor' => $data['pageInfo']['endCursor'],
856 - 'reports_m_cursor' => $data['pageInfo']['endCursor'],
857 - ]);
858 -
859 - // MultiSite page header (site name)
860 -// if (WebTotem::isMultiSite() and is_super_admin()) {
861 -// // Submenu block.
862 -// $pages['reports'] = 'wtotem_page-header__link_active';
863 -//
864 -// $build[] = [
865 -// 'variables' => [
866 -// 'is_active' => $pages,
867 -// 'site_name' => $host['name'],
868 -// 'hid' => $host['id'],
869 -// ],
870 -// 'template' => 'multisite_submenu',
871 -// ];
872 -// }
873 -
874 - // Reports form.
875 - $build[] = [
876 - 'template' => 'reports_form',
877 - ];
878 -
879 - // Reports.
880 - $build[] = [
881 - 'variables' => [
882 - "reports" => WebTotem::getReports($data['edges']),
883 - "has_next_page" => $data['pageInfo']['hasNextPage'],
884 - ],
885 - 'template' => 'reports',
886 - ];
887 -
888 - $page_content = $template->arrayRender($build);
889 - echo $template->baseTemplate($page_content);
890 -}
891 -
892 -/**
893 - * Scan WP page.
894 - *
895 - * @return void
896 - */
897 -function wtotem_wpscan_page()
898 -{
899 - $template = new WebTotemTemplate();
900 - $audit_logs = WebTotemDB::getRows([], 'audit_logs');
901 - $confidential_files = WebTotemDB::getRows([], 'confidential_files');
902 - $links = WebTotemDB::getRows(['AND', ['data_type' => 'links']], 'scan_logs', 'content');
903 - $scripts = WebTotemDB::getRows(['AND', ['data_type' => 'scripts']], 'scan_logs', 'content');
904 - $iframes = WebTotemDB::getRows(['AND', ['data_type' => 'iframes']], 'scan_logs', 'content');
905 -
906 -// $plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => 1]);
907 -// require_once ABSPATH . 'wp-admin/includes/plugin.php';
908 -// $have_all_plugins_auto_update = count(get_plugins() ?: []) == count(get_site_option( 'auto_update_plugins' ) ?: []);
909 -
910 - $events = [
911 - 'User authentication succeeded',
912 - 'User authentication failed',
913 - 'User account created',
914 - 'User account deleted',
915 - 'User account edited',
916 - 'Attempt to reset password',
917 - 'Password retrieval attempt',
918 - 'User added to website',
919 - 'User removed from website',
920 - 'WordPress updated',
921 -
922 - 'User account deleted',
923 - 'Bookmark link added',
924 - 'Bookmark link edited',
925 - 'Category created',
926 - 'Publication was published',
927 - 'Publication was updated',
928 - 'Post status has been changed',
929 - 'Post deleted',
930 - 'Post moved to trash',
931 - 'Media file added',
932 - 'Plugin activated',
933 - 'Plugin deactivated',
934 - 'Theme activated',
935 - 'Settings changed',
936 - 'Plugins deleted',
937 - 'Plugin editor used',
938 - 'Plugin installed',
939 - 'Plugins updated',
940 - 'Theme deleted',
941 - 'Theme editor used',
942 - 'Theme installed',
943 - 'Themes updated',
944 - 'Widget deleted',
945 - 'Widget added',
946 - ];
947 -
948 - $until_next_scan = wp_next_scheduled('webtotem_daily_cron') - time();
949 -
950 - $hr = floor($until_next_scan / 3600);
951 - $min = floor(($until_next_scan % 3600) / 60);
952 -
953 - // Scan logs block.
954 - $build[] = [
955 - 'variables' => [
956 - "audit_logs_count" => $audit_logs['count'],
957 - "audit_logs" => WebTotem::getAuditLogs($audit_logs['data'], $audit_logs['dates_count']),
958 - "audit_logs_pagination" => WebTotem::paginationBuild(10, $audit_logs['count']),
959 - "audit_logs_events" => WebTotemDB::checkAvailability('audit_logs', $events, 'event'),
960 -
961 - "confidential_files_count" => $confidential_files['count'],
962 - "confidential_files" => WebTotem::getConfidentialFiles($confidential_files['data']),
963 - "confidential_files_pagination" => WebTotem::paginationBuild(10, $confidential_files['count']),
964 -
965 - "links_count" => $links['count'],
966 - "links" => WebTotem::prepareLinksData($links['data']),
967 - "links_pagination" => WebTotem::paginationBuild(10, $links['count']),
968 -
969 - "scripts_count" => $scripts['count'],
970 - "scripts" => WebTotem::prepareLinksData($scripts['data']),
971 - "scripts_pagination" => WebTotem::paginationBuild(10, $scripts['count']),
972 -
973 - "iframes_count" => $iframes['count'],
974 - "iframes" => WebTotem::prepareLinksData($iframes['data']),
975 - "iframes_pagination" => WebTotem::paginationBuild(10, $iframes['count']),
976 -
977 -// "plugins_cve_list_count" => $plugins_cve_list['count'],
978 -// "plugins_cve_list" => WebTotem::preparePluginsCveList($plugins_cve_list['data']),
979 -// "plugins_cve_list_pagination" => WebTotem::paginationBuild(8, $plugins_cve_list['count']),
980 -// "have_all_plugins_auto_update" => $have_all_plugins_auto_update,
981 -
982 - "next_scan" => sprintf(__('%dh %dm', 'wtotem'), $hr, $min),
983 - "scan_init" => WebTotemOption::getOption('scan_init') ?: 0,
984 - ],
985 - 'template' => 'scan_logs',
986 - ];
987 -
988 - $page_content = $template->arrayRender($build);
989 - echo $template->baseTemplate($page_content);
990 -}
991 -
992 -
993 -/**
994 - * Information page.
995 - *
996 - * @return void
997 - */
998 -function wtotem_documentation_page()
999 -{
1000 - $template = new WebTotemTemplate();
1001 -
1002 - $build[] = [
1003 - 'template' => 'help',
1004 - ];
1005 -
1006 - $page_content = $template->arrayRender($build);
1007 - echo $template->baseTemplate($page_content);
1008 -}
1009 -
1 +<?php
2 +
3 +/**
4 + * Load page and ajax handlers
5 + */
6 +
7 +if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
8 + if (!headers_sent()) {
9 + header('HTTP/1.1 403 Forbidden');
10 + }
11 + die("Protected By WebTotem!");
12 +}
13 +
14 +/**
15 + * Handles all the AJAX plugin's requests.
16 + *
17 + * @return void
18 + */
19 +function wtotem_ajax_callback() {
20 +
21 + if (WebTotemRequest::post('ajax_action') != NULL && WebTotemInterface::checkNonce()) {
22 +
23 + WebTotemAjax::activation();
24 + WebTotemAjax::agentsInstallation();
25 + WebTotemAjax::reinstallAgents();
26 + WebTotemAjax::chart();
27 + WebTotemAjax::wafDateFilter();
28 + WebTotemAjax::ignorePorts();
29 + WebTotemAjax::lazyLoad();
30 + WebTotemAjax::antivirus();
31 + WebTotemAjax::changeThemeMode();
32 + WebTotemAjax::userTimeZone();
33 + WebTotemAjax::quarantine();
34 + WebTotemAjax::reports();
35 + WebTotemAjax::settings();
36 + WebTotemAjax::remove();
37 + WebTotemAjax::reloadPage();
38 + WebTotemAjax::logout();
39 + WebTotemAjax::popup();
40 + WebTotemAjax::multisite();
41 + }
42 +
43 + wp_send_json([
44 + 'success' => false,
45 + 'error' => 'invalid ajax request',
46 + 'notifications' => WebTotemAjax::notifications(),
47 + ], 200);
48 +}
49 +
50 +/**
51 + * Activation page.
52 + *
53 + * @return void
54 + */
55 +function wtotem_activation_page() {
56 +
57 + $build[] = [
58 + 'variables' => [
59 + 'notifications' => WebTotem::getNotifications(),
60 + 'current_year' => date('Y'),
61 + ],
62 + 'template' => 'activation'
63 + ];
64 +
65 + $template = new WebTotemTemplate();
66 + echo $template->arrayRender($build);
67 +}
68 +
69 +/**
70 + * All sites page.
71 + *
72 + * @return void
73 + */
74 +function wtotem_all_sites_page() {
75 +
76 + $allSites = WebTotemAPI::getSites();
77 +
78 + // Reset session data.
79 + WebTotemOption::setSessionOptions([
80 + 'sites_cursor' => $allSites['pageInfo']['endCursor'],
81 + ]);
82 +
83 + $build[] = [
84 + 'variables' => [
85 + 'notifications' => WebTotem::getNotifications(),
86 + 'current_year' => date('Y'),
87 + 'sites' => WebTotem::allSitesData($allSites),
88 + 'theme_mode' => WebTotem::getThemeMode()
89 + ],
90 + 'template' => 'multisite'
91 + ];
92 +
93 + $template = new WebTotemTemplate();
94 + $page_content = $template->arrayRender($build);
95 + echo $template->baseTemplate($page_content);
96 +}
97 +/**
98 + * Error page.
99 + *
100 + * @return void
101 + */
102 +function wtotem_error_page(){
103 + $template = new WebTotemTemplate();
104 + $build[] = [
105 + 'template' => 'error',
106 + ];
107 + $page_content = $template->arrayRender($build);
108 + echo $template->baseTemplate($page_content);
109 +}
110 +
111 +/**
112 + * Dashboard, main page.
113 + *
114 + * @return void
115 + */
116 +function wtotem_dashboard_page() {
117 +
118 + if(WebTotemRequest::get('hid')){
119 + $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
120 + } else {
121 + $host = WebTotemAPI::siteInfo();
122 + }
123 +
124 + $template = new WebTotemTemplate();
125 + if (!isset($host['id']) && !$host['id']) {
126 + wtotem_error_page();
127 + exit();
128 + }
129 +
130 + // Get data from WebTotem API.
131 + $data = WebTotemAPI::getAllData($host['id']);
132 + if (empty($data)) {
133 + wtotem_error_page();
134 + exit();
135 + }
136 +
137 + // MultiSite page header (site name)
138 + if(WebTotem::isMultiSite() and is_super_admin()){
139 + // Submenu block.
140 + $pages['dashboard'] = 'wtotem_page-header__link_active';
141 +
142 + $build[] = [
143 + 'variables' => [
144 + 'is_active' => $pages,
145 + 'site_name' => $host['name'],
146 + 'hid' => $host['id'],
147 + ],
148 + 'template' => 'multisite_submenu',
149 + ];
150 + }
151 +
152 + // Reset session data.
153 + WebTotemOption::setSessionOptions([
154 + 'firewall_period' => NULL,
155 + 'ram_period' => NULL,
156 + 'cpu_period' => NULL,
157 + ]);
158 +
159 + // Scoring block.
160 + $service_data = $data['scoring']['result'];
161 + $total_score = round($data['scoring']['score']);
162 + $score_grading = WebTotem::scoreGrading($total_score);
163 + $build[] = [
164 + 'variables' => [
165 + "host_id" => $host['id'],
166 + "total_score" => $total_score . "%",
167 + "tested_on" => $data['scoring']['lastTest']['time'],
168 + "server_ip" => $service_data['ip'] ?: ' - ',
169 + "location" => WebTotem::getCountryName($service_data['country']) ?: ' - ',
170 + "is_higher_than" => $service_data['isHigherThan'] . '%',
171 + "grade" => $score_grading['grade'],
172 + "color" => $score_grading['color'],
173 + ],
174 + 'template' => 'score',
175 + ];
176 +
177 + // Agents installing process.
178 + $agents_data = [
179 + 'av' => $data['antivirus']['status'],
180 + 'waf' => $data['firewall']['status'],
181 + ];
182 +
183 + $agents_statuses = WebTotem::getAgentsStatuses($agents_data);
184 +
185 + if (!$agents_statuses['option_statuses']['av'] or !$agents_statuses['option_statuses']['waf']) {
186 +
187 + $status = [
188 + 'av' => $agents_statuses['process_statuses']['av'] == 'installed',
189 + 'waf' => $agents_statuses['process_statuses']['waf'] == 'installed',
190 + ];
191 +
192 + WebTotemOption::setOptions([
193 + 'av_installed' => $status['av'],
194 + 'waf_installed' => $status['waf'],
195 + ]);
196 +
197 + $build[] = [
198 + 'variables' => [
199 + "process_status" => $agents_statuses['process_statuses'],
200 + ],
201 + 'template' => 'agents',
202 + ];
203 + }
204 +
205 + // Firewall header.
206 + $build[] = [
207 + 'variables' => [
208 + "title" => __('Firewall activity', 'wtotem'),
209 + ],
210 + 'template' => 'section_header',
211 + ];
212 +
213 + // Firewall stats.
214 + $service_data = (isset($data['firewall'])) ? $data['firewall'] : [];
215 + $chart = WebTotem::generateWafChart($service_data['chart']);
216 + $build[] = [
217 + 'variables' => [
218 + "is_waf_training" => $data['agentManager'] && WebTotem::isWafTraining( $data['agentManager']['createdAt'] ),
219 + "most_attacks" => WebTotem::getMostAttacksData($service_data['map']),
220 + "all_attacks" => $chart['count_attacks'],
221 + "blocking" => $chart['count_blocks'],
222 + "not_blocking" => (int) $chart['count_attacks'] - (int) $chart['count_blocks'],
223 + ],
224 + 'template' => 'firewall_stats',
225 + ];
226 +
227 + // Firewall filter form
228 + $build[] = [
229 + 'template' => 'waf_filter_form',
230 + ];
231 +
232 + // Firewall blocks.
233 + $build[] = [
234 + 'variables' => [
235 + "chart" => $chart['chart'],
236 + "logs" => WebTotem::wafLogs($service_data['logs']['edges']),
237 + ],
238 + 'template' => 'firewall',
239 + ];
240 +
241 + // Display AV and SS data only to the super admin, or it's not a MultiSite network.
242 + if(!WebTotem::isMultiSite() or is_super_admin()) {
243 +
244 + // Server Status header.
245 + $build[] = [
246 + 'variables' => [
247 + "title" => __('Server resources', 'wtotem'),
248 + "tooltip" => [
249 + 'title' => __('Server resources', 'wtotem'),
250 + 'test' => __('Displays critical data about web-server usage. A large load on a server can slow down the website performance.', 'wtotem'),
251 + ],
252 + ],
253 + 'template' => 'section_header',
254 + ];
255 +
256 + // Server Status RAM.
257 + $service_data = $data['serverStatus'];
258 + $build[] = [
259 + 'variables' => [
260 + "info" => $service_data['info'],
261 + "ram_chart" => WebTotem::generateChart($service_data['ramChart']),
262 + ],
263 + 'template' => 'server_status_ram',
264 + ];
265 +
266 + // Server Status CPU.
267 + $build[] = [
268 + 'variables' => [
269 + "cpu_chart" => WebTotem::generateChart($service_data['cpuChart']),
270 + ],
271 +
272 + 'template' => 'server_status_cpu',
273 + ];
274 +
275 + // Antivirus header.
276 + $build[] = [
277 + 'variables' => [
278 + "title" => __('Antivirus', 'wtotem'),
279 + ],
280 + 'template' => 'section_header',
281 + ];
282 +
283 + // Antivirus stats blocks.
284 + $antivirus_stats = $data['antivirus']['stats'];
285 + $build[] = [
286 + 'variables' => [
287 + "changes" => $antivirus_stats['changed'] ?: 0,
288 + "scanned" => $antivirus_stats['scanned'] ?: 0,
289 + "deleted" => $antivirus_stats['deleted'] ?: 0,
290 + "infected" => $antivirus_stats["infected"] ?: 0,
291 + ],
292 +
293 + 'template' => 'antivirus_stats',
294 + ];
295 + }
296 +
297 + // Monitoring header.
298 + $build[] = [
299 + 'variables' => [
300 + "title" => __('Monitoring', 'wtotem'),
301 + ],
302 + 'template' => 'section_header',
303 + ];
304 +
305 + // Monitoring blocks.
306 + $build[] = [
307 + 'variables' => [
308 + "ssl" => [
309 + 'status' => WebTotem::getStatusData($data['ssl']['status']),
310 + 'days_left' => WebTotem::daysLeft($data['ssl']['expiryDate']),
311 + 'issue_date' => WebTotem::dateFormatter($data['ssl']['issueDate']),
312 + 'expiry_date' => WebTotem::dateFormatter($data['ssl']['expiryDate']),
313 + ],
314 + "availability" => [
315 + 'status' => WebTotem::getStatusData($data['availability']['status']),
316 + "percent" => $data['availability']['percent'],
317 + "response_time" => ceil($data['availability']['responseTime'] / 1000000) . ' ' . __('ms.', 'wtotem'),
318 + "downtime" => ceil($data['availability']['downTime'] / 1000000) . ' ' . __('ms.', 'wtotem'),
319 + "last_test" => WebTotem::dateFormatter($data['availability']['lastTest']['time']),
320 + ],
321 + 'reputation' => [
322 + "status" => WebTotem::getStatusData($data['reputation']['status']),
323 + "blacklists_entries" => WebTotem::blacklistsEntries(
324 + $data['reputation']['status'],
325 + $data['reputation']['virusList']),
326 + "info" => WebTotem::getReputationInfo($data['reputation']['status']),
327 + "last_test" => WebTotem::dateFormatter($data['reputation']['lastTest']['time']),
328 + ],
329 + ],
330 + 'template' => 'monitoring',
331 + ];
332 +
333 + $build[] = [
334 + 'variables' => [
335 + "ports" => WebTotemAPI::getAllPortsList($host['id']),
336 + ],
337 + 'template' => 'ports_form',
338 + ];
339 +
340 + // Scanning header.
341 + $build[] = [
342 + 'variables' => [
343 + "title" => __('Scanning', 'wtotem'),
344 + ],
345 + 'template' => 'section_header',
346 + ];
347 +
348 + $disc_usage_data = $data['serverStatus']['discUsage'];
349 + $disc_usage = [
350 + 'total' => $disc_usage_data['total'],
351 + 'free' => $disc_usage_data['free'],
352 + 'used' => $disc_usage_data['total'] - $disc_usage_data['free'],
353 + ];
354 +
355 + // Scanning blocks.
356 + $build[] = [
357 + 'variables' => [
358 + "ports" => [
359 + 'status' => WebTotem::getStatusData($data['ports']['status']),
360 + "ip" => $data['ports']['ip'],
361 + "number" => count($data['ports']['tcp']),
362 + "tcp" => $data['ports']['tcp'],
363 + "ignore_ports" => $data['ports']['ignorePorts'],
364 + "last_test" => WebTotem::dateFormatter($data['ports']['lastTest']['time']),
365 + ],
366 + "deface" => [
367 + 'status' => WebTotem::getStatusData($data['deface']['status']),
368 + "number" => $data['deface']['count'],
369 + "words" => !empty($data['deface']['words']) ? implode(",", $data['deface']['words']) : '',
370 + "last_test" => WebTotem::dateFormatter($data['deface']['lastTest']['time']),
371 + ],
372 + "disc_usage" => $disc_usage,
373 + "disc_chart" => json_encode($disc_usage),
374 + ],
375 + 'template' => 'scanning',
376 + ];
377 +
378 + $page_content = $template->arrayRender($build);
379 + echo $template->baseTemplate($page_content);
380 +
381 +}
382 +
383 +/**Firewall page.
384 + *
385 + * @return void
386 + */
387 +function wtotem_firewall_page() {
388 +
389 + if(WebTotemRequest::get('hid')){
390 + $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
391 + } else {
392 + $host = WebTotemAPI::siteInfo();
393 + }
394 +
395 + $template = new WebTotemTemplate();
396 + if (!isset($host['id']) && !$host['id']) {
397 + wtotem_error_page();
398 + exit();
399 + }
400 +
401 + // Get data from WebTotem API.
402 + $data = WebTotemAPI::getFirewall($host['id'], 10, NULL, 7);
403 + if (empty($data)) {
404 + wtotem_error_page();
405 + exit();
406 + }
407 +
408 + $service_data = $data['firewall'];
409 +
410 + // Reset session data.
411 + WebTotemOption::setSessionOptions([
412 + 'firewall_period' => NULL,
413 + 'firewall_cursor' => $service_data['logs']['pageInfo']['endCursor'],
414 + ]);
415 +
416 + // MultiSite page header (site name)
417 + if(WebTotem::isMultiSite() and is_super_admin()){
418 + // Submenu block.
419 + $pages['firewall'] = 'wtotem_page-header__link_active';
420 +
421 + $build[] = [
422 + 'variables' => [
423 + 'is_active' => $pages,
424 + 'site_name' => $host['name'],
425 + 'hid' => $host['id'],
426 + ],
427 + 'template' => 'multisite_submenu',
428 + ];
429 + }
430 +
431 + // Start build array for rendering.
432 + // Firewall header.
433 + $build[] = [
434 + 'variables' => [
435 + "title" => __('Firewall activity', 'wtotem'),
436 + ],
437 + 'template' => 'section_header',
438 + ];
439 +
440 + // Attacks map blocks.
441 + // Get world_map json data
442 + $world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json';
443 + $map_data = WebTotem::generateAttacksMapChart($service_data['map']);
444 +
445 + $build[] = [
446 + 'variables' => [
447 + "attacks_map" => $map_data,
448 + "world_map_json" => $world_map_json,
449 + ],
450 + 'template' => 'attacks_map',
451 + ];
452 +
453 + $build[] = [
454 + 'variables' => [
455 + "title" => __('Firewall activity', 'wtotem'),
456 + ],
457 + 'template' => 'section_header',
458 + ];
459 +
460 + // Firewall stats.
461 + $chart = WebTotem::generateWafChart($service_data['chart']);
462 + $build[] = [
463 + 'variables' => [
464 + "is_waf_training" => isset( $data['agentManager']['createdAt'] ) && WebTotem::isWafTraining( $data['agentManager']['createdAt'] ),
465 + "all_attacks" => $chart['count_attacks'],
466 + "blocking" => $chart['count_blocks'],
467 + "not_blocking" => $chart['count_attacks'] - $chart['count_blocks'],
468 + "most_attacks" => WebTotem::getMostAttacksData($service_data['map']),
469 + ],
470 + 'template' => 'firewall_stats',
471 + ];
472 +
473 + // Firewall filter form
474 + $build[] = [
475 + 'template' => 'waf_filter_form',
476 + ];
477 +
478 + // Firewall blocks.
479 + $build[] = [
480 + 'variables' => [
481 + "chart" => $chart['chart'],
482 + "logs" => WebTotem::wafLogs($service_data['logs']['edges']),
483 + 'has_next_page' => $service_data['logs']['pageInfo']['hasNextPage'],
484 + 'page' => 'firewall',
485 + ],
486 + 'template' => 'firewall',
487 + ];
488 +
489 + $page_content = $template->arrayRender($build);
490 + echo $template->baseTemplate($page_content);
491 +
492 +}
493 +
494 +/**
495 + * Antivirus page.
496 + *
497 + * @return void
498 + */
499 +function wtotem_antivirus_page() {
500 +
501 + $host = WebTotemAPI::siteInfo();
502 +
503 + $template = new WebTotemTemplate();
504 + if (!isset($host['id']) && !$host['id']) {
505 + wtotem_error_page();
506 + exit();
507 + }
508 +
509 + if(WebTotem::isMultiSite() and !is_super_admin()) {
510 + echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
511 + exit();
512 + }
513 +
514 + $params = [
515 + 'host_id' => $host['id'],
516 + 'limit' => 10,
517 + 'cursor' => NULL,
518 + 'days' => 365,
519 + 'event' => FALSE,
520 + 'permissions' => FALSE,
521 + ];
522 +
523 + // Get data from WebTotem API.
524 + $data = WebTotemAPI::getAntivirus($params);
525 + if (empty($data)) {
526 + wtotem_error_page();
527 + exit();
528 + }
529 +
530 + // Reset session data.
531 + WebTotemOption::setSessionOptions([
532 + 'antivirus_event' => NULL,
533 + 'antivirus_permissions' => NULL,
534 + 'antivirus_cursor' => $data['log']['pageInfo']['endCursor'],
535 + ]);
536 +
537 + // MultiSite page header (site name)
538 + if(WebTotem::isMultiSite() and is_super_admin()){
539 + // Submenu block.
540 + $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
541 + $pages['antivirus'] = 'wtotem_page-header__link_active';
542 +
543 + $build[] = [
544 + 'variables' => [
545 + 'is_active' => $pages,
546 + 'site_name' => $host_['name'],
547 + 'hid' => $host_['id'],
548 + ],
549 + 'template' => 'multisite_submenu',
550 + ];
551 + }
552 +
553 + // Antivirus header.
554 + $build[] = [
555 + 'variables' => [
556 + "title" => __('Antivirus', 'wtotem'),
557 + ],
558 + 'template' => 'section_header',
559 + ];
560 +
561 + // Antivirus stats blocks.
562 + $stats = $data['stats'];
563 + $build[] = [
564 + 'variables' => [
565 + 'changes' => $stats['changed'] ?: 0,
566 + 'scanned' => $stats['scanned'] ?: 0,
567 + 'deleted' => $stats['deleted'] ?: 0,
568 + 'infected' => $stats["infected"] ?: 0,
569 + 'page' => 'antivirus',
570 + ],
571 + 'template' => 'antivirus_stats',
572 + ];
573 +
574 + // Quarantine logs blocks.
575 + $quarantine_logs = $data['quarantine'] ?: [];
576 + $quarantine_count = count($quarantine_logs);
577 +
578 + $build[] = [
579 + 'variables' => [
580 + "logs" => WebTotem::getQuarantineLogs($quarantine_logs) ?: [],
581 + "count" => $quarantine_count,
582 + ],
583 + 'template' => 'quarantine',
584 + ];
585 +
586 + // Antivirus filter form.
587 + $build[] = [
588 + 'template' => 'antivirus_filter_form',
589 + ];
590 +
591 + // Antivirus blocks.
592 + $build[] = [
593 + 'variables' => [
594 + "logs" => WebTotem::getAntivirusLogs($data['log']['edges']),
595 + "has_next_page" => $data['log']['pageInfo']['hasNextPage'],
596 + 'last_scan' => WebTotem::dateFormatter($data['lastTest']['time']),
597 + ],
598 +
599 + 'template' => 'antivirus',
600 + ];
601 +
602 + $page_content = $template->arrayRender($build);
603 + echo $template->baseTemplate($page_content);
604 +}
605 +
606 +/**
607 + * Settings page
608 + *
609 + * @return void
610 + */
611 +function wtotem_settings_page() {
612 +
613 + $host = WebTotemAPI::siteInfo();
614 +
615 + $template = new WebTotemTemplate();
616 + if (!isset($host['id']) && !$host['id']) {
617 + wtotem_error_page();
618 + exit();
619 + }
620 +
621 + if(WebTotem::isMultiSite() and !is_super_admin()) {
622 + echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
623 + exit();
624 + }
625 +
626 + // Get data from WebTotem API.
627 + $configs_data = WebTotemAPI::getConfigs($host['id']);
628 + $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI($host['id']);
629 + $ip_list = WebTotemAPI::getIpLists($host['id']);
630 + $url_list = WebTotemAPI::getAllowUrlList($host['id']) ?: [] ;
631 +
632 + if (empty($configs_data) or
633 + empty($agents_statuses) or
634 + empty($ip_list)
635 + ) {
636 + wtotem_error_page();
637 + exit();
638 + }
639 +
640 + // MultiSite page header (site name)
641 + if(WebTotem::isMultiSite() and is_super_admin()){
642 + // Submenu block.
643 +
644 + $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
645 + $pages['settings'] = 'wtotem_page-header__link_active';
646 +
647 + $build[] = [
648 + 'variables' => [
649 + 'is_active' => $pages,
650 + 'site_name' => $host_['name'],
651 + 'hid' => $host_['id'],
652 + ],
653 + 'template' => 'multisite_submenu',
654 + ];
655 + }
656 +
657 + // Settings form.
658 + $build[] = [
659 + 'variables' => [
660 + 'configs' => WebTotem::getConfigsData($configs_data, 'service'),
661 + 'deny_list' => WebTotem::getIpList($ip_list['blackList'], 'ip_deny'),
662 + 'allow_list' => WebTotem::getIpList($ip_list['whiteList'], 'ip_allow'),
663 + 'url_list' => WebTotem::getUrlAllowList($url_list),
664 + 'av_status' => WebTotem::getStatusData($agents_statuses['av']['status']),
665 + 'waf_status' => WebTotem::getStatusData($agents_statuses['waf']['status']),
666 + 'waf_settings' => WebTotem::getWafSettingData($ip_list['settings']),
667 + ],
668 +
669 + 'template' => 'settings_form',
670 + ];
671 +
672 + $page_content = $template->arrayRender($build);
673 + echo $template->baseTemplate($page_content);
674 +}
675 +
676 +
677 +/**
678 + * Reports page.
679 + *
680 + * @return void
681 + */
682 +function wtotem_reports_page() {
683 +
684 + if(WebTotemRequest::get('hid')){
685 + $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
686 + } else {
687 + $host = WebTotemAPI::siteInfo();
688 + }
689 +
690 + $template = new WebTotemTemplate();
691 + if (!isset($host['id']) && !$host['id']) {
692 + wtotem_error_page();
693 + exit();
694 + }
695 +
696 + // Get data from WebTotem API.
697 + $data = WebTotemAPI::getAllReports($host['id']);
698 + if (empty($data)) {
699 + wtotem_error_page();
700 + exit();
701 + }
702 +
703 + WebTotemOption::setSessionOptions([
704 + 'reports_cursor' => $data['pageInfo']['endCursor'],
705 + 'reports_m_cursor' => $data['pageInfo']['endCursor'],
706 + ]);
707 +
708 + // MultiSite page header (site name)
709 + if(WebTotem::isMultiSite() and is_super_admin()){
710 + // Submenu block.
711 + $pages['antivirus'] = 'wtotem_page-header__link_active';
712 +
713 + $build[] = [
714 + 'variables' => [
715 + 'is_active' => $pages,
716 + 'site_name' => $host['name'],
717 + 'hid' => $host['id'],
718 + ],
719 + 'template' => 'multisite_submenu',
720 + ];
721 + }
722 +
723 + // Reports form.
724 + $build[] = [
725 + 'template' => 'reports_form',
726 + ];
727 +
728 + // Reports.
729 + $build[] = [
730 + 'variables' => [
731 + "reports" => WebTotem::getReports($data['edges']),
732 + "has_next_page" => $data['pageInfo']['hasNextPage'],
733 + ],
734 + 'template' => 'reports',
735 + ];
736 +
737 + $page_content = $template->arrayRender($build);
738 + echo $template->baseTemplate($page_content);
739 +
740 +}
741 +
742 +/**
743 + * Information page.
744 + *
745 + * @return void
746 + */
747 +function wtotem_documentation_page() {
748 +
749 + $template = new WebTotemTemplate();
750 +
751 + $build[] = [
752 + 'template' => 'help',
753 + ];
754 +
755 + $page_content = $template->arrayRender($build);
756 + echo $template->baseTemplate($page_content);
757 +}
758 +