Esempio n. 1
0
        $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 {
        $agentless = Ossec_agentless::get_object($conn, $sensor_id, $ip);
        if (is_object($agentless) && !empty($agentless)) {
            if ($agentless->get_status() != 0) {
                Ossec_agentless::delete_from_config($sensor_id, $ip);
                $agentless->set_status($conn, 0);
            } else {
                Ossec_agentless::save_in_config($conn, $sensor_id, array($agentless));
            }
        } else {
            $txt_error = _('Agentless not found');
        }
    } catch (Exception $e) {
        $txt_error = $e->getMessage();
    }
}
$db->close();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title> <?php 
Esempio n. 2
0
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;
}
Esempio n. 3
0
    $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();
    }
} else {
    $data['status'] = 'error';