PluginProbe
WebTotem Security / 2.4.22
WebTotem Security v2.4.22
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
wt-security / src / PageHandler.php

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

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