function deploy_agents($conn, $wizard)
{
    //Aux variable that is returned
    $data = array();
    //If we have already initialized the deploy, we return true to check the status
    $started = $wizard->get_step_data('deploy_initialized');
    if ($started === TRUE) {
        $response['error'] = FALSE;
        $response['data'] = $data;
        return $response;
    }
    //Retrieving the params
    $os = $wizard->get_step_data('deploy_os');
    $username = $wizard->get_step_data('deploy_username');
    $domain = $wizard->get_step_data('deploy_domain');
    //Getting the array of hosts
    $hosts = $wizard->get_step_data('deploy_hosts');
    $hosts = is_array($hosts) ? $hosts : array();
    //Getting the password and decrypting
    $password = $wizard->get_step_data('deploy_password');
    $password = Util::decrypt($password, Util::get_system_uuid());
    $total_ip = 0;
    //Performing linux deployment --> Agentless
    if ($os == 'linux') {
        $sensor_id = get_sensor_id();
        $deploy = 0;
        //Num of successful deployments --> Initially 0
        //Arguments for the agentless entries
        $arguments = '/etc /usr/bin /usr/sbin /bin /sbin';
        foreach ($hosts as $h) {
            $ips = Asset_host_ips::get_ips_to_string($conn, $h);
            $ips = explode(',', $ips);
            $hostname = Asset_host::get_name_by_id($conn, $h);
            foreach ($ips as $ip) {
                try {
                    //Adding Aggentless
                    Ossec_agentless::save_in_db($conn, $ip, $sensor_id, $hostname, $username, $password, '', FALSE, '');
                    //Adding Aggentless Entries
                    Ossec_agentless::add_monitoring_entry($conn, $ip, $sensor_id, 'ssh_integrity_check_bsd', 3600, 'periodic', $arguments);
                    Ossec_agentless::add_monitoring_entry($conn, $ip, $sensor_id, 'ssh_integrity_check_linux', 3600, 'periodic', $arguments);
                    $deploy++;
                } catch (Exception $e) {
                    Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage());
                }
                $total_ip++;
            }
        }
        //Saving the number of the successful deployments
        $wizard->set_step_data('deploy_success', $deploy);
    } elseif ($os == 'windows') {
        $jobs = array();
        foreach ($hosts as $h) {
            $ips = Asset_host_ips::get_ips_to_string($conn, $h);
            $ips = explode(',', $ips);
            foreach ($ips as $ip) {
                try {
                    //Adding job to deploy ossec.
                    $name = 'Windows-' . str_replace('.', '-', $ip);
                    $job = Welcome_wizard::launch_ossec_deploy($name, $ip, $username, $domain, $password);
                    $jid = md5($h . $ip);
                    $jobs[$jid] = array('job_id' => $job['job_id'], 'agent' => $name . '(' . $ip . ')');
                } catch (Exception $e) {
                    Av_exception::write_log(Av_exception::USER_ERROR, $e->getMessage());
                }
                $total_ip++;
            }
        }
        //Saving the jobs IDs in the wizard object
        $wizard->set_step_data('deploy_jobs', $jobs);
    }
    $total_ip = $total_ip > count($hosts) ? $total_ip : count($hosts);
    $data['total_ips'] = $total_ip;
    //Setting the total of ips.
    $wizard->set_step_data('deploy_total_ips', $total_ip);
    //Setting to true the flag that warns that the deploy has been already initialized.
    $wizard->set_step_data('deploy_initialized', TRUE);
    //Saving the wizard status
    $wizard->save_status();
    $response['error'] = FALSE;
    $response['data'] = $data;
    return $response;
}
Exemple #2
0
if (is_array($validation_errors) && !empty($validation_errors)) {
    $validation_errors['html_errors'] = "<div>" . _('We found the following errors') . ":</div><div style='padding:5px;'>" . implode("<br/>", $validation_errors) . "</div>";
    $data['status'] = 'error';
    $data['data'] = $validation_errors;
    echo json_encode($data);
    exit;
}
$data['status'] = 'success';
switch ($action) {
    case 'add_monitoring_entry':
        if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) {
            $data['status'] = 'error';
            $data['data'] = _('Error! Sensor not allowed');
        } else {
            try {
                $id = Ossec_agentless::add_monitoring_entry($conn, $ip, $sensor_id, $type, $frequency, $state, $arguments);
                if ($id !== FALSE) {
                    $data['data'] = "<tr id='m_entry_{$id}'>\n    \t\t\t\t\t\t\t\t\t<td class='nobborder center' id='al_type_{$id}'>{$type}</td>\n    \t\t\t\t\t\t\t\t\t<td class='nobborder center' id='al_frequency_{$id}'>{$frequency}</td>\n    \t\t\t\t\t\t\t\t\t<td class='nobborder center' id='al_state_{$id}'>{$state}</td>\n    \t\t\t\t\t\t\t\t\t<td class='nobborder left' id='al_arguments_{$id}'>" . Util::htmlentities($arguments) . "</td>\n    \t\t\t\t\t\t\t\t\t<td class='center nobborder'>\n    \t\t\t\t\t\t\t\t\t\t<a onclick=\"add_values('{$id}')\"><img src='" . OSSIM_IMG_PATH . "/pencil.png' align='absmiddle' alt='" . _('Modify monitoring entry') . "' title='" . _('Modify monitoring entry') . "'/></a>\n    \t\t\t\t\t\t\t\t\t\t<a onclick=\"delete_monitoring('{$id}')\" style='margin-right:5px;'><img src='" . OSSIM_IMG_PATH . "/delete.gif' align='absmiddle' alt='" . _('Delete monitoring entry') . "' title='" . _('Delete monitoring entry') . "'/></a>\n    \t\t\t\t\t\t\t\t\t</td>\n    \t\t\t\t\t\t\t\t</tr>";
                } else {
                    $data['status'] = 'error';
                    $data['data'] = _('Error to Add Monitoring Entry');
                }
            } catch (Exception $e) {
                $data['status'] = 'error';
                $data['data'] = $e->getMessage();
            }
        }
        break;
    case 'delete_monitoring_entry':
        try {
            Ossec_agentless::delete_monitoring_entry($conn, $id);