| 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 |
|
| 759 |
|