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