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
16global $config;
17
18// Login check
19check_login ();
20
21if (! check_acl ($config['id_user'], 0, "LW")) {
22	db_pandora_audit("ACL Violation",
23		"Trying to access Alert Management");
24	require ("general/noaccess.php");
25	exit;
26}
27
28include_once($config['homedir'] . "/include/functions_agents.php");
29include_once($config['homedir'] . '/include/functions_users.php');
30
31$pure = get_parameter('pure', 0);
32
33$table->id = 'add_alert_table';
34$table->class = 'databox filters';
35$table->width = '100%';
36$table->head = array ();
37$table->data = array ();
38$table->size = array ();
39$table->size = array ();
40$table->size[0] = '10%';
41$table->size[1] = '25%';
42$table->size[2] = '10%';
43$table->size[3] = '20%';
44$table->style[0] = 'font-weight: bold; ';
45$table->style[1] = 'font-weight: bold; ';
46$table->style[2] = 'font-weight: bold; ';
47$table->style[3] = 'font-weight: bold; ';
48
49// This is because if this view is reused after list alert view then
50// styles in the previous view can affect this table.
51$table->rowstyle[0] = '';
52$table->rowstyle[1] = '';
53$table->rowstyle[2] = '';
54$table->rowstyle[3] = '';
55
56
57/* Add an agent selector */
58if (! $id_agente) {
59	$table->data['agent'][0] = __('Agent');
60
61	$params = array();
62	$params['return'] = true;
63	$params['show_helptip'] = true;
64	$params['input_name'] = 'id_agent';
65	$params['selectbox_id'] = 'id_agent_module';
66	$params['javascript_is_function_select'] = true;
67	$params['metaconsole_enabled'] = false;
68	$table->data['agent'][1] = ui_print_agent_autocomplete_input($params);
69}
70
71$table->data[0][0] = __('Module');
72$modules = array ();
73if ($id_agente)
74	$modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0));
75
76$table->data[0][1] = html_print_select ($modules, 'id_agent_module', 0, true,
77	__('Select'), 0, true, false, true, '', ($id_agente == 0), 'width: 250px;');
78$table->data[0][1] .= ' <span id="latest_value" class="invisible">'.__('Latest value').': ';
79$table->data[0][1] .= '<span id="value">&nbsp;</span></span>';
80$table->data[0][1] .= ' <span id="module_loading" class="invisible">';
81$table->data[0][1] .= html_print_image('images/spinner.png', true) . '</span>';
82
83$table->data[0][2] = __('Template');
84$own_info = get_user_info ($config['id_user']);
85if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
86	$templates = alerts_get_alert_templates (false, array ('id', 'name'));
87else {
88	$usr_groups = users_get_groups($config['id_user'], 'LW', true);
89	$filter_groups = '';
90	$filter_groups = implode(',', array_keys($usr_groups));
91	$templates = alerts_get_alert_templates (array ('id_group IN (' . $filter_groups . ')'), array ('id', 'name'));
92}
93
94$table->data[0][3] = html_print_select (index_array ($templates, 'id', 'name'),
95	'template', '', '', __('Select'), 0, true, false, true, '', false, 'width: 250px;');
96$table->data[0][3] .= ' <a class="template_details invisible" href="#">' .
97	html_print_image("images/zoom.png", true, array("class" => 'img_help')) . '</a>';
98if (check_acl ($config['id_user'], 0, "LM")) {
99	$table->data[0][3] .= '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$pure.'">';
100	$table->data[0][3] .= html_print_image ('images/add.png', true);
101	$table->data[0][3] .= "<div style='float:right;padding-top:5px;' >" . __('Create Template') . "</div>";
102	$table->data[0][3] .= '</a>';
103}
104
105$table->data[1][0] = __('Actions');
106
107$groups_user = users_get_groups($config["id_user"]);
108if (!empty($groups_user)) {
109	$groups = implode(',', array_keys($groups_user));
110	$sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)";
111	$actions = db_get_all_rows_sql($sql);
112}
113
114$table->data[1][1] = html_print_select(
115	index_array($actions, 'id', 'name'), 'action_select', '', '',
116	__('Default action'), '0', true, '', true, '', false,
117	'width: 250px;');
118$table->data[1][1] .= '<span id="advanced_action" class="advanced_actions invisible"><br>';
119$table->data[1][1] .= __('Number of alerts match from').' ';
120$table->data[1][1] .= html_print_input_text ('fires_min', '', '', 4, 10, true);
121$table->data[1][1] .= ' ' . __('to') . ' ';
122$table->data[1][1] .= html_print_input_text ('fires_max', '', '', 4, 10, true);
123$table->data[1][1] .= ui_print_help_icon ("alert-matches", true,
124	ui_get_full_url(false, false, false, false));
125$table->data[1][1] .= '</span>';
126if (check_acl ($config['id_user'], 0, "LM")) {
127
128	$table->data[1][1] .= '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_action&pure='.$pure.'">';
129	$table->data[1][1] .= '  ' . __('Create Action');
130	$table->data[1][1] .= '</a>';
131}
132$table->data[1][2] = __('Threshold');
133$table->data[1][3] = html_print_extended_select_for_time ('module_action_threshold', 0, '', 0,
134	__('None'), false, true) . ui_print_help_icon ('action_threshold', true, ui_get_full_url(false, false, false, false));
135
136echo '<form class="add_alert_form" method="post">';
137
138html_print_table ($table);
139
140echo '<div class="action-buttons" style="width: '.$table->width.'">';
141html_print_submit_button (__('Add alert'), 'add', false, 'class="sub wand"');
142html_print_input_hidden ('create_alert', 1);
143echo '</div></form>';
144
145ui_require_css_file ('cluetip');
146ui_require_jquery_file ('cluetip');
147ui_require_jquery_file ('pandora.controls');
148ui_require_jquery_file ('bgiframe');
149?>
150<script type="text/javascript">
151/* <![CDATA[ */
152$(document).ready (function () {
153<?php if (! $id_agente) : ?>
154	$("#id_group").pandoraSelectGroupAgent ({
155		callbackBefore: function () {
156			$select = $("#id_agent_module").disable ();
157			$select.siblings ("span#latest_value").hide ();
158			$("option[value!=0]", $select).remove ();
159			return true;
160		}
161	});
162<?php endif; ?>
163
164	$("select#template").change (function () {
165		id = this.value;
166		$a = $(this).siblings ("a.template_details");
167		if (id == 0) {
168			$a.hide ();
169			return;
170		}
171		$a.unbind ()
172			.attr ("href",<?php echo "'" . ui_get_full_url(false, false, false, false) . "'"; ?> + "ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template="+id)
173			.show ()
174			.cluetip ({
175				arrows: true,
176				attribute: 'href',
177				cluetipClass: 'default'
178			}).click (function () {
179				return false;
180			});
181
182		$("#action_loading").show ();
183	});
184
185	$(".actions_container [name='action_select']").change(function () {
186			if ($(this).val() != '0') {
187				$('#advanced_action').show();
188			}
189			else {
190				$('#advanced_action').hide();
191			}
192		}
193	);
194
195	$("#id_agent_module").change (function () {
196		var $value = $(this).siblings ("span#latest_value").hide ();
197		var $loading = $(this).siblings ("span#module_loading").show ();
198		$("#value", $value).empty ();
199		jQuery.post (<?php echo "'" . ui_get_full_url(false, false, false, false) . "'"; ?> + "ajax.php",
200			{"page" : "operation/agentes/estado_agente",
201			"get_agent_module_last_value" : 1,
202			"id_agent_module" : this.value
203			},
204			function (data, status) {
205				if (data === false) {
206					$("#value", $value).append ("<em><?php echo __('Unknown') ?></em>");
207				}
208				else if (data == "") {
209					$("#value", $value).append ("<em><?php echo __('Empty') ?></em>");
210				}
211				else {
212					$("#value", $value).append (data);
213				}
214				$loading.hide ();
215				$value.show ();
216			},
217			"json"
218		);
219	});
220});
221/* ]]> */
222</script>
223