Beispiel #1
0
function do_ping($wizard)
{
    $step = intval($wizard->get_step_data('scan_step'));
    if ($step == 0) {
        $nets = $wizard->get_step_data('scan_nets');
        if (count($nets) < 1) {
            $msg = _('Invalid networks selected to scan');
            set_scan_error_message($wizard, $msg);
            $response['error'] = TRUE;
            return $response;
        }
        $nets = implode(' ', $nets);
        $obj = new Scan($nets);
        // ping scan
        $obj->search_hosts();
        $wizard->set_step_data('scan_step', 1);
    } else {
        $obj = new Scan();
    }
    $data = array();
    $status = $obj->get_status();
    if ($status == 'Searching Hosts') {
        $data['finish'] = FALSE;
    } elseif ($status == 'Search Finished') {
        $total = $obj->get_num_of_hosts();
        if ($total == 0) {
            $next_step = 3;
            $obj->delete_data();
        } else {
            $res = $obj->launch_scan();
            if ($res === FALSE) {
                $msg = _('Impossible to launch NMAP scan');
                set_scan_error_message($wizard, $msg);
                $response['error'] = TRUE;
                return $response;
            }
            $next_step = 2;
        }
        $wizard->set_step_data('scan_hosts', $total);
        $wizard->set_step_data('scan_step', $next_step);
        $data['finish'] = TRUE;
    } else {
        $msg = _("Invalid NMAP status ({$status}). Expecting 'Searching Hosts' or 'Search Finished'");
        set_scan_error_message($wizard, $msg);
        $response['error'] = TRUE;
        return $response;
    }
    $response['error'] = FALSE;
    $response['data'] = $data;
    $wizard->save_status();
    return $response;
}