コード例 #1
0
ファイル: scan_ajax.php プロジェクト: jackpf/ossim-arc
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;
}
コード例 #2
0
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;
}