PluginProbe
WebTotem Security / 2.4.19
WebTotem Security v2.4.19
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 / src / PageHandler.php

PageHandler.php in WebTotem Security 2.4.19, at src/PageHandler.php

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