function check_deploy_status($conn, $wizard)
{
    $data = array();
    $os = $wizard->get_step_data('deploy_os');
    //Linux Deployment Status --> Apply Configuration
    if ($os == 'linux') {
        $sensor_id = get_sensor_id();
        $error_apply = FALSE;
        try {
            list($agentless_list, $al_total) = Ossec_agentless::get_list($conn, $sensor_id, ' AND status = 1');
            if ($al_total > 0) {
                Ossec_agentless::save_in_config($conn, $sensor_id, $agentless_list);
            }
            //Enabling agentless
            Ossec_control::execute_action($sensor_id, 'enable_al');
            //Restarting ossec
            Ossec_control::execute_action($sensor_id, 'restart');
            // Delete "/var/tmp/.reload_<sensor_id>" file in order to hide the "Apply Changes" button
            @unlink('/var/tmp/.reload_' . $sensor_id);
        } catch (Exception $e) {
            $error_apply = $e->getMessage();
        }
        //If there was an error applying the configuration we show the error
        if ($error_apply !== FALSE) {
            $error_apply_msg = _('Error Applying Agentless Configuration');
            set_scan_error_message($wizard, $error_apply_msg);
            Av_exception::write_log(Av_exception::USER_ERROR, $error_apply);
            $response['error'] = TRUE;
            return $response;
        }
        //If everything was right, the percent is 100% and the remaining is 0
        $data['finish'] = TRUE;
        $data['percent'] = 100;
        $data['remaining'] = 0;
        //Setting the deployment status to 3 --> Finished
        $wizard->set_step_data('deploy_step', 3);
    } elseif ($os == 'windows') {
        $jobs = $wizard->get_step_data('deploy_jobs');
        //If the array of jobs IDs is empty, we are finished
        if (!is_array($jobs) || count($jobs) == 0) {
            $data['finish'] = TRUE;
            $data['percent'] = 100;
            $data['remaining'] = 0;
            //Setting the deployment status to 3 --> Finished
            $wizard->set_step_data('deploy_step', 3);
        } else {
            $succes = 0;
            //Going through the jobs
            foreach ($jobs as $id => $job) {
                try {
                    //Getting the status of the job
                    $state = Welcome_wizard::current_jobs($job['job_id']);
                    if ($state['job_status'] == 'task-succeeded') {
                        //If it is success, we count it and we delete it from the jobs array
                        if ($state['job_result'][0] === TRUE) {
                            unset($jobs[$id]);
                            $succes++;
                        } elseif ($state['job_result'][0] === FALSE) {
                            unset($jobs[$id]);
                            Av_exception::write_log(Av_exception::USER_ERROR, $job['agent'] . ': ' . $state['job_result'][1]);
                        }
                    } elseif ($state['job_status'] == 'task-failed' || $state['job_status'] == 'task-revoked') {
                        unset($jobs[$id]);
                        $_msg = $job['agent'] . ': ' . _("Couldn't complete windows OSSEC agent deploy: ") . $state['job_status'];
                        Av_exception::write_log(Av_exception::USER_ERROR, $_msg);
                    }
                } catch (Exception $e) {
                    //In case of critical error we delete from the array to avoid loops
                    unset($jobs[$id]);
                    Av_exception::write_log(Av_exception::USER_ERROR, $job['agent'] . ': ' . $e->getMessage());
                }
            }
            //IF after checking the status, the array is empty, we are finished
            if (!is_array($jobs) || count($jobs) == 0) {
                $data['finish'] = TRUE;
                $data['percent'] = 100;
                $data['remaining'] = 0;
                //Setting the deployment status to 3 --> Finished
                $wizard->set_step_data('deploy_step', 3);
            } else {
                //Total number of host that were selected to be deployed
                $total = $wizard->get_step_data('deploy_total_ips');
                $total = $total < 1 ? 1 : $total;
                //Number of host left to be deployed --> Pending jobs
                $current = count($jobs);
                //Percentage of the remaining hosts
                $pending = $total - $current;
                $percent = round(100 * ($pending / $total));
                $data['finish'] = FALSE;
                $data['percent'] = $percent;
                $data['remaining'] = $current;
            }
            //Updating the number of host successfully deployed
            $deployed = $wizard->get_step_data('deploy_success');
            $deployed += $succes;
            $wizard->set_step_data('deploy_success', $deployed);
            //Updating the array of jobs left
            $wizard->set_step_data('deploy_jobs', $jobs);
        }
    }
    //Saving wizard status
    $wizard->save_status();
    $response['error'] = FALSE;
    $response['data'] = $data;
    return $response;
}
    $db->close();
    echo "<rows>\n<page>1</page>\n<total>0</total>\n</rows>\n";
    exit;
}
$sensor = escape_sql($sensor, $conn);
$sortname = !empty($sortname) ? $sortname : "hostname";
$sortname = $sortname == 'ip' ? "INET_ATON(ip)" : $sortname;
$sortorder = !empty($sortorder) && strtolower($sortorder) == 'desc' ? 'DESC' : 'ASC';
$order = $sortname . " " . $sortorder;
$start = ($page - 1) * $rp;
$limit = "LIMIT {$start}, {$rp}";
/* Storing the sensor in session to remember the selection in the sensor combo */
$_SESSION['ossec_sensor'] = $sensor;
Ossec_agentless::syncronize_ossec_agentless($conn, $sensor);
$extra = !empty($where) ? $where . " ORDER BY {$order} {$limit}" : " ORDER BY {$order} {$limit}";
list($agentless_list, $total) = Ossec_agentless::get_list($conn, $sensor, $extra);
$xml = "<rows>\n";
$xml .= "<page>{$page}</page>\n";
$xml .= "<total>{$total}</total>\n";
foreach ($agentless_list as $agentless) {
    $ip = $agentless->get_ip();
    $hostname = "<a style='font-weight:bold;' href='data/agentless/al_modifyform.php?sensor={$sensor}&ip=" . urlencode($ip) . "'>" . $agentless->get_hostname() . "</a>";
    $user = $agentless->get_user();
    $status = $agentless->get_status();
    if ($status == 0) {
        $status = "<img src='" . OSSIM_IMG_PATH . "/tables/cross.png' alt='" . _('Disabled') . "' title='" . _('Disabled') . "'/>";
    } else {
        if ($status == 1) {
            $status = "<img src='" . OSSIM_IMG_PATH . "/tables/exclamation.png' alt='" . _('Modified') . "' title='" . _('Not configured') . "'/>";
        } else {
            $status = "<img src='" . OSSIM_IMG_PATH . "/tables/tick.png' alt='" . _('Enabled') . "' title='" . _('Enabled') . "'/>";
Beispiel #3
0
$token = POST('token');
ossim_valid($sensor_id, OSS_HEX, 'illegal:' . _('Sensor'));
if (ossim_error()) {
    $txt_error = ossim_get_error_clean();
} else {
    if (!Token::verify('tk_al_apply_conf', $token)) {
        $txt_error = Token::create_error_message();
    } else {
        if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) {
            $txt_error = _('Error! Sensor not allowed');
        }
    }
}
if (empty($txt_error)) {
    try {
        list($agentless_list, $al_total) = Ossec_agentless::get_list($conn, $sensor_id, ' AND status = 1');
        //If we have agentless to modify
        if ($al_total > 0) {
            Ossec_agentless::save_in_config($conn, $sensor_id, $agentless_list);
        }
        //Enabling agentless
        Ossec_control::execute_action($sensor_id, 'enable_al');
        //Restarting ossec
        Ossec_control::execute_action($sensor_id, 'restart');
        $data['status'] = 'success';
        $data['data'] = _('Configuration applied successfully');
        // Delete "/var/tmp/.reload_<sensor_id>" file in order to hide the "Apply Changes" button
        @unlink('/var/tmp/.reload_' . $sensor_id);
    } catch (Exception $e) {
        $data['status'] = 'error';
        $data['data'] = $e->getMessage();