PluginProbe
WebTotem Security / 2.4.12
WebTotem Security v2.4.12
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.12, at src/PageHandler.php

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