# wt-security/3.0.2/src/PageHandler.php

WebTotem Security, version 3.0.2. 954 lines.

- Page: https://pluginprobe.com/plugins/wt-security/3.0.2/code/src/PageHandler.php
- Raw: https://pluginprobe.com/plugins/wt-security/3.0.2/raw/src/PageHandler.php
- Modified: 2026-09-14T08:28:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wt-security/3.0.2/code/src/PageHandler.php#L10-L20`.

```php
<?php

/**
 * Load page and ajax handlers
 */

if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
    if (!headers_sent()) {
        header('HTTP/1.1 403 Forbidden');
    }
    die("Protected By WebTotem!");
}

/**
 * Handles all the AJAX plugin's requests.
 *
 * @return void
 */
function wtotem_ajax_callback()
{
    /**
     * Actions that carry their own authorization.
     *
     * `two_factor_auth` is reachable from the user profile screen, where a user
     * without `manage_options` manages their own second factor; the handler
     * itself checks that the target user is the current one (or that the caller
     * is an administrator).
     */
    $self_authorizing_actions = ['two_factor_auth'];

    $post_action = WebTotemRequest::post('ajax_action');
    $get_action = WebTotemRequest::get('ajax_action');

    // Everything this plugin exposes over AJAX belongs to its admin screens,
    // which are registered with `manage_options`. A valid nonce proves the
    // request came from our form; it says nothing about who sent it, so the
    // capability has to be checked separately.
    $is_privileged = current_user_can('manage_options');

    if ($get_action != NULL) {
        if (!$is_privileged) {
            wtotem_ajax_forbidden();
        }

        WebTotemAjax::wtotem_scan();
    }

    $composer_autoload = WEBTOTEM_PLUGIN_PATH . '/vendor/autoload.php';
    if (file_exists($composer_autoload)) {
        require_once $composer_autoload;
    }

    if ($post_action != NULL) {
        WebTotemAjax::authenticate();
    }

    if ($post_action != NULL && WebTotemInterface::checkNonce()) {

        if (!$is_privileged && !in_array($post_action, $self_authorizing_actions, TRUE)) {
            wtotem_ajax_forbidden();
        }

        if ($is_privileged) {
            WebTotemAjax::activation();
            WebTotemAjax::agentsInstallation();
            WebTotemAjax::reinstallAgents();
            WebTotemAjax::chart();
            WebTotemAjax::logs();
            WebTotemAjax::wafDateFilter();
            WebTotemAjax::pagination();
            WebTotemAjax::antivirus();
            WebTotemAjax::changeThemeMode();
            WebTotemAjax::userTimeZone();
            WebTotemAjax::quarantine();
            WebTotemAjax::cashUpdate();
            WebTotemAjax::settings();
            WebTotemAjax::remove();
            WebTotemAjax::logout();
            WebTotemAjax::popup();
            WebTotemAjax::getWsTicket();
            WebTotemAjax::force_check();
        }

        WebTotemAjax::twoFactorAuth();

    }

    wp_send_json([
        'success' => false,
        'error' => 'invalid ajax request',
        'notifications' => WebTotemAjax::notifications(),
    ], 200);
}

/**
 * Ends an AJAX request that the current user is not allowed to make.
 *
 * @return void
 */
function wtotem_ajax_forbidden()
{
    wp_send_json([
        'success' => false,
        'error' => 'forbidden',
    ], 403);
}

/**
 * Handles all the AJAX plugin's public requests.
 *
 * @return void
 */
function wtotem_public_ajax_callback()
{

    if (WebTotemRequest::post('ajax_action') != NULL) {
        WebTotemAjax::authenticate();
    }

    wp_send_json([
        'success' => false,
        'error' => 'invalid ajax request',
    ], 200);

}

/**
 * Error page.
 *
 * @return void
 */
function wtotem_error_page($data = [])
{
    $composer_autoload = WEBTOTEM_PLUGIN_PATH . '/vendor/autoload.php';
    if (file_exists($composer_autoload)) {
        require_once $composer_autoload;
    }

    $template = new WebTotemTemplate();
    $parse = parse_url(WebTotemOption::getOption('api_url'));
    $domain = str_ireplace('api.', '', $parse['host']);

    if ($data['errors'] == 'PASSWORD_EXPIRED') {

        $build[] = [
            'variables' => [
                'message' => __('Your password has expired. You need to update it in cabinet.', 'wtotem'),
                'is_cabinet_link' => true,
                'cabinet_link' => 'https://' . $domain . '/cabinet/sign-in',
            ],
            'template' => 'error',
        ];
    } elseif ($data['errors'] == 'TARIFF_EXPIRED') {

        $build[] = [
            'variables' => [
                'message' => __('Your subscription plan has expired. Please renew it in your account dashboard.', 'wtotem'),
                'is_cabinet_link' => true,
                'cabinet_link' => 'https://' . $domain . '/cabinet/pricing',
            ],
            'template' => 'error',
        ];
    } else {
        $build[] = [
            'variables' => [
                'message' => __('Try reinstalling the agents or changing the API key', 'wtotem'),
                'is_bnt' => true,
            ],
            'template' => 'error',
        ];
    }

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}

/**
 * Activation page.
 *
 * @return void
 */
function wtotem_activation_page()
{
     $build[] = [
        'variables' => [
            'notifications' => WebTotem::getNotifications(),
            'current_year' => date('Y'),
            'page' => 'activation',
        ],
        'template' => 'activation'
    ];

    $template = new WebTotemTemplate();
    echo $template->arrayRender($build);
}


/**
 * All sites page.
 *
 * @return void
 */
function wtotem_all_sites_page()
{
    $allSites = WebTotemAPI::getSites(1, 1000000);

    // Reset session data.
    WebTotemOption::setSessionOptions([
        'sites_cursor' => $allSites['pageInfo']['endCursor'],
    ]);

    $build[] = [
        'variables' => [
            'notifications' => WebTotem::getNotifications(),
            'current_year' => date('Y'),
            'sites' => WebTotem::allSitesData($allSites),
            'theme_mode' => WebTotem::getThemeMode()
        ],
        'template' => 'multisite'
    ];

    $template = new WebTotemTemplate();
    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}

/**
 * Dashboard, main page.
 *
 * @return void
 */
function wtotem_dashboard_page()
{

    if (WebTotemRequest::get('hid')) {
        $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
    } else {
        $host = WebTotemAPI::siteInfo();
    }

    $template = new WebTotemTemplate();
    if (!isset($host['id']) or !$host['id']) {
        wtotem_error_page();
        exit();
    }

    // Get monitoring data from WebTotem API.
    if ($cacheData = WebTotemCache::getdata('getMonitoringData', $host['id'])) {
        $data = $cacheData['data'];
    } else {
        $data = WebTotemAPI::getMonitoringData($host['id']);
        WebTotemCache::setData(['getMonitoringData' => $data], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) {
        $firewall_data = $cacheData['data'];
    } else {
        $firewall_data = WebTotemAPI::getFirewall(10, 1, 7);
        WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) {
        $firewall_chart_data = $cacheData['data'];
    } else {
        $firewall_chart_data = WebTotemAPI::getFirewallStatistics();
        WebTotemCache::setData(['getFirewallStatistics' => $firewall_chart_data], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) {
        $agents_statuses_api = $cacheData['data'];
    } else {
        $agents_statuses_api = WebTotemAPI::getAgentsStatusesFromAPI();
        WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses_api], $host['id']);
    }


    if (empty($data)) {
        wtotem_error_page();
        exit();
    }

    // MultiSite page header (site name)
//    if (WebTotem::isMultiSite() and is_super_admin()) {
//        // Submenu block.
//        $pages['dashboard'] = 'wtotem_page-header__link_active';
//
//        $build[] = [
//            'variables' => [
//                'is_active' => $pages,
//                'site_name' => $host['name'],
//                'hid' => $host['id'],
//            ],
//            'template' => 'multisite_submenu',
//        ];
//    }

    // Reset session data.
    WebTotemOption::setSessionOptions([
        'firewall_period' => NULL,
        'ram_period' => NULL,
        'cpu_period' => NULL,
    ]);

    // Scoring block.
//    $service_data = $data['scoring']['result'];
//    $total_score = round($data['scoring']['score']);
//    $score_grading = WebTotem::scoreGrading($total_score);
//    $build[] = [
//        'variables' => [
//            "host_id" => $host['id'],
//            "total_score" => $total_score . "%",
//            "tested_on" => WebTotem::dateFormatter($data['scoring']['lastTest']['time']),
//            "server_ip" => $service_data['ip'] ?: ' - ',
//            "location" => WebTotem::getCountryName($service_data['country']) ?: ' - ',
//            "is_higher_than" => $service_data['isHigherThan'] . '%',
//            "grade" => $score_grading['grade'],
//            "color" => $score_grading['color'],
//        ],
//        'template' => 'score',
//    ];

    // Agents installing process.

    $agents_data = [
        'av' => $agents_statuses_api['av'] ?? '',
        'waf' => $agents_statuses_api['waf'] ?? '',
    ];

    $agents_statuses = WebTotem::getAgentsStatuses($agents_data);

    if (!$agents_statuses['option_statuses']['av'] or !$agents_statuses['option_statuses']['waf']) {

        $status = [
            'av' => $agents_statuses['process_statuses']['av'] == 'available',
            'waf' => $agents_statuses['process_statuses']['waf'] == 'available',
        ];

        WebTotemOption::setOptions([
            'av_installed' => $status['av'],
            'waf_installed' => $status['waf'],
        ]);

        $build[] = [
            'variables' => [
                "process_status" => $agents_statuses['process_statuses'],
            ],
            'template' => 'agents',
        ];
    }



    // Monitoring header.
    $build[] = [
        'variables' => [
            "title" => __('Monitoring', 'wtotem'),
        ],
        'template' => 'section_header',
    ];

    $ssl = false;
    if ($data['module_ssl']) {
        $ssl = [
            'status' => WebTotem::getStatusData($data['module_ssl']['info']['status']),
            'cert_name' => $data['module_ssl']['result']['certificate_name'],
            'days_left' => $data['module_ssl']['result']['days_left'],
            'issue_date' => WebTotem::dateFormatter($data['module_ssl']['result']['issue_date']),
            'expiry_date' => WebTotem::dateFormatter($data['module_ssl']['result']['expiry_date']),
        ];
    }

    $domain = [
        'status' => WebTotem::getStatusData($data['module_location']['info']['status']),
        "redirect_link" => $data['module_location']['result']['redirect_link'],
        "is_created_at" => (bool)$data['module_location']['result']['checked_at'],
        "created_at" => WebTotem::dateFormatter($data['module_location']['result']['checked_at']),
        "is_taken" => $data['module_location']['result']['is_taken'],
        "ips" => $data['module_location']['result']['locations'],
        "protection" => $data['module_location']['result']['protection'],
    ];

    // Monitoring blocks.
    $build[] = [
        'variables' => [
            "host_id" => $host['id'],
            'ws_url' => WebTotemAPI::getWsUrl(),
            "ssl" => $ssl,
            "domain_module" => $domain,
            'reputation' => [
                "status" => WebTotem::getStatusData($data['module_reputation']['info']['status'] ?? ''),
//                "blacklists_entries" => WebTotem::blacklistsEntries(
//                    $data['reputation']['status'] ?? '',
//                    $data['reputation']['antivirus'] ?? []),
                "info" => WebTotem::getReputationInfo($data['reputation']['result']['status'] ?? ''),
                "last_test" => WebTotem::dateFormatter($data['reputation']['result']['checked_at'] ?? ''),
            ],

            'availability' => [
                'chart' => json_encode($data['module_availability']['result']['stats_by_day']),
                'status' => WebTotem::getStatusData($data['module_availability']['info']['status'])
            ],
        ],
        'template' => 'monitoring',
    ];

    $build[] = [
        'variables' => [
            "ports" => [
                "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []),
                "ignorePorts" => [],
            ],
        ],
        'template' => 'ports_form',
    ];

    // Scanning header.
    $build[] = [
        'variables' => [
            "title" => __('Scanning', 'wtotem'),
        ],
        'template' => 'section_header',
    ];


    // Scanning blocks.
    $build[] = [
        'variables' => [
            "ports" => [
                'status' => WebTotem::getStatusData($data['module_port_scanner']['info']['status'] ?? 'clean'),
                "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []),
                "ignore_ports" => [],
                "last_test" => WebTotem::dateFormatter($data['module_port_scanner']['result']['checked_at'] ?? false),
            ],
            "open_path" => [
                'status' => WebTotem::getStatusData($data['module_open_paths']['info']['status'] ),
                "last_test" => WebTotem::dateFormatter($data['module_open_paths']['result']['checked_at']  ?? false),
                "paths" => $data['module_open_paths']['result']['open_paths'] ?? [],
            ],
        ],
        'template' => 'scanning',
    ];


    // Firewall header.
    $build[] = [
        'variables' => [
            "title" => __('Firewall activity', 'wtotem'),
        ],
        'template' => 'section_header',
    ];

    $is_period_available = WebTotem::isPeriodAvailable();

    // Firewall stats.
    $chart = WebTotem::generateWafChart($firewall_chart_data['signatures_statistic'] ?? []);
    $build[] = [
        'variables' => [
            "is_waf_training" => WebTotem::isWafTraining(),
            "is_period_available" => $is_period_available,
            "most_attacks" => WebTotem::getMostAttacksData($firewall_chart_data['countries_statistics'] ?? []),
        ],
        'template' => 'firewall_stats',
    ];

    // Firewall filter form
    $build[] = [
        'variables' => [
            "is_period_available" => $is_period_available,
        ],
        'template' => 'waf_filter_form',
    ];

    // Firewall blocks.
    $build[] = [
        'variables' => [
            "chart" => $chart['chart'],
            "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []),
            'host_name' => $host['name'],
        ],
        'template' => 'firewall',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);

}

/** Open paths page.
 *
 * @return void
 */
function wtotem_open_paths_page()
{
    if (WebTotemRequest::get('hid')) {
        $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
    } else {
        $host = WebTotemAPI::siteInfo();
    }

    $template = new WebTotemTemplate();
    if (!isset($host['id']) or !$host['id']) {
        wtotem_error_page();
        exit();
    }

    // Get data from WebTotem API.
    if ($cacheData = WebTotemCache::getdata('getOpenPaths', $host['id'])) {
        $open_path = $cacheData['data'];
    } else {
        $data = WebTotemAPI::getMonitoringData($host['id']);
        $open_path = $data['module_open_paths']['result']['open_paths'];
        WebTotemCache::setData(['getOpenPaths' => $open_path], $host['id']);
    }

    $build[] = [
        'variables' => [
            "paths" => $open_path ?? [],
        ],
        'template' => 'open_paths_page',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);

}

/** Firewall page.
 *
 * @return void
 */
function wtotem_firewall_page()
{
    if (WebTotemRequest::get('hid')) {
        $host = WebTotemOption::getHost(WebTotemRequest::get('hid'));
    } else {
        $host = WebTotemAPI::siteInfo();
    }

    $template = new WebTotemTemplate();
    if (!isset($host['id']) or !$host['id']) {
        wtotem_error_page();
        exit();
    }

    // Get data from WebTotem API.
    if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) {
        $data = $cacheData['data'];
    } else {
        $data = WebTotemAPI::getFirewallStatistics();
        WebTotemCache::setData(['getFirewallStatistics' => $data], $host['id']);
    }
    if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) {
        $firewall_data = $cacheData['data'];
    } else {
        $firewall_data = WebTotemAPI::getFirewall(10, 1, 7);
        WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']);
    }

    if (empty($data)) {
        wtotem_error_page();
        exit();
    }


    // MultiSite page header (site name)
//    if (WebTotem::isMultiSite() and is_super_admin()) {
//        // Submenu block.
//        $pages['firewall'] = 'wtotem_page-header__link_active';
//
//        $build[] = [
//            'variables' => [
//                'is_active' => $pages,
//                'site_name' => $host['name'],
//                'hid' => $host['id'],
//            ],
//            'template' => 'multisite_submenu',
//        ];
//    }

    // Firewall header.
    $build[] = [
        'variables' => [
            "title" => __('Firewall activity', 'wtotem'),
        ],
        'template' => 'section_header',
    ];

    // Attacks map blocks.
    // Get world_map json data
    $world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json';
    $map_data = WebTotem::generateAttacksMapChart($data['countries_statistics'] ?? []);
    $is_period_available = WebTotem::isPeriodAvailable();

    $build[] = [
        'variables' => [
            "is_period_available" => $is_period_available,
            "attacks_map" => $map_data,
            "world_map_json" => $world_map_json,
        ],
        'template' => 'attacks_map',
    ];

    // Firewall stats.
    $build[] = [
        'variables' => [
            "is_waf_training" => WebTotem::isWafTraining(),
            "is_period_available" => $is_period_available,
            "most_attacks" => WebTotem::getMostAttacksData($data['countries_statistics'] ?? []),
//            "all_attacks" => $firewall_statistics_data['weekly_blocked_attacks'],
//            "blocking" => $chart['count_blocks'],
//            "not_blocking" => (int)$chart['count_attacks'] - (int)$chart['count_blocks'],
        ],
        'template' => 'firewall_stats',
    ];

    // Firewall filter form
    $build[] = [
        'variables' => [
            "is_period_available" => $is_period_available,
        ],
        'template' => 'waf_filter_form',
    ];

    // Firewall blocks.
		$chart = WebTotem::generateWafChart($data['signatures_statistic'] ?? []);
    $build[] = [
        'variables' => [
            'page' => 'firewall',
            "chart" => $chart['chart'],
            "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []),
            'host_name' => $host['name'],
            "firewall_logs_pagination" => WebTotem::paginationBuild(10, $firewall_data['total']),
        ],
        'template' => 'firewall',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);

}

/**
 * Antivirus page.
 *
 * @return void
 */
function wtotem_antivirus_page()
{
    $host = WebTotemAPI::siteInfo();

    $template = new WebTotemTemplate();
    if (!isset($host['id']) or !$host['id']) {
        wtotem_error_page();
        exit();
    }

    // Get data from WebTotem API.
    if ($cacheData = WebTotemCache::getdata('getAntivirusHistory', $host['id'])) {
        $antivirus_history_data = $cacheData['data'];
    } else {
        $antivirus_history_data = WebTotemAPI::getAntivirusHistory();
        WebTotemCache::setData(['getAntivirusHistory' => $antivirus_history_data], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getAntivirusCurrentDetails', $host['id'])) {
        $infected_files = $cacheData['data'];
    } else {
        $infected_files = WebTotemAPI::getAntivirusCurrentDetails();
        WebTotemCache::setData(['getAntivirusCurrentDetails' => $infected_files], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getQuarantineList', $host['id'])) {
        $quarantine_files = $cacheData['data'];
    } else {
        $quarantine_files = WebTotemAPI::getQuarantineList();
        WebTotemCache::setData(['getQuarantineList' => $quarantine_files], $host['id']);
    }


    if (empty($antivirus_history_data)) {
        wtotem_error_page();
        exit();
    }

    // Reset session data.
    WebTotemOption::setSessionOptions([
        'antivirus_event' => NULL,
        'antivirus_permissions' => NULL,
        'antivirus_current_page' => 1,
    ]);

    // Antivirus header.
    $build[] = [
        'variables' => [
            "title" => __('Antivirus', 'wtotem'),
        ],
        'template' => 'section_header',
    ];

    // Antivirus stats blocks.
    $build[] = [
        'variables' => [
            'ws_url' => WebTotemAPI::getWsUrl(),
            'config_id' =>  WebTotemOption::getOption('config_id'),
            'page' => 'antivirus',
        ],
        'template' => 'antivirus_stats',
    ];

  // Quarantine and infected files logs blocks.


    $build[] = [
        'variables' => [
            "infected_files" => WebTotem::getInfectedFilesData($infected_files['current_infected_files'] ?? []),
            "infected_files_pagination" => WebTotem::paginationBuild(5, (int)$infected_files['total']),
            'infected_files_total' => (int)$infected_files['total'],
            "quarantine_files" => WebTotem::getQuarantineListData($quarantine_files['quarantine_files'] ?? []),
            "quarantine_files_pagination" => WebTotem::paginationBuild(5, (int)$quarantine_files['total']),
            'quarantine_files_total' => (int)$quarantine_files['total'],
        ],
        'template' => 'quarantine',
    ];

    // History blocks.
    $build[] = [
        'variables' => [
            "logs" => WebTotem::getAntivirusLogsData($antivirus_history_data['history']),
            "antivirus_history_pagination" => WebTotem::paginationBuild(10, (int)$antivirus_history_data['total']),
        ],
        'template' => 'antivirus_history',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}

/**
 * Settings page
 *
 * @return void
 */
function wtotem_settings_page()
{
    $host = WebTotemAPI::siteInfo();

    $template = new WebTotemTemplate();
    if (!isset($host['id']) or !$host['id']) {
        wtotem_error_page();
        exit();
    }

//    if (WebTotem::isMultiSite() and !is_super_admin()) {
//        echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem'));
//        exit();
//    }

    // Get data from WebTotem API.

    if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) {
        $agents_statuses = $cacheData['data'];
    } else {
        $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI();
        WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getFirewallSettings', $host['id'])) {
        $waf_settings = $cacheData['data'];
    } else {
        $waf_settings = WebTotemAPI::getFirewallSettings();
        WebTotemCache::setData(['getFirewallSettings' => $waf_settings], $host['id']);
    }

    if ($cacheData = WebTotemCache::getdata('getIpLists_whitelist', $host['id'])) {
        $ip_whiteList = $cacheData['data'];
    } else {
        $ip_whiteList = WebTotemAPI::getIpLists('whitelist');
        WebTotemCache::setData(['getIpLists_whitelist' => $ip_whiteList], $host['id']);
    }
    if ($cacheData = WebTotemCache::getdata('getIpLists_blacklist', $host['id'])) {
        $ip_blackList = $cacheData['data'];
    } else {
        $ip_blackList = WebTotemAPI::getIpLists();
        WebTotemCache::setData(['getIpLists_blacklist' => $ip_blackList], $host['id']);
    }
    if ($cacheData = WebTotemCache::getdata('getIpLists_checklist', $host['id'])) {
        $ip_checklist = $cacheData['data'];
    } else {
        $ip_checklist = WebTotemAPI::getIpLists('checklist');
        WebTotemCache::setData(['getIpLists_checklist' => $ip_checklist], $host['id']);
    }

    if (empty($agents_statuses) ) {
        wtotem_error_page();
        exit();
    }

    // MultiSite page header (site name)
//    if (WebTotem::isMultiSite() and is_super_admin()) {
//        // Submenu block.
//
//        $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid'));
//        $pages['settings'] = 'wtotem_page-header__link_active';
//
//        $build[] = [
//            'variables' => [
//                'is_active' => $pages,
//                'site_name' => $host_['name'],
//                'hid' => $host_['id'],
//            ],
//            'template' => 'multisite_submenu',
//        ];
//    }


    // Settings form.
    $build[] = [
        'variables' => [
            'deny_list' => WebTotem::getIpList($ip_blackList, 'ip_deny'),
            'allow_list' => WebTotem::getIpList($ip_whiteList, 'ip_allow'),
            'url_list' => WebTotem::getIpList($ip_checklist, 'allow_url'),
            'av_status' => WebTotem::getStatusData($agents_statuses['av']),
            'waf_status' => WebTotem::getStatusData($agents_statuses['waf']),
            'waf_settings' => WebTotem::getWafSettingData($waf_settings),
            'plugin_settings' => WebTotem::getPluginSettingsData(),
            'two_factor' => WebTotemLogin::getTwoFactorData(),
        ],

        'template' => 'settings_form',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}

/**
 * Scan WP page.
 *
 * @return void
 */
function wtotem_wpscan_page()
{
    $template = new WebTotemTemplate();
    $audit_logs = WebTotemDB::getRows([], 'audit_logs');
    $confidential_files = WebTotemDB::getRows([], 'confidential_files');
    $links = WebTotemDB::getRows(['AND', ['data_type' => 'links']], 'scan_logs', 'content');
    $scripts = WebTotemDB::getRows(['AND', ['data_type' => 'scripts']], 'scan_logs', 'content');
    $iframes = WebTotemDB::getRows(['AND', ['data_type' => 'iframes']], 'scan_logs', 'content');

//    $plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => 1]);
//    require_once ABSPATH . 'wp-admin/includes/plugin.php';
//    $have_all_plugins_auto_update = count(get_plugins() ?: []) == count(get_site_option( 'auto_update_plugins' ) ?: []);

    $events = [
        'User authentication succeeded',
        'User authentication failed',
        'User account created',
        'User account deleted',
        'User account edited',
        'Attempt to reset password',
        'Password retrieval attempt',
        'User added to website',
        'User removed from website',
        'WordPress updated',

        'User account deleted',
        'Bookmark link added',
        'Bookmark link edited',
        'Category created',
        'Publication was published',
        'Publication was updated',
        'Post status has been changed',
        'Post deleted',
        'Post moved to trash',
        'Media file added',
        'Plugin activated',
        'Plugin deactivated',
        'Theme activated',
        'Settings changed',
        'Plugins deleted',
        'Plugin editor used',
        'Plugin installed',
        'Plugins updated',
        'Theme deleted',
        'Theme editor used',
        'Theme installed',
        'Themes updated',
        'Widget deleted',
        'Widget added',
    ];

    $until_next_scan = wp_next_scheduled('webtotem_daily_cron') - time();

    $hr = floor($until_next_scan / 3600);
    $min = floor(($until_next_scan % 3600) / 60);

    // Scan logs block.
    $build[] = [
        'variables' => [
            "audit_logs_count" => $audit_logs['count'],
            "audit_logs" => WebTotem::getAuditLogs($audit_logs['data'], $audit_logs['dates_count']),
            "audit_logs_pagination" => WebTotem::paginationBuild(10, $audit_logs['count']),
            "audit_logs_events" => WebTotemDB::checkAvailability('audit_logs', $events, 'event'),

            "confidential_files_count" => $confidential_files['count'],
            "confidential_files" => WebTotem::getConfidentialFiles($confidential_files['data']),
            "confidential_files_pagination" => WebTotem::paginationBuild(10, $confidential_files['count']),

            "links_count" => $links['count'],
            "links" =>  WebTotem::prepareLinksData($links['data']),
            "links_pagination" => WebTotem::paginationBuild(10, $links['count']),

            "scripts_count" => $scripts['count'],
            "scripts" => WebTotem::prepareLinksData($scripts['data']),
            "scripts_pagination" => WebTotem::paginationBuild(10, $scripts['count']),

            "iframes_count" => $iframes['count'],
            "iframes" => WebTotem::prepareLinksData($iframes['data']),
            "iframes_pagination" => WebTotem::paginationBuild(10, $iframes['count']),

//            "plugins_cve_list_count" => $plugins_cve_list['count'],
//            "plugins_cve_list" => WebTotem::preparePluginsCveList($plugins_cve_list['data']),
//            "plugins_cve_list_pagination" => WebTotem::paginationBuild(8, $plugins_cve_list['count']),
//            "have_all_plugins_auto_update" => $have_all_plugins_auto_update,

            "next_scan" => sprintf(__('%dh %dm', 'wtotem'), $hr, $min),
            "scan_init" => WebTotemOption::getOption('scan_init') ?: 0,
        ],
        'template' => 'scan_logs',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}


/**
 * Information page.
 *
 * @return void
 */
function wtotem_documentation_page()
{
    $template = new WebTotemTemplate();

    $build[] = [
        'template' => 'help',
    ];

    $page_content = $template->arrayRender($build);
    echo $template->baseTemplate($page_content);
}


```
