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