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