PluginProbe
WebTotem Security / 2.4.13
WebTotem Security v2.4.13
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.13, at src/PageHandler.php

837 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 ],
273 'template' => 'firewall',
274 ];
275
276 // Display AV and SS data only to the super admin, or it's not a MultiSite network.
277 if(!WebTotem::isMultiSite() or is_super_admin()) {
278
279 // Server Status header.
280 $build[] = [
281 'variables' => [
282 "title" => __('Server resources', 'wtotem'),
283 "tooltip" => [
284 'title' => __('Server resources', 'wtotem'),
285 'test' => __('Displays critical data about web-server usage. A large load on a server can slow down the website performance.', 'wtotem'),
286 ],
287 ],
288 'template' => 'section_header',
289 ];
290
291 // Server Status RAM.
292 $service_data = $data['serverStatus'];
293 $build[] = [
294 'variables' => [
295 "info" => $service_data['info'],
296 "ram_chart" => WebTotem::generateChart($service_data['ramChart']),
297 ],
298 'template' => 'server_status_ram',
299 ];
300
301 // Server Status CPU.
302 $build[] = [
303 'variables' => [
304 "cpu_chart" => WebTotem::generateChart($service_data['cpuChart']),
305 ],
306
307 'template' => 'server_status_cpu',
308 ];
309
310 // Antivirus header.
311 $build[] = [
312 'variables' => [
313 "title" => __('Antivirus', 'wtotem'),
314 ],
315 'template' => 'section_header',
316 ];
317
318 // Antivirus stats blocks.
319 $antivirus_stats = $data['antivirus']['stats'];
320 $build[] = [
321 'variables' => [
322 "changes" => $antivirus_stats['changed'] ?: 0,
323 "scanned" => $antivirus_stats['scanned'] ?: 0,
324 "deleted" => $antivirus_stats['deleted'] ?: 0,
325 "infected" => $antivirus_stats["infected"] ?: 0,
326 ],
327
328 'template' => 'antivirus_stats',
329 ];
330 }
331
332 // Monitoring header.
333 $build[] = [
334 'variables' => [
335 "title" => __('Monitoring', 'wtotem'),
336 ],
337 'template' => 'section_header',
338 ];
339
340 // Monitoring blocks.
341 $build[] = [
342 'variables' => [
343 "ssl" => [
344 'status' => WebTotem::getStatusData($data['ssl']['status']),
345 'days_left' => WebTotem::daysLeft($data['ssl']['expiryDate']),
346 'issue_date' => WebTotem::dateFormatter($data['ssl']['issueDate']),
347 'expiry_date' => WebTotem::dateFormatter($data['ssl']['expiryDate']),
348 ],
349 "availability" => [
350 'status' => WebTotem::getStatusData($data['availability']['status']),
351 "percent" => $data['availability']['percent'],
352 "response_time" => ceil($data['availability']['responseTime'] / 1000000) . ' ' . __('ms.', 'wtotem'),
353 "downtime" => ceil($data['availability']['downTime'] / 1000000) . ' ' . __('ms.', 'wtotem'),
354 "last_test" => WebTotem::dateFormatter($data['availability']['lastTest']['time']),
355 ],
356 'reputation' => [
357 "status" => WebTotem::getStatusData($data['reputation']['status']),
358 "blacklists_entries" => WebTotem::blacklistsEntries(
359 $data['reputation']['status'],
360 $data['reputation']['virusList']),
361 "info" => WebTotem::getReputationInfo($data['reputation']['status']),
362 "last_test" => WebTotem::dateFormatter($data['reputation']['lastTest']['time']),
363 ],
364 ],
365 'template' => 'monitoring',
366 ];
367
368 $build[] = [
369 'variables' => [
370 "ports" => WebTotemAPI::getAllPortsList($host['id']),
371 ],
372 'template' => 'ports_form',
373 ];
374
375 // Scanning header.
376 $build[] = [
377 'variables' => [
378 "title" => __('Scanning', 'wtotem'),
379 ],
380 'template' => 'section_header',
381 ];
382
383 $disc_usage_data = $data['serverStatus']['discUsage'];
384 $disc_usage = [
385 'total' => $disc_usage_data['total'],
386 'free' => $disc_usage_data['free'],
387 'used' => $disc_usage_data['total'] - $disc_usage_data['free'],
388 ];
389
390 // Scanning blocks.
391 $build[] = [
392 'variables' => [
393 "ports" => [
394 'status' => WebTotem::getStatusData($data['ports']['status']),
395 "ip" => $data['ports']['ip'],
396 "number" => count($data['ports']['tcp']),
397 "tcp" => $data['ports']['tcp'],
398 "ignore_ports" => $data['ports']['ignorePorts'],
399 "last_test" => WebTotem::dateFormatter($data['ports']['lastTest']['time']),
400 ],
401 "deface" => [
402 'status' => WebTotem::getStatusData($data['deface']['status']),
403 "number" => $data['deface']['count'],
404 "words" => !empty($data['deface']['words']) ? implode(",", $data['deface']['words']) : '',
405 "last_test" => WebTotem::dateFormatter($data['deface']['lastTest']['time']),
406 ],
407 "disc_usage" => $disc_usage,
408 "disc_chart" => json_encode($disc_usage),
409 ],
410 'template' => 'scanning',
411 ];
412
413 $page_content = $template->arrayRender($build);
414 echo $template->baseTemplate($page_content);
415 }
416
417 /** Firewall page.
418 *
419 * @return void
420 */
421 function wtotem_firewall_page() {
422
423 if(WebTotemRequest::get('hid')){
424 $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
425 } else {
426 $host = WebTotemAPI::siteInfo();
427 }
428
429 $template = new WebTotemTemplate();
430 if (!isset($host['id']) or !$host['id']) {
431 wtotem_error_page();
432 exit();
433 }
434
435 // Get data from WebTotem API.
436 if($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])){
437 $data = $cacheData['data'];
438 } else {
439 $data = WebTotemAPI::getFirewall($host['id'], 10, NULL, 7);
440 WebTotemCache::setData(['getFirewall' => $data], $host['id'], 1);
441 }
442
443 if (empty($data)) {
444 wtotem_error_page();
445 exit();
446 }
447
448 $service_data = $data['firewall'];
449
450 // Reset session data.
451 WebTotemOption::setSessionOptions([
452 'firewall_period' => NULL,
453 'firewall_cursor' => $service_data['logs']['pageInfo']['endCursor'],
454 ]);
455
456 // MultiSite page header (site name)
457 if(WebTotem::isMultiSite() and is_super_admin()){
458 // Submenu block.
459 $pages['firewall'] = 'wtotem_page-header__link_active';
460
461 $build[] = [
462 'variables' => [
463 'is_active' => $pages,
464 'site_name' => $host['name'],
465 'hid' => $host['id'],
466 ],
467 'template' => 'multisite_submenu',
468 ];
469 }
470
471 // Start build array for rendering.
472 // Firewall header.
473 $build[] = [
474 'variables' => [
475 "title" => __('Firewall activity', 'wtotem'),
476 ],
477 'template' => 'section_header',
478 ];
479
480 // Attacks map blocks.
481 // Get world_map json data
482 $world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json';
483 $map_data = WebTotem::generateAttacksMapChart($service_data['map']);
484
485 $build[] = [
486 'variables' => [
487 "attacks_map" => $map_data,
488 "world_map_json" => $world_map_json,
489 ],
490 'template' => 'attacks_map',
491 ];
492
493 $build[] = [
494 'variables' => [
495 "title" => __('Firewall activity', 'wtotem'),
496 ],
497 'template' => 'section_header',
498 ];
499
500 // Firewall stats.
501 $chart = WebTotem::generateWafChart($service_data['chart']);
502 $build[] = [
503 'variables' => [
504 "is_waf_training" => isset( $data['agentManager']['createdAt'] ) && WebTotem::isWafTraining( $data['agentManager']['createdAt'] ),
505 "all_attacks" => $chart['count_attacks'],
506 "blocking" => $chart['count_blocks'],
507 "not_blocking" => $chart['count_attacks'] - $chart['count_blocks'],
508 "most_attacks" => WebTotem::getMostAttacksData($service_data['map']),
509 ],
510 'template' => 'firewall_stats',
511 ];
512
513 // Firewall filter form
514 $build[] = [
515 'template' => 'waf_filter_form',
516 ];
517
518 // Firewall blocks.
519 $build[] = [
520 'variables' => [
521 "chart" => $chart['chart'],
522 "logs" => WebTotem::wafLogs($service_data['logs']['edges']),
523 'has_next_page' => $service_data['logs']['pageInfo']['hasNextPage'],
524 'page' => 'firewall',
525 ],
526 'template' => 'firewall',
527 ];
528
529 $page_content = $template->arrayRender($build);
530 echo $template->baseTemplate($page_content);
531
532 }
533
534 /**
535 * Antivirus page.
536 *
537 * @return void
538 */
539 function wtotem_antivirus_page() {
540
541 $host = WebTotemAPI::siteInfo();
542
543 $template = new WebTotemTemplate();
544 if (!isset($host['id']) or !$host['id']) {
545 wtotem_error_page();
546 exit();
547 }
548
549 if(WebTotem::isMultiSite() and !is_super_admin()) {
550 echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
551 exit();
552 }
553
554 $params = [
555 'host_id' => $host['id'],
556 'limit' => 10,
557 'cursor' => NULL,
558 'days' => 365,
559 'event' => FALSE,
560 'permissions' => FALSE,
561 ];
562
563 // Get data from WebTotem API.
564 if($cacheData = WebTotemCache::getdata('getAntivirus', $host['id'])){
565
566 $data = $cacheData['data'];
567 } else {
568 $data = WebTotemAPI::getAntivirus($params);
569 WebTotemCache::setData(['getAntivirus' => $data], $host['id']);
570 }
571
572 if (empty($data)) {
573 wtotem_error_page();
574 exit();
575 }
576
577 // Reset session data.
578 WebTotemOption::setSessionOptions([
579 'antivirus_event' => NULL,
580 'antivirus_permissions' => NULL,
581 'antivirus_cursor' => $data['log']['pageInfo']['endCursor'],
582 ]);
583
584 // MultiSite page header (site name)
585 if(WebTotem::isMultiSite() and is_super_admin()){
586 // Submenu block.
587 $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
588 $pages['antivirus'] = 'wtotem_page-header__link_active';
589
590 $build[] = [
591 'variables' => [
592 'is_active' => $pages,
593 'site_name' => $host_['name'],
594 'hid' => $host_['id'],
595 ],
596 'template' => 'multisite_submenu',
597 ];
598 }
599
600 // Antivirus header.
601 $build[] = [
602 'variables' => [
603 "title" => __('Antivirus', 'wtotem'),
604 ],
605 'template' => 'section_header',
606 ];
607
608 // Antivirus stats blocks.
609 $stats = $data['stats'];
610 $build[] = [
611 'variables' => [
612 'changes' => $stats['changed'] ?: 0,
613 'scanned' => $stats['scanned'] ?: 0,
614 'deleted' => $stats['deleted'] ?: 0,
615 'infected' => $stats["infected"] ?: 0,
616 'page' => 'antivirus',
617 ],
618 'template' => 'antivirus_stats',
619 ];
620
621 // Quarantine logs blocks.
622 $quarantine_logs = $data['quarantine'] ?: [];
623 $quarantine_count = count($quarantine_logs);
624
625 $build[] = [
626 'variables' => [
627 "logs" => WebTotem::getQuarantineLogs($quarantine_logs) ?: [],
628 "count" => $quarantine_count,
629 ],
630 'template' => 'quarantine',
631 ];
632
633 // Antivirus filter form.
634 $build[] = [
635 'template' => 'antivirus_filter_form',
636 ];
637
638 // Antivirus blocks.
639 $build[] = [
640 'variables' => [
641 "logs" => WebTotem::getAntivirusLogs($data['log']['edges']),
642 "has_next_page" => $data['log']['pageInfo']['hasNextPage'],
643 'last_scan' => WebTotem::dateFormatter($data['lastTest']['time']),
644 ],
645
646 'template' => 'antivirus',
647 ];
648
649 $page_content = $template->arrayRender($build);
650 echo $template->baseTemplate($page_content);
651 }
652
653 /**
654 * Settings page
655 *
656 * @return void
657 */
658 function wtotem_settings_page() {
659
660 $host = WebTotemAPI::siteInfo();
661
662 $template = new WebTotemTemplate();
663 if (!isset($host['id']) or !$host['id']) {
664 wtotem_error_page();
665 exit();
666 }
667
668 if(WebTotem::isMultiSite() and !is_super_admin()) {
669 echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
670 exit();
671 }
672
673 // Get data from WebTotem API.
674 if($cacheData = WebTotemCache::getdata('getConfigs', $host['id'])){
675 $configs_data = $cacheData['data'];
676 } else {
677 $configs_data = WebTotemAPI::getConfigs($host['id']);
678 WebTotemCache::setData(['getConfigs' => $configs_data], $host['id']);
679 }
680
681 if($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])){
682 $agents_statuses = $cacheData['data'];
683 } else {
684 $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI($host['id']);
685 WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses], $host['id']);
686 }
687
688 if($cacheData = WebTotemCache::getdata('getIpLists', $host['id'])){
689 $ip_list = $cacheData['data'];
690 } else {
691 $ip_list = WebTotemAPI::getIpLists($host['id']);
692 WebTotemCache::setData(['getIpLists' => $ip_list], $host['id']);
693 }
694
695 if($cacheData = WebTotemCache::getdata('getAllowUrlList', $host['id'])){
696 $url_list = $cacheData['data'];
697 } else {
698 $url_list = WebTotemAPI::getAllowUrlList($host['id']) ?: [];
699 WebTotemCache::setData(['getAllowUrlList' => $url_list], $host['id']);
700 }
701
702 if (empty($configs_data) or
703 empty($agents_statuses) or
704 empty($ip_list)
705 ) {
706 wtotem_error_page();
707 exit();
708 }
709
710 // MultiSite page header (site name)
711 if(WebTotem::isMultiSite() and is_super_admin()){
712 // Submenu block.
713
714 $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
715 $pages['settings'] = 'wtotem_page-header__link_active';
716
717 $build[] = [
718 'variables' => [
719 'is_active' => $pages,
720 'site_name' => $host_['name'],
721 'hid' => $host_['id'],
722 ],
723 'template' => 'multisite_submenu',
724 ];
725 }
726
727 // Settings form.
728 $build[] = [
729 'variables' => [
730 'configs' => WebTotem::getConfigsData($configs_data, 'service'),
731 'deny_list' => WebTotem::getIpList($ip_list['blackList'], 'ip_deny'),
732 'allow_list' => WebTotem::getIpList($ip_list['whiteList'], 'ip_allow'),
733 'url_list' => WebTotem::getUrlAllowList($url_list),
734 'av_status' => WebTotem::getStatusData($agents_statuses['av']['status']),
735 'waf_status' => WebTotem::getStatusData($agents_statuses['waf']['status']),
736 'waf_settings' => WebTotem::getWafSettingData($ip_list['settings']),
737 'plugin_settings' => WebTotem::getPluginSettingsData(),
738 'two_factor' => WebTotemLogin::getTwoFactorData(),
739 ],
740
741 'template' => 'settings_form',
742 ];
743
744 $page_content = $template->arrayRender($build);
745 echo $template->baseTemplate($page_content);
746 }
747
748
749 /**
750 * Reports page.
751 *
752 * @return void
753 */
754 function wtotem_reports_page() {
755
756 if(WebTotemRequest::get('hid')){
757 $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
758 } else {
759 $host = WebTotemAPI::siteInfo();
760 }
761
762 $template = new WebTotemTemplate();
763 if (!isset($host['id']) or !$host['id']) {
764 wtotem_error_page();
765 exit();
766 }
767
768 // Get data from WebTotem API.
769 if($cacheData = WebTotemCache::getdata('getAllReports', $host['id'])){
770 $data = $cacheData['data'];
771 } else {
772 $data = WebTotemAPI::getAllReports($host['id']);
773 WebTotemCache::setData(['getAllReports' => $data], $host['id']);
774 }
775
776 if (empty($data)) {
777 wtotem_error_page();
778 exit();
779 }
780
781 WebTotemOption::setSessionOptions([
782 'reports_cursor' => $data['pageInfo']['endCursor'],
783 'reports_m_cursor' => $data['pageInfo']['endCursor'],
784 ]);
785
786 // MultiSite page header (site name)
787 if(WebTotem::isMultiSite() and is_super_admin()){
788 // Submenu block.
789 $pages['reports'] = 'wtotem_page-header__link_active';
790
791 $build[] = [
792 'variables' => [
793 'is_active' => $pages,
794 'site_name' => $host['name'],
795 'hid' => $host['id'],
796 ],
797 'template' => 'multisite_submenu',
798 ];
799 }
800
801 // Reports form.
802 $build[] = [
803 'template' => 'reports_form',
804 ];
805
806 // Reports.
807 $build[] = [
808 'variables' => [
809 "reports" => WebTotem::getReports($data['edges']),
810 "has_next_page" => $data['pageInfo']['hasNextPage'],
811 ],
812 'template' => 'reports',
813 ];
814
815 $page_content = $template->arrayRender($build);
816 echo $template->baseTemplate($page_content);
817
818 }
819
820 /**
821 * Information page.
822 *
823 * @return void
824 */
825 function wtotem_documentation_page() {
826
827 $template = new WebTotemTemplate();
828
829 $build[] = [
830 'template' => 'help',
831 ];
832
833 $page_content = $template->arrayRender($build);
834 echo $template->baseTemplate($page_content);
835 }
836
837