1<?php 2 3// Pandora FMS - http://pandorafms.com 4// ================================================== 5// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas 6// Please see http://pandorafms.org for full contribution list 7 8// This program is free software; you can redistribute it and/or 9// modify it under the terms of the GNU General Public License 10// as published by the Free Software Foundation for version 2. 11// This program is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16 17// Load global vars 18check_login (); 19 20if (! check_acl ($config['id_user'], 0, "AW")) { 21 db_pandora_audit("ACL Violation", 22 "Trying to access massive alert deletion"); 23 require ("general/noaccess.php"); 24 return; 25} 26 27require_once ('include/functions_agents.php'); 28require_once ('include/functions_alerts.php'); 29require_once ('include/functions_users.php'); 30 31if (is_ajax ()) { 32 $get_alerts = (bool) get_parameter ('get_alerts'); 33 34 if ($get_alerts) { 35 $id_agents = get_parameter ('id_agents'); 36 $get_templates = (bool) get_parameter ('get_templates'); 37 38 if ($get_templates) { 39 if (!is_array($id_agents)) { 40 echo json_encode (''); 41 return; 42 } 43 $alert_templates = agents_get_alerts_simple ($id_agents); 44 echo json_encode (index_array ($alert_templates, 'id_alert_template', 'template_name')); 45 return; 46 } 47 else { 48 $id_alert_templates = (array) get_parameter ('id_alert_templates'); 49 $standby = (int) get_parameter ('standby'); 50 51 $agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, false, 52 array('order' => 'tagente.nombre, talert_template_modules.standby', 'talert_template_modules.standby' => $standby), 53 array ('CONCAT(tagente.nombre, " - ", tagente_modulo.nombre) as agent_agentmodule_name', 54 'talert_template_modules.id as template_module_id'), $id_agents); 55 56 echo json_encode (index_array ($agents_alerts, 'template_module_id', 'agent_agentmodule_name')); 57 return; 58 } 59 } 60 return; 61} 62 63$id_group = (int) get_parameter ('id_group'); 64$id_agents = (array) get_parameter ('id_agents'); 65$action = (string) get_parameter ('action', ''); 66$recursion = get_parameter ('recursion'); 67 68$result = false; 69 70switch($action) { 71 case 'set_off_standby_alerts': 72 $id_alert_templates = (int) get_parameter ('id_alert_template_standby', 0); 73 $id_standby_alerts = get_parameter_post ('id_standby_alerts', array()); 74 foreach($id_standby_alerts as $id_alert) { 75 $result = alerts_agent_module_standby ($id_alert, false); 76 } 77 78 ui_print_result_message ($result, __('Successfully set off standby'), __('Could not be set off standby')); 79 80 $info = 'Alert: ' . json_encode($id_standby_alerts); 81 if ($result) { 82 db_pandora_audit("Massive management", "Set off standby alerts", false, false, $info); 83 } 84 else { 85 db_pandora_audit("Massive management", "Fail try to set off standby alerts", false, false, $info); 86 } 87 break; 88 case 'set_standby_alerts': 89 $id_alert_templates = (int) get_parameter ('id_alert_template_standby', 0); 90 $id_not_standby_alerts = get_parameter_post ('id_not_standby_alerts', array()); 91 92 foreach($id_not_standby_alerts as $id_alert) { 93 $result = alerts_agent_module_standby ($id_alert, true); 94 } 95 96 ui_print_result_message ($result, __('Successfully set standby'), __('Could not be set standby')); 97 98 $info = 'Alert: ' . json_encode($id_not_standby_alerts); 99 if ($result) { 100 db_pandora_audit("Massive management", "Set on standby alerts", false, false, $info); 101 } 102 else { 103 db_pandora_audit("Massive management", "Fail try to set on standby alerts", false, false, $info); 104 } 105 break; 106 default: 107 $id_alert_templates = (int) get_parameter ('id_alert_template', 0); 108 break; 109} 110 111$groups = users_get_groups (); 112$own_info = get_user_info($config['id_user']); 113if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW")) 114 $return_all_group = false; 115else 116 $return_all_group = true; 117 118$table->id = 'delete_table'; 119$table->class = 'databox filters'; 120$table->width = '100%'; 121$table->data = array (); 122$table->style = array (); 123$table->style[0] = 'font-weight: bold; vertical-align:top'; 124$table->style[2] = 'font-weight: bold'; 125$table->size = array (); 126$table->size[0] = '15%'; 127$table->size[1] = '55%'; 128$table->size[2] = '15%'; 129$table->size[3] = '15%'; 130 131$table->data = array (); 132 133$templates = alerts_get_alert_templates (false, array ('id', 'name')); 134$table->data[0][0] = '<form method="post" id="form_alerts" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&tab=massive_alerts&option=standby_alerts&action=set_standby_alerts">'; 135$table->data[0][0] .= html_print_input_hidden('id_alert_template_not_standby', $id_alert_templates, true); 136$table->data[0][0] .= __('Group'); 137$table->data[0][1] = html_print_select_groups(false, "AW", $return_all_group, 138 'id_group', $id_group, '', '', '', true, false, true, ''); 139$table->data[0][2] = __('Group recursion'); 140$table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); 141 142$table->data[1][0] = __('Agents'); 143$table->data[1][0] .= '<span id="agent_loading" class="invisible">'; 144$table->data[1][0] .= html_print_image('images/spinner.png', true); 145$table->data[1][0] .= '</span>'; 146$table->data[1][1] = html_print_select (agents_get_group_agents (array_keys (users_get_groups ($config["id_user"], "AW", false))), 147 'id_agents[]', 0, false, '', '', true, true); 148$table->data[2][0] = __('Alert template'); 149$table->data[2][0] .= '<span id="template_loading" class="invisible">'; 150$table->data[2][0] .= html_print_image('images/spinner.png', true); 151$table->data[2][0] .= '</span>'; 152$table->data[2][1] = html_print_select ('', 'id_alert_templates[]', '', '', '', '', true, true, true, '', true); 153 154$table->data[3][0] = __('Not standby alerts').ui_print_help_tip(__('Format').":<br> ".__('Agent')." - ".__('Module'), true); 155$table->data[3][0] .= '<span id="alerts_loading" class="invisible">'; 156$table->data[3][0] .= html_print_image('images/spinner.png', true); 157$table->data[3][0] .= '</span>'; 158$agents_alerts = alerts_get_agents_with_alert_template ($id_alert_templates, $id_group, 159 false, array ('tagente.nombre', 'tagente.id_agente')); 160$table->data[3][1] = html_print_select (index_array ($agents_alerts, 'id_agente', 'nombre'), 161 'id_not_standby_alerts[]', '', '', '', '', true, true, true, '', $id_alert_templates == 0); 162 163$table->data[4][0] = __('Action'); 164 165$table->data[4][1] = "<table border='0' width='100%'><tr><td>".html_print_input_image ('standby_alerts', 'images/darrowdown.png', 1, 'margin-left: 150px;', true, array ('title' => __('Set standby selected alerts')))."</td><td>"; 166$table->data[4][1] .= '</form>'; 167$table->data[4][1] .= '<form method="post" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&tab=massive_alerts&option=standby_alerts&action=set_off_standby_alerts" onsubmit="if (! confirm(\''.__('Are you sure?').'\')) return false;">'; 168$table->data[4][1] .= html_print_input_hidden('id_alert_template_standby', $id_alert_templates, true); 169$table->data[4][1] .= html_print_input_image ('set_off_standby_alerts', 'images/darrowup.png', 1, 'margin-left: 200px;', true, array ('title' => __('Set standby selected alerts')))."</td></tr></table>"; 170 171$table->data[5][0] = __('Standby alerts').ui_print_help_tip(__('Format').":<br> ".__('Agent')." - ".__('Module'), true); 172$table->data[5][0] .= '<span id="alerts_loading2" class="invisible">'; 173$table->data[5][0] .= html_print_image('images/spinner.png', true); 174$table->data[5][0] .= '</span>'; 175$table->data[5][1] = html_print_select (index_array ($agents_alerts, 'id_agente2', 'nombre'), 176 'id_standby_alerts[]', '', '', '', '', true, true, true, '', $id_alert_templates == 0); 177$table->data[5][1] .= '</form>'; 178 179html_print_table ($table); 180 181echo '<h3 class="error invisible" id="message"> </h3>'; 182 183ui_require_jquery_file ('form'); 184ui_require_jquery_file ('pandora.controls'); 185?> 186 187<script type="text/javascript"> 188/* <![CDATA[ */ 189$(document).ready (function () { 190 clear_alert_fields(); 191 192 var recursion; 193 $("#checkbox-recursion").click(function () { 194 recursion = this.checked ? 1 : 0; 195 $("#id_group").trigger("change"); 196 }); 197 198 $("#id_group").pandoraSelectGroupAgent ({ 199 agentSelect: "select#id_agents", 200 privilege: "AW", 201 recursion: function() {return recursion}, 202 callbackPost: function () { 203 clear_alert_fields(); 204 } 205 }); 206 207 $("#id_agents").change (function () { 208 clear_alert_fields(); 209 update_alert_templates(); 210 }); 211 212 $("#id_alert_templates").change (function () { 213 if (this.value != 0) { 214 $("#id_not_standby_alerts").enable (); 215 $("#id_standby_alerts").enable (); 216 } 217 else { 218 $("#id_group, #id_not_standby_alerts").disable (); 219 $("#id_group, #id_standby_alerts").disable (); 220 } 221 update_alerts(); 222 }); 223 224 function update_alert_templates() { 225 var idAgents = Array(); 226 jQuery.each ($("#id_agents option:selected"), function (i, val) { 227 idAgents.push($(val).val()); 228 }); 229 $("#template_loading").show(); 230 231 var $select_template = $("#id_alert_templates").disable (); 232 $("option", $select_template).remove (); 233 234 jQuery.post ("ajax.php", 235 {"page" : "godmode/massive/massive_standby_alerts", 236 "get_alerts" : 1, 237 "get_templates" : 1, 238 "id_agents[]" : idAgents 239 }, 240 function (data, status) { 241 options = ""; 242 jQuery.each (data, function (id, value) { 243 options += "<option value=\""+id+"\">"+value+"</option>"; 244 }); 245 $("#id_alert_templates").append (options); 246 $("#template_loading").hide (); 247 $select_template.enable (); 248 }, 249 "json" 250 ); 251 } 252 253 function update_alerts() { 254 var idAgents = Array(); 255 jQuery.each ($("#id_agents option:selected"), function (i, val) { 256 idAgents.push($(val).val()); 257 }); 258 var idAlertTemplates = Array(); 259 jQuery.each ($("#id_alert_templates option:selected"), function (i, val) { 260 idAlertTemplates.push($(val).val()); 261 }); 262 263 var $select = $("#id_not_standby_alerts").disable (); 264 var $select2 = $("#id_standby_alerts").disable (); 265 $("#alerts_loading").show (); 266 $("#alerts_loading2").show (); 267 $("option", $select).remove (); 268 $("option", $select2).remove (); 269 270 jQuery.post ("ajax.php", 271 {"page" : "godmode/massive/massive_standby_alerts", 272 "get_alerts" : 1, 273 "get_templates" : 0, 274 "id_agents[]" : idAgents, 275 "id_alert_templates[]" : idAlertTemplates, 276 "standby" : 0 277 }, 278 function (data, status) { 279 options = ""; 280 jQuery.each (data, function (id, value) { 281 options += "<option value=\""+id+"\">"+value+"</option>"; 282 }); 283 $("#id_not_standby_alerts").append (options); 284 $("#alerts_loading").hide (); 285 $select.enable (); 286 }, 287 "json" 288 ); 289 290 jQuery.post ("ajax.php", 291 {"page" : "godmode/massive/massive_standby_alerts", 292 "get_alerts" : 1, 293 "get_templates" : 0, 294 "id_agents[]" : idAgents, 295 "id_alert_templates[]" : idAlertTemplates, 296 "standby" : 1 297 }, 298 function (data, status) { 299 options = ""; 300 jQuery.each (data, function (id, value) { 301 options += "<option value=\""+id+"\">"+value+"</option>"; 302 }); 303 $("#id_standby_alerts").append (options); 304 $("#alerts_loading2").hide (); 305 $select2.enable (); 306 }, 307 "json" 308 ); 309 } 310 311 function clear_alert_fields() { 312 var $select_template = $("#id_alert_templates").disable (); 313 var $select_not_standby = $("#id_not_standby_alerts").disable (); 314 var $select_standby = $("#id_standby_alerts").disable (); 315 $("option", $select_template).remove (); 316 $("option", $select_not_standby).remove (); 317 $("option", $select_standby).remove (); 318 } 319}); 320/* ]]> */ 321</script> 322