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