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; }
} elseif ($step == 1 || $step == 2 && !empty($back)) { $hostname = $_SESSION['_al_new']['hostname'] = POST('hostname'); $ip = $_SESSION['_al_new']['ip'] = POST('ip'); $user = $_SESSION['_al_new']['user'] = POST('user'); $pass = $_SESSION['_al_new']['pass'] = POST('pass'); $passc = $_SESSION['_al_new']['passc'] = POST('passc'); $ppass = $_SESSION['_al_new']['ppass'] = POST('ppass'); $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;';
$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');