function check_scan_progress($conn, $wizard) { //File to cache scan object $user = Session::get_session_user(); $scan_file = 'w_last_asset_object-' . md5($user); $data = array(); try { $obj = Av_scan::get_object_from_file($scan_file); //Get status $aux_status = $obj->get_status(); $status = $aux_status['status']['code']; if ($status == Av_scan::ST_SCAN_FINISHED) { //Scanning has finished properly $info = array(); $scan_report = $obj->download_scan_report(); //Delete scan $obj->delete_scan(); Cache_file::remove_file($scan_file); //Parsing scan report $nmap_parser = new Nmap_parser(); $scan_report = $nmap_parser->parse_json($scan_report, $obj->get_sensor()); // Add summary $scan_report['nmap_data']['elapsed'] = $aux_status['elapsed_time']; $info = Welcome_wizard::format_result_scan($conn, $scan_report); $wizard->set_step_data('scan_step', 3); $wizard->set_step_data('scan_info', $info); $data['finish'] = TRUE; } else { $percent = $aux_status['scanned_targets'] / $aux_status['number_of_targets'] * 100; $data['finish'] = FALSE; $data['percent'] = round($percent); $data['current'] = $aux_status['scanned_targets']; $data['total'] = $aux_status['number_of_targets']; if ($aux_status['remaining_time'] == -1) { $data['time'] = _('Calculating Remaining Time'); } else { $data['time'] = Welcome_wizard::format_time($aux_status['remaining_time']) . ' ' . _('remaining'); } } $response['error'] = FALSE; $response['data'] = $data; $wizard->save_status(); } catch (Exception $e) { $msg = _('Error! Asset scan cannot be completed. Please try again'); set_scan_error_message($wizard, $msg); $response['error'] = TRUE; } return $response; }
function check_scan_progress($conn, $wizard) { $data = array(); $obj = new Scan(); $status = $obj->get_status(); //Get status if ($status == 'Scan Finished') { $info = array(); $result = $obj->get_results(); $obj->delete_data(); $info = Welcome_wizard::format_result_scan($conn, $result); $wizard->set_step_data('scan_step', 3); $wizard->set_step_data('scan_info', $info); $data['finish'] = TRUE; } elseif ($status == 'Scanning Hosts') { $progress = $obj->get_progress(); $percent = $progress['hosts_scanned'] / $progress['total_hosts'] * 100; $data['finish'] = FALSE; $data['percent'] = round($percent); $data['current'] = $progress['hosts_scanned']; $data['total'] = $progress['total_hosts']; if ($progress['remaining'] == -1) { $data['time'] = _('Calculating Remaining Time'); } else { $data['time'] = Welcome_wizard::format_time($progress['remaining']) . ' ' . _('remaining'); } } else { $msg = _("Invalid NMAP status ({$status}). Expecting 'Scanning Hosts' or 'Scan Finished'"); set_scan_error_message($wizard, $msg); $response['error'] = TRUE; return $response; } $response['error'] = FALSE; $response['data'] = $data; $wizard->save_status(); return $response; }
$task = _('Scan Finished'); } } } } } if ($data['state'] != 'launching_local_scan') { $data['message'] = sprintf(_('%s: <strong>%s</strong> with local sensor, please wait...'), $task, $sc_asset); $progress = $obj->get_progress(); $data['progress']['percent'] = round($progress['hosts_scanned'] / $progress['total_hosts'] * 100); $data['progress']['current'] = $progress['hosts_scanned']; $data['progress']['total'] = $progress['total_hosts']; if ($progress['remaining'] == -1) { $data['progress']['time'] = _('Calculating Remaining Time'); } else { $data['progress']['time'] = Welcome_wizard::format_time($progress['remaining']) . ' ' . _('remaining'); } } else { $data['message'] = NULL; $data['progress'] = NULL; $data['debug_info'] = NULL; } $data['debug_info'] = NULL; } } } else { $scan = new Scan(); if (preg_match('/finished/i', $scan->get_status())) { $lastscan = $scan->get_results(); $debug_info = ''; if (is_array($lastscan['nmap_data']) && !empty($lastscan['nmap_data'])) {
$targets = $av_scan->get_targets('scan_format'); $targets_txt = Av_scan::targets_to_string($targets); //Database connection list($db, $conn) = Ossim_db::get_conn_db(); $sensor = Av_sensor::get_object($conn, $av_scan->get_sensor()); $sensor_txt = $sensor->get_name() . ' [' . $sensor->get_ip() . ']'; $db->close(); $scan_status['message'] = sprintf(_('Scanning target/s: <strong>%s</strong> with sensor <strong>%s</strong>, please wait...'), $targets_txt, $sensor_txt); $scan_status['status'] = $status['status']; $scan_status['progress']['percent'] = round($status['scanned_targets'] / $status['number_of_targets'] * 100); $scan_status['progress']['current'] = $status['scanned_targets']; $scan_status['progress']['total'] = $status['number_of_targets']; if (intval($status['remaining_time']) < 0) { $scan_status['progress']['time'] = _('Calculating Remaining Time'); } else { $scan_status['progress']['time'] = Welcome_wizard::format_time($status['remaining_time']) . ' ' . _('remaining'); } } $data['status'] = 'success'; $data['data'] = $scan_status; break; case 'show_scan_report': if (file_exists($scan_report_file)) { require_once 'scan_util.php'; $scan_report = file_get_contents($scan_report_file); $scan_report = unserialize($scan_report); $data['status'] = 'success'; $data['data'] = NULL; if (!empty($scan_report['scanned_ips'])) { ob_start(); //Database connection