PluginProbe
WebTotem Security / 2.4.24
WebTotem Security v2.4.24
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.24, at src/PageHandler.php

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