PluginProbe
WebTotem Security / 2.4.15
WebTotem Security v2.4.15
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.15, at src/PageHandler.php

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