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;
}
Exemple #2
0
    }
    $db->close();
}
if (is_array($validation_errors) && !empty($validation_errors)) {
    $validation_errors['html_errors'] = "<div style='text-align: left;'>" . _('The following errors occurred') . ":</div>\n                                         <div style='padding-left:15px; text-align: left;'>" . implode('<br/>', $validation_errors) . "</div>";
    $data['status'] = 'error';
    $data['data'] = $validation_errors;
} else {
    $ret = NULL;
    $data['status'] = 'success';
    try {
        $new_agent = Ossec_agent::create($sensor_id, $agent_name, $ip_cidr, $asset_id);
        //If ossec-remoted is not running, we have to restart Ossec Server
        $ossec_status = Ossec_control::execute_action($sensor_id, 'status');
        if ('UP' !== $ossec_status['general_status']['ossec-remoted']) {
            Ossec_control::execute_action($sensor_id, 'restart');
        }
        if (is_array($new_agent) && !empty($new_agent)) {
            $agent_id = $new_agent['id'];
            $agent_info = array('name' => $new_agent['name'], 'ip_cidr' => $new_agent['ip_cidr'], 'status' => $new_agent['status']);
            $agent_actions = Ossec_agent::get_actions($agent_id, $new_agent);
            $data['data'] = _("HIDS agent has been created. To deploy the agent, please choose one of the options under the 'Actions' column") . "###" . $agent_id . "###";
            $a_unique_id = md5($agent_id);
            if (valid_hex32($new_agent['host_id'])) {
                $db = new Ossim_db();
                $conn = $db->connect();
                $asset_name = Asset_host::get_name_by_id($conn, $new_agent['host_id']);
                $db->close();
            } else {
                $asset_name = '-';
            }
Exemple #3
0
$db = new ossim_db();
$conn = $db->connect();
$s_data = Ossec_utilities::get_sensors($conn, $sensor_id);
$sensor_opt = $s_data['sensor_opt'];
$db->close();
//Check available sensors
if (!is_array($s_data['sensors']) || empty($s_data['sensors'])) {
    $styles = 'width: 90%; text-align:left; margin: 50px auto;';
    echo ossim_error(_('There is no sensor available'), AV_INFO, $styles);
    exit;
}
$oss_plugin_id = OSSEC_MIN_PLUGIN_ID . '-' . OSSEC_MAX_PLUGIN_ID;
$link_siem = Menu::get_menu_url("/ossim/forensics/base_qry_main.php?&plugin={$oss_plugin_id}&num_result_rows=-1&submit=Query+DB&current_view=-1&sort_order=time_d", 'analysis', 'security_events', 'security_events');
//Ossec Status
$response = Ossec_control::execute_action($sensor_id, 'status');
$response = Ossec_control::get_html_status($response);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title> <?php 
echo _("OSSIM Framework");
?>
 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <meta http-equiv="Pragma" content="no-cache"/>
    <link rel="stylesheet" type="text/css" href="/ossim/style/av_common.css?t=<?php 
echo Util::get_css_id();
?>
"/>
Exemple #4
0
             } catch (Exception $e) {
                 $data['status'] = 'error';
                 $data['data'] = $e->getMessage();
             }
         } else {
             $data['status'] = 'error';
             $data['data'] = _('Error! Agentless not found');
         }
     }
     break;
 case 'get_agentless_status':
     if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) {
         $data['status'] = 'error';
         $data['data'] = _('Error! Sensor not allowed');
     } else {
         $sensor_status = Ossec_control::execute_action($sensor_id, 'status');
         $data['data']['status'] = $sensor_status['service_status']['agentless'];
         $data['data']['reload'] = file_exists("/var/tmp/.reload_{$sensor_id}") ? 'reload_red' : 'reload';
         //Logged user
         $user = Session::get_session_user();
         //Error file
         $agenteless_error_log = "/tmp/_agentless_error_{$user}" . '.log';
         if (file_exists($agenteless_error_log)) {
             $msgs = file($agenteless_error_log);
             $data['data']['log'] = '';
             foreach ($msgs as $msg) {
                 if (trim($msg) == '') {
                     continue;
                 }
                 $data['data']['log'] .= $msg . '<br>';
             }