| 1 |
<?php |
| 2 |
if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) { |
| 3 |
if (!headers_sent()) { |
| 4 |
header('HTTP/1.1 403 Forbidden'); |
| 5 |
} |
| 6 |
die('Protected By WebTotem!'); |
| 7 |
} |
| 8 |
|
| 9 |
class WebTotemAjax |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* Activation plugin. |
| 14 |
* |
| 15 |
* @return void |
| 16 |
*/ |
| 17 |
public static function activation() |
| 18 |
{ |
| 19 |
|
| 20 |
if (WebTotemRequest::post('ajax_action') !== 'activation') { |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
if ($api_key = WebTotemRequest::post('api_key')) { |
| 25 |
|
| 26 |
$result = WebTotemAPI::auth($api_key); |
| 27 |
|
| 28 |
if ($result == 'success') { |
| 29 |
// if (WebTotem::isMultiSite()) { |
| 30 |
// $link = WebTotem::adminURL('admin.php?page=wtotem_all_sites'); |
| 31 |
// } else { |
| 32 |
// $link = WebTotem::adminURL('admin.php?page=wtotem'); |
| 33 |
// } |
| 34 |
$link = WebTotem::adminURL('admin.php?page=wtotem'); |
| 35 |
// $email = WebTotemAPI::getEmail(); |
| 36 |
// WebTotemOption::setOptions(['user_email' => $email]); |
| 37 |
wp_send_json([ |
| 38 |
'link' => $link, |
| 39 |
'success' => true, |
| 40 |
// 'user' => $email, |
| 41 |
], 200); |
| 42 |
} else { |
| 43 |
|
| 44 |
wp_send_json([ |
| 45 |
'notifications' => self::notifications(), |
| 46 |
'success' => false, |
| 47 |
], 200); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* The process of installing agents (WAF, AV) on the main page. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public static function agentsInstallation() |
| 59 |
{ |
| 60 |
|
| 61 |
if (WebTotemRequest::post('ajax_action') !== 'agents_installation') { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
$av_installed = WebTotemOption::getOption('av_installed'); |
| 66 |
$waf_installed = WebTotemOption::getOption('waf_installed'); |
| 67 |
|
| 68 |
// Check if the agents are installed. |
| 69 |
if ($av_installed and $waf_installed) { |
| 70 |
$agents_statuses = [ |
| 71 |
'process_statuses' => [ |
| 72 |
'av' => 'available', |
| 73 |
'waf' => 'available', |
| 74 |
], |
| 75 |
]; |
| 76 |
} else { |
| 77 |
// If not installed, then request statuses from the WebTotem API. |
| 78 |
$data = WebTotemAPI::getAgentsStatusesFromAPI(); |
| 79 |
|
| 80 |
$agents_statuses = [ |
| 81 |
'av' => $data['av'], |
| 82 |
'waf' => $data['waf'], |
| 83 |
]; |
| 84 |
|
| 85 |
$agents_statuses = WebTotem::getAgentsStatuses($agents_statuses); |
| 86 |
} |
| 87 |
|
| 88 |
$build[] = [ |
| 89 |
'variables' => [ |
| 90 |
'process_status' => $agents_statuses['process_statuses'], |
| 91 |
], |
| 92 |
'template' => 'agents_installation', |
| 93 |
]; |
| 94 |
|
| 95 |
$status = [ |
| 96 |
'av' => $agents_statuses['process_statuses']['av'] == 'available', |
| 97 |
'waf' => $agents_statuses['process_statuses']['waf'] == 'available', |
| 98 |
]; |
| 99 |
|
| 100 |
WebTotemOption::setOptions([ |
| 101 |
'av_installed' => $status['av'], |
| 102 |
'waf_installed' => $status['waf'], |
| 103 |
]); |
| 104 |
|
| 105 |
$template = new WebTotemTemplate(); |
| 106 |
$agents = $template->arrayRender($build); |
| 107 |
|
| 108 |
wp_send_json([ |
| 109 |
'success' => true, |
| 110 |
'notifications' => self::notifications(), |
| 111 |
'agents' => $agents, |
| 112 |
'agents_statuses' => $status['av'] && $status['waf'], |
| 113 |
]); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Reinstall agents. |
| 118 |
* |
| 119 |
* @return void |
| 120 |
*/ |
| 121 |
public static function reinstallAgents() |
| 122 |
{ |
| 123 |
|
| 124 |
if (WebTotemRequest::post('ajax_action') !== 'reinstall_agents') { |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
WebTotemAgentManager::amInstall(); |
| 129 |
|
| 130 |
$response['success'] = true; |
| 131 |
$response['redirect_link'] = WebTotem::adminURL('admin.php?page=wtotem'); |
| 132 |
wp_send_json($response); |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Deleting plugin activation data and redirecting to the activation page. |
| 138 |
* |
| 139 |
* @return void |
| 140 |
*/ |
| 141 |
public static function logout() |
| 142 |
{ |
| 143 |
|
| 144 |
if (WebTotemRequest::post('ajax_action') !== 'logout') { |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
WebTotemOption::logout(); |
| 149 |
|
| 150 |
$response['success'] = true; |
| 151 |
$response['redirect_link'] = WebTotem::adminURL('admin.php?page=wtotem_activation'); |
| 152 |
wp_send_json($response); |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Creating a modal window. |
| 158 |
* |
| 159 |
* @return void |
| 160 |
*/ |
| 161 |
public static function popup() |
| 162 |
{ |
| 163 |
|
| 164 |
if (WebTotemRequest::post('ajax_action') !== 'popup') { |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
$action = WebTotemRequest::post('popup_action'); |
| 169 |
$template = new WebTotemTemplate(); |
| 170 |
|
| 171 |
if ($action) { |
| 172 |
switch ($action) { |
| 173 |
case 'reinstall_agents': |
| 174 |
$build[] = [ |
| 175 |
'variables' => [ |
| 176 |
'message' => sprintf(__('Some scanning data for %s may be deleted.', 'wtotem'), WEBTOTEM_SITE_DOMAIN), |
| 177 |
'action' => 'reinstall_agents', |
| 178 |
'page_nonce' => wp_create_nonce('wtotem_page_nonce'), |
| 179 |
], |
| 180 |
'template' => 'popup', |
| 181 |
]; |
| 182 |
break; |
| 183 |
|
| 184 |
case 'logout': |
| 185 |
$build[] = [ |
| 186 |
'variables' => [ |
| 187 |
'message' => __('Are you sure you want to change the API key?', 'wtotem'), |
| 188 |
'action' => 'logout', |
| 189 |
'page_nonce' => wp_create_nonce('wtotem_page_nonce'), |
| 190 |
], |
| 191 |
'template' => 'popup', |
| 192 |
]; |
| 193 |
break; |
| 194 |
|
| 195 |
|
| 196 |
case 'update_plugin': |
| 197 |
$build[] = [ |
| 198 |
'variables' => [ |
| 199 |
'message' => __('Do you really want to update the plugin?', 'wtotem'), |
| 200 |
'action' => 'update_plugin', |
| 201 |
'slug' => WebTotemRequest::post('slug'), |
| 202 |
'page_nonce' => wp_create_nonce('wtotem_page_nonce'), |
| 203 |
], |
| 204 |
'template' => 'popup', |
| 205 |
]; |
| 206 |
break; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
wp_send_json([ |
| 211 |
'success' => true, |
| 212 |
'content' => $template->arrayRender($build), |
| 213 |
]); |
| 214 |
} |
| 215 |
|
| 216 |
wp_send_json([ |
| 217 |
'success' => false, |
| 218 |
]); |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Request to update charts with parameters. |
| 224 |
* |
| 225 |
* @return void |
| 226 |
*/ |
| 227 |
public static function chart() |
| 228 |
{ |
| 229 |
|
| 230 |
if (WebTotemRequest::post('ajax_action') !== 'chart') { |
| 231 |
return; |
| 232 |
} |
| 233 |
|
| 234 |
$template = new WebTotemTemplate(); |
| 235 |
|
| 236 |
$days = (integer)WebTotemRequest::post('days'); |
| 237 |
$service = WebTotemRequest::post('service'); |
| 238 |
|
| 239 |
$host = WebTotemAPI::siteInfo(); |
| 240 |
|
| 241 |
switch ($service) { |
| 242 |
case 'waf': |
| 243 |
|
| 244 |
WebTotemOption::setSessionOptions(['firewall_period' => $days]); |
| 245 |
|
| 246 |
// Firewall chart. |
| 247 |
$data = WebTotemAPI::getFirewallStatistics($days); |
| 248 |
$chart = WebTotem::generateWafChart($data['signatures_statistic'] ?? []); |
| 249 |
|
| 250 |
$_chart[] = [ |
| 251 |
'variables' => [ |
| 252 |
'days' => $days, |
| 253 |
'chart' => $chart['chart'], |
| 254 |
], |
| 255 |
'template' => 'firewall_chart', |
| 256 |
]; |
| 257 |
|
| 258 |
$response = [ |
| 259 |
'chart' => $template->arrayRender($_chart), |
| 260 |
'service' => 'waf', |
| 261 |
]; |
| 262 |
|
| 263 |
break; |
| 264 |
|
| 265 |
case 'cpu': |
| 266 |
WebTotemOption::setSessionOptions(['cpu_period' => $days]); |
| 267 |
|
| 268 |
$data = WebTotemAPI::getServerStatusData($host['id'], $days); |
| 269 |
$chart = WebTotem::generateChart($data['cpuChart'], $days); |
| 270 |
|
| 271 |
$_chart[] = [ |
| 272 |
'variables' => [ |
| 273 |
'days' => $days, |
| 274 |
'chart' => $chart, |
| 275 |
], |
| 276 |
'template' => 'cpu_chart', |
| 277 |
]; |
| 278 |
|
| 279 |
$response = [ |
| 280 |
'chart' => $template->arrayRender($_chart), |
| 281 |
'service' => 'cpu', |
| 282 |
]; |
| 283 |
|
| 284 |
break; |
| 285 |
|
| 286 |
case 'ram': |
| 287 |
WebTotemOption::setSessionOptions(['ram_period' => $days]); |
| 288 |
|
| 289 |
$data = WebTotemAPI::getServerStatusData($host['id'], $days); |
| 290 |
$chart = WebTotem::generateChart($data['ramChart'], $days); |
| 291 |
|
| 292 |
$_chart[] = [ |
| 293 |
'variables' => [ |
| 294 |
'days' => $days, |
| 295 |
'chart' => $chart, |
| 296 |
], |
| 297 |
'template' => 'ram_chart', |
| 298 |
]; |
| 299 |
|
| 300 |
$response = [ |
| 301 |
'chart' => $template->arrayRender($_chart), |
| 302 |
'service' => 'ram', |
| 303 |
]; |
| 304 |
|
| 305 |
break; |
| 306 |
|
| 307 |
case 'map': |
| 308 |
|
| 309 |
$data = WebTotemAPI::getFirewallStatistics($days); |
| 310 |
$chart = WebTotem::generateAttacksMapChart($data['countries_statistics'] ?? []); |
| 311 |
$world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json'; |
| 312 |
|
| 313 |
$_chart[] = [ |
| 314 |
'variables' => [ |
| 315 |
'attacks_map' => $chart, |
| 316 |
'world_map_json' => $world_map_json, |
| 317 |
], |
| 318 |
'template' => 'map_chart', |
| 319 |
]; |
| 320 |
|
| 321 |
$response = [ |
| 322 |
'chart' => $template->arrayRender($_chart), |
| 323 |
'service' => 'map', |
| 324 |
]; |
| 325 |
|
| 326 |
break; |
| 327 |
|
| 328 |
} |
| 329 |
|
| 330 |
if ($service) { |
| 331 |
$response['success'] = true; |
| 332 |
$response['notifications'] = self::notifications(); |
| 333 |
wp_send_json($response); |
| 334 |
} |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
/** |
| 340 |
* Pagination. |
| 341 |
* @return void |
| 342 |
*/ |
| 343 |
public static function pagination() |
| 344 |
{ |
| 345 |
|
| 346 |
if (WebTotemRequest::post('ajax_action') !== 'pagination') { |
| 347 |
return; |
| 348 |
} |
| 349 |
|
| 350 |
$template = new WebTotemTemplate(); |
| 351 |
|
| 352 |
$service = WebTotemRequest::post('service'); |
| 353 |
$current_page = WebTotemRequest::post('current_page'); |
| 354 |
|
| 355 |
|
| 356 |
switch ($service) { |
| 357 |
|
| 358 |
case 'firewall': |
| 359 |
$firewall_data = WebTotemAPI::getFirewall(10, $current_page, 7); |
| 360 |
|
| 361 |
$build[] = [ |
| 362 |
'variables' => [ |
| 363 |
"logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []), |
| 364 |
], |
| 365 |
'template' => 'firewall_logs', |
| 366 |
]; |
| 367 |
$pagination = WebTotem::paginationBuild(10, $firewall_data['total'], $current_page); |
| 368 |
|
| 369 |
break; |
| 370 |
|
| 371 |
case 'antivirus': |
| 372 |
$antivirus_history_data = WebTotemAPI::getAntivirusHistory($current_page); |
| 373 |
$build[] = [ |
| 374 |
'variables' => [ |
| 375 |
"logs" => WebTotem::getAntivirusLogsData($antivirus_history_data['history']), |
| 376 |
], |
| 377 |
'template' => 'antivirus_history_items', |
| 378 |
]; |
| 379 |
|
| 380 |
$pagination = WebTotem::paginationBuild(10, $antivirus_history_data['total'], $current_page); |
| 381 |
|
| 382 |
break; |
| 383 |
|
| 384 |
case 'infected_files': |
| 385 |
$infected_files = WebTotemAPI::getAntivirusCurrentDetails($current_page); |
| 386 |
$build[] = [ |
| 387 |
'variables' => [ |
| 388 |
"logs" => WebTotem::getInfectedFilesData($infected_files['current_infected_files'] ?? []), |
| 389 |
"type" => 'infected', |
| 390 |
], |
| 391 |
'template' => 'quarantine_logs', |
| 392 |
]; |
| 393 |
|
| 394 |
$pagination = WebTotem::paginationBuild(5, (int)$infected_files['total'], $current_page); |
| 395 |
break; |
| 396 |
|
| 397 |
case 'quarantine': |
| 398 |
$quarantine_files = WebTotemAPI::getQuarantineList($current_page); |
| 399 |
$build[] = [ |
| 400 |
'variables' => [ |
| 401 |
"logs" => WebTotem::getQuarantineListData($quarantine_files['quarantine_files'] ?? []), |
| 402 |
"type" => 'quarantine', |
| 403 |
], |
| 404 |
'template' => 'quarantine_logs', |
| 405 |
]; |
| 406 |
|
| 407 |
$pagination = WebTotem::paginationBuild(5, (int)$quarantine_files['total'], $current_page); |
| 408 |
break; |
| 409 |
} |
| 410 |
|
| 411 |
if ($service) { |
| 412 |
|
| 413 |
wp_send_json([ |
| 414 |
'success' => true, |
| 415 |
'content' => $template->arrayRender($build), |
| 416 |
'pagination' => $pagination, |
| 417 |
'notifications' => self::notifications(), |
| 418 |
]); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
/** |
| 424 |
* Data lazy load. |
| 425 |
* @return void |
| 426 |
*/ |
| 427 |
public static function logs() |
| 428 |
{ |
| 429 |
if (WebTotemRequest::post('ajax_action') !== 'logs') { |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
$template = new WebTotemTemplate(); |
| 434 |
$logs_action = WebTotemRequest::post('logs_action'); |
| 435 |
|
| 436 |
switch ($logs_action) { |
| 437 |
case 'audit_logs_pagination': |
| 438 |
$order = WebTotemRequest::post('order') === 'ascending' ? 'ASC' : 'DESC'; |
| 439 |
$current_page = (int)WebTotemRequest::post('current_page'); |
| 440 |
$event = WebTotemRequest::post('event'); |
| 441 |
$filter = $event === 'All' ? [] : ['LIKE', ['event' => $event . '%']]; |
| 442 |
|
| 443 |
$audit_logs = WebTotemDB::getRows( |
| 444 |
$filter, |
| 445 |
'audit_logs', |
| 446 |
false, |
| 447 |
['limit' => 10, 'page' => $current_page], |
| 448 |
['order_by' => 'created_at', 'direction' => $order] |
| 449 |
); |
| 450 |
|
| 451 |
$build[] = [ |
| 452 |
'variables' => [ |
| 453 |
"audit_logs" => WebTotem::getAuditLogs($audit_logs['data'], $audit_logs['dates_count']), |
| 454 |
], |
| 455 |
'template' => 'scan_audit_logs', |
| 456 |
]; |
| 457 |
|
| 458 |
$response = [ |
| 459 |
'success' => true, |
| 460 |
'content' => $template->arrayRender($build), |
| 461 |
"pagination" => WebTotem::paginationBuild(10, $audit_logs['count'], $current_page), |
| 462 |
'notifications' => self::notifications(), |
| 463 |
]; |
| 464 |
|
| 465 |
break; |
| 466 |
case 'cve_logs_pagination': |
| 467 |
$current_page = (int)WebTotemRequest::post('current_page'); |
| 468 |
|
| 469 |
$plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => $current_page]); |
| 470 |
|
| 471 |
$build[] = [ |
| 472 |
'variables' => [ |
| 473 |
"logs" => WebTotem::preparePluginsCveList($plugins_cve_list['data']), |
| 474 |
], |
| 475 |
'template' => 'scan_logs_cve', |
| 476 |
]; |
| 477 |
|
| 478 |
$response = [ |
| 479 |
'success' => true, |
| 480 |
'content' => $template->arrayRender($build), |
| 481 |
"pagination" => WebTotem::paginationBuild(8, $plugins_cve_list['count'], $current_page), |
| 482 |
'notifications' => self::notifications(), |
| 483 |
]; |
| 484 |
|
| 485 |
break; |
| 486 |
|
| 487 |
case 'audit_logs_sort_filter': |
| 488 |
$order = WebTotemRequest::post('order') === 'ascending' ? 'ASC' : 'DESC'; |
| 489 |
$event = WebTotemRequest::post('event'); |
| 490 |
$filter = $event === 'All' ? [] : ['LIKE', ['event' => $event . '%']]; |
| 491 |
$audit_logs = WebTotemDB::getRows( |
| 492 |
$filter, |
| 493 |
'audit_logs', |
| 494 |
false, |
| 495 |
['limit' => 10, 'page' => 1], |
| 496 |
['order_by' => 'created_at', 'direction' => $order] |
| 497 |
); |
| 498 |
|
| 499 |
$build[] = [ |
| 500 |
'variables' => [ |
| 501 |
"audit_logs" => WebTotem::getAuditLogs($audit_logs['data'], $audit_logs['dates_count']), |
| 502 |
], |
| 503 |
'template' => 'scan_audit_logs', |
| 504 |
]; |
| 505 |
|
| 506 |
$response = [ |
| 507 |
'success' => true, |
| 508 |
'content' => $template->arrayRender($build), |
| 509 |
"pagination" => WebTotem::paginationBuild(10, $audit_logs['count'], 1), |
| 510 |
'notifications' => self::notifications(), |
| 511 |
]; |
| 512 |
|
| 513 |
break; |
| 514 |
|
| 515 |
case 'confidential_files': |
| 516 |
$id = WebTotemRequest::post('id') ?? false; |
| 517 |
if ($id) { |
| 518 |
$file = WebTotemDB::getData(['id' => $id], 'confidential_files'); |
| 519 |
if ($file['path']) { |
| 520 |
$path = urldecode($file['path']); |
| 521 |
if(file_exists($path)) unlink($path); |
| 522 |
WebTotemDB::deleteData(['id' => $id], 'confidential_files'); |
| 523 |
WebTotemOption::setNotification('info', sprintf(__('File %s was deleted', 'wtotem'), json_decode($file['name']))); |
| 524 |
} |
| 525 |
} |
| 526 |
$order_by = WebTotemRequest::post('order'); |
| 527 |
$direction = WebTotemRequest::post('direction') === 'ascending' ? 'ASC' : 'DESC'; |
| 528 |
$current_page = (int)WebTotemRequest::post('current_page') ?: 1; |
| 529 |
|
| 530 |
$confidential_files = WebTotemDB::getRows( |
| 531 |
[], |
| 532 |
'confidential_files', |
| 533 |
false, |
| 534 |
['limit' => 10, 'page' => $current_page], |
| 535 |
$order_by ? ['order_by' => $order_by, 'direction' => $direction] : ['order_by' => 'id', 'direction' => 'DESC'] |
| 536 |
); |
| 537 |
|
| 538 |
$build[] = [ |
| 539 |
'variables' => [ |
| 540 |
"confidential_files" => WebTotem::getConfidentialFiles($confidential_files['data']), |
| 541 |
], |
| 542 |
'template' => 'scan_confidential_files', |
| 543 |
]; |
| 544 |
|
| 545 |
$response = [ |
| 546 |
'success' => true, |
| 547 |
'content' => $template->arrayRender($build), |
| 548 |
'count' => $confidential_files['count'], |
| 549 |
"pagination" => WebTotem::paginationBuild(10, $confidential_files['count'], $current_page), |
| 550 |
'notifications' => self::notifications(), |
| 551 |
]; |
| 552 |
|
| 553 |
break; |
| 554 |
|
| 555 |
case 'logs_pagination': |
| 556 |
$current_page = (int)WebTotemRequest::post('current_page'); |
| 557 |
$type = WebTotemRequest::post('type'); |
| 558 |
$direction = WebTotemRequest::post('direction') === 'ascending' ? 'ASC' : 'DESC'; |
| 559 |
|
| 560 |
$scan_logs = WebTotemDB::getRows( |
| 561 |
['AND', ['data_type' => $type]], |
| 562 |
'scan_logs', |
| 563 |
'content', |
| 564 |
['limit' => 10, 'page' => $current_page], |
| 565 |
!empty($direction) ? ['order_by' => 'is_internal', 'direction' => $direction] : ['order_by' => 'id', 'direction' => 'DESC'] |
| 566 |
); |
| 567 |
|
| 568 |
$build[] = [ |
| 569 |
'variables' => [ |
| 570 |
"logs" => WebTotem::prepareLinksData($scan_logs['data']), |
| 571 |
"data_type" => $type |
| 572 |
], |
| 573 |
'template' => 'scan_logs_items', |
| 574 |
]; |
| 575 |
|
| 576 |
$response = [ |
| 577 |
'success' => true, |
| 578 |
'content' => $template->arrayRender($build), |
| 579 |
"pagination" => WebTotem::paginationBuild(10, $scan_logs['count'], $current_page), |
| 580 |
'notifications' => self::notifications(), |
| 581 |
]; |
| 582 |
|
| 583 |
break; |
| 584 |
|
| 585 |
case 'rescan': |
| 586 |
// WebTotem::updateCveData(); |
| 587 |
WebTotemOption::setOptions(['scan_init' => 1]); |
| 588 |
WebTotemScan::initialize(); |
| 589 |
$response = [ |
| 590 |
'success' => true, |
| 591 |
'notifications' => self::notifications(), |
| 592 |
]; |
| 593 |
|
| 594 |
break; |
| 595 |
|
| 596 |
case 'check_scan': |
| 597 |
|
| 598 |
if(WebTotemOption::getOption('scan_init')){ |
| 599 |
WebTotemScan::initialize(); |
| 600 |
$response = [ |
| 601 |
'success' => true, |
| 602 |
'scan_finished' => false, |
| 603 |
'notifications' => self::notifications(), |
| 604 |
]; |
| 605 |
} else { |
| 606 |
$content = []; |
| 607 |
$pagination = []; |
| 608 |
$count = []; |
| 609 |
$types = ['links', 'scripts', 'iframes']; |
| 610 |
|
| 611 |
foreach ($types as $type) { |
| 612 |
$scan_logs = WebTotemDB::getRows( |
| 613 |
['AND', ['data_type' => $type]], |
| 614 |
'scan_logs', |
| 615 |
'content' |
| 616 |
); |
| 617 |
|
| 618 |
$build[$type][] = [ |
| 619 |
'variables' => [ |
| 620 |
"logs" => $scan_logs['data'], |
| 621 |
"data_type" => $type |
| 622 |
], |
| 623 |
'template' => 'scan_logs_items', |
| 624 |
]; |
| 625 |
$content[$type] = $template->arrayRender($build[$type]); |
| 626 |
$pagination[$type] = WebTotem::paginationBuild(10, $scan_logs['count']); |
| 627 |
$count[$type] = $scan_logs['count']; |
| 628 |
} |
| 629 |
|
| 630 |
$plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => 1]); |
| 631 |
$content['cve'] = $template->arrayRender([ |
| 632 |
'variables' => [ |
| 633 |
"logs" => WebTotem::preparePluginsCveList($plugins_cve_list['data']), |
| 634 |
], |
| 635 |
'template' => 'scan_logs_cve', |
| 636 |
]); |
| 637 |
$count['cve'] = $plugins_cve_list['count']; |
| 638 |
$pagination['cve'] = WebTotem::paginationBuild(8, $plugins_cve_list['count']); |
| 639 |
|
| 640 |
$confidential_files = WebTotemDB::getRows([], 'confidential_files'); |
| 641 |
$content['confidential_files'] = $template->arrayRender([ |
| 642 |
'variables' => [ |
| 643 |
"confidential_files" => WebTotem::getConfidentialFiles($confidential_files['data']), |
| 644 |
], |
| 645 |
'template' => 'scan_confidential_files', |
| 646 |
]); |
| 647 |
$pagination['confidential_files'] = WebTotem::paginationBuild(10, $confidential_files['count']); |
| 648 |
$count['confidential_files'] = $confidential_files['count']; |
| 649 |
|
| 650 |
// Resetting the task in the cron. |
| 651 |
wp_clear_scheduled_hook('webtotem_daily_cron'); |
| 652 |
wp_schedule_event(time() + 86395, 'daily', 'webtotem_daily_cron'); |
| 653 |
|
| 654 |
$until_next_scan = wp_next_scheduled('webtotem_daily_cron') - time(); |
| 655 |
|
| 656 |
$hr = floor($until_next_scan / 3600); |
| 657 |
$min = floor(($until_next_scan % 3600) / 60); |
| 658 |
|
| 659 |
$response = [ |
| 660 |
'success' => true, |
| 661 |
'scan_finished' => true, |
| 662 |
'content' => $content, |
| 663 |
"pagination" => $pagination, |
| 664 |
"next_scan" => sprintf(__('%dh %dm', 'wtotem'), $hr, $min), |
| 665 |
"count" => $count, |
| 666 |
'notifications' => self::notifications(), |
| 667 |
]; |
| 668 |
} |
| 669 |
|
| 670 |
break; |
| 671 |
} |
| 672 |
|
| 673 |
wp_send_json($response ?? []); |
| 674 |
} |
| 675 |
|
| 676 |
/** |
| 677 |
* Add date filter. |
| 678 |
* |
| 679 |
* @return void |
| 680 |
*/ |
| 681 |
public static function wafDateFilter() |
| 682 |
{ |
| 683 |
|
| 684 |
if (WebTotemRequest::post('ajax_action') !== 'waf_date_filter') { |
| 685 |
return; |
| 686 |
} |
| 687 |
|
| 688 |
$template = new WebTotemTemplate(); |
| 689 |
|
| 690 |
$period = [WebTotemRequest::post('date_from'), WebTotemRequest::post('date_to')]; |
| 691 |
WebTotemOption::setSessionOptions(['firewall_period' => $period]); |
| 692 |
|
| 693 |
// Firewall logs. |
| 694 |
$data = WebTotemAPI::getFirewall(10, 1, $period); |
| 695 |
$firewall = $data['firewall']; |
| 696 |
|
| 697 |
$waf_logs[] = [ |
| 698 |
'variables' => [ |
| 699 |
'logs' => WebTotem::wafLogs($firewall['logs']['edges']), |
| 700 |
], |
| 701 |
'template' => 'firewall_logs', |
| 702 |
]; |
| 703 |
|
| 704 |
// Firewall chart. |
| 705 |
$data = WebTotemAPI::getFirewallStatistics($period); |
| 706 |
$chart = WebTotem::generateWafChart($data['signatures_statistic']); |
| 707 |
|
| 708 |
$_chart[] = [ |
| 709 |
'variables' => [ |
| 710 |
'days' => $chart['days'], |
| 711 |
'chart' => $chart['chart'], |
| 712 |
], |
| 713 |
'template' => 'firewall_chart', |
| 714 |
]; |
| 715 |
|
| 716 |
// Firewall stats. |
| 717 |
$waf_stats[] = [ |
| 718 |
'variables' => [ |
| 719 |
'is_waf_training' => WebTotem::isWafTraining(), |
| 720 |
'all_attacks' => $chart['count_attacks'], |
| 721 |
'blocking' => $chart['count_blocks'], |
| 722 |
'not_blocking' => $chart['count_attacks'] - $chart['count_blocks'], |
| 723 |
'most_attacks' => WebTotem::getMostAttacksData($firewall['map']), |
| 724 |
], |
| 725 |
'template' => 'firewall_stats', |
| 726 |
]; |
| 727 |
|
| 728 |
WebTotemOption::setSessionOptions([ |
| 729 |
'firewall_cursor' => $firewall['logs']['pageInfo']['endCursor'], |
| 730 |
]); |
| 731 |
|
| 732 |
$has_next_page = $firewall['logs']['pageInfo']['hasNextPage']; |
| 733 |
|
| 734 |
$response = [ |
| 735 |
'success' => true, |
| 736 |
'chart' => $template->arrayRender($_chart), |
| 737 |
'waf_logs' => $template->arrayRender($waf_logs), |
| 738 |
'waf_stats' => $template->arrayRender($waf_stats), |
| 739 |
'has_next_page' => $has_next_page, |
| 740 |
'notifications' => self::notifications(), |
| 741 |
]; |
| 742 |
|
| 743 |
wp_send_json($response); |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
/** |
| 748 |
* Request to restart re-scan and receive antivirus data. |
| 749 |
* |
| 750 |
* @return void |
| 751 |
*/ |
| 752 |
public static function antivirus() |
| 753 |
{ |
| 754 |
|
| 755 |
if (WebTotemRequest::post('ajax_action') !== 'antivirus') { |
| 756 |
return; |
| 757 |
} |
| 758 |
|
| 759 |
$action = WebTotemRequest::post('av_action'); |
| 760 |
$host = WebTotemAPI::siteInfo(); |
| 761 |
$template = new WebTotemTemplate(); |
| 762 |
|
| 763 |
switch ($action) { |
| 764 |
|
| 765 |
|
| 766 |
case 'get_infected_files': |
| 767 |
$session_id = WebTotemRequest::post('session_id'); |
| 768 |
$page_num = WebTotemRequest::post('page_num') ?? 1; |
| 769 |
|
| 770 |
$infected_files = WebTotemAPI::getAntivirusHistoryDetails($session_id, $page_num); |
| 771 |
|
| 772 |
$infected_files_wrap[] = [ |
| 773 |
'variables' => [ |
| 774 |
"logs" => WebTotem::getInfectedFilesData($infected_files['history_details']), |
| 775 |
"total" => $infected_files['total'], |
| 776 |
"type" => 'infected_ajax', |
| 777 |
], |
| 778 |
'template' => 'quarantine_logs', |
| 779 |
]; |
| 780 |
|
| 781 |
$response['content'] = $template->arrayRender($infected_files_wrap); |
| 782 |
|
| 783 |
break; |
| 784 |
} |
| 785 |
|
| 786 |
$response['success'] = true; |
| 787 |
$response['notifications'] = self::notifications(); |
| 788 |
|
| 789 |
wp_send_json($response); |
| 790 |
} |
| 791 |
|
| 792 |
/** |
| 793 |
* Request to add a file to quarantine. |
| 794 |
* |
| 795 |
* @return void |
| 796 |
*/ |
| 797 |
public static function quarantine() |
| 798 |
{ |
| 799 |
if (WebTotemRequest::post('ajax_action') !== 'quarantine') { |
| 800 |
return; |
| 801 |
} |
| 802 |
|
| 803 |
$action = WebTotemRequest::post('quarantine_action'); |
| 804 |
$path = urlencode(WebTotemRequest::post('path')); |
| 805 |
|
| 806 |
$response = []; |
| 807 |
|
| 808 |
switch ($action) { |
| 809 |
case 'add': |
| 810 |
$api_response = WebTotemAPI::moveToQuarantine($path); |
| 811 |
break; |
| 812 |
|
| 813 |
case 'remove': |
| 814 |
$api_response = WebTotemAPI::moveFromQuarantine($path); |
| 815 |
break; |
| 816 |
} |
| 817 |
|
| 818 |
$response['success'] = false; |
| 819 |
if (!isset($api_response['message'])) { |
| 820 |
|
| 821 |
$infected_files_data = WebTotemAPI::getAntivirusCurrentDetails(); |
| 822 |
$quarantine_files_data = WebTotemAPI::getQuarantineList(); |
| 823 |
|
| 824 |
$quarantine = [ |
| 825 |
'variables' => [ |
| 826 |
"logs" => WebTotem::getQuarantineListData($quarantine_files_data['quarantine_files'] ?? []), |
| 827 |
"type" => 'quarantine', |
| 828 |
], |
| 829 |
'template' => 'quarantine_logs', |
| 830 |
]; |
| 831 |
$pagination_quarantine = WebTotem::paginationBuild(5, (int)$quarantine_files_data['total']); |
| 832 |
|
| 833 |
$infected_files = [ |
| 834 |
'variables' => [ |
| 835 |
"logs" => WebTotem::getInfectedFilesData($infected_files_data['current_infected_files'] ?? []), |
| 836 |
"type" => 'infected', |
| 837 |
], |
| 838 |
'template' => 'quarantine_logs', |
| 839 |
]; |
| 840 |
$pagination_infected_files = WebTotem::paginationBuild(5, (int)$infected_files_data['total']); |
| 841 |
|
| 842 |
$template = new WebTotemTemplate(); |
| 843 |
$response = [ |
| 844 |
'infected_files' => $template->arrayRender($infected_files), |
| 845 |
'quarantine_files' => $template->arrayRender($quarantine), |
| 846 |
'pagination_infected_files' => $pagination_infected_files, |
| 847 |
'pagination_quarantine' => $pagination_quarantine, |
| 848 |
'infected_files_total' => (int)$infected_files_data['total'], |
| 849 |
'quarantine_files_total' => (int)$quarantine_files_data['total'], |
| 850 |
]; |
| 851 |
|
| 852 |
$response['success'] = true; |
| 853 |
} |
| 854 |
|
| 855 |
$response['notifications'] = self::notifications(); |
| 856 |
|
| 857 |
wp_send_json($response); |
| 858 |
|
| 859 |
} |
| 860 |
|
| 861 |
/** |
| 862 |
* Request to add or remove a port to the ignore list. |
| 863 |
* |
| 864 |
* @return void |
| 865 |
*/ |
| 866 |
public static function ignorePorts() |
| 867 |
{ |
| 868 |
|
| 869 |
if (WebTotemRequest::post('ajax_action') !== 'ignore_ports') { |
| 870 |
return; |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
$action = WebTotemRequest::post('port_action'); |
| 875 |
$port = (int)WebTotemRequest::post('port'); |
| 876 |
|
| 877 |
$host = WebTotemAPI::siteInfo(); |
| 878 |
|
| 879 |
switch ($action) { |
| 880 |
case 'add': |
| 881 |
$response = WebTotemAPI::addIgnorePort($host['id'], $port); |
| 882 |
break; |
| 883 |
|
| 884 |
case 'remove': |
| 885 |
$response = WebTotemAPI::removeIgnorePort($host['id'], $port); |
| 886 |
break; |
| 887 |
} |
| 888 |
|
| 889 |
if (!isset($response['errors'])) { |
| 890 |
|
| 891 |
$ports = WebTotemAPI::getAllPortsList($host['id']); |
| 892 |
$open_ports[] = [ |
| 893 |
'variables' => [ |
| 894 |
"ports" => $ports['TCPResults'] ? WebTotem::getOpenPortsData(array_slice($ports['TCPResults'], 0, 3)) : [], |
| 895 |
'more' => true, |
| 896 |
], |
| 897 |
'template' => 'open_ports', |
| 898 |
]; |
| 899 |
|
| 900 |
$open_ports_modal[] = [ |
| 901 |
'variables' => [ |
| 902 |
"ports" => WebTotem::getOpenPortsData($ports['TCPResults']), |
| 903 |
], |
| 904 |
'template' => 'open_ports', |
| 905 |
]; |
| 906 |
|
| 907 |
$ignore_ports[] = [ |
| 908 |
'variables' => [ |
| 909 |
"ports" => $ports, |
| 910 |
], |
| 911 |
'template' => 'ignore_ports', |
| 912 |
]; |
| 913 |
|
| 914 |
$template = new WebTotemTemplate(); |
| 915 |
$response = [ |
| 916 |
'open_ports' => $template->arrayRender($open_ports), |
| 917 |
'open_ports_modal' => $template->arrayRender($open_ports_modal), |
| 918 |
'ignore_ports' => $template->arrayRender($ignore_ports), |
| 919 |
]; |
| 920 |
|
| 921 |
} |
| 922 |
|
| 923 |
$response['success'] = true; |
| 924 |
$response['notifications'] = self::notifications(); |
| 925 |
|
| 926 |
wp_send_json($response); |
| 927 |
} |
| 928 |
|
| 929 |
/** |
| 930 |
* Request for a report link. |
| 931 |
* |
| 932 |
* @return void |
| 933 |
*/ |
| 934 |
public static function reports() |
| 935 |
{ |
| 936 |
|
| 937 |
if (WebTotemRequest::post('ajax_action') !== 'reports') { |
| 938 |
return; |
| 939 |
} |
| 940 |
|
| 941 |
$template = new WebTotemTemplate(); |
| 942 |
|
| 943 |
$action = WebTotemRequest::post('report_action'); |
| 944 |
|
| 945 |
switch ($action) { |
| 946 |
case 'download': |
| 947 |
$id = WebTotemRequest::post('id'); |
| 948 |
$link = WebTotemAPI::downloadReport($id); |
| 949 |
if ($link) { |
| 950 |
$response['link'] = $link; |
| 951 |
} |
| 952 |
break; |
| 953 |
case 'report_form': |
| 954 |
|
| 955 |
$period = [WebTotemRequest::post('date_from'), WebTotemRequest::post('date_to')]; |
| 956 |
$modules_data = WebTotemRequest::post('modules'); |
| 957 |
|
| 958 |
$modules = [ |
| 959 |
'wa' => 'false', |
| 960 |
'dc' => 'false', |
| 961 |
'ps' => 'false', |
| 962 |
'rc' => 'false', |
| 963 |
'sc' => 'false', |
| 964 |
'av' => 'false', |
| 965 |
'waf' => 'false' |
| 966 |
]; |
| 967 |
|
| 968 |
foreach ($modules_data as $module => $value) { |
| 969 |
$modules[$module] = 'true'; |
| 970 |
} |
| 971 |
|
| 972 |
$host = WebTotemAPI::siteInfo(); |
| 973 |
$api_response = WebTotemAPI::generateReport($host['id'], $period, $modules); |
| 974 |
|
| 975 |
if (!$api_response) { |
| 976 |
$massage = '<div class="message error_message">' . __('Report generation error', 'wtotem') . '</div>'; |
| 977 |
} else { |
| 978 |
$data = WebTotemAPI::getAllReports($host['id']); |
| 979 |
WebTotemCache::setData(['getAllReports' => $data], $host['id']); |
| 980 |
|
| 981 |
// Reports. |
| 982 |
$build[] = [ |
| 983 |
'variables' => [ |
| 984 |
"reports" => WebTotem::getReports($data['edges']), |
| 985 |
"has_next_page" => $data['pageInfo']['hasNextPage'], |
| 986 |
], |
| 987 |
'template' => 'reports_list', |
| 988 |
]; |
| 989 |
|
| 990 |
// Reports mobile. |
| 991 |
$build_mobile[] = [ |
| 992 |
'variables' => [ |
| 993 |
"reports" => WebTotem::getReports($data['edges']), |
| 994 |
"has_next_page" => $data['pageInfo']['hasNextPage'], |
| 995 |
], |
| 996 |
'template' => 'reports_list_mobile', |
| 997 |
]; |
| 998 |
|
| 999 |
$response = [ |
| 1000 |
'reports' => $template->arrayRender($build), |
| 1001 |
'reports_m' => $template->arrayRender($build_mobile), |
| 1002 |
'link' => $api_response, |
| 1003 |
]; |
| 1004 |
|
| 1005 |
$massage = '<div class="message success_message">' . __('The report was successfully generated', 'wtotem') . '</div>'; |
| 1006 |
} |
| 1007 |
|
| 1008 |
$response['massage'] = $massage; |
| 1009 |
|
| 1010 |
break; |
| 1011 |
} |
| 1012 |
|
| 1013 |
$response['success'] = true; |
| 1014 |
$response['notifications'] = self::notifications(); |
| 1015 |
wp_send_json($response); |
| 1016 |
} |
| 1017 |
|
| 1018 |
/** |
| 1019 |
* Request for a report link. |
| 1020 |
* |
| 1021 |
* @return void |
| 1022 |
*/ |
| 1023 |
public static function settings() |
| 1024 |
{ |
| 1025 |
|
| 1026 |
if (WebTotemRequest::post('ajax_action') !== 'settings') { |
| 1027 |
return; |
| 1028 |
} |
| 1029 |
|
| 1030 |
$av_installed = WebTotemOption::getOption('av_installed'); |
| 1031 |
$waf_installed = WebTotemOption::getOption('waf_installed'); |
| 1032 |
$action = WebTotemRequest::post('settings_action'); |
| 1033 |
|
| 1034 |
if (in_array($action, ['module_toggle', 'module_notifications', 'waf_settings', 'add_allow_ip', 'add_deny_ip', 'add_allow_url', 'add_ip_list', 'country_blocking'])) { |
| 1035 |
if (!$av_installed && !$waf_installed) { |
| 1036 |
WebTotemOption::setNotification('warning', __('It is not possible to make changes because the agents are not installed.', 'wtotem')); |
| 1037 |
|
| 1038 |
wp_send_json([ |
| 1039 |
'success' => false, |
| 1040 |
'notifications' => self::notifications() |
| 1041 |
]); |
| 1042 |
return; |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
$host = WebTotemAPI::siteInfo(); |
| 1047 |
$template = new WebTotemTemplate(); |
| 1048 |
|
| 1049 |
switch ($action) { |
| 1050 |
|
| 1051 |
case 'module_toggle': |
| 1052 |
$config = WebTotemAPI::toggleConfigs(WebTotemRequest::post('value')); |
| 1053 |
|
| 1054 |
$configs_data = WebTotemAPI::getConfigs($host['id']); |
| 1055 |
WebTotemCache::setData(['getConfigs' => $configs_data], $host['id']); |
| 1056 |
|
| 1057 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1058 |
$response['isActive'] = $config['isActive']; |
| 1059 |
$response['success'] = true; |
| 1060 |
break; |
| 1061 |
|
| 1062 |
case 'country_blocking': |
| 1063 |
$countries = WebTotemRequest::post('checked_countries'); |
| 1064 |
|
| 1065 |
if (WebTotemAPI::syncBlockedCountries($host['id'], $countries)) { |
| 1066 |
$waf_data = WebTotemAPI::getBlockedCountries($host['id']); |
| 1067 |
WebTotemCache::setData(['getBlockedCountries' => $waf_data], $host['id']); |
| 1068 |
|
| 1069 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1070 |
$response['blocked_countries_list'] = $waf_data['blockedCountries']; |
| 1071 |
$response['success'] = true; |
| 1072 |
} else { |
| 1073 |
WebTotemOption::setNotification('success', __('Your changes have not been applied.', 'wtotem')); |
| 1074 |
$response['success'] = false; |
| 1075 |
} |
| 1076 |
|
| 1077 |
break; |
| 1078 |
|
| 1079 |
case 'module_notifications': |
| 1080 |
$config = WebTotemAPI::toggleNotifications($host['id'], WebTotemRequest::post('value')); |
| 1081 |
|
| 1082 |
$configs_data = WebTotemAPI::getConfigs($host['id']); |
| 1083 |
WebTotemCache::setData(['getConfigs' => $configs_data], $host['id']); |
| 1084 |
|
| 1085 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1086 |
$response['isActive'] = $config; |
| 1087 |
$response['success'] = true; |
| 1088 |
break; |
| 1089 |
|
| 1090 |
case 'waf_settings': |
| 1091 |
|
| 1092 |
$response['success'] = true; |
| 1093 |
|
| 1094 |
$dos = filter_var( WebTotemRequest::post('dos'), FILTER_VALIDATE_BOOLEAN); |
| 1095 |
$dos_limit = WebTotemRequest::post('dos_limit'); |
| 1096 |
$gdn= filter_var( WebTotemRequest::post('gdn'), FILTER_VALIDATE_BOOLEAN); |
| 1097 |
// $login_attempt = filter_var( WebTotemRequest::post('login_attempt'), FILTER_VALIDATE_BOOLEAN); |
| 1098 |
// $login_attempt_limit = WebTotemRequest::post('login_attempt_limit'); |
| 1099 |
|
| 1100 |
if ($dos) { |
| 1101 |
if (empty($dos_limit)) { |
| 1102 |
$response['errors']['dos_limit'] = __('The field is required.', 'wtotem'); |
| 1103 |
} else if ($dos_limit < 500 or $dos_limit > 10000) { |
| 1104 |
$response['success'] = false; |
| 1105 |
$response['errors']['dos_limit'] = sprintf(__('Please specify a value from %s to %s.', 'wtotem'), '500', '10 000'); |
| 1106 |
} |
| 1107 |
} |
| 1108 |
|
| 1109 |
// if ($login_attempt) { |
| 1110 |
// if (empty($login_attempt_limit)) { |
| 1111 |
// $response['errors']['login_attempt_limit'] = __('The field is required.', 'wtotem'); |
| 1112 |
// } else if ($login_attempt_limit < 5 or $login_attempt_limit > 30) { |
| 1113 |
// $response['success'] = false; |
| 1114 |
// $response['errors']['login_attempt_limit'] = sprintf(__('Please specify a value from %s to %s.', 'wtotem'), '5', '30'); |
| 1115 |
// } |
| 1116 |
// } |
| 1117 |
|
| 1118 |
if (!$response['success']) { |
| 1119 |
break; |
| 1120 |
} else { |
| 1121 |
$response['errors'] = false; |
| 1122 |
} |
| 1123 |
|
| 1124 |
$waf_settings = WebTotemAPI::getFirewallSettings(); |
| 1125 |
|
| 1126 |
$waf_settings['dos_protect'] = $dos; |
| 1127 |
$waf_settings['dos_limit'] = (int) $dos_limit; |
| 1128 |
$waf_settings['global_defense_network'] = $gdn; |
| 1129 |
|
| 1130 |
$api_response = WebTotemAPI::setFirewallSettings($waf_settings); |
| 1131 |
WebTotemCache::setData(['getFirewallSettings' => $waf_settings], $host['id']); |
| 1132 |
|
| 1133 |
if (!$api_response['message']) { |
| 1134 |
|
| 1135 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1136 |
} |
| 1137 |
|
| 1138 |
break; |
| 1139 |
|
| 1140 |
case 'recaptcha_settings': |
| 1141 |
|
| 1142 |
$recaptcha_v3_site_key = WebTotemRequest::post('recaptcha_v3_site_key'); |
| 1143 |
$recaptcha_v3_secret = WebTotemRequest::post('recaptcha_v3_secret'); |
| 1144 |
$recaptcha_token = WebTotemRequest::post('recaptcha_token'); |
| 1145 |
$recaptcha = filter_var(WebTotemRequest::post('recaptcha'), FILTER_VALIDATE_BOOLEAN) ?: false; |
| 1146 |
|
| 1147 |
if ($recaptcha) { |
| 1148 |
if (empty($recaptcha_v3_site_key) or empty($recaptcha_v3_secret) or strlen($recaptcha_v3_site_key) != 40 or strlen($recaptcha_v3_secret) != 40) { |
| 1149 |
$response['success'] = false; |
| 1150 |
|
| 1151 |
$response['errors'] = ['recaptcha_v3_site_key' => '', 'recaptcha_v3_secret' => '']; |
| 1152 |
|
| 1153 |
if (empty($recaptcha_v3_site_key)) { |
| 1154 |
$response['errors']['recaptcha_v3_site_key'] = __('The field is required.', 'wtotem'); |
| 1155 |
} else if (strlen($recaptcha_v3_site_key) != 40) { |
| 1156 |
$response['errors']['recaptcha_v3_site_key'] = __('Invalid field length.', 'wtotem'); |
| 1157 |
} |
| 1158 |
if (empty($recaptcha_v3_secret)) { |
| 1159 |
$response['errors']['recaptcha_v3_secret'] = __('The field is required.', 'wtotem'); |
| 1160 |
} else if (strlen($recaptcha_v3_secret) != 40) { |
| 1161 |
$response['errors']['recaptcha_v3_secret'] = __('Invalid field length.', 'wtotem'); |
| 1162 |
} |
| 1163 |
|
| 1164 |
break; |
| 1165 |
} |
| 1166 |
|
| 1167 |
$score = WebTotemCaptcha::score($recaptcha_token, $recaptcha_v3_secret); |
| 1168 |
|
| 1169 |
if ($score == 0) { |
| 1170 |
$response['success'] = false; |
| 1171 |
$response['errors']['recaptcha_v3_secret'] = __('Please check your keys and try again.', 'wtotem'); |
| 1172 |
$response['errors']['recaptcha_v3_site_key'] = __('Please check your keys and try again.', 'wtotem'); |
| 1173 |
break; |
| 1174 |
} |
| 1175 |
} |
| 1176 |
|
| 1177 |
if ($recaptcha) { |
| 1178 |
$settings = [ |
| 1179 |
'recaptcha_v3_site_key' => $recaptcha_v3_site_key, |
| 1180 |
'recaptcha_v3_secret' => $recaptcha_v3_secret, |
| 1181 |
]; |
| 1182 |
} |
| 1183 |
$settings['recaptcha'] = $recaptcha; |
| 1184 |
|
| 1185 |
if ($settings['hide_wp_version']) { |
| 1186 |
WebTotemOption::hideReadme(); |
| 1187 |
} else { |
| 1188 |
WebTotemOption::restoreReadme(); |
| 1189 |
} |
| 1190 |
|
| 1191 |
WebTotemOption::setPluginSettings($settings); |
| 1192 |
|
| 1193 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1194 |
if($recaptcha){ |
| 1195 |
WebTotemOption::setNotification('warning', __('Please make sure that no other recaptcha is used on your site. Otherwise, there may be a conflict that will cause problems when logging into the admin panel.', 'wtotem')); |
| 1196 |
} |
| 1197 |
|
| 1198 |
$response['success'] = true; |
| 1199 |
|
| 1200 |
|
| 1201 |
break; |
| 1202 |
|
| 1203 |
case 'two_factor_settings': |
| 1204 |
$two_factor = filter_var(WebTotemRequest::post('two_factor'), FILTER_VALIDATE_BOOLEAN) ?: false; |
| 1205 |
|
| 1206 |
WebTotemOption::setPluginSettings([ |
| 1207 |
'two_factor' => $two_factor, |
| 1208 |
]); |
| 1209 |
|
| 1210 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1211 |
if ($two_factor) { |
| 1212 |
WebTotemOption::setNotification('warning', __('Please make sure that no other 2FA is used on your site. Otherwise, there may be a conflict that will cause problems when logging into the admin panel.', 'wtotem')); |
| 1213 |
} |
| 1214 |
|
| 1215 |
$response['success'] = true; |
| 1216 |
|
| 1217 |
break; |
| 1218 |
|
| 1219 |
|
| 1220 |
case 'other_settings': |
| 1221 |
|
| 1222 |
$settings = [ |
| 1223 |
'hide_wp_version' => filter_var(WebTotemRequest::post('hide_wp_version'), FILTER_VALIDATE_BOOLEAN) ?: false, |
| 1224 |
'disable_user_enumeration' => filter_var(WebTotemRequest::post('disable_user_enumeration'), FILTER_VALIDATE_BOOLEAN) ?: false, |
| 1225 |
]; |
| 1226 |
|
| 1227 |
if ($settings['hide_wp_version']) { |
| 1228 |
WebTotemOption::hideReadme(); |
| 1229 |
|
| 1230 |
} else { |
| 1231 |
WebTotemOption::restoreReadme(); |
| 1232 |
} |
| 1233 |
|
| 1234 |
WebTotemOption::setPluginSettings($settings); |
| 1235 |
|
| 1236 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1237 |
|
| 1238 |
$response['success'] = true; |
| 1239 |
|
| 1240 |
break; |
| 1241 |
|
| 1242 |
case 'bruteforce_protection_settings': |
| 1243 |
|
| 1244 |
$data = WebTotemRequest::post('data'); |
| 1245 |
$response['success'] = true; |
| 1246 |
|
| 1247 |
$login_attempts = filter_var($data['login_attempts'], FILTER_VALIDATE_BOOLEAN) ?: false; |
| 1248 |
$password_reset = filter_var($data['password_reset'], FILTER_VALIDATE_BOOLEAN) ?: false; |
| 1249 |
|
| 1250 |
if ($login_attempts) { |
| 1251 |
$response['errors'] = ['login_number_of_attempts' => '', 'login_minutes_of_ban' => '']; |
| 1252 |
|
| 1253 |
if (empty($data['login_number_of_attempts']) or empty($data['login_minutes_of_ban'])) { |
| 1254 |
$response['success'] = false; |
| 1255 |
|
| 1256 |
if (empty($data['login_number_of_attempts'])) { |
| 1257 |
$response['errors']['login_number_of_attempts'] = __('The field is required.', 'wtotem'); |
| 1258 |
} |
| 1259 |
if (empty($data['login_minutes_of_ban'])) { |
| 1260 |
$response['errors']['login_minutes_of_ban'] = __('The field is required.', 'wtotem'); |
| 1261 |
} |
| 1262 |
} else if ($data['login_number_of_attempts'] <= 0 or $data['login_number_of_attempts'] > 1000000) { |
| 1263 |
$response['success'] = false; |
| 1264 |
$response['errors']['login_number_of_attempts'] = sprintf(__('Please specify a value from %s to %s.', 'wtotem'), '1', '1000000'); |
| 1265 |
} |
| 1266 |
} |
| 1267 |
|
| 1268 |
if ($password_reset) { |
| 1269 |
if (empty($data['password_reset_number_of_attempts']) or empty($data['password_reset_minutes_of_ban'])) { |
| 1270 |
$response['success'] = false; |
| 1271 |
|
| 1272 |
$response['errors']['password_reset_number_of_attempts'] = ''; |
| 1273 |
$response['errors']['password_reset_minutes_of_ban'] = ''; |
| 1274 |
|
| 1275 |
if (empty($data['password_reset_number_of_attempts'])) { |
| 1276 |
$response['errors']['password_reset_number_of_attempts'] = __('The field is required.', 'wtotem'); |
| 1277 |
} |
| 1278 |
if (empty($data['password_reset_minutes_of_ban'])) { |
| 1279 |
$response['errors']['password_reset_minutes_of_ban'] = __('The field is required.', 'wtotem'); |
| 1280 |
} |
| 1281 |
} else if ($data['password_reset_number_of_attempts'] <= 0 or $data['password_reset_number_of_attempts'] > 1000000) { |
| 1282 |
$response['success'] = false; |
| 1283 |
$response['errors']['password_reset_number_of_attempts'] = sprintf(__('Please specify a value from %s to %s.', 'wtotem'), '1', '1000000'); |
| 1284 |
} |
| 1285 |
} |
| 1286 |
if (!$response['success']) { |
| 1287 |
break; |
| 1288 |
} else { |
| 1289 |
$response['errors'] = false; |
| 1290 |
} |
| 1291 |
|
| 1292 |
$settings = [ |
| 1293 |
'login_attempts' => $login_attempts, |
| 1294 |
'password_reset' => $password_reset, |
| 1295 |
]; |
| 1296 |
|
| 1297 |
if ($login_attempts) { |
| 1298 |
$settings['login_number_of_attempts'] = $data['login_number_of_attempts']; |
| 1299 |
$settings['login_minutes_of_ban'] = $data['login_minutes_of_ban']; |
| 1300 |
} |
| 1301 |
if ($password_reset) { |
| 1302 |
$settings['password_reset_number_of_attempts'] = $data['password_reset_number_of_attempts']; |
| 1303 |
$settings['password_reset_minutes_of_ban'] = $data['password_reset_minutes_of_ban']; |
| 1304 |
} |
| 1305 |
|
| 1306 |
WebTotemOption::setPluginSettings($settings); |
| 1307 |
|
| 1308 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1309 |
|
| 1310 |
break; |
| 1311 |
|
| 1312 |
case 'add_allow_ip': |
| 1313 |
$ip = WebTotemRequest::post('value'); |
| 1314 |
if(!WebTotem::validateIpOrCidr($ip)){ |
| 1315 |
WebTotemOption::setNotification('warning', __('The IP address is incorrect', 'wtotem')); |
| 1316 |
$response['success'] = false; |
| 1317 |
break; |
| 1318 |
} |
| 1319 |
if($ip){ |
| 1320 |
$api_response = WebTotemAPI::addIpToList([$ip], 'whitelist'); |
| 1321 |
if ($api_response) { |
| 1322 |
|
| 1323 |
$data = WebTotemAPI::getIpLists('whitelist'); |
| 1324 |
WebTotemCache::setData(['getIpLists_whitelist' => $data], $host['id']); |
| 1325 |
|
| 1326 |
$build[] = [ |
| 1327 |
'variables' => [ |
| 1328 |
"list" => WebTotem::getIpList($data, 'ip_allow'), |
| 1329 |
], |
| 1330 |
'template' => 'allow_deny_list', |
| 1331 |
]; |
| 1332 |
|
| 1333 |
$response['content'] = $template->arrayRender($build); |
| 1334 |
} |
| 1335 |
|
| 1336 |
$response['success'] = true; |
| 1337 |
} else { |
| 1338 |
$response['success'] = false; |
| 1339 |
} |
| 1340 |
|
| 1341 |
break; |
| 1342 |
|
| 1343 |
case 'add_deny_ip': |
| 1344 |
$ip = WebTotemRequest::post('value'); |
| 1345 |
if(!WebTotem::validateIpOrCidr($ip)){ |
| 1346 |
WebTotemOption::setNotification('warning', __('The IP address is incorrect', 'wtotem')); |
| 1347 |
$response['success'] = false; |
| 1348 |
break; |
| 1349 |
} |
| 1350 |
if($ip){ |
| 1351 |
$api_response = WebTotemAPI::addIpToList([$ip], 'blacklist'); |
| 1352 |
if ($api_response) { |
| 1353 |
$data = WebTotemAPI::getIpLists(); |
| 1354 |
WebTotemCache::setData(['getIpLists_blacklist' => $data], $host['id']); |
| 1355 |
|
| 1356 |
$build[] = [ |
| 1357 |
'variables' => [ |
| 1358 |
"list" => WebTotem::getIpList($data, 'ip_deny'), |
| 1359 |
], |
| 1360 |
'template' => 'allow_deny_list', |
| 1361 |
]; |
| 1362 |
|
| 1363 |
$response['content'] = $template->arrayRender($build); |
| 1364 |
} |
| 1365 |
|
| 1366 |
$response['success'] = true; |
| 1367 |
} else { |
| 1368 |
$response['success'] = false; |
| 1369 |
} |
| 1370 |
break; |
| 1371 |
|
| 1372 |
case 'add_allow_url': |
| 1373 |
$url = WebTotemRequest::post('value'); |
| 1374 |
if($url){ |
| 1375 |
$api_response = WebTotemAPI::addIpToList([$url], 'checklist'); |
| 1376 |
if ($api_response) { |
| 1377 |
$data = WebTotemAPI::getIpLists('checklist'); |
| 1378 |
WebTotemCache::setData(['getIpLists_checklist' => $data], $host['id']); |
| 1379 |
|
| 1380 |
$build[] = [ |
| 1381 |
'variables' => [ |
| 1382 |
"list" => WebTotem::getIpList($data, 'allow_url'), |
| 1383 |
], |
| 1384 |
'template' => 'allow_deny_list', |
| 1385 |
]; |
| 1386 |
|
| 1387 |
$response['content'] = $template->arrayRender($build); |
| 1388 |
} |
| 1389 |
|
| 1390 |
$response['success'] = true; |
| 1391 |
} else { |
| 1392 |
$response['success'] = false; |
| 1393 |
} |
| 1394 |
break; |
| 1395 |
|
| 1396 |
case 'add_ip_list': |
| 1397 |
$ips = WebTotem::convertIpListForApi(WebTotemRequest::post('ips')); |
| 1398 |
$list_name = WebTotemRequest::post('list'); |
| 1399 |
|
| 1400 |
foreach ($ips as $key => $ip){ |
| 1401 |
if(!WebTotem::validateIpOrCidr($ip)){ |
| 1402 |
WebTotemOption::setNotification('warning', __('The IP address is incorrect', 'wtotem')) . ': ' . $ip; |
| 1403 |
unset($ips[$key]); |
| 1404 |
} |
| 1405 |
} |
| 1406 |
|
| 1407 |
$api_response = WebTotemAPI::addIpToList($ips, $list_name); |
| 1408 |
|
| 1409 |
if ($api_response) { |
| 1410 |
$data = WebTotemAPI::getIpLists($list_name); |
| 1411 |
WebTotemCache::setData(['getIpLists_' . $list_name => $data], $host['id']); |
| 1412 |
$ip_list = ($list_name == 'whitelist') ? 'ip_allow' : 'ip_deny'; |
| 1413 |
|
| 1414 |
$build[] = [ |
| 1415 |
'variables' => [ |
| 1416 |
"list" => WebTotem::getIpList($data, $ip_list), |
| 1417 |
], |
| 1418 |
'template' => 'allow_deny_list', |
| 1419 |
]; |
| 1420 |
|
| 1421 |
if ($api_response['status'] != 0) { |
| 1422 |
$response['invalidIPs'] = implode("\n", $api_response['invalidIPs']); |
| 1423 |
} |
| 1424 |
|
| 1425 |
$response['wrap'] = ($list_name == 'white') ? '#wtotem_ip_allow_list' : '#wtotem_ip_deny_list'; |
| 1426 |
$response['content'] = $template->arrayRender($build); |
| 1427 |
} |
| 1428 |
$response['success'] = true; |
| 1429 |
|
| 1430 |
break; |
| 1431 |
} |
| 1432 |
|
| 1433 |
$response['notifications'] = self::notifications(); |
| 1434 |
wp_send_json($response); |
| 1435 |
} |
| 1436 |
|
| 1437 |
|
| 1438 |
/** |
| 1439 |
* Update cash data. |
| 1440 |
* |
| 1441 |
* @return void |
| 1442 |
*/ |
| 1443 |
public static function cashUpdate() |
| 1444 |
{ |
| 1445 |
|
| 1446 |
if (WebTotemRequest::post('ajax_action') !== 'cash_update') { |
| 1447 |
return; |
| 1448 |
} |
| 1449 |
|
| 1450 |
$page = WebTotemRequest::post('page'); |
| 1451 |
|
| 1452 |
$host = WebTotemAPI::siteInfo(); |
| 1453 |
$template = new WebTotemTemplate(); |
| 1454 |
|
| 1455 |
switch ($page) { |
| 1456 |
case 'dashboard': |
| 1457 |
|
| 1458 |
if ($cacheData = WebTotemCache::getdata('getMonitoringData', $host['id'])) { |
| 1459 |
if ($cacheData['remained'] < 60) { |
| 1460 |
$data_monitoring = WebTotemAPI::getMonitoringData($host['id']); |
| 1461 |
WebTotemCache::setData(['getMonitoringData' => $data_monitoring], $host['id']); |
| 1462 |
} |
| 1463 |
} |
| 1464 |
if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) { |
| 1465 |
if ($cacheData['remained'] < 60) { |
| 1466 |
$data_firewall = WebTotemAPI::getFirewall(10, 1, 7); |
| 1467 |
WebTotemCache::setData(['getFirewall' => $data_firewall], $host['id']); |
| 1468 |
} |
| 1469 |
} |
| 1470 |
if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) { |
| 1471 |
if ($cacheData['remained'] < 60) { |
| 1472 |
$data_firewall_statistics = WebTotemAPI::getFirewallStatistics(); |
| 1473 |
WebTotemCache::setData(['getFirewallStatistics' => $data_firewall_statistics], $host['id']); |
| 1474 |
} |
| 1475 |
} |
| 1476 |
if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) { |
| 1477 |
if ($cacheData['remained'] < 60) { |
| 1478 |
$data_agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI(); |
| 1479 |
WebTotemCache::setData(['getAgentsStatusesFromAPI' => $data_agents_statuses], $host['id']); |
| 1480 |
} |
| 1481 |
} |
| 1482 |
break; |
| 1483 |
|
| 1484 |
case 'open_paths': |
| 1485 |
if($cacheData = WebTotemCache::getdata('getMonitoringData', $host['id'])) { |
| 1486 |
if ($cacheData['remained'] < 60) { |
| 1487 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 1488 |
WebTotemCache::setData(['getMonitoringData' => $data], $host['id']); |
| 1489 |
} |
| 1490 |
} |
| 1491 |
break; |
| 1492 |
|
| 1493 |
|
| 1494 |
case 'firewall': |
| 1495 |
if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) { |
| 1496 |
if ($cacheData['remained'] < 60) { |
| 1497 |
$data_firewall_statistics = WebTotemAPI::getFirewallStatistics(); |
| 1498 |
WebTotemCache::setData(['getFirewallStatistics' => $data_firewall_statistics], $host['id']); |
| 1499 |
} |
| 1500 |
} |
| 1501 |
if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) { |
| 1502 |
if ($cacheData['remained'] < 60) { |
| 1503 |
$data_firewall = WebTotemAPI::getFirewall(10, 1, 7); |
| 1504 |
WebTotemCache::setData(['getFirewall' => $data_firewall], $host['id']); |
| 1505 |
} |
| 1506 |
} |
| 1507 |
break; |
| 1508 |
|
| 1509 |
case 'antivirus': |
| 1510 |
if ($cacheData = WebTotemCache::getdata('getAntivirusHistory', $host['id'])) { |
| 1511 |
if ($cacheData['remained'] < 60) { |
| 1512 |
|
| 1513 |
$antivirus_history_data = WebTotemAPI::getAntivirusHistory(); |
| 1514 |
WebTotemCache::setData(['getAntivirusHistory' => $antivirus_history_data], $host['id']); |
| 1515 |
} |
| 1516 |
} |
| 1517 |
if ($cacheData = WebTotemCache::getdata('getAntivirusCurrentDetails', $host['id'])) { |
| 1518 |
if ($cacheData['remained'] < 60) { |
| 1519 |
$infected_files = WebTotemAPI::getAntivirusCurrentDetails(); |
| 1520 |
WebTotemCache::setData(['getAntivirusCurrentDetails' => $infected_files], $host['id']); |
| 1521 |
|
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
if ($cacheData = WebTotemCache::getdata('getQuarantineList', $host['id'])) { |
| 1526 |
if ($cacheData['remained'] < 60) { |
| 1527 |
$quarantine_files = WebTotemAPI::getQuarantineList(); |
| 1528 |
WebTotemCache::setData(['getQuarantineList' => $quarantine_files], $host['id']); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
break; |
| 1532 |
|
| 1533 |
case 'settings': |
| 1534 |
if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) { |
| 1535 |
if ($cacheData['remained'] < 60) { |
| 1536 |
$agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI(); |
| 1537 |
WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses], $host['id']); |
| 1538 |
} |
| 1539 |
} |
| 1540 |
if ($cacheData = WebTotemCache::getdata('getFirewallSettings', $host['id'])) { |
| 1541 |
if ($cacheData['remained'] < 60) { |
| 1542 |
$waf_settings = WebTotemAPI::getFirewallSettings(); |
| 1543 |
WebTotemCache::setData(['getFirewallSettings' => $waf_settings], $host['id']); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
if ($cacheData = WebTotemCache::getdata('getIpLists_whitelist', $host['id'])) { |
| 1547 |
if ($cacheData['remained'] < 60) { |
| 1548 |
$ip_whiteList = WebTotemAPI::getIpLists('whitelist'); |
| 1549 |
WebTotemCache::setData(['getIpLists_whitelist' => $ip_whiteList], $host['id']); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
if ($cacheData = WebTotemCache::getdata('getIpLists_blacklist', $host['id'])) { |
| 1553 |
if ($cacheData['remained'] < 60) { |
| 1554 |
$ip_blackList = WebTotemAPI::getIpLists(); |
| 1555 |
WebTotemCache::setData(['getIpLists_blacklist' => $ip_blackList], $host['id']); |
| 1556 |
} |
| 1557 |
} |
| 1558 |
if ($cacheData = WebTotemCache::getdata('getIpLists_checklist', $host['id'])) { |
| 1559 |
if ($cacheData['remained'] < 60) { |
| 1560 |
$ip_checklist = WebTotemAPI::getIpLists('checklist'); |
| 1561 |
WebTotemCache::setData(['getIpLists_checklist' => $ip_checklist], $host['id']); |
| 1562 |
} |
| 1563 |
} |
| 1564 |
break; |
| 1565 |
|
| 1566 |
} |
| 1567 |
|
| 1568 |
$response['success'] = true; |
| 1569 |
$response['notifications'] = self::notifications(); |
| 1570 |
wp_send_json($response); |
| 1571 |
} |
| 1572 |
|
| 1573 |
/** |
| 1574 |
* Request to remove from the list of deny/allowed ip or url addresses. |
| 1575 |
* |
| 1576 |
* @return void |
| 1577 |
*/ |
| 1578 |
public static function remove() |
| 1579 |
{ |
| 1580 |
|
| 1581 |
if (WebTotemRequest::post('ajax_action') !== 'remove') { |
| 1582 |
return; |
| 1583 |
} |
| 1584 |
|
| 1585 |
$av_installed = WebTotemOption::getOption('av_installed'); |
| 1586 |
$waf_installed = WebTotemOption::getOption('waf_installed'); |
| 1587 |
|
| 1588 |
if (!$av_installed && !$waf_installed) { |
| 1589 |
WebTotemOption::setNotification('warning', __('It is not possible to make changes because the agents are not installed.', 'wtotem')); |
| 1590 |
|
| 1591 |
wp_send_json([ |
| 1592 |
'success' => false, |
| 1593 |
'notifications' => self::notifications() |
| 1594 |
]); |
| 1595 |
} |
| 1596 |
|
| 1597 |
$action = WebTotemRequest::post('remove_action'); |
| 1598 |
$host = WebTotemAPI::siteInfo(); |
| 1599 |
$template = new WebTotemTemplate(); |
| 1600 |
|
| 1601 |
switch ($action) { |
| 1602 |
case 'ip_allow': |
| 1603 |
$api_response = WebTotemAPI::removeIpFromList(WebTotemRequest::post('ip'), 'whitelist'); |
| 1604 |
|
| 1605 |
if ($api_response) { |
| 1606 |
$data = WebTotemAPI::getIpLists('whitelist'); |
| 1607 |
WebTotemCache::setData(['getIpLists_whitelist' => $data], $host['id']); |
| 1608 |
|
| 1609 |
$build[] = [ |
| 1610 |
'variables' => [ |
| 1611 |
"list" => WebTotem::getIpList($data, 'ip_allow'), |
| 1612 |
], |
| 1613 |
'template' => 'allow_deny_list', |
| 1614 |
]; |
| 1615 |
|
| 1616 |
$response['content'] = $template->arrayRender($build); |
| 1617 |
$response['wrap'] = '#wtotem_ip_allow_list'; |
| 1618 |
} |
| 1619 |
break; |
| 1620 |
|
| 1621 |
case 'ip_deny': |
| 1622 |
$api_response = WebTotemAPI::removeIpFromList(WebTotemRequest::post('ip'), 'blacklist'); |
| 1623 |
|
| 1624 |
if ($api_response) { |
| 1625 |
$data = WebTotemAPI::getIpLists(); |
| 1626 |
WebTotemCache::setData(['getIpLists_blacklist' => $data], $host['id']); |
| 1627 |
|
| 1628 |
$build[] = [ |
| 1629 |
'variables' => [ |
| 1630 |
"list" => WebTotem::getIpList($data, 'ip_deny'), |
| 1631 |
], |
| 1632 |
'template' => 'allow_deny_list', |
| 1633 |
]; |
| 1634 |
|
| 1635 |
$response['content'] = $template->arrayRender($build); |
| 1636 |
$response['wrap'] = '#wtotem_ip_deny_list'; |
| 1637 |
} |
| 1638 |
break; |
| 1639 |
|
| 1640 |
case 'url_allow': |
| 1641 |
$api_response = WebTotemAPI::removeIpFromList(WebTotemRequest::post('ip'), 'checklist'); |
| 1642 |
|
| 1643 |
if ($api_response) { |
| 1644 |
$data = WebTotemAPI::getIpLists('checklist'); |
| 1645 |
WebTotemCache::setData(['getIpLists_checklist' => $data], $host['id']); |
| 1646 |
|
| 1647 |
$build[] = [ |
| 1648 |
'variables' => [ |
| 1649 |
"list" => WebTotem::getIpList($data, 'allow_url'), |
| 1650 |
], |
| 1651 |
'template' => 'allow_deny_list', |
| 1652 |
]; |
| 1653 |
|
| 1654 |
$response['content'] = $template->arrayRender($build); |
| 1655 |
$response['wrap'] = '#wtotem_allow_url'; |
| 1656 |
} |
| 1657 |
break; |
| 1658 |
} |
| 1659 |
|
| 1660 |
$response['success'] = true; |
| 1661 |
$response['notifications'] = self::notifications(); |
| 1662 |
wp_send_json($response); |
| 1663 |
} |
| 1664 |
|
| 1665 |
/** |
| 1666 |
* Request to remove site from WebTotem. |
| 1667 |
* |
| 1668 |
* @return void |
| 1669 |
*/ |
| 1670 |
public static function multisite() |
| 1671 |
{ |
| 1672 |
|
| 1673 |
if (WebTotemRequest::post('ajax_action') !== 'multisite') { |
| 1674 |
return; |
| 1675 |
} |
| 1676 |
|
| 1677 |
$action = WebTotemRequest::post('multisite_action'); |
| 1678 |
$template = new WebTotemTemplate(); |
| 1679 |
|
| 1680 |
switch ($action) { |
| 1681 |
case 'remove_site': |
| 1682 |
|
| 1683 |
$host_id = WebTotemRequest::post('hid'); |
| 1684 |
$main_host = WebTotemOption::getMainHost(); |
| 1685 |
|
| 1686 |
if ($host_id == $main_host['id']) { |
| 1687 |
WebTotemOption::setNotification('error', __('You cannot delete the primary domain.', 'wtotem')); |
| 1688 |
break; |
| 1689 |
} |
| 1690 |
WebTotemAPI::removeMultiSiteHost($host_id); |
| 1691 |
|
| 1692 |
break; |
| 1693 |
|
| 1694 |
case 'add_site': |
| 1695 |
|
| 1696 |
$new_site = WebTotemRequest::post('site_name'); |
| 1697 |
WebTotemAPI::addMultiSiteNewSites([$new_site]); |
| 1698 |
|
| 1699 |
break; |
| 1700 |
} |
| 1701 |
|
| 1702 |
$allSites = WebTotemAPI::getSites(); |
| 1703 |
$has_next_page = $allSites['pageInfo']['hasNextPage']; |
| 1704 |
|
| 1705 |
WebTotemOption::setSessionOptions([ |
| 1706 |
'sites_cursor' => $allSites['pageInfo']['endCursor'], |
| 1707 |
]); |
| 1708 |
|
| 1709 |
// Sites list. |
| 1710 |
$build[] = [ |
| 1711 |
'variables' => [ |
| 1712 |
'sites' => WebTotem::allSitesData($allSites), |
| 1713 |
'has_next_page' => $has_next_page, |
| 1714 |
], |
| 1715 |
'template' => 'multisite_list' |
| 1716 |
]; |
| 1717 |
|
| 1718 |
$response['content'] = $template->arrayRender($build); |
| 1719 |
|
| 1720 |
$response['success'] = true; |
| 1721 |
$response['notifications'] = self::notifications(); |
| 1722 |
wp_send_json($response); |
| 1723 |
} |
| 1724 |
|
| 1725 |
/** |
| 1726 |
* Request to remove site from WebTotem. |
| 1727 |
* |
| 1728 |
* @return void |
| 1729 |
*/ |
| 1730 |
public static function twoFactorAuth() |
| 1731 |
{ |
| 1732 |
|
| 1733 |
if (WebTotemRequest::post('ajax_action') !== 'two_factor_auth') { |
| 1734 |
return; |
| 1735 |
} |
| 1736 |
|
| 1737 |
$action = WebTotemRequest::post('case_action'); |
| 1738 |
$template = new WebTotemTemplate(); |
| 1739 |
$current_user = wp_get_current_user(); |
| 1740 |
|
| 1741 |
if ($user_id = (int)WebTotemRequest::post('user_id')) { |
| 1742 |
if ($current_user->ID !== $user_id and !current_user_can('manage_options')) { |
| 1743 |
|
| 1744 |
WebTotemOption::setNotification('info', '$current_user->ID: ' . $current_user->ID . ', $user_id: ' . $user_id); |
| 1745 |
WebTotemOption::setNotification('error', __('You cannot edit this user.', 'wtotem')); |
| 1746 |
return; |
| 1747 |
} |
| 1748 |
$user = get_user_by('id', $user_id); |
| 1749 |
} else { |
| 1750 |
$user = $current_user; |
| 1751 |
} |
| 1752 |
|
| 1753 |
switch ($action) { |
| 1754 |
case 'activate': |
| 1755 |
|
| 1756 |
$g = new WebTotemGoogleAuthenticator(); |
| 1757 |
|
| 1758 |
$secret = WebTotemRequest::post('secret'); |
| 1759 |
$recovery = WebTotemRequest::post('recovery'); |
| 1760 |
$code = WebTotemRequest::post('code'); |
| 1761 |
|
| 1762 |
if ($g->checkCode($secret, $code)) { |
| 1763 |
WebTotemLogin::saveData($user->ID, $recovery, $secret); |
| 1764 |
WebTotemOption::setNotification('success', __('Your changes have been applied successfully.', 'wtotem')); |
| 1765 |
$response['success'] = true; |
| 1766 |
} else { |
| 1767 |
WebTotemOption::setNotification('error', __('You have entered an incorrect activation code.', 'wtotem')); |
| 1768 |
$response['success'] = false; |
| 1769 |
} |
| 1770 |
|
| 1771 |
break; |
| 1772 |
|
| 1773 |
case 'deactivate': |
| 1774 |
|
| 1775 |
WebTotemLogin::delete($user->ID); |
| 1776 |
|
| 1777 |
$response['success'] = true; |
| 1778 |
|
| 1779 |
break; |
| 1780 |
} |
| 1781 |
|
| 1782 |
$build[] = [ |
| 1783 |
'variables' => [ |
| 1784 |
'two_factor' => WebTotemLogin::getTwoFactorData($user), |
| 1785 |
'page_nonce' => wp_create_nonce('wtotem_page_nonce'), |
| 1786 |
'user_id' => $user->ID, |
| 1787 |
], |
| 1788 |
'template' => 'two_factor_auth' |
| 1789 |
]; |
| 1790 |
|
| 1791 |
$response['content'] = $template->arrayRender($build); |
| 1792 |
|
| 1793 |
$response['notifications'] = self::notifications(); |
| 1794 |
wp_send_json($response); |
| 1795 |
} |
| 1796 |
|
| 1797 |
/** |
| 1798 |
* Changing the theme mode. |
| 1799 |
* |
| 1800 |
* @return void |
| 1801 |
*/ |
| 1802 |
public static function changeThemeMode() |
| 1803 |
{ |
| 1804 |
|
| 1805 |
if (WebTotemRequest::post('ajax_action') !== 'theme_mode') { |
| 1806 |
return; |
| 1807 |
} |
| 1808 |
|
| 1809 |
$theme_mode = WebTotemOption::getSessionOption('theme_mode'); |
| 1810 |
|
| 1811 |
if ($theme_mode == 'dark') { |
| 1812 |
WebTotemOption::setSessionOptions(['theme_mode' => 'light']); |
| 1813 |
$response = 'light'; |
| 1814 |
} else { |
| 1815 |
WebTotemOption::setSessionOptions(['theme_mode' => 'dark']); |
| 1816 |
$response = 'dark'; |
| 1817 |
} |
| 1818 |
|
| 1819 |
wp_send_json($response); |
| 1820 |
} |
| 1821 |
|
| 1822 |
/** |
| 1823 |
* Set user time zone offset. |
| 1824 |
* |
| 1825 |
* @return void |
| 1826 |
*/ |
| 1827 |
public static function userTimeZone() |
| 1828 |
{ |
| 1829 |
|
| 1830 |
if (WebTotemRequest::post('ajax_action') !== 'set_time_zone') { |
| 1831 |
return; |
| 1832 |
} |
| 1833 |
|
| 1834 |
$time_zone_offset = WebTotemRequest::post('offset'); |
| 1835 |
$now = strtotime('now'); |
| 1836 |
$check = WebTotemOption::getOption('time_zone_check') ?: 0; |
| 1837 |
|
| 1838 |
// Checking whether an hour has elapsed since the previous request. |
| 1839 |
if ($now >= $check) { |
| 1840 |
$time_zone = WebTotemAPI::getTimeZone(); |
| 1841 |
if ($time_zone) { |
| 1842 |
$time_zone_offset = timezone_offset_get(new \DateTimeZone($time_zone), new \DateTime('now', new \DateTimeZone('Europe/London'))) / 3600; |
| 1843 |
WebTotemOption::setOptions(['time_zone_check' => $now + 3600]); |
| 1844 |
} |
| 1845 |
WebTotemOption::setOptions(['time_zone_offset' => $time_zone_offset]); |
| 1846 |
} |
| 1847 |
|
| 1848 |
wp_send_json([ |
| 1849 |
'success' => true, |
| 1850 |
'time_zone_offset' => $time_zone_offset |
| 1851 |
]); |
| 1852 |
|
| 1853 |
} |
| 1854 |
|
| 1855 |
/** |
| 1856 |
* Forced checking of services. |
| 1857 |
* |
| 1858 |
* @return void |
| 1859 |
*/ |
| 1860 |
public static function force_check() |
| 1861 |
{ |
| 1862 |
if (WebTotemRequest::post('ajax_action') !== 'force_check') { |
| 1863 |
return; |
| 1864 |
} |
| 1865 |
|
| 1866 |
$service = WebTotemRequest::post('service'); |
| 1867 |
$host = WebTotemAPI::siteInfo(); |
| 1868 |
$template = new WebTotemTemplate(); |
| 1869 |
|
| 1870 |
$response['success'] = false; |
| 1871 |
|
| 1872 |
if($service){ |
| 1873 |
|
| 1874 |
$services = [ |
| 1875 |
'ssl' => 'ssl', |
| 1876 |
'rc' => 'reputation', |
| 1877 |
// 'dec' => 'location', |
| 1878 |
'ops' => 'openPath', |
| 1879 |
'ps' => 'openPort', |
| 1880 |
'availability' => 'availability', |
| 1881 |
]; |
| 1882 |
|
| 1883 |
// force check service |
| 1884 |
if($service == 'av'){ |
| 1885 |
$_response = WebTotemAPI::forceCheckAV(); |
| 1886 |
} else { |
| 1887 |
if(isset( $services[$service] )){ |
| 1888 |
$_response = WebTotemAPI::forceCheck($host['id'], $services[$service]); |
| 1889 |
} |
| 1890 |
} |
| 1891 |
|
| 1892 |
if (!isset($_response['message'])) { |
| 1893 |
|
| 1894 |
switch ($service) { |
| 1895 |
|
| 1896 |
case 'ssl': |
| 1897 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 1898 |
|
| 1899 |
$ssl = [ |
| 1900 |
'status' => WebTotem::getStatusData($data['module_ssl']['info']['status']), |
| 1901 |
'cert_name' => $data['module_ssl']['result']['certificate_name'], |
| 1902 |
'days_left' => $data['module_ssl']['result']['days_left'], |
| 1903 |
'issue_date' => WebTotem::dateFormatter($data['module_ssl']['result']['issue_date']), |
| 1904 |
'expiry_date' => WebTotem::dateFormatter($data['module_ssl']['result']['expiry_date']), |
| 1905 |
]; |
| 1906 |
|
| 1907 |
$build[] = [ |
| 1908 |
'variables' => [ |
| 1909 |
'ssl' => $ssl, |
| 1910 |
], |
| 1911 |
'template' => 'monitoring_ssl', |
| 1912 |
]; |
| 1913 |
|
| 1914 |
$response['content'] = $template->arrayRender($build); |
| 1915 |
$response['success'] = true; |
| 1916 |
break; |
| 1917 |
|
| 1918 |
case 'availability': |
| 1919 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 1920 |
|
| 1921 |
$domain = [ |
| 1922 |
'status' => WebTotem::getStatusData($data['module_location']['info']['status']), |
| 1923 |
"redirect_link" => $data['module_location']['result']['redirect_link'], |
| 1924 |
"is_created_at" => (bool)$data['module_location']['result']['checked_at'], |
| 1925 |
"created_at" => WebTotem::dateFormatter($data['module_location']['result']['checked_at']), |
| 1926 |
"is_taken" => $data['module_location']['result']['is_taken'], |
| 1927 |
"ips" => $data['module_location']['result']['locations'], |
| 1928 |
"protection" => $data['module_location']['result']['protection'], |
| 1929 |
]; |
| 1930 |
|
| 1931 |
$build[] = [ |
| 1932 |
'variables' => [ |
| 1933 |
'domain' => $domain, |
| 1934 |
'availability' => [ |
| 1935 |
'chart' => json_encode($data['module_availability']['result']['stats_by_day']), |
| 1936 |
'status' => WebTotem::getStatusData($data['module_availability']['info']['status']) |
| 1937 |
], |
| 1938 |
], |
| 1939 |
'template' => 'monitoring_domain', |
| 1940 |
]; |
| 1941 |
|
| 1942 |
$response['content'] = $template->arrayRender($build); |
| 1943 |
$response['success'] = true; |
| 1944 |
break; |
| 1945 |
|
| 1946 |
case 'rc': |
| 1947 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 1948 |
|
| 1949 |
$reputation = [ |
| 1950 |
"status" => WebTotem::getStatusData($data['module_reputation']['info']['status'] ?? ''), |
| 1951 |
"info" => WebTotem::getReputationInfo($data['reputation']['result']['status'] ?? ''), |
| 1952 |
"last_test" => WebTotem::dateFormatter($data['reputation']['result']['checked_at'] ?? ''), |
| 1953 |
]; |
| 1954 |
|
| 1955 |
$build[] = [ |
| 1956 |
'variables' => [ |
| 1957 |
'reputation' => $reputation, |
| 1958 |
], |
| 1959 |
'template' => 'monitoring_reputation', |
| 1960 |
]; |
| 1961 |
|
| 1962 |
$response['content'] = $template->arrayRender($build); |
| 1963 |
$response['success'] = true; |
| 1964 |
break; |
| 1965 |
|
| 1966 |
case 'ps': |
| 1967 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 1968 |
$ports = $data['module_port_scanner']['result']['open_ports']; |
| 1969 |
|
| 1970 |
if($ports['TCPResults']){ |
| 1971 |
$open_ports[] = [ |
| 1972 |
'variables' => [ |
| 1973 |
"ports" => WebTotem::getOpenPortsData($ports['open_ports'] ?? []), |
| 1974 |
], |
| 1975 |
'template' => 'open_ports', |
| 1976 |
]; |
| 1977 |
|
| 1978 |
$open_ports_few[] = [ |
| 1979 |
'variables' => [ |
| 1980 |
"ports" => $ports['open_ports'] ? WebTotem::getOpenPortsData(array_slice($ports['open_ports'], 0, 3)) : [], |
| 1981 |
"more" => true, |
| 1982 |
], |
| 1983 |
'template' => 'open_ports', |
| 1984 |
]; |
| 1985 |
} |
| 1986 |
|
| 1987 |
$ignore_ports[] = [ |
| 1988 |
'variables' => [ |
| 1989 |
"ports" => [], /** TODO ignore_ports **/ |
| 1990 |
], |
| 1991 |
'template' => 'ignore_ports', |
| 1992 |
]; |
| 1993 |
$response = [ |
| 1994 |
'status' => WebTotem::getStatusData($ports['module_port_scanner']['info']['status']), |
| 1995 |
'last_test' => WebTotem::dateFormatter($data['module_port_scanner']['result']['checked_at']), |
| 1996 |
'open_ports' => (isset($open_ports)) ? $template->arrayRender($open_ports) : '', |
| 1997 |
'open_ports_few' => (isset($open_ports_few)) ? $template->arrayRender($open_ports_few) : '', |
| 1998 |
'ignore_ports' => $template->arrayRender($ignore_ports), |
| 1999 |
]; |
| 2000 |
|
| 2001 |
$response['success'] = true; |
| 2002 |
|
| 2003 |
break; |
| 2004 |
|
| 2005 |
case 'ops': |
| 2006 |
|
| 2007 |
$data = WebTotemAPI::getMonitoringData($host['id']); |
| 2008 |
$open_path[] = [ |
| 2009 |
'variables' => [ |
| 2010 |
"paths" => $data['module_open_paths']['result']['open_paths'], |
| 2011 |
], |
| 2012 |
'template' => 'open_paths', |
| 2013 |
]; |
| 2014 |
|
| 2015 |
$response = [ |
| 2016 |
'status' => WebTotem::getStatusData($data['module_open_paths']['info']['status'] ), |
| 2017 |
"last_test" => WebTotem::dateFormatter($data['module_open_paths']['result']['checked_at'] ?? false), |
| 2018 |
'open_paths' => $template->arrayRender($open_path), |
| 2019 |
]; |
| 2020 |
|
| 2021 |
$response['success'] = true; |
| 2022 |
break; |
| 2023 |
} |
| 2024 |
|
| 2025 |
} |
| 2026 |
} |
| 2027 |
|
| 2028 |
$response['notifications'] = self::notifications(); |
| 2029 |
|
| 2030 |
wp_send_json($response); |
| 2031 |
} |
| 2032 |
|
| 2033 |
/** |
| 2034 |
* Initialization scanning and checking the current status. |
| 2035 |
* |
| 2036 |
* @return void |
| 2037 |
*/ |
| 2038 |
public static function wtotem_scan() |
| 2039 |
{ |
| 2040 |
|
| 2041 |
if (WebTotemRequest::get('ajax_action') !== 'wtotem_scan') { |
| 2042 |
return; |
| 2043 |
} |
| 2044 |
|
| 2045 |
$logs_action = WebTotemRequest::get('scan_action'); |
| 2046 |
|
| 2047 |
switch ($logs_action) { |
| 2048 |
case 'init': |
| 2049 |
if(!WebTotemOption::getOption('scan_init')){ |
| 2050 |
WebTotemOption::setOptions(['scan_init' => 1]); |
| 2051 |
WebTotemScan::initialize(); |
| 2052 |
$response = [ |
| 2053 |
'success' => true, |
| 2054 |
'scan_start' => 'success', |
| 2055 |
]; |
| 2056 |
} else { |
| 2057 |
$response = [ |
| 2058 |
'success' => false, |
| 2059 |
'error' => 'The scan is already running', |
| 2060 |
]; |
| 2061 |
} |
| 2062 |
|
| 2063 |
break; |
| 2064 |
|
| 2065 |
case 'push': |
| 2066 |
if(WebTotemOption::getOption('scan_init')) { |
| 2067 |
WebTotemScan::initialize(); |
| 2068 |
$response = [ |
| 2069 |
'success' => true, |
| 2070 |
'scan_finished' => false, |
| 2071 |
'push' => 'success', |
| 2072 |
]; |
| 2073 |
} else { |
| 2074 |
$response = [ |
| 2075 |
'success' => false, |
| 2076 |
'scan_finished' => true, |
| 2077 |
'push' => 'fail', |
| 2078 |
'error' => 'Scan completed', |
| 2079 |
]; |
| 2080 |
} |
| 2081 |
|
| 2082 |
break; |
| 2083 |
} |
| 2084 |
|
| 2085 |
|
| 2086 |
wp_send_json($response ?? ['success' => false, 'error' => 'No action found']); |
| 2087 |
} |
| 2088 |
|
| 2089 |
/** |
| 2090 |
* Forced checking of services. |
| 2091 |
* |
| 2092 |
* @return void |
| 2093 |
*/ |
| 2094 |
public static function user_feedback() { |
| 2095 |
if (WebTotemRequest::post('ajax_action') !== 'user_feedback') { |
| 2096 |
return; |
| 2097 |
} |
| 2098 |
|
| 2099 |
$data = [ |
| 2100 |
'score' => (int)WebTotemRequest::post('score'), |
| 2101 |
'feedback' => WebTotemRequest::post('feedback') ?? "", |
| 2102 |
]; |
| 2103 |
|
| 2104 |
$response_data = WebTotemAPI::setFeedback($data); |
| 2105 |
if($response_data['message'] == 'Score added'){ |
| 2106 |
$response['content'] = '<div style="text-align: center;"><img src="'.WebTotem::getImagePath('').'popup_success_icon.svg" style="width: 85px;"><p class="user-feedback__title" style="margin-bottom: 20px">'.__('Thank you for feedback', 'wtotem').'</p><button id="user-feedback-ok" class="wtotem_control__btn">Okay</button></div>'; |
| 2107 |
$response['success'] = true; |
| 2108 |
WebTotemOption::setNotification('success', __('Your reply has been sent successfully.', 'wtotem')); |
| 2109 |
} else { |
| 2110 |
WebTotemOption::setNotification('error', __('There were difficulties. Your reply has not been sent.', 'wtotem')); |
| 2111 |
$response['success'] = false; |
| 2112 |
} |
| 2113 |
|
| 2114 |
$response['notifications'] = self::notifications(); |
| 2115 |
|
| 2116 |
wp_send_json($response); |
| 2117 |
} |
| 2118 |
|
| 2119 |
public static function update_plugin() { |
| 2120 |
|
| 2121 |
if (WebTotemRequest::post('ajax_action') !== 'update_plugin') { |
| 2122 |
return; |
| 2123 |
} |
| 2124 |
$plugin_slug = WebTotemRequest::post('slug'); |
| 2125 |
|
| 2126 |
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); |
| 2127 |
|
| 2128 |
$plugin = $plugin_slug . '/' . $plugin_slug . '.php'; |
| 2129 |
|
| 2130 |
$upgrader = new Plugin_Upgrader(); |
| 2131 |
$upgrader->upgrade($plugin); |
| 2132 |
|
| 2133 |
WebTotemOption::setNotification('success', __('The plugin has been updated', 'wtotem')); |
| 2134 |
die(); |
| 2135 |
} |
| 2136 |
|
| 2137 |
public static function after_plugin_update(){ |
| 2138 |
|
| 2139 |
if (WebTotemRequest::post('ajax_action') !== 'after_plugin_update') { |
| 2140 |
return; |
| 2141 |
} |
| 2142 |
$plugin_slug = WebTotemRequest::post('slug'); |
| 2143 |
|
| 2144 |
$plugin_info = WebTotem::get_plugin_info($plugin_slug); |
| 2145 |
|
| 2146 |
// if( WebTotem::updateCveDataByPluginName($plugin_info)){ |
| 2147 |
// |
| 2148 |
// $template = new WebTotemTemplate(); |
| 2149 |
// $plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => 1]); |
| 2150 |
// $response['content'] = $template->arrayRender([ |
| 2151 |
// 'variables' => [ |
| 2152 |
// "logs" => WebTotem::preparePluginsCveList($plugins_cve_list['data']), |
| 2153 |
// ], |
| 2154 |
// 'template' => 'scan_logs_cve', |
| 2155 |
// ]); |
| 2156 |
// $response['count'] = $plugins_cve_list['count']; |
| 2157 |
// $response['pagination'] = WebTotem::paginationBuild(8, $plugins_cve_list['count']); |
| 2158 |
// } |
| 2159 |
|
| 2160 |
$response['notifications'] = self::notifications(); |
| 2161 |
|
| 2162 |
wp_send_json($response); |
| 2163 |
} |
| 2164 |
|
| 2165 |
public static function authenticate() |
| 2166 |
{ |
| 2167 |
|
| 2168 |
if (WebTotemRequest::post('ajax_action') !== 'authenticate') { |
| 2169 |
return; |
| 2170 |
} |
| 2171 |
|
| 2172 |
$credentials = array( |
| 2173 |
'log' => 'pwd', |
| 2174 |
'username' => 'password' |
| 2175 |
); |
| 2176 |
$username = null; |
| 2177 |
$password = null; |
| 2178 |
foreach ($credentials as $usernameKey => $passwordKey) { |
| 2179 |
if (array_key_exists($usernameKey, $_POST) && |
| 2180 |
array_key_exists($passwordKey, $_POST) && |
| 2181 |
is_string($_POST[$usernameKey]) && |
| 2182 |
is_string($_POST[$passwordKey])) { |
| 2183 |
$username = $_POST[$usernameKey]; |
| 2184 |
$password = $_POST[$passwordKey]; |
| 2185 |
break; |
| 2186 |
} |
| 2187 |
} |
| 2188 |
if (empty($username) || empty($password)) { |
| 2189 |
$response['error'] = wp_kses(sprintf(__('<strong>ERROR</strong>: A username and password must be provided. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()), array('strong' => array(), 'a' => array('href' => array(), 'title' => array()))); |
| 2190 |
} |
| 2191 |
|
| 2192 |
do_action_ref_array('wp_authenticate', array(&$username, &$password)); |
| 2193 |
|
| 2194 |
$user = wp_authenticate($username, $password); |
| 2195 |
$user = WebTotemBFProtection::checkBruteForceAttempts($user, $username); |
| 2196 |
|
| 2197 |
if (is_object($user) && ($user instanceof \WP_User)) { |
| 2198 |
|
| 2199 |
$response['login'] = true; |
| 2200 |
|
| 2201 |
if (WebTotemLogin::hasUser2faActivated($user)) { |
| 2202 |
|
| 2203 |
$template = new WebTotemTemplate(); |
| 2204 |
|
| 2205 |
$response['2fa'] = true; |
| 2206 |
$response['content'] = $template->getHtml('login_auth_form'); |
| 2207 |
|
| 2208 |
} |
| 2209 |
} else if (is_wp_error($user)) { |
| 2210 |
$errors = array(); |
| 2211 |
foreach ($user->get_error_codes() as $code) { |
| 2212 |
if ($code == 'invalid_username' || $code == 'invalid_email' || $code == 'incorrect_password' || $code == 'authentication_failed') { |
| 2213 |
$errors[] = wp_kses(sprintf(__('<strong>ERROR</strong>: The username or password you entered is incorrect. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()), array('strong' => array(), 'a' => array('href' => array(), 'title' => array()))); |
| 2214 |
} else { |
| 2215 |
foreach ($user->get_error_messages($code) as $error_message) { |
| 2216 |
$errors[] = $error_message; |
| 2217 |
} |
| 2218 |
} |
| 2219 |
} |
| 2220 |
|
| 2221 |
if (!empty($errors)) { |
| 2222 |
$errors = implode('<br>', $errors); |
| 2223 |
$response['error'] = apply_filters('login_errors', $errors); |
| 2224 |
} |
| 2225 |
|
| 2226 |
} |
| 2227 |
|
| 2228 |
wp_send_json($response); |
| 2229 |
} |
| 2230 |
|
| 2231 |
/** |
| 2232 |
* Notification output. |
| 2233 |
* |
| 2234 |
* @return string |
| 2235 |
*/ |
| 2236 |
public static function notifications() |
| 2237 |
{ |
| 2238 |
|
| 2239 |
$notifications = WebTotem::getNotifications(); |
| 2240 |
|
| 2241 |
if ($notifications) { |
| 2242 |
$build[] = [ |
| 2243 |
'variables' => [ |
| 2244 |
'notifications' => $notifications, |
| 2245 |
], |
| 2246 |
|
| 2247 |
'template' => 'notifications', |
| 2248 |
]; |
| 2249 |
|
| 2250 |
$template = new WebTotemTemplate(); |
| 2251 |
return $template->arrayRender($build); |
| 2252 |
} |
| 2253 |
return false; |
| 2254 |
|
| 2255 |
} |
| 2256 |
|
| 2257 |
|
| 2258 |
} |
| 2259 |
|