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