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// Load global vars 17global $config; 18 19require_once ($config['homedir'] . '/include/functions_alerts.php'); 20require_once ($config['homedir'] . '/include/functions_users.php'); 21enterprise_include_once ('meta/include/functions_alerts_meta.php'); 22 23check_login (); 24 25enterprise_hook('open_meta_frame'); 26 27if (! check_acl ($config['id_user'], 0, "LM")) { 28 db_pandora_audit("ACL Violation", 29 "Trying to access Alert Management"); 30 require ("general/noaccess.php"); 31 exit; 32} 33 34$id = (int) get_parameter ('id'); 35 36$al_action = alerts_get_alert_action ($id); 37$pure = get_parameter('pure', 0); 38 39if (defined('METACONSOLE')) 40 $sec = 'advanced'; 41else 42 $sec = 'galertas'; 43 44if ($al_action !== false) { 45 $own_info = get_user_info ($config['id_user']); 46 if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) 47 $own_groups = array_keys(users_get_groups($config['id_user'], "LM")); 48 else 49 $own_groups = array_keys(users_get_groups($config['id_user'], "LM", false)); 50 $is_in_group = in_array($al_action['id_group'], $own_groups); 51 52 // Header 53 if (defined('METACONSOLE')) 54 alerts_meta_print_header(); 55 else 56 ui_print_page_header (__('Alerts') . ' » ' . 57 __('Configure alert action'), "images/gm_alerts.png", false, 58 "alert_config", true); 59} 60else { 61 // Header 62 if (defined('METACONSOLE')) 63 alerts_meta_print_header(); 64 else 65 ui_print_page_header (__('Alerts') . ' » ' . 66 __('Configure alert action'), "images/gm_alerts.png", false, 67 "alert_config", true); 68} 69 70 71$name = ''; 72$id_command = ''; 73$group = 0; //All group is 0 74$action_threshold = 0; //All group is 0 75 76if ($id) { 77 $action = alerts_get_alert_action ($id); 78 $name = $action['name']; 79 $id_command = $action['id_alert_command']; 80 81 $group = $action ['id_group']; 82 $action_threshold = $action ['action_threshold']; 83} 84 85// Hidden div with help hint to fill with javascript 86html_print_div( 87 array('id' => 'help_alert_macros_hint', 88 'content' => ui_print_help_icon ('alert_macros', true), 89 'hidden' => true)); 90 91$table = new stdClass(); 92$table->id = 'table_macros'; 93$table->width = '100%'; 94$table->class = 'databox filters'; 95 96if (defined('METACONSOLE')) { 97 if ($id) { 98 $table->head[0] = __('Update Action'); 99 } 100 else { 101 $table->head[0] = __('Create Action'); 102 } 103 104 $table->head_colspan[0] = 4; 105 $table->headstyle[0] = 'text-align: center'; 106} 107$table->style = array (); 108$table->style[0] = 'font-weight: bold'; 109$table->size = array (); 110$table->size[0] = '20%'; 111$table->data = array (); 112$table->data[0][0] = __('Name'); 113$table->data[0][1] = html_print_input_text ('name', $name, '', 35, 255, true); 114$table->colspan[0][1] = 2; 115 116$table->data[1][0] = __('Group'); 117 118$groups = users_get_groups (); 119$own_info = get_user_info ($config['id_user']); 120// Only display group "All" if user is administrator or has "PM" privileges 121if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) 122 $display_all_group = true; 123else 124 $display_all_group = false; 125$table->data[1][1] = html_print_select_groups(false, "LW", $display_all_group, 'group', $group, '', '', 0, true); 126$table->colspan[1][1] = 2; 127 128$table->data[2][0] = __('Command'); 129$table->data[2][1] = html_print_select_from_sql ('SELECT id, name 130 FROM talert_commands', 131 'id_command', $id_command, '', __('None'), 0, true); 132$table->data[2][1] .= ' '; 133if (check_acl ($config['id_user'], 0, "PM")) { 134 $table->data[2][1] .= html_print_image ('images/add.png', true); 135 $table->data[2][1] .= '<a href="index.php?sec=' . $sec . '&sec2=godmode/alerts/configure_alert_command&pure='.$pure.'">'; 136 $table->data[2][1] .= __('Create Command'); 137 $table->data[2][1] .= '</a>'; 138} 139$table->data[2][1] .= '<div id="command_description" style=""></div>'; 140$table->colspan[2][1] = 2; 141 142$table->data[3][0] = __('Threshold'); 143$table->data[3][1] = html_print_input_text ('action_threshold', $action_threshold, '', 5, 7, true); 144$table->data[3][1] .= ' ' . __('seconds') . ui_print_help_icon ('action_threshold', true); 145$table->colspan[3][1] = 2; 146 147$table->data[4][0] = ''; 148$table->data[4][1] = __('Firing'); 149$table->data[4][2] = __('Recovery'); 150$table->cellstyle[4][1] = 'font-weight: bold;'; 151$table->cellstyle[4][2] = 'font-weight: bold;'; 152 153$table->data[5][0] = __('Command preview'); 154$table->data[5][1] = html_print_textarea ('command_preview', 5, 30, '', 155 'disabled="disabled"', true); 156$table->data[5][2] = html_print_textarea ('command_recovery_preview', 5, 30, '', 157 'disabled="disabled"', true); 158 159$row = 6; 160for ($i = 1; $i <= 10; $i++) { 161 $table->data['field' . $i][0] = html_print_image( 162 'images/spinner.gif', true); 163 $table->data['field' . $i][1] = html_print_image( 164 'images/spinner.gif', true); 165 $table->data['field' . $i][2] = html_print_image( 166 'images/spinner.gif', true); 167 168 // Store the value in a hidden to keep it on first execution 169 $table->data['field' . $i][1] .= html_print_input_hidden( 170 'field' . $i . '_value', 171 !empty($action['field' . $i]) ? 172 $action['field' . $i] : '', 173 true); 174 $table->data['field' . $i][2] .= html_print_input_hidden( 175 'field' . $i . '_recovery_value', 176 !empty($action['field' . $i . '_recovery']) ? 177 $action['field' . $i . '_recovery'] : '', 178 true); 179} 180 181echo '<form method="post" action="' . 182 'index.php?sec=' . $sec . '&' . 183 'sec2=godmode/alerts/alert_actions&' . 184 'pure=' . $pure . '">'; 185$table_html = html_print_table ($table, true); 186 187//////////////////////////////////////////////////////////////////////// 188//Hack to hook the bubble dialog of clippy in any place, the intro.js 189//fails with new elements in the dom from javascript code 190//---------------------------------------------------------------------- 191/* 192$table_html = str_replace( 193 "</table>", 194 "</div>", 195 $table_html); 196$table_html = str_replace( 197 '<tr id="table_macros-field1" style="" class="datos2">', 198 "</tbody></table> 199 <div id=\"clippy_fields\"> 200 <table> 201 <tbody> 202 <tr id=\"table_macros-field1\" class=\"datos\">", 203 $table_html); 204*/ 205//////////////////////////////////////////////////////////////////////// 206 207echo $table_html; 208 209echo '<div class="action-buttons" style="width: '.$table->width.'">'; 210if ($id) { 211 html_print_input_hidden ('id', $id); 212 if ($al_action['id_group'] == 0) { 213 // then must have "PM" access privileges 214 if (check_acl ($config['id_user'], 0, "PM")) { 215 html_print_input_hidden ('update_action', 1); 216 html_print_submit_button (__('Update'), 'create', false, 'class="sub upd"'); 217 } 218 } 219 else { 220 221 html_print_input_hidden ('update_action', 1); 222 html_print_submit_button (__('Update'), 'create', false, 'class="sub upd"'); 223 } 224} 225else { 226 html_print_input_hidden ('create_action', 1); 227 html_print_submit_button (__('Create'), 'create', false, 'class="sub wand"'); 228} 229echo '</div>'; 230echo '</form>'; 231 232enterprise_hook('close_meta_frame'); 233 234ui_require_javascript_file ('pandora_alerts'); 235ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/'); 236?> 237 238<script type="text/javascript"> 239$(document).ready (function () { 240 <?php 241 if ($id_command) { 242 ?> 243 original_command = "<?php 244 $command = alerts_get_alert_command_command ($id_command); 245 $command = io_safe_output($command); 246 echo addslashes($command); 247 ?>"; 248 render_command_preview (original_command); 249 command_description = "<?php echo str_replace("\r\n","<br>",addslashes(io_safe_output(alerts_get_alert_command_description ($id_command)))); ?>"; 250 251 render_command_description(command_description); 252 <?php 253 } 254 ?> 255 256 $("#id_command").change (function () { 257 values = Array (); 258 values.push({ 259 name: "page", 260 value: "godmode/alerts/alert_commands"}); 261 values.push({ 262 name: "get_alert_command", 263 value: "1"}); 264 values.push({ 265 name: "id", 266 value: this.value}); 267 268 jQuery.get (<?php echo "'" . ui_get_full_url("ajax.php", false, false, false) . "'"; ?>, 269 values, 270 function (data, status) { 271 original_command = js_html_entity_decode (data["command"]); 272 render_command_preview (original_command); 273 command_description = js_html_entity_decode (data["description"]); 274 render_command_description(command_description); 275 276 277 for (i = 1; i <= 10; i++) { 278 var old_value = ''; 279 var old_recovery_value = ''; 280 var field_row = data["fields_rows"][i]; 281 var $table_macros_field = $('#table_macros-field' + i); 282 283 // If the row is empty, hide it 284 if (field_row == '') { 285 $table_macros_field.hide(); 286 continue; 287 } 288 old_value = ''; 289 old_recovery_value = ''; 290 // Only keep the value if is provided from hidden (first time) 291 if (($("[name=field" + i + "_value]").attr('id')) 292 == ("hidden-field" + i + "_value")) { 293 294 old_value = $("[name=field" + i + "_value]").val(); 295 } 296 297 if (($("[name=field" + i + "_recovery_value]").attr('id')) 298 == ("hidden-field" + i + "_recovery_value")) { 299 300 old_recovery_value = 301 $("[name=field" + i + "_recovery_value]").val(); 302 } 303 304 // Replace the old column with the new 305 $table_macros_field.replaceWith(field_row); 306 if (old_value != '' || old_recovery_value != '') { 307 $("[name=field" + i + "_value]").val(old_value); 308 $("[name=field" + i + "_recovery_value]").val(old_recovery_value); 309 } 310 else { 311 $("[name=field" + i + "_value]") 312 .val($("[name=field" + i + "_value]") 313 .val()); 314 $("[name=field" + i + "_recovery_value]") 315 .val($("[name=field" + i + "_recovery_value]") 316 .val()); 317 } 318 // Add help hint only in first field 319 if (i == 1) { 320 var td_content = $table_macros_field.find('td').eq(0); 321 322 $(td_content) 323 .html( 324 $(td_content).html() + 325 $('#help_alert_macros_hint').html()); 326 } 327 328 $table_macros_field.show(); 329 } 330 331 tinyMCE.init({ 332 selector: 'textarea.tiny-mce-editor', 333 theme : "advanced", 334 plugins : "preview, print, table, searchreplace, nonbreaking, xhtmlxtras, noneditable", 335 theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsize,select", 336 theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,image,|,cleanup,code,preview,|,forecolor,backcolor", 337 theme_advanced_buttons3 : "", 338 theme_advanced_toolbar_location : "top", 339 theme_advanced_toolbar_align : "left", 340 theme_advanced_resizing : true, 341 theme_advanced_statusbar_location : "bottom", 342 force_p_newlines : false, 343 forced_root_block : '', 344 inline_styles : true, 345 valid_children : "+body[style]", 346 element_format : "html" 347 }); 348 349 render_command_preview(original_command); 350 render_command_recovery_preview(original_command); 351 352 $(".fields").keyup(function() { 353 render_command_preview(original_command); 354 }); 355 $(".fields_recovery").keyup(function() { 356 render_command_recovery_preview(original_command); 357 }); 358 $("select.fields").change(function() { 359 render_command_preview(original_command); 360 }); 361 $("select.fields_recovery").change(function() { 362 render_command_recovery_preview(original_command); 363 }); 364 }, 365 "json" 366 ); 367 }).change(); 368}); 369 370</script> 371