$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') . "'/>";
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; }
$ppassc = $_SESSION['_al_new']['ppassc'] = POST('ppassc'); $use_su = $_SESSION['_al_new']['use_su'] = intval(POST('use_su')); $descr = $_SESSION['_al_new']['descr'] = POST('descr'); $sensor_id = $_SESSION['_al_new']['sensor']; $sensor_name = $_SESSION['_al_new']['sensor_name']; if ($step == 1) { if (empty($info_error)) { try { $res = Ossec_agentless::save_in_db($conn, $ip, $sensor_id, $hostname, $user, $pass, $ppass, $use_su, $descr); } catch (Exception $e) { $info_error = $e->getMessage(); } } if (!empty($ip)) { try { $monitoring_entries = Ossec_agentless::get_list_m_entries($conn, $sensor_id, " AND ip = '{$ip}'"); } catch (Exception $e) { $monitoring_entries = array(); $error_m_entries = $e->getMessage(); } } if (!empty($info_error)) { $step = NULL; $display = 'display: block;'; $action_form = 'al_newform.php'; } } } else { if ($step == 2) { if (isset($_POST['finish'])) { header('Location: /ossim/ossec/agentless.php');
foreach ($entries as $entry) { ossim_valid($entry['id_type'], OSS_NOECHARS, OSS_SCORE, OSS_LETTER, 'illegal:' . _('Type')); ossim_valid($entry['frequency'], OSS_DIGIT, 'illegal:' . _('frequency')); ossim_valid($entry['state'], OSS_NOECHARS, OSS_SCORE, OSS_LETTER, 'illegal:' . _('State')); ossim_valid($entry['arguments'], OSS_NOECHARS, OSS_TEXT, OSS_SPACE, OSS_AT, OSS_NULLABLE, OSS_PUNC_EXT, '\\`', '\\<', '\\>', 'illegal:' . _('Arguments')); if (ossim_error()) { Util::response_bad_request(ossim_get_error_clean()); } } $ip = POST('ip'); $sensor_id = POST('sensor'); $hostname = POST('hostname'); $user = POST('user'); $pass = POST('pass'); $ppass = POST('ppass'); $use_su = POST('use_su'); $descr = Util::utf8entities(POST('descr')); $descr = mb_convert_encoding($descr, 'ISO-8859-1', 'UTF-8'); try { $agentless = Ossec_agentless::get_object($conn, $sensor_id, $ip); $status = is_object($agentless) && $agentless->get_status() == 0 ? 0 : 1; } catch (Exception $e) { $status = 1; } try { Ossec_agentless::save_in_db($conn, $ip, $sensor_id, $hostname, $user, $pass, $ppass, $use_su, $descr, $status); Ossec_agentless::save_agentless_monitoring_entries($conn, $ip, $sensor_id, $entries); } catch (Exception $e) { Util::response_bad_request($e->getMessage()); } $db->close();
$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
$db = new ossim_db(); $conn = $db->connect(); if (ossim_error()) { $txt_error = ossim_get_error_clean(); } else { if (!Token::verify('tk_al_delete', $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 { Ossec_agentless::delete_from_db($conn, $sensor_id, $ip); } 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 echo _('OSSIM Framework'); ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
$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';
$data['data'] = "<td class='nobborder center' id='al_type_{$id}'>" . Ossec_agentless::get_type($type) . "</td>\n\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 <td class='nobborder center' id='al_state_{$id}'>{$state}</td>\n\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 <td class='center nobborder'>\n\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<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 </td>"; } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = $e->getMessage(); } break; case 'modify_host_data': if (!Ossec_utilities::is_sensor_allowed($conn, $sensor_id)) { $data['status'] = 'error'; $data['data'] = _('Error! Sensor not allowed'); } else { $agentless = Ossec_agentless::get_object($conn, $sensor_id, $ip); if (is_object($agentless) && !empty($agentless)) { $status = $agentless->get_status() != 0 ? 1 : 0; try { Ossec_agentless::save_in_db($conn, $ip, $sensor_id, POST('hostname'), POST('user'), POST('pass'), POST('ppass'), POST('use_su'), POST('descr'), $status); $data['data'] = _('Host Successfully updated'); } 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');