| @@ -17,32 +17,10 @@ | ||
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | 19 | function wtotem_ajax_callback() |
| 20 | 20 | { |
| 21 | - /** | |
| 22 | - * Actions that carry their own authorization. | |
| 23 | - * | |
| 24 | - * `two_factor_auth` is reachable from the user profile screen, where a user | |
| 25 | - * without `manage_options` manages their own second factor; the handler | |
| 26 | - * itself checks that the target user is the current one (or that the caller | |
| 27 | - * is an administrator). | |
| 28 | - */ | |
| 29 | - $self_authorizing_actions = ['two_factor_auth']; | |
| 30 | 21 | |
| 31 | - $post_action = WebTotemRequest::post('ajax_action'); | |
| 32 | - $get_action = WebTotemRequest::get('ajax_action'); | |
| 33 | - | |
| 34 | - // Everything this plugin exposes over AJAX belongs to its admin screens, | |
| 35 | - // which are registered with `manage_options`. A valid nonce proves the | |
| 36 | - // request came from our form; it says nothing about who sent it, so the | |
| 37 | - // capability has to be checked separately. | |
| 38 | - $is_privileged = current_user_can('manage_options'); | |
| 39 | - | |
| 40 | - if ($get_action != NULL) { | |
| 41 | - if (!$is_privileged) { | |
| 42 | - wtotem_ajax_forbidden(); | |
| 43 | - } | |
| 44 | - | |
| 22 | + if (WebTotemRequest::get('ajax_action') != NULL) { | |
| 45 | 23 | WebTotemAjax::wtotem_scan(); |
| 46 | 24 | } |
| 47 | 25 | |
| 48 | 26 | $composer_autoload = WEBTOTEM_PLUGIN_PATH . '/vendor/autoload.php'; |
| @@ -49,41 +27,38 @@ | ||
| 49 | 27 | if (file_exists($composer_autoload)) { |
| 50 | 28 | require_once $composer_autoload; |
| 51 | 29 | } |
| 52 | 30 | |
| 53 | - if ($post_action != NULL) { | |
| 31 | + if (WebTotemRequest::post('ajax_action') != NULL) { | |
| 54 | 32 | WebTotemAjax::authenticate(); |
| 55 | 33 | } |
| 56 | 34 | |
| 57 | - if ($post_action != NULL && WebTotemInterface::checkNonce()) { | |
| 35 | + if (WebTotemRequest::post('ajax_action') != NULL && WebTotemInterface::checkNonce()) { | |
| 58 | 36 | |
| 59 | - if (!$is_privileged && !in_array($post_action, $self_authorizing_actions, TRUE)) { | |
| 60 | - wtotem_ajax_forbidden(); | |
| 61 | - } | |
| 62 | - | |
| 63 | - if ($is_privileged) { | |
| 64 | - WebTotemAjax::activation(); | |
| 65 | - WebTotemAjax::agentsInstallation(); | |
| 66 | - WebTotemAjax::reinstallAgents(); | |
| 67 | - WebTotemAjax::chart(); | |
| 68 | - WebTotemAjax::logs(); | |
| 69 | - WebTotemAjax::wafDateFilter(); | |
| 70 | - WebTotemAjax::pagination(); | |
| 71 | - WebTotemAjax::antivirus(); | |
| 72 | - WebTotemAjax::changeThemeMode(); | |
| 73 | - WebTotemAjax::userTimeZone(); | |
| 74 | - WebTotemAjax::quarantine(); | |
| 75 | - WebTotemAjax::cashUpdate(); | |
| 76 | - WebTotemAjax::settings(); | |
| 77 | - WebTotemAjax::remove(); | |
| 78 | - WebTotemAjax::logout(); | |
| 79 | - WebTotemAjax::popup(); | |
| 80 | - WebTotemAjax::getWsTicket(); | |
| 81 | - WebTotemAjax::force_check(); | |
| 82 | - } | |
| 83 | - | |
| 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(); | |
| 84 | 56 | WebTotemAjax::twoFactorAuth(); |
| 85 | - | |
| 57 | + WebTotemAjax::force_check(); | |
| 58 | + WebTotemAjax::user_feedback(); | |
| 59 | + WebTotemAjax::update_plugin(); | |
| 60 | + WebTotemAjax::after_plugin_update(); | |
| 86 | 61 | } |
| 87 | 62 | |
| 88 | 63 | wp_send_json([ |
| 89 | 64 | 'success' => false, |
| @@ -92,21 +67,8 @@ | ||
| 92 | 67 | ], 200); |
| 93 | 68 | } |
| 94 | 69 | |
| 95 | 70 | /** |
| 96 | - * Ends an AJAX request that the current user is not allowed to make. | |
| 97 | - * | |
| 98 | - * @return void | |
| 99 | - */ | |
| 100 | -function wtotem_ajax_forbidden() | |
| 101 | -{ | |
| 102 | - wp_send_json([ | |
| 103 | - 'success' => false, | |
| 104 | - 'error' => 'forbidden', | |
| 105 | - ], 403); | |
| 106 | -} | |
| 107 | - | |
| 108 | -/** | |
| 109 | 71 | * Handles all the AJAX plugin's public requests. |
| 110 | 72 | * |
| 111 | 73 | * @return void |
| 112 | 74 | */ |
| @@ -180,9 +142,9 @@ | ||
| 180 | 142 | * @return void |
| 181 | 143 | */ |
| 182 | 144 | function wtotem_activation_page() |
| 183 | 145 | { |
| 184 | - $build[] = [ | |
| 146 | + $build[] = [ | |
| 185 | 147 | 'variables' => [ |
| 186 | 148 | 'notifications' => WebTotem::getNotifications(), |
| 187 | 149 | 'current_year' => date('Y'), |
| 188 | 150 | 'page' => 'activation', |
| @@ -194,8 +156,9 @@ | ||
| 194 | 156 | echo $template->arrayRender($build); |
| 195 | 157 | } |
| 196 | 158 | |
| 197 | 159 | |
| 160 | + | |
| 198 | 161 | /** |
| 199 | 162 | * All sites page. |
| 200 | 163 | * |
| 201 | 164 | * @return void |
| @@ -201,9 +164,9 @@ | ||
| 201 | 164 | * @return void |
| 202 | 165 | */ |
| 203 | 166 | function wtotem_all_sites_page() |
| 204 | 167 | { |
| 205 | - $allSites = WebTotemAPI::getSites(1, 1000000); | |
| 168 | + $allSites = WebTotemAPI::getSites(null, 1000000); | |
| 206 | 169 | |
| 207 | 170 | // Reset session data. |
| 208 | 171 | WebTotemOption::setSessionOptions([ |
| 209 | 172 | 'sites_cursor' => $allSites['pageInfo']['endCursor'], |
| @@ -230,9 +193,8 @@ | ||
| 230 | 193 | * @return void |
| 231 | 194 | */ |
| 232 | 195 | function wtotem_dashboard_page() |
| 233 | 196 | { |
| 234 | - | |
| 235 | 197 | if (WebTotemRequest::get('hid')) { |
| 236 | 198 | $host = WebTotemOption::getHost(WebTotemRequest::get('hid')); |
| 237 | 199 | } else { |
| 238 | 200 | $host = WebTotemAPI::siteInfo(); |
| @@ -243,38 +205,16 @@ | ||
| 243 | 205 | wtotem_error_page(); |
| 244 | 206 | exit(); |
| 245 | 207 | } |
| 246 | 208 | |
| 247 | - // Get monitoring data from WebTotem API. | |
| 248 | - if ($cacheData = WebTotemCache::getdata('getMonitoringData', $host['id'])) { | |
| 209 | + // Get data from WebTotem API. | |
| 210 | + if ($cacheData = WebTotemCache::getdata('getAllData', $host['id'])) { | |
| 249 | 211 | $data = $cacheData['data']; |
| 250 | 212 | } else { |
| 251 | - $data = WebTotemAPI::getMonitoringData($host['id']); | |
| 252 | - WebTotemCache::setData(['getMonitoringData' => $data], $host['id']); | |
| 213 | + $data = WebTotemAPI::getAllData($host['id']); | |
| 214 | + WebTotemCache::setData(['getAllData' => $data], $host['id']); | |
| 253 | 215 | } |
| 254 | 216 | |
| 255 | - if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) { | |
| 256 | - $firewall_data = $cacheData['data']; | |
| 257 | - } else { | |
| 258 | - $firewall_data = WebTotemAPI::getFirewall(10, 1, 7); | |
| 259 | - WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']); | |
| 260 | - } | |
| 261 | - | |
| 262 | - if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) { | |
| 263 | - $firewall_chart_data = $cacheData['data']; | |
| 264 | - } else { | |
| 265 | - $firewall_chart_data = WebTotemAPI::getFirewallStatistics(); | |
| 266 | - WebTotemCache::setData(['getFirewallStatistics' => $firewall_chart_data], $host['id']); | |
| 267 | - } | |
| 268 | - | |
| 269 | - if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) { | |
| 270 | - $agents_statuses_api = $cacheData['data']; | |
| 271 | - } else { | |
| 272 | - $agents_statuses_api = WebTotemAPI::getAgentsStatusesFromAPI(); | |
| 273 | - WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses_api], $host['id']); | |
| 274 | - } | |
| 275 | - | |
| 276 | - | |
| 277 | 217 | if (empty($data)) { |
| 278 | 218 | wtotem_error_page(); |
| 279 | 219 | exit(); |
| 280 | 220 | } |
| @@ -279,22 +219,22 @@ | ||
| 279 | 219 | exit(); |
| 280 | 220 | } |
| 281 | 221 | |
| 282 | 222 | // MultiSite page header (site name) |
| 283 | -// if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 284 | -// // Submenu block. | |
| 285 | -// $pages['dashboard'] = 'wtotem_page-header__link_active'; | |
| 286 | -// | |
| 287 | -// $build[] = [ | |
| 288 | -// 'variables' => [ | |
| 289 | -// 'is_active' => $pages, | |
| 290 | -// 'site_name' => $host['name'], | |
| 291 | -// 'hid' => $host['id'], | |
| 292 | -// ], | |
| 293 | -// 'template' => 'multisite_submenu', | |
| 294 | -// ]; | |
| 295 | -// } | |
| 223 | + if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 224 | + // Submenu block. | |
| 225 | + $pages['dashboard'] = 'wtotem_page-header__link_active'; | |
| 296 | 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 | + | |
| 297 | 237 | // Reset session data. |
| 298 | 238 | WebTotemOption::setSessionOptions([ |
| 299 | 239 | 'firewall_period' => NULL, |
| 300 | 240 | 'ram_period' => NULL, |
| @@ -301,30 +241,29 @@ | ||
| 301 | 241 | 'cpu_period' => NULL, |
| 302 | 242 | ]); |
| 303 | 243 | |
| 304 | 244 | // Scoring block. |
| 305 | -// $service_data = $data['scoring']['result']; | |
| 306 | -// $total_score = round($data['scoring']['score']); | |
| 307 | -// $score_grading = WebTotem::scoreGrading($total_score); | |
| 308 | -// $build[] = [ | |
| 309 | -// 'variables' => [ | |
| 310 | -// "host_id" => $host['id'], | |
| 311 | -// "total_score" => $total_score . "%", | |
| 312 | -// "tested_on" => WebTotem::dateFormatter($data['scoring']['lastTest']['time']), | |
| 313 | -// "server_ip" => $service_data['ip'] ?: ' - ', | |
| 314 | -// "location" => WebTotem::getCountryName($service_data['country']) ?: ' - ', | |
| 315 | -// "is_higher_than" => $service_data['isHigherThan'] . '%', | |
| 316 | -// "grade" => $score_grading['grade'], | |
| 317 | -// "color" => $score_grading['color'], | |
| 318 | -// ], | |
| 319 | -// 'template' => 'score', | |
| 320 | -// ]; | |
| 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 | + ]; | |
| 321 | 261 | |
| 322 | 262 | // Agents installing process. |
| 323 | - | |
| 324 | 263 | $agents_data = [ |
| 325 | - 'av' => $agents_statuses_api['av'] ?? '', | |
| 326 | - 'waf' => $agents_statuses_api['waf'] ?? '', | |
| 264 | + 'av' => $data['antivirus']['status'], | |
| 265 | + 'waf' => $data['firewall']['status'], | |
| 327 | 266 | ]; |
| 328 | 267 | |
| 329 | 268 | $agents_statuses = WebTotem::getAgentsStatuses($agents_data); |
| 330 | 269 | |
| @@ -330,10 +269,10 @@ | ||
| 330 | 269 | |
| 331 | 270 | if (!$agents_statuses['option_statuses']['av'] or !$agents_statuses['option_statuses']['waf']) { |
| 332 | 271 | |
| 333 | 272 | $status = [ |
| 334 | - 'av' => $agents_statuses['process_statuses']['av'] == 'available', | |
| 335 | - 'waf' => $agents_statuses['process_statuses']['waf'] == 'available', | |
| 273 | + 'av' => $agents_statuses['process_statuses']['av'] == 'installed', | |
| 274 | + 'waf' => $agents_statuses['process_statuses']['waf'] == 'installed', | |
| 336 | 275 | ]; |
| 337 | 276 | |
| 338 | 277 | WebTotemOption::setOptions([ |
| 339 | 278 | 'av_installed' => $status['av'], |
| @@ -347,10 +286,109 @@ | ||
| 347 | 286 | 'template' => 'agents', |
| 348 | 287 | ]; |
| 349 | 288 | } |
| 350 | 289 | |
| 290 | + // Firewall header. | |
| 291 | + $build[] = [ | |
| 292 | + 'variables' => [ | |
| 293 | + "title" => __('Firewall activity', 'wtotem'), | |
| 294 | + ], | |
| 295 | + 'template' => 'section_header', | |
| 296 | + ]; | |
| 351 | 297 | |
| 298 | + $is_period_available = WebTotem::isPeriodAvailable($data['agentManager']['createdAt']); | |
| 352 | 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 | + | |
| 353 | 391 | // Monitoring header. |
| 354 | 392 | $build[] = [ |
| 355 | 393 | 'variables' => [ |
| 356 | 394 | "title" => __('Monitoring', 'wtotem'), |
| @@ -358,57 +396,53 @@ | ||
| 358 | 396 | 'template' => 'section_header', |
| 359 | 397 | ]; |
| 360 | 398 | |
| 361 | 399 | $ssl = false; |
| 362 | - if ($data['module_ssl']) { | |
| 400 | + if ($data['sslResults']['results']) { | |
| 363 | 401 | $ssl = [ |
| 364 | - 'status' => WebTotem::getStatusData($data['module_ssl']['info']['status']), | |
| 365 | - 'cert_name' => $data['module_ssl']['result']['certificate_name'], | |
| 366 | - 'days_left' => $data['module_ssl']['result']['days_left'], | |
| 367 | - 'issue_date' => WebTotem::dateFormatter($data['module_ssl']['result']['issue_date']), | |
| 368 | - 'expiry_date' => WebTotem::dateFormatter($data['module_ssl']['result']['expiry_date']), | |
| 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']), | |
| 369 | 407 | ]; |
| 370 | 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 | + } | |
| 371 | 421 | |
| 372 | - $domain = [ | |
| 373 | - 'status' => WebTotem::getStatusData($data['module_location']['info']['status']), | |
| 374 | - "redirect_link" => $data['module_location']['result']['redirect_link'], | |
| 375 | - "is_created_at" => (bool)$data['module_location']['result']['checked_at'], | |
| 376 | - "created_at" => WebTotem::dateFormatter($data['module_location']['result']['checked_at']), | |
| 377 | - "is_taken" => $data['module_location']['result']['is_taken'], | |
| 378 | - "ips" => $data['module_location']['result']['locations'], | |
| 379 | - "protection" => $data['module_location']['result']['protection'], | |
| 380 | - ]; | |
| 381 | - | |
| 382 | 422 | // Monitoring blocks. |
| 383 | 423 | $build[] = [ |
| 384 | 424 | 'variables' => [ |
| 385 | - "host_id" => $host['id'], | |
| 386 | - 'ws_url' => WebTotemAPI::getWsUrl(), | |
| 387 | 425 | "ssl" => $ssl, |
| 388 | - "domain_module" => $domain, | |
| 426 | + "domain" => $domain, | |
| 389 | 427 | 'reputation' => [ |
| 390 | - "status" => WebTotem::getStatusData($data['module_reputation']['info']['status'] ?? ''), | |
| 391 | -// "blacklists_entries" => WebTotem::blacklistsEntries( | |
| 392 | -// $data['reputation']['status'] ?? '', | |
| 393 | -// $data['reputation']['antivirus'] ?? []), | |
| 394 | - "info" => WebTotem::getReputationInfo($data['reputation']['result']['status'] ?? ''), | |
| 395 | - "last_test" => WebTotem::dateFormatter($data['reputation']['result']['checked_at'] ?? ''), | |
| 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'] ?? ''), | |
| 396 | 434 | ], |
| 397 | - | |
| 398 | - 'availability' => [ | |
| 399 | - 'chart' => json_encode($data['module_availability']['result']['stats_by_day']), | |
| 400 | - 'status' => WebTotem::getStatusData($data['module_availability']['info']['status']) | |
| 401 | - ], | |
| 402 | 435 | ], |
| 403 | 436 | 'template' => 'monitoring', |
| 404 | 437 | ]; |
| 405 | 438 | |
| 439 | + $ports = WebTotemAPI::getAllPortsList($host['id']); | |
| 406 | 440 | $build[] = [ |
| 407 | 441 | 'variables' => [ |
| 408 | 442 | "ports" => [ |
| 409 | - "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []), | |
| 410 | - "ignorePorts" => [], | |
| 443 | + "TCPResults" => WebTotem::getOpenPortsData($ports['TCPResults']), | |
| 444 | + "ignorePorts" => $ports['ignorePorts'], | |
| 411 | 445 | ], |
| 412 | 446 | ], |
| 413 | 447 | 'template' => 'ports_form', |
| 414 | 448 | ]; |
| @@ -425,65 +459,24 @@ | ||
| 425 | 459 | // Scanning blocks. |
| 426 | 460 | $build[] = [ |
| 427 | 461 | 'variables' => [ |
| 428 | 462 | "ports" => [ |
| 429 | - 'status' => WebTotem::getStatusData($data['module_port_scanner']['info']['status'] ?? 'clean'), | |
| 430 | - "TCPResults" => WebTotem::getOpenPortsData($data['module_port_scanner']['result']['open_ports'] ?? []), | |
| 431 | - "ignore_ports" => [], | |
| 432 | - "last_test" => WebTotem::dateFormatter($data['module_port_scanner']['result']['checked_at'] ?? false), | |
| 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']), | |
| 433 | 467 | ], |
| 434 | 468 | "open_path" => [ |
| 435 | - 'status' => WebTotem::getStatusData($data['module_open_paths']['info']['status'] ), | |
| 436 | - "last_test" => WebTotem::dateFormatter($data['module_open_paths']['result']['checked_at'] ?? false), | |
| 437 | - "paths" => $data['module_open_paths']['result']['open_paths'] ?? [], | |
| 469 | + 'status' => WebTotem::getStatusData(($data['openPathSearch']['paths']) ? 'warning' : 'clean'), | |
| 470 | + "last_test" => WebTotem::dateFormatter($data['openPathSearch']['time']), | |
| 471 | + "paths" => $data['openPathSearch']['paths'], | |
| 438 | 472 | ], |
| 439 | 473 | ], |
| 440 | 474 | 'template' => 'scanning', |
| 441 | 475 | ]; |
| 442 | 476 | |
| 443 | - | |
| 444 | - // Firewall header. | |
| 445 | - $build[] = [ | |
| 446 | - 'variables' => [ | |
| 447 | - "title" => __('Firewall activity', 'wtotem'), | |
| 448 | - ], | |
| 449 | - 'template' => 'section_header', | |
| 450 | - ]; | |
| 451 | - | |
| 452 | - $is_period_available = WebTotem::isPeriodAvailable(); | |
| 453 | - | |
| 454 | - // Firewall stats. | |
| 455 | - $chart = WebTotem::generateWafChart($firewall_chart_data['signatures_statistic'] ?? []); | |
| 456 | - $build[] = [ | |
| 457 | - 'variables' => [ | |
| 458 | - "is_waf_training" => WebTotem::isWafTraining(), | |
| 459 | - "is_period_available" => $is_period_available, | |
| 460 | - "most_attacks" => WebTotem::getMostAttacksData($firewall_chart_data['countries_statistics'] ?? []), | |
| 461 | - ], | |
| 462 | - 'template' => 'firewall_stats', | |
| 463 | - ]; | |
| 464 | - | |
| 465 | - // Firewall filter form | |
| 466 | - $build[] = [ | |
| 467 | - 'variables' => [ | |
| 468 | - "is_period_available" => $is_period_available, | |
| 469 | - ], | |
| 470 | - 'template' => 'waf_filter_form', | |
| 471 | - ]; | |
| 472 | - | |
| 473 | - // Firewall blocks. | |
| 474 | - $build[] = [ | |
| 475 | - 'variables' => [ | |
| 476 | - "chart" => $chart['chart'], | |
| 477 | - "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []), | |
| 478 | - 'host_name' => $host['name'], | |
| 479 | - ], | |
| 480 | - 'template' => 'firewall', | |
| 481 | - ]; | |
| 482 | - | |
| 483 | 477 | $page_content = $template->arrayRender($build); |
| 484 | 478 | echo $template->baseTemplate($page_content); |
| 485 | - | |
| 486 | 479 | } |
| 487 | 480 | |
| 488 | 481 | /** Open paths page. |
| 489 | 482 | * |
| @@ -506,16 +499,15 @@ | ||
| 506 | 499 | // Get data from WebTotem API. |
| 507 | 500 | if ($cacheData = WebTotemCache::getdata('getOpenPaths', $host['id'])) { |
| 508 | 501 | $open_path = $cacheData['data']; |
| 509 | 502 | } else { |
| 510 | - $data = WebTotemAPI::getMonitoringData($host['id']); | |
| 511 | - $open_path = $data['module_open_paths']['result']['open_paths']; | |
| 512 | - WebTotemCache::setData(['getOpenPaths' => $open_path], $host['id']); | |
| 503 | + $open_path = WebTotemAPI::getOpenPaths($host['id']);; | |
| 504 | + WebTotemCache::setData(['getOpenPaths' => $open_path], $host['id'], 1); | |
| 513 | 505 | } |
| 514 | 506 | |
| 515 | 507 | $build[] = [ |
| 516 | 508 | 'variables' => [ |
| 517 | - "paths" => $open_path ?? [], | |
| 509 | + "paths" => $open_path['paths'], | |
| 518 | 510 | ], |
| 519 | 511 | 'template' => 'open_paths_page', |
| 520 | 512 | ]; |
| 521 | 513 | |
| @@ -542,20 +534,14 @@ | ||
| 542 | 534 | exit(); |
| 543 | 535 | } |
| 544 | 536 | |
| 545 | 537 | // Get data from WebTotem API. |
| 546 | - if ($cacheData = WebTotemCache::getdata('getFirewallStatistics', $host['id'])) { | |
| 538 | + if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) { | |
| 547 | 539 | $data = $cacheData['data']; |
| 548 | 540 | } else { |
| 549 | - $data = WebTotemAPI::getFirewallStatistics(); | |
| 550 | - WebTotemCache::setData(['getFirewallStatistics' => $data], $host['id']); | |
| 541 | + $data = WebTotemAPI::getFirewall($host['id'], 10, NULL, 7); | |
| 542 | + WebTotemCache::setData(['getFirewall' => $data], $host['id'], 1); | |
| 551 | 543 | } |
| 552 | - if ($cacheData = WebTotemCache::getdata('getFirewall', $host['id'])) { | |
| 553 | - $firewall_data = $cacheData['data']; | |
| 554 | - } else { | |
| 555 | - $firewall_data = WebTotemAPI::getFirewall(10, 1, 7); | |
| 556 | - WebTotemCache::setData(['getFirewall' => $firewall_data], $host['id']); | |
| 557 | - } | |
| 558 | 544 | |
| 559 | 545 | if (empty($data)) { |
| 560 | 546 | wtotem_error_page(); |
| 561 | 547 | exit(); |
| @@ -560,24 +546,32 @@ | ||
| 560 | 546 | wtotem_error_page(); |
| 561 | 547 | exit(); |
| 562 | 548 | } |
| 563 | 549 | |
| 550 | + $service_data = $data['firewall']; | |
| 564 | 551 | |
| 552 | + // Reset session data. | |
| 553 | + WebTotemOption::setSessionOptions([ | |
| 554 | + 'firewall_period' => NULL, | |
| 555 | + 'firewall_cursor' => $service_data['logs']['pageInfo']['endCursor'], | |
| 556 | + ]); | |
| 557 | + | |
| 565 | 558 | // MultiSite page header (site name) |
| 566 | -// if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 567 | -// // Submenu block. | |
| 568 | -// $pages['firewall'] = 'wtotem_page-header__link_active'; | |
| 569 | -// | |
| 570 | -// $build[] = [ | |
| 571 | -// 'variables' => [ | |
| 572 | -// 'is_active' => $pages, | |
| 573 | -// 'site_name' => $host['name'], | |
| 574 | -// 'hid' => $host['id'], | |
| 575 | -// ], | |
| 576 | -// 'template' => 'multisite_submenu', | |
| 577 | -// ]; | |
| 578 | -// } | |
| 559 | + if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 560 | + // Submenu block. | |
| 561 | + $pages['firewall'] = 'wtotem_page-header__link_active'; | |
| 579 | 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. | |
| 580 | 574 | // Firewall header. |
| 581 | 575 | $build[] = [ |
| 582 | 576 | 'variables' => [ |
| 583 | 577 | "title" => __('Firewall activity', 'wtotem'), |
| @@ -587,10 +581,10 @@ | ||
| 587 | 581 | |
| 588 | 582 | // Attacks map blocks. |
| 589 | 583 | // Get world_map json data |
| 590 | 584 | $world_map_json = WEBTOTEM_URL . '/includes/js/world_map.json'; |
| 591 | - $map_data = WebTotem::generateAttacksMapChart($data['countries_statistics'] ?? []); | |
| 592 | - $is_period_available = WebTotem::isPeriodAvailable(); | |
| 585 | + $map_data = WebTotem::generateAttacksMapChart($service_data['map']); | |
| 586 | + $is_period_available = WebTotem::isPeriodAvailable($data['agentManager']['createdAt']); | |
| 593 | 587 | |
| 594 | 588 | $build[] = [ |
| 595 | 589 | 'variables' => [ |
| 596 | 590 | "is_period_available" => $is_period_available, |
| @@ -600,16 +594,17 @@ | ||
| 600 | 594 | 'template' => 'attacks_map', |
| 601 | 595 | ]; |
| 602 | 596 | |
| 603 | 597 | // Firewall stats. |
| 598 | + $chart = WebTotem::generateWafChart($service_data['chart']); | |
| 604 | 599 | $build[] = [ |
| 605 | 600 | 'variables' => [ |
| 606 | - "is_waf_training" => WebTotem::isWafTraining(), | |
| 601 | + "is_waf_training" => isset($data['agentManager']['createdAt']) && WebTotem::isWafTraining($data['agentManager']['createdAt']), | |
| 607 | 602 | "is_period_available" => $is_period_available, |
| 608 | - "most_attacks" => WebTotem::getMostAttacksData($data['countries_statistics'] ?? []), | |
| 609 | -// "all_attacks" => $firewall_statistics_data['weekly_blocked_attacks'], | |
| 610 | -// "blocking" => $chart['count_blocks'], | |
| 611 | -// "not_blocking" => (int)$chart['count_attacks'] - (int)$chart['count_blocks'], | |
| 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']), | |
| 612 | 607 | ], |
| 613 | 608 | 'template' => 'firewall_stats', |
| 614 | 609 | ]; |
| 615 | 610 | |
| @@ -614,23 +609,19 @@ | ||
| 614 | 609 | ]; |
| 615 | 610 | |
| 616 | 611 | // Firewall filter form |
| 617 | 612 | $build[] = [ |
| 618 | - 'variables' => [ | |
| 619 | - "is_period_available" => $is_period_available, | |
| 620 | - ], | |
| 621 | 613 | 'template' => 'waf_filter_form', |
| 622 | 614 | ]; |
| 623 | 615 | |
| 624 | 616 | // Firewall blocks. |
| 625 | - $chart = WebTotem::generateWafChart($data['signatures_statistic'] ?? []); | |
| 626 | 617 | $build[] = [ |
| 627 | 618 | 'variables' => [ |
| 628 | - 'page' => 'firewall', | |
| 629 | 619 | "chart" => $chart['chart'], |
| 630 | - "logs" => WebTotem::wafLogs($firewall_data['logs'] ?? []), | |
| 620 | + "logs" => WebTotem::wafLogs($service_data['logs']['edges']), | |
| 621 | + 'has_next_page' => $service_data['logs']['pageInfo']['hasNextPage'], | |
| 631 | 622 | 'host_name' => $host['name'], |
| 632 | - "firewall_logs_pagination" => WebTotem::paginationBuild(10, $firewall_data['total']), | |
| 623 | + 'page' => 'firewall', | |
| 633 | 624 | ], |
| 634 | 625 | 'template' => 'firewall', |
| 635 | 626 | ]; |
| 636 | 627 | |
| @@ -653,32 +644,31 @@ | ||
| 653 | 644 | wtotem_error_page(); |
| 654 | 645 | exit(); |
| 655 | 646 | } |
| 656 | 647 | |
| 657 | - // Get data from WebTotem API. | |
| 658 | - if ($cacheData = WebTotemCache::getdata('getAntivirusHistory', $host['id'])) { | |
| 659 | - $antivirus_history_data = $cacheData['data']; | |
| 660 | - } else { | |
| 661 | - $antivirus_history_data = WebTotemAPI::getAntivirusHistory(); | |
| 662 | - WebTotemCache::setData(['getAntivirusHistory' => $antivirus_history_data], $host['id']); | |
| 648 | + if (WebTotem::isMultiSite() and !is_super_admin()) { | |
| 649 | + echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem')); | |
| 650 | + exit(); | |
| 663 | 651 | } |
| 664 | 652 | |
| 665 | - if ($cacheData = WebTotemCache::getdata('getAntivirusCurrentDetails', $host['id'])) { | |
| 666 | - $infected_files = $cacheData['data']; | |
| 667 | - } else { | |
| 668 | - $infected_files = WebTotemAPI::getAntivirusCurrentDetails(); | |
| 669 | - WebTotemCache::setData(['getAntivirusCurrentDetails' => $infected_files], $host['id']); | |
| 670 | - } | |
| 653 | + $params = [ | |
| 654 | + 'host_id' => $host['id'], | |
| 655 | + 'limit' => 10, | |
| 656 | + 'cursor' => NULL, | |
| 657 | + 'days' => 365, | |
| 658 | + 'event' => FALSE, | |
| 659 | + 'permissions' => FALSE, | |
| 660 | + ]; | |
| 671 | 661 | |
| 672 | - if ($cacheData = WebTotemCache::getdata('getQuarantineList', $host['id'])) { | |
| 673 | - $quarantine_files = $cacheData['data']; | |
| 662 | + // Get data from WebTotem API. | |
| 663 | + if ($cacheData = WebTotemCache::getdata('getAntivirus', $host['id'])) { | |
| 664 | + $data = $cacheData['data']; | |
| 674 | 665 | } else { |
| 675 | - $quarantine_files = WebTotemAPI::getQuarantineList(); | |
| 676 | - WebTotemCache::setData(['getQuarantineList' => $quarantine_files], $host['id']); | |
| 666 | + $data = WebTotemAPI::getAntivirus($params); | |
| 667 | + WebTotemCache::setData(['getAntivirus' => $data], $host['id']); | |
| 677 | 668 | } |
| 678 | 669 | |
| 679 | - | |
| 680 | - if (empty($antivirus_history_data)) { | |
| 670 | + if (empty($data)) { | |
| 681 | 671 | wtotem_error_page(); |
| 682 | 672 | exit(); |
| 683 | 673 | } |
| 684 | 674 | |
| @@ -685,11 +675,27 @@ | ||
| 685 | 675 | // Reset session data. |
| 686 | 676 | WebTotemOption::setSessionOptions([ |
| 687 | 677 | 'antivirus_event' => NULL, |
| 688 | 678 | 'antivirus_permissions' => NULL, |
| 689 | - 'antivirus_current_page' => 1, | |
| 679 | + 'antivirus_cursor' => $data['log']['pageInfo']['endCursor'], | |
| 690 | 680 | ]); |
| 691 | 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 | + | |
| 692 | 698 | // Antivirus header. |
| 693 | 699 | $build[] = [ |
| 694 | 700 | 'variables' => [ |
| 695 | 701 | "title" => __('Antivirus', 'wtotem'), |
| @@ -697,39 +703,46 @@ | ||
| 697 | 703 | 'template' => 'section_header', |
| 698 | 704 | ]; |
| 699 | 705 | |
| 700 | 706 | // Antivirus stats blocks. |
| 707 | + $stats = $data['stats']; | |
| 701 | 708 | $build[] = [ |
| 702 | 709 | 'variables' => [ |
| 703 | - 'ws_url' => WebTotemAPI::getWsUrl(), | |
| 704 | - 'config_id' => WebTotemOption::getOption('config_id'), | |
| 710 | + 'changes' => $stats['changed'] ?: 0, | |
| 711 | + 'scanned' => $stats['scanned'] ?: 0, | |
| 712 | + 'deleted' => $stats['deleted'] ?: 0, | |
| 713 | + 'infected' => $stats["infected"] ?: 0, | |
| 705 | 714 | 'page' => 'antivirus', |
| 706 | 715 | ], |
| 707 | 716 | 'template' => 'antivirus_stats', |
| 708 | 717 | ]; |
| 709 | 718 | |
| 710 | - // Quarantine and infected files logs blocks. | |
| 719 | + // Quarantine logs blocks. | |
| 720 | + $quarantine_logs = $data['quarantine'] ?: []; | |
| 721 | + $quarantine_count = count($quarantine_logs); | |
| 711 | 722 | |
| 712 | - | |
| 713 | 723 | $build[] = [ |
| 714 | 724 | 'variables' => [ |
| 715 | - "infected_files" => WebTotem::getInfectedFilesData($infected_files['current_infected_files'] ?? []), | |
| 716 | - "infected_files_pagination" => WebTotem::paginationBuild(5, (int)$infected_files['total']), | |
| 717 | - 'infected_files_total' => (int)$infected_files['total'], | |
| 718 | - "quarantine_files" => WebTotem::getQuarantineListData($quarantine_files['quarantine_files'] ?? []), | |
| 719 | - "quarantine_files_pagination" => WebTotem::paginationBuild(5, (int)$quarantine_files['total']), | |
| 720 | - 'quarantine_files_total' => (int)$quarantine_files['total'], | |
| 725 | + "logs" => WebTotem::getQuarantineLogs($quarantine_logs) ?: [], | |
| 726 | + "count" => $quarantine_count, | |
| 721 | 727 | ], |
| 722 | 728 | 'template' => 'quarantine', |
| 723 | 729 | ]; |
| 724 | 730 | |
| 725 | - // History blocks. | |
| 731 | + // Antivirus filter form. | |
| 726 | 732 | $build[] = [ |
| 733 | + 'template' => 'antivirus_filter_form', | |
| 734 | + ]; | |
| 735 | + | |
| 736 | + // Antivirus blocks. | |
| 737 | + $build[] = [ | |
| 727 | 738 | 'variables' => [ |
| 728 | - "logs" => WebTotem::getAntivirusLogsData($antivirus_history_data['history']), | |
| 729 | - "antivirus_history_pagination" => WebTotem::paginationBuild(10, (int)$antivirus_history_data['total']), | |
| 739 | + "logs" => WebTotem::getAntivirusLogs($data['log']['edges']), | |
| 740 | + "has_next_page" => $data['log']['pageInfo']['hasNextPage'], | |
| 741 | + 'last_scan' => WebTotem::dateFormatter($data['lastTest']['time']), | |
| 730 | 742 | ], |
| 731 | - 'template' => 'antivirus_history', | |
| 743 | + | |
| 744 | + 'template' => 'antivirus', | |
| 732 | 745 | ]; |
| 733 | 746 | |
| 734 | 747 | $page_content = $template->arrayRender($build); |
| 735 | 748 | echo $template->baseTemplate($page_content); |
| @@ -749,82 +762,89 @@ | ||
| 749 | 762 | wtotem_error_page(); |
| 750 | 763 | exit(); |
| 751 | 764 | } |
| 752 | 765 | |
| 753 | -// if (WebTotem::isMultiSite() and !is_super_admin()) { | |
| 754 | -// echo $template->baseTemplate(__('Sorry, you are not allowed to view this page.', 'wtotem')); | |
| 755 | -// exit(); | |
| 756 | -// } | |
| 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 | + } | |
| 757 | 770 | |
| 758 | 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 | + } | |
| 759 | 778 | |
| 760 | 779 | if ($cacheData = WebTotemCache::getdata('getAgentsStatusesFromAPI', $host['id'])) { |
| 761 | 780 | $agents_statuses = $cacheData['data']; |
| 762 | 781 | } else { |
| 763 | - $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI(); | |
| 782 | + $agents_statuses = WebTotemAPI::getAgentsStatusesFromAPI($host['id']); | |
| 764 | 783 | WebTotemCache::setData(['getAgentsStatusesFromAPI' => $agents_statuses], $host['id']); |
| 765 | 784 | } |
| 766 | 785 | |
| 767 | - if ($cacheData = WebTotemCache::getdata('getFirewallSettings', $host['id'])) { | |
| 768 | - $waf_settings = $cacheData['data']; | |
| 786 | + if ($cacheData = WebTotemCache::getdata('getIpLists', $host['id'])) { | |
| 787 | + $ip_list = $cacheData['data']; | |
| 769 | 788 | } else { |
| 770 | - $waf_settings = WebTotemAPI::getFirewallSettings(); | |
| 771 | - WebTotemCache::setData(['getFirewallSettings' => $waf_settings], $host['id']); | |
| 789 | + $ip_list = WebTotemAPI::getIpLists($host['id']); | |
| 790 | + WebTotemCache::setData(['getIpLists' => $ip_list], $host['id']); | |
| 772 | 791 | } |
| 773 | 792 | |
| 774 | - if ($cacheData = WebTotemCache::getdata('getIpLists_whitelist', $host['id'])) { | |
| 775 | - $ip_whiteList = $cacheData['data']; | |
| 793 | + if ($cacheData = WebTotemCache::getdata('getAllowUrlList', $host['id'])) { | |
| 794 | + $url_list = $cacheData['data']; | |
| 776 | 795 | } else { |
| 777 | - $ip_whiteList = WebTotemAPI::getIpLists('whitelist'); | |
| 778 | - WebTotemCache::setData(['getIpLists_whitelist' => $ip_whiteList], $host['id']); | |
| 796 | + $url_list = WebTotemAPI::getAllowUrlList($host['id']) ?: []; | |
| 797 | + WebTotemCache::setData(['getAllowUrlList' => $url_list], $host['id']); | |
| 779 | 798 | } |
| 780 | - if ($cacheData = WebTotemCache::getdata('getIpLists_blacklist', $host['id'])) { | |
| 781 | - $ip_blackList = $cacheData['data']; | |
| 799 | + | |
| 800 | + if ($cacheData = WebTotemCache::getdata('getBlockedCountries', $host['id'])) { | |
| 801 | + $waf_data = $cacheData['data']; | |
| 782 | 802 | } else { |
| 783 | - $ip_blackList = WebTotemAPI::getIpLists(); | |
| 784 | - WebTotemCache::setData(['getIpLists_blacklist' => $ip_blackList], $host['id']); | |
| 803 | + $waf_data = WebTotemAPI::getBlockedCountries($host['id']); | |
| 804 | + WebTotemCache::setData(['getBlockedCountries' => $waf_data], $host['id']); | |
| 785 | 805 | } |
| 786 | - if ($cacheData = WebTotemCache::getdata('getIpLists_checklist', $host['id'])) { | |
| 787 | - $ip_checklist = $cacheData['data']; | |
| 788 | - } else { | |
| 789 | - $ip_checklist = WebTotemAPI::getIpLists('checklist'); | |
| 790 | - WebTotemCache::setData(['getIpLists_checklist' => $ip_checklist], $host['id']); | |
| 791 | - } | |
| 792 | 806 | |
| 793 | - if (empty($agents_statuses) ) { | |
| 807 | + if (empty($configs_data) or | |
| 808 | + empty($agents_statuses) or | |
| 809 | + empty($ip_list) | |
| 810 | + ) { | |
| 794 | 811 | wtotem_error_page(); |
| 795 | 812 | exit(); |
| 796 | 813 | } |
| 797 | 814 | |
| 798 | 815 | // MultiSite page header (site name) |
| 799 | -// if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 800 | -// // Submenu block. | |
| 801 | -// | |
| 802 | -// $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid')); | |
| 803 | -// $pages['settings'] = 'wtotem_page-header__link_active'; | |
| 804 | -// | |
| 805 | -// $build[] = [ | |
| 806 | -// 'variables' => [ | |
| 807 | -// 'is_active' => $pages, | |
| 808 | -// 'site_name' => $host_['name'], | |
| 809 | -// 'hid' => $host_['id'], | |
| 810 | -// ], | |
| 811 | -// 'template' => 'multisite_submenu', | |
| 812 | -// ]; | |
| 813 | -// } | |
| 816 | + if (WebTotem::isMultiSite() and is_super_admin()) { | |
| 817 | + // Submenu block. | |
| 814 | 818 | |
| 819 | + $host_ = WebTotemOption::getHost(WebTotemRequest::get('hid')); | |
| 820 | + $pages['settings'] = 'wtotem_page-header__link_active'; | |
| 815 | 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 | + | |
| 816 | 833 | // Settings form. |
| 817 | 834 | $build[] = [ |
| 818 | 835 | 'variables' => [ |
| 819 | - 'deny_list' => WebTotem::getIpList($ip_blackList, 'ip_deny'), | |
| 820 | - 'allow_list' => WebTotem::getIpList($ip_whiteList, 'ip_allow'), | |
| 821 | - 'url_list' => WebTotem::getIpList($ip_checklist, 'allow_url'), | |
| 822 | - 'av_status' => WebTotem::getStatusData($agents_statuses['av']), | |
| 823 | - 'waf_status' => WebTotem::getStatusData($agents_statuses['waf']), | |
| 824 | - 'waf_settings' => WebTotem::getWafSettingData($waf_settings), | |
| 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']), | |
| 825 | 843 | 'plugin_settings' => WebTotem::getPluginSettingsData(), |
| 826 | 844 | 'two_factor' => WebTotemLogin::getTwoFactorData(), |
| 845 | + 'blocked_countries_list' => json_encode($waf_data['blockedCountries']), | |
| 846 | + 'mock_attacks' => json_encode(WebTotem::getTreeMostAttacksData($waf_data['map'])), | |
| 827 | 847 | ], |
| 828 | 848 | |
| 829 | 849 | 'template' => 'settings_form', |
| 830 | 850 | ]; |
| @@ -833,8 +853,78 @@ | ||
| 833 | 853 | echo $template->baseTemplate($page_content); |
| 834 | 854 | } |
| 835 | 855 | |
| 836 | 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 | +/** | |
| 837 | 927 | * Scan WP page. |
| 838 | 928 | * |
| 839 | 929 | * @return void |
| 840 | 930 | */ |
| @@ -846,11 +936,11 @@ | ||
| 846 | 936 | $links = WebTotemDB::getRows(['AND', ['data_type' => 'links']], 'scan_logs', 'content'); |
| 847 | 937 | $scripts = WebTotemDB::getRows(['AND', ['data_type' => 'scripts']], 'scan_logs', 'content'); |
| 848 | 938 | $iframes = WebTotemDB::getRows(['AND', ['data_type' => 'iframes']], 'scan_logs', 'content'); |
| 849 | 939 | |
| 850 | -// $plugins_cve_list = WebTotemDB::getRows([], 'plugins_cve_list', false, ['limit' => 8, 'page' => 1]); | |
| 851 | -// require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 852 | -// $have_all_plugins_auto_update = count(get_plugins() ?: []) == count(get_site_option( 'auto_update_plugins' ) ?: []); | |
| 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' ) ?: []); | |
| 853 | 943 | |
| 854 | 944 | $events = [ |
| 855 | 945 | 'User authentication succeeded', |
| 856 | 946 | 'User authentication failed', |
| @@ -917,12 +1007,12 @@ | ||
| 917 | 1007 | "iframes_count" => $iframes['count'], |
| 918 | 1008 | "iframes" => WebTotem::prepareLinksData($iframes['data']), |
| 919 | 1009 | "iframes_pagination" => WebTotem::paginationBuild(10, $iframes['count']), |
| 920 | 1010 | |
| 921 | -// "plugins_cve_list_count" => $plugins_cve_list['count'], | |
| 922 | -// "plugins_cve_list" => WebTotem::preparePluginsCveList($plugins_cve_list['data']), | |
| 923 | -// "plugins_cve_list_pagination" => WebTotem::paginationBuild(8, $plugins_cve_list['count']), | |
| 924 | -// "have_all_plugins_auto_update" => $have_all_plugins_auto_update, | |
| 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, | |
| 925 | 1015 | |
| 926 | 1016 | "next_scan" => sprintf(__('%dh %dm', 'wtotem'), $hr, $min), |
| 927 | 1017 | "scan_init" => WebTotemOption::getOption('scan_init') ?: 0, |
| 928 | 1018 | ], |