Esempio n. 1
0
function form_save()
{
    if (isset_request_var('save_component_removal') && isempty_request_var('add_dq_y')) {
        $removalid = api_syslog_removal_save(get_filter_request_var('id'), get_nfilter_request_var('name'), get_nfilter_request_var('type'), get_nfilter_request_var('message'), get_nfilter_request_var('rmethod'), get_nfilter_request_var('notes'), get_nfilter_request_var('enabled'));
        if (is_error_message() || get_filter_request_var('id') != get_filter_request_var('_id')) {
            header('Location: syslog_removal.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
        } else {
            header('Location: syslog_removal.php?header=false');
        }
    }
}
Esempio n. 2
0
function tholds($header_label)
{
    global $item_rows, $config;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $thold_actions = array(1 => __('Associate'), 2 => __('Disassociate'));
    thold_request_validation();
    $statefilter = '';
    if (isset_request_var('state')) {
        if (get_request_var('state') == '-1') {
            $statefilter = '';
        } else {
            if (get_request_var('state') == '0') {
                $statefilter = "td.thold_enabled='off'";
            }
            if (get_request_var('state') == '2') {
                $statefilter = "td.thold_enabled='on'";
            }
            if (get_request_var('state') == '1') {
                $statefilter = '(td.thold_alert!=0 OR td.bl_alert>0)';
            }
            if (get_request_var('state') == '3') {
                $statefilter = '(td.thold_alert!=0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert>0 AND td.bl_fail_count >= td.bl_fail_trigger)';
            }
        }
    }
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $sql_where = '';
    $sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    $limit = $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (!isempty_request_var('template') && get_request_var('template') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template');
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . "td.name LIKE '%" . get_request_var('filter') . "%'";
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . $statefilter;
    }
    if (get_request_var('associated') == 'true') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . '(td.notify_warning=' . get_request_var('id') . ' OR td.notify_alert=' . get_request_var('id') . ')';
    }
    cacti_log($sql_where);
    $result = get_allowed_thresholds($sql_where, $sort, $limit, $total_rows);
    $data_templates = db_fetch_assoc('SELECT DISTINCT dt.id, dt.name
		FROM data_template AS dt
		INNER JOIN thold_data AS td
		ON td.data_template_id = dt.id
		ORDER BY dt.name');
    html_start_box(__('Associated Thresholds') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' method='get' action='notify_lists.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='template' onChange='applyFilter()'>
							<option value='-1'><?php 
    print __('Any');
    ?>
</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset_request_var('template') && $row['id'] == get_request_var('template') ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('State');
    ?>
					</td>
					<td>
						<select id='state' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('state') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('state') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Breached');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('state') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Triggered');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('state') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Enabled');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('state') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Disabled');
    ?>
</option>
						</select>
					</td>
					<td>
						<?php 
    print __('Thresholds');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' name='clearf' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
			<input type='hidden' id='tab' value='tholds'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php 
    print get_request_var('id');
    ?>
'
			strURL += '&associated=' + $('#associated').is(':checked');;
			strURL += '&state=' + $('#state').val();
			strURL += '&rows=' + $('#rows').val();
			strURL += '&template=' + $('#template').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL = 'notify_lists.php?header=false&action=edit&tab=tholds&id=<?php 
    print get_request_var('id');
    ?>
&clearf=true'
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('notify_lists.php?action=edit&tab=tholds', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Thresholds'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array(__('Name'), 'ASC'), 'id' => array(__('ID'), 'ASC'), 'nosort1' => array(__('Warning Lists'), 'ASC'), 'nosort2' => array(__('Alert Lists'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'thold_alert' => array(__('Triggered'), 'ASC'), 'thold_enabled' => array(__('Enabled'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=tholds&id=' . get_filter_request_var('id'));
    $c = 0;
    $i = 0;
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] != 1) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                }
            }
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell('SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=' . $row['id']);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>" . __('Select Users') . "</span>";
            }
            if (strlen($row['notify_extra'])) {
                $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_alert'])) {
                if (get_request_var('id') == $row['notify_alert']) {
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $alert_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_alert']);
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $alert_list . '</span>';
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row['notify_warning_extra'])) {
                $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_warning'])) {
                if (get_request_var('id') == $row['notify_warning']) {
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $warn_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_warning']);
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $warn_list . '</span>';
                }
            }
            if (!strlen($warn_stat) && ($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '' || $row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>" . __('None') . "</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            if ($row['name'] != '') {
                $name = $row['name'];
            } else {
                $name = $row['name_cache'] . ' [' . $row['data_source_name'] . ']';
            }
            form_alternate_row('line' . $row['id'], true);
            form_selectable_cell(filter_value($name, get_request_var('filter')), $row['id']);
            form_selectable_cell($row['id'], $row['id']);
            form_selectable_cell($warn_stat, $row['id']);
            form_selectable_cell($alert_stat, $row['id']);
            form_selectable_cell($thold_types[$row['thold_type']], $row['id']);
            form_selectable_cell($alertstat, $row['id']);
            form_selectable_cell($row['thold_enabled'] == 'off' ? __('Disabled') : __('Enabled'), $row['id']);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        print "<tr class='even' <td colspan='8'><i>" . __('No Thresholds') . "</i></td></tr>\n";
    }
    html_end_box(false);
    if (count($result)) {
        print $nav;
    }
    form_hidden_box('tab', 'tholds', '');
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_tholds', '1', '');
    draw_actions_dropdown($thold_actions);
    form_end();
}
Esempio n. 3
0
function list_tholds()
{
    global $thold_states, $config, $host_id, $timearray, $thold_types;
    $thold_actions = array(1 => __('Delete'), 2 => __('Disable'), 3 => __('Enable'), 4 => __('Reapply Suggested Names'), 5 => __('Propagate Template'));
    thold_request_validation();
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $statefilter = '';
    if (isset_request_var('state')) {
        if (get_request_var('state') == '-1') {
            $statefilter = '';
        } else {
            if (get_request_var('state') == '0') {
                $statefilter = "thold_data.thold_enabled='off'";
            }
            if (get_request_var('state') == '2') {
                $statefilter = "thold_data.thold_enabled='on'";
            }
            if (get_request_var('state') == '1') {
                $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)';
            }
            if (get_request_var('state') == '3') {
                $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))';
            }
        }
    }
    top_header();
    $sql_where = '';
    $sort = get_request_var('sort_column');
    $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (!isempty_request_var('host_id') && get_request_var('host_id') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.host_id = " . get_request_var('host_id');
    }
    if (!isempty_request_var('data_template_id') && get_request_var('data_template_id') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.data_template_id = " . get_request_var('data_template_id');
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "{$statefilter}";
    }
    if ($sql_where != '') {
        $sql_where .= ')';
    }
    $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows);
    $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data \n\t\tON thold_data.data_template_id = data_template.id\n\t\tORDER BY data_template.name");
    html_start_box(__('Threshold Management'), '100%', '', '3', 'center', 'thold.php?action=add');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' action='thold.php' method='post'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<?php 
    print html_host_filter(get_request_var('host_id'));
    ?>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='data_template_id' onChange='applyFilter()'>
							<option value='-1'><?php 
    print __('Any');
    ?>
</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset_request_var('data_template_id') && $row['id'] == get_request_var('data_template_id') ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('State');
    ?>
					</td>
					<td>
						<select id='state' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('state') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('state') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Breached');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('state') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Triggered');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('state') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Enabled');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('state') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Disabled');
    ?>
</option>
						</select>
					</td>
					<td>
						<input type='button' id='refresh' value='<?php 
    print __('Go');
    ?>
' title='<?php 
    print __('Apply Filters');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input type='button' id='clear' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Return to Defaults');
    ?>
' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='search' value='search'>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'thold.php?header=false&host_id=' + $('#host_id').val();
			strURL += '&state=' + $('#state').val();
			strURL += '&data_template_id=' + $('#data_template_id').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL  = 'thold.php?header=false&clear=1';
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('thold.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 14, __('Thresholds'), 'page', 'main');
    form_start('thold.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'right'), 'data_source' => array('display' => __('DSName'), 'sort' => 'ASC', 'align' => 'right'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('The last measured value for the Data Source')), 'thold_hi' => array('display' => __('High'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('High Threshold values for Warning/Alert')), 'thold_low' => array('display' => __('Low'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('Low Threshold values for Warning/Alert')), 'nosort3' => array('display' => __('Trigger'), 'sort' => '', 'align' => 'right'), 'nosort4' => array('display' => __('Duration'), 'sort' => '', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'), 'template_enabled' => array('display' => __('Templated'), 'sort' => 'ASC', 'align' => 'right'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    $c = 0;
    $i = 0;
    if (sizeof($tholds)) {
        foreach ($tholds as $thold_data) {
            $c++;
            $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id
				FROM graph_templates_item, data_template_rrd
				WHERE (data_template_rrd.local_data_id=' . $thold_data['local_data_id'] . ' 
				AND data_template_rrd.id=graph_templates_item.task_item_id)');
            $local_graph_id = $grapharr['local_graph_id'];
            $alertstat = __('No');
            $bgcolor = 'green';
            if ($thold_data['thold_type'] == 0) {
                if ($thold_data['thold_alert'] != 0) {
                    $alertstat = __('Yes');
                    if ($thold_data['thold_fail_count'] >= $thold_data['thold_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['thold_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } elseif ($thold_data['thold_type'] == 2) {
                if ($thold_data['thold_alert'] != 0) {
                    $alertstat = __('Yes');
                    if ($thold_data['thold_fail_count'] >= $thold_data['time_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['time_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } else {
                if ($thold_data['bl_alert'] == 1) {
                    $alertstat = __('baseline-LOW');
                    $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow';
                } elseif ($thold_data['bl_alert'] == 2) {
                    $alertstat = __('baseline-HIGH');
                    $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow';
                }
            }
            $data_source = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id']));
            if ($thold_data['thold_enabled'] == 'off') {
                print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $thold_data['id'] . "'>\n";
            } else {
                print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $thold_data['id'] . "'>\n";
            }
            form_selectable_cell(filter_value($thold_data['name'] != '' ? $thold_data['name'] : $thold_data['name_cache'] . ' [' . $thold_data['data_source_name'] . ']', get_request_var('filter'), 'thold.php?action=edit&id=' . $thold_data['id']) . '</a>', $thold_data['id'], '', 'text-align:left');
            form_selectable_cell($thold_data['id'], $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($thold_types[$thold_data['thold_type']], $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($data_source, $thold_data['id'], '', 'text-align:right');
            switch ($thold_data['thold_type']) {
                case 0:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['thold_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
                    break;
                case 1:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['bl_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell($timearray[$thold_data['bl_ref_time_range'] / 300], $thold_data['id'], '', 'text-align:right');
                    break;
                case 2:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['time_warning_hi']) . ' / ' . thold_format_number($thold_data['time_hi']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(thold_format_number($thold_data['time_warning_low']) . ' / ' . thold_format_number($thold_data['time_low']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . __('%d Triggers', $thold_data['time_fail_trigger']) . '</i>', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['time_fail_length'], 'time') . '</i>', $thold_data['id'], '', 'text-align:right');
                    break;
                default:
                    form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
                    form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right');
            }
            form_selectable_cell($thold_data['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['repeat_alert'], 'repeat'), $thold_data['id'], '', 'text-align:right');
            form_selectable_cell($alertstat, $thold_data['id'], '', 'text-align:right');
            if ($thold_data['thold_template_id'] != 0) {
                form_selectable_cell($thold_data['template_enabled'] == '' ? __('No') : __('Yes'), $thold_data['id'], '', 'text-align:right');
            } else {
                form_selectable_cell(__('No'), $thold_data['id'], '', 'text-align:right');
            }
            form_checkbox_cell($thold_data['name'], $thold_data['id'], '', 'text-align:left');
            form_end_row();
        }
    } else {
        print "<tr class='even'><td colspan='14'><center>" . __('No Thresholds') . "</center></td></tr>\n";
    }
    html_end_box(false);
    if (sizeof($tholds)) {
        print $nav;
    }
    thold_legend();
    draw_actions_dropdown($thold_actions);
    if (isset($host_id) && $host_id != '') {
        print "<input type='hidden' name='host_id' value='{$host_id}'>";
    }
    form_end();
    bottom_footer();
}
Esempio n. 4
0
function mactrack_get_devices(&$sql_where, $row_limit, $apply_limits = TRUE)
{
    /* form the 'where' clause for our main sql query */
    if (get_request_var('filter') != '') {
        $sql_where = (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(mac_track_devices.hostname like '%%" . get_request_var('filter') . "%%'\n\t\t\tOR mac_track_devices.device_name like '%%" . get_request_var('filter') . "%%'\n\t\t\tOR mac_track_devices.notes like '%%" . get_request_var('filter') . "%%')";
    }
    if (get_request_var('status') == '-1') {
        /* Show all items */
    } elseif (get_request_var('status') == '-2') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(mac_track_devices.disabled='on')";
    } elseif (get_request_var('status') == '5') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.host_id=0)';
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.snmp_status=' . get_request_var('status') . " AND mac_track_devices.disabled = '')";
    }
    if (get_request_var('type_id') == '-1') {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.scan_type=' . get_request_var('type_id') . ')';
    }
    if (get_request_var('device_type_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('device_type_id') == '-2') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(mac_track_device_types.description='')";
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.device_type_id=' . get_request_var('device_type_id') . ')';
    }
    if (get_request_var('site_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('site_id') == '-2') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_sites.site_id IS NULL)';
    } elseif (!isempty_request_var('site_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.site_id=' . get_request_var('site_id') . ')';
    }
    $query_string = "SELECT\n\t\tmac_track_device_types.description as device_type,\n\t\tmac_track_devices.*,\n\t\tmac_track_sites.site_name\n\t\tFROM mac_track_sites\n\t\tRIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id\n\t\tLEFT JOIN mac_track_device_types ON mac_track_devices.device_type_id=mac_track_device_types.device_type_id\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    if ($apply_limits) {
        $query_string .= ' LIMIT ' . $row_limit * (get_request_var('page') - 1) . ',' . $row_limit;
    }
    return db_fetch_assoc($query_string);
}
Esempio n. 5
0
function hmib_view_graphs()
{
    global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    if (!isset($_SESSION['sess_hmib_gt'])) {
        $_SESSION['sess_hmib_gt'] = implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id 
			FROM graph_local AS gl 
			WHERE gl.host_id IN(
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			)'), 'graph_template_id', 'graph_template_id'));
    }
    $gt = $_SESSION['sess_hmib_gt'];
    if (!isset($_SESSION['sess_hmib_hosts'])) {
        $_SESSION['sess_hmib_hosts'] = implode(',', array_rekey(db_fetch_assoc('SELECT h.id 
			FROM host AS h 
			WHERE h.id IN (
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			) 
			UNION 
			SELECT h.id 
			FROM host AS h
			INNER JOIN host_template AS ht
			ON h.host_template_id=ht.id
			WHERE hash="7c13344910097cc599f0d0485305361d" ORDER BY id DESC'), 'id', 'id'));
    }
    $hosts = $_SESSION['sess_hmib_hosts'];
    /* include graph view filter selector */
    html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('hmib.php', 'graphs', "h.id IN ({$hosts})", "gt.id IN ({$gt})");
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset_request_var('style')) {
        if (get_request_var('style') == 'selective') {
            /* process selected graphs */
            if (!isempty_request_var('graph_list')) {
                foreach (explode(',', get_request_var('graph_list')) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!isempty_request_var('graph_add')) {
                foreach (explode(',', get_request_var('graph_add')) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!isempty_request_var('graph_remove')) {
                foreach (explode(',', get_request_var('graph_remove')) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $graph_array = array_keys($graph_list);
            if (sizeof($graph_array)) {
                $sql_or = array_to_sql_or($graph_array, 'gl.id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if (get_request_var('host_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id');
    }
    // Graph Template Id sql_where
    if (get_request_var('graph_template_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . get_request_var('graph_template_id');
    }
    $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs');
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), 'Graphs', 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    }
    html_end_box();
    if ($total_graphs > 0) {
        print $nav;
    }
    bottom_footer();
}
Esempio n. 6
0
function sql_hosts_where($tab)
{
    global $hostfilter, $syslog_incoming_config;
    $hostfilter = '';
    if (!isempty_request_var('host') && get_request_var('host') != 'null') {
        $hostarray = explode(' ', get_request_var('host'));
        if ($hostarray[0] != '0') {
            foreach ($hostarray as $host_id) {
                input_validate_input_number($host_id);
            }
            $hostfilter .= (strlen($hostfilter) ? ' AND ' : '') . ' host_id IN(' . implode(',', $hostarray) . ')';
        }
    }
}
Esempio n. 7
0
function thold_hosts($header_label)
{
    global $assoc_actions, $item_rows;
    /* ================= input validation and session storage ================= */
    get_filter_request_var('id');
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'host_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'associated' => array('filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => array('options' => 'sanitize_search_string')));
    validate_store_request_vars($filters, 'sess_maint');
    /* ================= input validation ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == '-1') {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL  = 'maint.php?tab=hosts&action=edit&id=<?php 
    print get_request_var('id');
    ?>
'
		strURL += '&rows=' + $('#rows').val();
		strURL += '&host_template_id=' + $('#host_template_id').val();
		strURL += '&associated=' + $('#associated').is(':checked');
		strURL += '&filter=' + $('#filter').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = 'maint.php?tab=hosts&action=edit&id=<?php 
    print get_request_var('id');
    ?>
&clear=true&header=false'
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    html_start_box(__('Associated Devices %s', htmlspecialchars($header_label)), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form name='form_devices' method='post' action='maint.php?action=edit&tab=hosts'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Type');
    ?>
					</td>
					<td>
						<select id='host_template_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('host_template_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Any');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('host_template_id') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('None');
    ?>
</option>
							<?php 
    $host_templates = db_fetch_assoc('SELECT DISTINCT ht.id, ht.name 
								FROM host_template AS ht
								INNER JOIN host AS h
								ON h.host_template_id=ht.id 
								ORDER BY ht.name');
    if (sizeof($host_templates) > 0) {
        foreach ($host_templates as $host_template) {
            print "<option value='" . $host_template['id'] . "'";
            if (get_request_var('host_template_id') == $host_template['id']) {
                print ' selected';
            }
            print '>' . htmlspecialchars($host_template['name']) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Devices');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' name='clear' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_request_var('page');
    ?>
'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var('filter'))) {
        $sql_where = "WHERE (h.hostname LIKE '%" . get_request_var('filter') . "%' \n\t\t\tOR h.description LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    if (get_request_var('host_template_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_template_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' h.host_template_id=0';
    } elseif (!isempty_request_var('host_template_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' h.host_template_id=' . get_request_var('host_template_id');
    }
    if (get_request_var('associated') == 'false') {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' type=1 AND schedule=' . get_request_var('id');
    }
    if (get_request_var('id')) {
        $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(DISTINCT h.id)\n\t\t\tFROM host AS h\n\t\t\tLEFT JOIN (SELECT DISTINCT host_id FROM thold_data) AS td \n\t\t\tON h.id=td.host_id\n\t\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\t\tON h.id=pmh.host\n\t\t\tAND pmh.schedule=" . get_request_var('id') . "\n\t\t\t{$sql_where}");
    } else {
        $total_rows = 0;
    }
    $sortby = get_request_var('sort_column');
    if ($sortby == 'hostname') {
        $sortby = 'INET_ATON(hostname)';
    }
    if (get_request_var('id')) {
        $sql_query = 'SELECT h.*, pmh.type, graphs, data_sources, tholds, 
			(SELECT schedule FROM plugin_maint_hosts WHERE host=h.id AND schedule=' . get_request_var('id') . ") AS associated \n\t\t\tFROM host as h\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS tholds, host_id FROM thold_data GROUP BY host_id) AS td\n\t\t\tON td.host_id=h.id\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS graphs, host_id FROM graph_local GROUP BY host_id) AS gl\n\t\t\tON gl.host_id=h.id\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS data_sources, host_id FROM data_local GROUP BY host_id) AS dl\n\t\t\ton dl.host_id=h.id\n\t\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\t\tON pmh.host=h.id\n\t\t\tAND pmh.schedule=" . get_request_var('id') . "\n\t\t\t{$sql_where} \n\t\t\tGROUP BY h.id\n\t        ORDER BY " . $sortby . ' ' . get_request_var('sort_direction') . '
			LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows;
        $hosts = db_fetch_assoc($sql_query);
    } else {
        $hosts = array();
    }
    $display_text = array('description' => array('display' => __('Description'), 'align' => 'left', 'sort' => 'ASC'), 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'asc'), 'nosort' => array('display' => __('Associated Schedules'), 'align' => 'left', 'sort' => ''), 'graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'desc'), 'data_sources' => array('display' => __('Data Sources'), 'align' => 'right', 'sort' => 'desc'), 'tholds' => array('display' => __('Thresholds'), 'align' => 'right', 'sort' => 'desc'), 'nosort1' => array('display' => __('Status'), 'align' => 'center', 'sort' => ''), 'hostname' => array('display' => __('Hostname'), 'align' => 'left', 'sort' => 'desc'));
    /* generate page list */
    $nav = html_nav_bar('maint.php?action=edit&tab=hosts&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, __('Devices'), 'page', 'main');
    form_start('maint.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'maint.php?action=edit&tab=hosts&id=' . get_request_var('id'));
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            form_alternate_row('line' . $host['id']);
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['description'])) : htmlspecialchars($host['description']), $host['id'], 250);
            form_selectable_cell(number_format_i18n($host['id']), $host['id'], '', 'text-align:right');
            if ($host['associated'] != '') {
                $names = '<span class="deviceUp">' . __('Current Schedule') . '</span>';
            } else {
                $names = '';
            }
            if (sizeof($lists = db_fetch_assoc('SELECT name FROM plugin_maint_schedules INNER JOIN plugin_maint_hosts ON plugin_maint_schedules.id=plugin_maint_hosts.schedule WHERE type=1 AND host=' . $host['id'] . ' AND plugin_maint_schedules.id != ' . get_request_var('id')))) {
                foreach ($lists as $name) {
                    $names .= (strlen($names) ? ', ' : '') . "<span class='deviceRecovering'>" . $name['name'] . '</span>';
                }
            }
            if ($names == '') {
                form_selectable_cell('<span class="deviceUnknown">' . __('No Schedules') . '</span>', $host['id']);
            } else {
                form_selectable_cell($names, $host['id']);
            }
            form_selectable_cell(number_format_i18n($host['graphs']), $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format_i18n($host['data_sources']), $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format_i18n($host['tholds']), $host['id'], '', 'text-align:right');
            form_selectable_cell(get_colored_device_status($host['disabled'] == 'on' ? true : false, $host['status']), $host['id'], '', 'text-align:center');
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['hostname'])) : htmlspecialchars($host['hostname']), $host['id']);
            form_checkbox_cell($host['description'], $host['id']);
            form_end_row();
        }
    } else {
        print "<tr><td colspan='8'><em>" . __('No Associated Devices Found') . "</em></td></tr>";
    }
    html_end_box(false);
    if (sizeof($hosts)) {
        print $nav;
    }
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_hosts', '1', '');
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($assoc_actions);
    form_end();
}
Esempio n. 8
0
function edit_devices()
{
    global $device_edit;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    $device = array();
    if (!isempty_request_var('id')) {
        $device = db_fetch_row('SELECT * FROM plugin_flowview_devices WHERE id=' . get_request_var('id'), FALSE);
        $header_label = '[edit: ' . $device['name'] . ']';
    } else {
        $header_label = '[new]';
    }
    form_start('flowview_devices.php', 'chk');
    html_start_box("Device: {$header_label}", '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($device_edit, $device)));
    html_end_box();
    form_save_button('flowview_devices.php?tab=listeners');
}
Esempio n. 9
0
function syslog_action_edit()
{
    global $message_types, $severities;
    include dirname(__FILE__) . '/config.php';
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('type');
    get_filter_request_var('date');
    /* ==================================================== */
    if (!isempty_request_var('id') && get_nfilter_request_var('action') == 'edit') {
        $alert = syslog_db_fetch_row('SELECT *
			FROM `' . $syslogdb_default . '`.`syslog_alert`
			WHERE id=' . get_request_var('id'));
        if (sizeof($alert)) {
            $header_label = __('Alert Edit [edit: %s]' . $alert['name']);
        } else {
            $header_label = __('Alert Edit [new]');
        }
    } else {
        if (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') {
            $syslog_rec = syslog_db_fetch_row("SELECT * FROM `" . $syslogdb_default . "`.`syslog` WHERE seq=" . get_request_var("id") . (isset_request_var('date') ? " AND logtime='" . get_request_var("date") . "'" : ""));
            $header_label = __('Alert Ednt [new]');
            if (sizeof($syslog_rec)) {
                $alert['message'] = $syslog_rec['message'];
            }
            $alert['name'] = __('New Alert Rule');
        } else {
            $header_label = __('Alert Edit [new]');
            $alert['name'] = __('New Alert Rule');
        }
    }
    $alert_retention = read_config_option('syslog_alert_retention');
    if ($alert_retention != '' && $alert_retention > 0 && $alert_retention < 365) {
        $repeat_end = $alert_retention * 24 * 60 / 5;
    }
    $repeatarray = array(0 => __('Not Set'), 1 => __('%d Minutes', 5), 2 => __('%d Minutes', 10), 3 => __('%d Minutes', 15), 4 => __('%d Minutes', 20), 6 => __('%d Minutes', 30), 8 => __('%d Minutes', 45), 12 => __('%d Hour', 1), 24 => __('%d Hours', 2), 36 => __('%d Hours', 3), 48 => __('%d Hours', 4), 72 => __('%d Hours', 6), 96 => __('%d Hours', 8), 144 => __('%d Hours', 12), 288 => __('%d Day', 1), 576 => __('%d Days', 2), 2016 => __('%d Week', 1), 4032 => __('%d Weeks', 2), 8640 => __('Month'));
    if ($repeat_end) {
        foreach ($repeatarray as $i => $value) {
            if ($i > $repeat_end) {
                unset($repeatarray[$i]);
            }
        }
    }
    $fields_syslog_alert_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Alert Details')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Alert Name'), 'description' => __('Please describe this Alert.'), 'value' => '|arg1:name|', 'max_length' => '250', 'size' => 80), 'severity' => array('method' => 'drop_array', 'friendly_name' => __('Severity'), 'description' => __('What is the Severity Level of this Alert?'), 'value' => '|arg1:severity|', 'array' => $severities, 'default' => '1'), 'report_method' => array('method' => 'drop_array', 'friendly_name' => __('Reporting Method'), 'description' => __('Define how to Alert on the syslog messages.'), 'value' => '|arg1:method|', 'array' => array('0' => __('Individual'), '1' => __('Threshold')), 'default' => '0'), 'num' => array('method' => 'textbox', 'friendly_name' => __('Threshold'), 'description' => __('For the \'Threshold\' method, If the number seen is above this value an Alert will be triggered.'), 'value' => '|arg1:num|', 'size' => '4', 'max_length' => '10', 'default' => '1'), 'type' => array('method' => 'drop_array', 'friendly_name' => __('String Match Type'), 'description' => __('Define how you would like this string matched.  If using the SQL Expression type you may use any valid SQL expression
			to generate the alarm.  Available fields include \'message\', \'facility\', \'priority\', and \'host\'.'), 'value' => '|arg1:type|', 'array' => $message_types, 'on_change' => 'changeTypes()', 'default' => 'matchesc'), 'message' => array('friendly_name' => __('Syslog Message Match String'), 'description' => __('Enter the matching component of the syslog message, the facility or host name, or the SQL where clause if using the SQL Expression Match Type.'), 'textarea_rows' => '2', 'textarea_cols' => '70', 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:message|', 'default' => ''), 'enabled' => array('method' => 'drop_array', 'friendly_name' => __('Alert Enabled'), 'description' => __('Is this Alert Enabled?'), 'value' => '|arg1:enabled|', 'array' => array('on' => __('Enabled'), '' => __('Disabled')), 'default' => 'on'), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => '0', 'description' => __('Do not resend this alert again for the same host, until this amount of time has elapsed. For threshold based alarms, this applies to all hosts.'), 'value' => '|arg1:repeat_alert|'), 'notes' => array('friendly_name' => __('Alert Notes'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Space for Notes on the Alert'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:notes|', 'default' => ''), 'spacer1' => array('method' => 'spacer', 'friendly_name' => __('Alert Actions')), 'open_ticket' => array('method' => 'drop_array', 'friendly_name' => __('Open Ticket'), 'description' => __('Should a Help Desk Ticket be opened for this Alert'), 'value' => '|arg1:open_ticket|', 'array' => array('on' => __('Yes'), '' => __('No')), 'default' => ''), 'email' => array('method' => 'textarea', 'friendly_name' => __('E-Mails to Notify'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Please enter a comma delimited list of e-mail addresses to inform.  If you
			wish to send out e-mail to a recipient in SMS format, please prefix that recipient\'s e-mail address
			with <b>\'sms@\'</b>.  For example, if the recipients SMS address is <b>\'2485551212@mycarrier.net\'</b>, you would
			enter it as <b>\'sms@2485551212@mycarrier.net\'</b> and it will be formatted as an SMS message.'), 'class' => 'textAreaNotes', 'value' => '|arg1:email|', 'max_length' => '255'), 'command' => array('friendly_name' => __('Alert Command'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('When an Alert is triggered, run the following command.  The following replacement variables
			are available <b>\'&lt;HOSTNAME&gt;\'</b>, <b>\'&lt;ALERTID&gt;\'</b>, <b>\'&lt;MESSAGE&gt;\'</b>,
			<b>\'&lt;FACILITY&gt;\'</b>, <b>\'&lt;PRIORITY&gt;\'</b>, <b>\'&lt;SEVERITY&gt;\'</b>.  Please
			note that <b>\'&lt;HOSTNAME&gt;\'</b> is only available on individual thresholds.'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:command|', 'default' => ''), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_alert' => array('method' => 'hidden', 'value' => '1'));
    form_start('syslog_alerts.php', 'syslog_edit');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_syslog_alert_edit, sizeof($alert) ? $alert : array())));
    html_end_box();
    form_save_button('syslog_alerts.php', '', 'id');
    ?>
	<script type='text/javascript'>

	function changeTypes() {
		if ($('#type').val() == 'sql') {
			$('#message').prep('rows', 6);
		}else{
			$('#message').prep('rows', 2);
		}
	}
	</script>

	<?php 
}
Esempio n. 10
0
function mikrotik_view_graphs()
{
    global $current_user, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    /* include graph view filter selector */
    html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")');
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset_request_var('style')) {
        if (get_request_var('style') == 'selective') {
            /* process selected graphs */
            if (!isempty_request_var('graph_list')) {
                foreach (explode(',', get_request_var('graph_list')) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!isempty_request_var('graph_add')) {
                foreach (explode(',', get_request_var('graph_add')) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!isempty_request_var('graph_remove')) {
                foreach (explode(',', get_request_var('graph_remove')) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id');
                $set_rra_id = empty($rra_id) ? read_user_setting('default_rra_id') : get_request_var('rra_id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if (get_request_var('host_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id');
    } else {
        $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes);
        if (sizeof($host_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    // Graph Template Id sql_where
    if (get_request_var('graph_template_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN(' . get_request_var('graph_template_id') . ')';
    } else {
        $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes);
        if (sizeof($graph_template_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs');
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), __('Graphs'), 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    }
    html_end_box();
    if ($total_graphs > 0) {
        print $nav;
    }
    bottom_footer();
}
Esempio n. 11
0
function mactrack_macw_edit()
{
    global $fields_mactrack_macw_edit;
    /* ================= input validation ================= */
    get_filter_request_var('mac_id');
    /* ==================================================== */
    display_output_messages();
    if (!isempty_request_var('mac_id')) {
        $mac_record = db_fetch_row_prepared('SELECT * FROM mac_track_macwatch WHERE mac_id = ?', array(get_request_var('mac_id')));
        $header_label = __('MacTrack MacWatch [edit: %s]', $mac_record['name']);
    } else {
        $header_label = __('MacTrack MacWatch [new]');
    }
    form_start('mactrack_macwatch.php', 'mactrack_macwatch');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_macw_edit, isset($mac_record) ? $mac_record : array())));
    html_end_box();
    form_save_button('mactrack_macwatch.php', 'return');
}
function mactrack_device_type_edit()
{
    global $config, $fields_mactrack_device_type_edit;
    /* ================= input validation ================= */
    get_filter_request_var('device_type_id');
    /* ==================================================== */
    display_output_messages();
    if (!isempty_request_var('device_type_id')) {
        $device_type = db_fetch_row_prepared('SELECT * 
			FROM mac_track_device_types 
			WHERE device_type_id = ?', array(get_request_var('device_type_id')));
        $header_label = __('MacTrack Device Types [edit: %s]', $device_type['description']);
    } else {
        $header_label = __('MacTrack Device Types [new]');
    }
    form_start('mactrack_device_types.php', 'chk');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => 'true'), 'fields' => inject_form_variables($fields_mactrack_device_type_edit, isset($device_type) ? $device_type : array())));
    html_end_box();
    form_save_button('mactrack_device_types.php', 'return', 'device_type_id');
}
Esempio n. 13
0
function edit_schedule()
{
    global $config, $schedule_edit, $colors;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    $report = array();
    if (!isempty_request_var('id')) {
        $report = db_fetch_row('SELECT pfs.*, pfq.name 
			FROM plugin_flowview_schedules AS pfs 
			LEFT JOIN plugin_flowview_queries AS pfq
			ON (pfs.savedquery=pfq.id) 
			WHERE pfs.id=' . get_request_var('id'), FALSE);
        $header_label = '[edit: ' . $report['name'] . ']';
    } else {
        $header_label = '[new]';
    }
    form_start('flowview_schedules.php', 'chk');
    html_start_box('Report: ' . $header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($schedule_edit, $report)));
    html_end_box();
    ?>
	<script type='text/javascript'>
	var startOpen = false;

	$(function() {
		$('#start').after("<i id='startDate' class='calendar fa fa-calendar' title='Start Date Selector'></i>");
		$('#startDate').click(function() {
			if (startOpen) {
				startOpen = false;
				$('#start').datetimepicker('hide');
			}else{
				startOpen = true;
				$('#start').datetimepicker('show');
			}
		});

		$('#start').datetimepicker({
			minuteGrid: 10,
			stepMinute: 1,
			showAnim: 'slideDown',
			numberOfMonths: 1,
			timeFormat: 'HH:mm',
			dateFormat: 'yy-mm-dd',
			showButtonPanel: false
		});
	});
	</script>
	<?php 
    form_save_button('flowview_schedules.php?tab=sched');
}
Esempio n. 14
0
function thold_graph_button($data)
{
    global $config;
    $local_graph_id = $data[1]['local_graph_id'];
    $rra_id = $data[1]['rra'];
    if (isset_request_var('view_type') && !isempty_request_var('view_type')) {
        $view_type = get_request_var('view_type');
    } else {
        set_request_var('view_type', '');
        $view_type = read_config_option('dataquery_type');
    }
    if (isset_request_var('graph_start') && !isempty_request_var('graph_start')) {
        $start = get_request_var('graph_start');
    } else {
        set_request_var('graph_start', '');
        $start = time() - 3600;
    }
    if (isset_request_var('graph_end') && !isempty_request_var('graph_end')) {
        $end = get_request_var('graph_end');
    } else {
        set_request_var('graph_end', '');
        $end = time();
    }
    if (!isset($_SESSION['sess_config_array']['thold_draw_vrules'])) {
        $_SESSION['sess_config_array']['thold_draw_vrules'] = 'off';
    }
    $url = $_SERVER['REQUEST_URI'];
    $url = str_replace('&thold_vrule=on', '', $url);
    $url = str_replace('&thold_vrule=off', '', $url);
    if (!substr_count($url, '?')) {
        $separator = '?';
    } else {
        $separator = '&';
    }
    if (api_user_realm_auth('thold_graph.php')) {
        print '<a class="hyperLink" href="' . $url . $separator . 'thold_vrule=' . ($_SESSION['sess_config_array']['thold_draw_vrules'] == 'on' ? 'off' : 'on') . '"><img src="' . $config['url_path'] . 'plugins/thold/images/reddot.png" border="0" alt="" title="' . __('Toggle Threshold VRULES %s', $_SESSION['sess_config_array']['thold_draw_vrules'] == 'on' ? __('Off') : __('On')) . '" style="padding: 3px;"></a><br>';
    }
    // Add Threshold Creation button
    if (api_user_realm_auth('thold.php')) {
        if (isset_request_var('tree_id')) {
            get_filter_request_var('tree_id');
        }
        if (isset_request_var('leaf_id')) {
            get_filter_request_var('leaf_id');
        }
        print '<a class="hyperLink" href="' . htmlspecialchars($config['url_path'] . 'plugins/thold/thold.php?action=add' . '&usetemplate=1&local_graph_id=' . $local_graph_id) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Create Threshold') . '" style="padding: 3px;"></a><br>';
    }
}
Esempio n. 15
0
function save_thold()
{
    global $banner;
    $host_id = get_filter_request_var('host_id');
    $local_data_id = get_filter_request_var('local_data_id');
    $local_graph_id = get_filter_request_var('local_graph_id');
    $data_template_rrd_id = get_filter_request_var('data_template_rrd_id');
    $template_enabled = isset_request_var('template_enabled') && get_nfilter_request_var('template_enabled') == 'on' ? 'on' : '';
    if ($template_enabled == 'on') {
        if (!thold_user_auth_threshold($local_data_id)) {
            $banner = "<span class='textError'>" . __('Permission Denied') . "</span>";
            $_SESSION['thold_message'] = $banner;
            raise_message('thold_message');
            return;
        }
        $data = db_fetch_row_prepared('SELECT id, thold_template_id 
			FROM thold_data 
			WHERE local_data_id = ?
			AND data_template_rrd_id = ?', array($local_data_id, $data_template_rrd_id));
        thold_template_update_threshold($data['id'], $data['thold_template_id']);
        $banner = "<span class='textInfo'>" . __('Record Updated') . "</span>";
        plugin_thold_log_changes($data['id'], 'modified', array('id' => $data['id'], 'template_enabled' => 'on'));
        $_SESSION['thold_message'] = $banner;
        raise_message('thold_message');
        return get_filter_request_var('id');
    }
    if (isset_request_var('id')) {
        /* Do Some error Checks */
        $banner = "<span class='textError'>";
        if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_fail_trigger') != 0) {
            $banner .= __('You must specify either &quot;High Alert Threshold&quot; or &quot;Low Alert Threshold&quot; or both!<br>RECORD NOT UPDATED!</span>');
            $_SESSION['thold_message'] = $banner;
            raise_message('thold_message');
            return get_filter_request_var('id');
        }
        if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_warning_fail_trigger') != 0) {
            $banner .= __('You must specify either &quot;High Warning Threshold&quot; or &quot;Low Warning Threshold&quot; or both!<br>RECORD NOT UPDATED!</span>');
            $_SESSION['thold_message'] = $banner;
            raise_message('thold_message');
            return get_filter_request_var('id');
        }
        if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT) != '' && get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT) != '' && round(get_filter_request_var('thold_low'), 4) >= round(get_filter_request_var('thold_hi'), 4)) {
            $banner .= __('Impossible thresholds: &quot;High Threshold&quot; smaller than or equal to &quot;Low Threshold&quot;<br>RECORD NOT UPDATED!</span>');
            $_SESSION['thold_message'] = $banner;
            raise_message('thold_message');
            return get_filter_request_var('id');
        }
        if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT) != '' && get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT) != '' && round(get_filter_request_var('thold_warning_low'), 4) >= round(get_filter_request_var('thold_warning_hi'), 4)) {
            $banner .= __('Impossible thresholds: &quot;High Warning Threshold&quot; smaller than or equal to &quot;Low Warning Threshold&quot;<br>RECORD NOT UPDATED!</span>');
            $_SESSION['thold_message'] = $banner;
            raise_message('thold_message');
            return get_filter_request_var('id');
        }
        if (get_filter_request_var('thold_type') == 1) {
            $banner .= __('With baseline thresholds enabled.');
            if (!thold_mandatory_field_ok('bl_ref_time_range', 'Time reference in the past')) {
                $banner .= '</span>';
                $_SESSION['thold_message'] = $banner;
                raise_message('thold_message');
                return get_filter_request_var('id');
            }
            if (isempty_request_var('bl_pct_down') && isempty_request_var('bl_pct_up')) {
                $banner .= __('You must specify either &quot;Baseline Deviation UP&quot; or &quot;Baseline Deviation DOWN&quot; or both!<br>RECORD NOT UPDATED!</span>');
                $_SESSION['thold_message'] = $banner;
                raise_message('thold_message');
                return get_filter_request_var('id');
            }
        }
    }
    $save = array();
    if (isset_request_var('id')) {
        $save['id'] = get_filter_request_var('id');
    } else {
        $save['id'] = '0';
        $save['thold_template_id'] = '';
    }
    get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('thold_fail_trigger');
    get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('thold_warning_fail_trigger');
    get_filter_request_var('repeat_alert');
    get_filter_request_var('cdef');
    get_filter_request_var('local_data_id');
    get_filter_request_var('data_template_rrd_id');
    get_filter_request_var('thold_type');
    get_filter_request_var('time_hi', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('time_low', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('time_fail_trigger');
    get_filter_request_var('time_fail_length');
    get_filter_request_var('time_warning_hi', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('time_warning_low', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('time_warning_fail_trigger');
    get_filter_request_var('time_warning_fail_length');
    get_filter_request_var('data_type');
    get_filter_request_var('notify_warning');
    get_filter_request_var('notify_alert');
    get_filter_request_var('bl_ref_time_range');
    get_filter_request_var('bl_pct_down', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('bl_pct_up', FILTER_VALIDATE_FLOAT);
    get_filter_request_var('bl_fail_trigger');
    if (isset_request_var('snmp_event_category')) {
        set_request_var('snmp_event_category', trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('snmp_event_category'))));
    }
    if (isset_request_var('snmp_event_severity')) {
        get_filter_request_var('snmp_event_severity');
    }
    if (isset_request_var('snmp_event_warning_severity')) {
        get_filter_request_var('snmp_event_warning_severity');
    }
    if (!isempty_request_var('name')) {
        $name = str_replace(array("\\", '"', "'"), '', get_nfilter_request_var('name'));
    } elseif (isset_request_var('data_template_rrd_id')) {
        $data_source_name = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array(get_request_var('data_template_rrd_id')));
        $data_template = db_fetch_row_prepared('SELECT * FROM data_template_data WHERE id = ?', array(get_request_var('data_template_id')));
        $local_data_id = get_request_var('local_data_id');
        $local_graph_id = get_request_var('local_graph_id');
        $name = thold_format_name($data_template, $local_graph_id, $local_data_id, $data_source_name);
    }
    $save['name'] = trim_round_request_var('name');
    $save['host_id'] = $host_id;
    $save['data_template_rrd_id'] = get_request_var('data_template_rrd_id');
    $save['local_data_id'] = get_request_var('local_data_id');
    $save['thold_enabled'] = isset_request_var('thold_enabled') ? 'on' : 'off';
    $save['exempt'] = isset_request_var('exempt') ? 'on' : '';
    $save['restored_alert'] = isset_request_var('restored_alert') ? 'on' : '';
    $save['thold_type'] = get_request_var('thold_type');
    $save['template_enabled'] = isset_request_var('template_enabled') ? 'on' : '';
    // High / Low
    $save['thold_hi'] = trim_round_request_var('thold_hi', 4);
    $save['thold_low'] = trim_round_request_var('thold_low', 4);
    $save['thold_fail_trigger'] = isempty_request_var('thold_fail_trigger') ? read_config_option('alert_trigger') : get_nfilter_request_var('thold_fail_trigger');
    // Time Based
    $save['time_hi'] = trim_round_request_var('time_hi', 4);
    $save['time_low'] = trim_round_request_var('time_low', 4);
    $save['time_fail_trigger'] = isempty_request_var('time_fail_trigger') ? read_config_option('thold_warning_time_fail_trigger') : get_nfilter_request_var('time_fail_trigger');
    $save['time_fail_length'] = isempty_request_var('time_fail_length') ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : get_nfilter_request_var('time_fail_length');
    // Warning High / Low
    $save['thold_warning_hi'] = trim_round_request_var('thold_warning_hi', 4);
    $save['thold_warning_low'] = trim_round_request_var('thold_warning_low', 4);
    $save['thold_warning_fail_trigger'] = isempty_request_var('thold_warning_fail_trigger') ? read_config_option('alert_trigger') : get_nfilter_request_var('thold_warning_fail_trigger');
    // Warning Time Based
    $save['time_warning_hi'] = trim_round_request_var('time_warning_hi', 4);
    $save['time_warning_low'] = trim_round_request_var('time_warning_low', 4);
    $save['time_warning_fail_trigger'] = isempty_request_var('time_warning_fail_trigger') ? read_config_option('thold_warning_time_fail_trigger') : get_nfilter_request_var('time_warning_fail_trigger');
    $save['time_warning_fail_length'] = isempty_request_var('time_warning_fail_length') ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : get_nfilter_request_var('time_warning_fail_length');
    // Baseline
    $save['bl_thold_valid'] = '0';
    $save['bl_ref_time_range'] = isempty_request_var('bl_ref_time_range') ? read_config_option('alert_bl_timerange_def') : get_nfilter_request_var('bl_ref_time_range');
    $save['bl_pct_down'] = trim_round_request_var('bl_pct_down');
    $save['bl_pct_up'] = trim_round_request_var('bl_pct_up');
    $save['bl_fail_trigger'] = isempty_request_var('bl_fail_trigger') ? read_config_option("alert_bl_trigger") : get_nfilter_request_var('bl_fail_trigger');
    $save['repeat_alert'] = trim_round_request_var('repeat_alert');
    // Notification
    $save['notify_extra'] = trim_round_request_var('notify_extra');
    $save['notify_warning_extra'] = trim_round_request_var('notify_warning_extra');
    $save['notify_warning'] = trim_round_request_var('notify_warning');
    $save['notify_alert'] = trim_round_request_var('notify_alert');
    // Data Manipulation
    $save['data_type'] = get_nfilter_request_var('data_type');
    if (isset_request_var('percent_ds')) {
        $save['percent_ds'] = get_nfilter_request_var('percent_ds');
    } else {
        $save['percent_ds'] = '';
    }
    $save['cdef'] = trim_round_request_var('cdef');
    if (isset_request_var('expression')) {
        $save['expression'] = get_nfilter_request_var('expression');
    } else {
        $save['expression'] = '';
    }
    // SNMP Information
    $save['snmp_event_category'] = trim_round_request_var('snmp_event_category');
    $save['snmp_event_severity'] = isset_request_var('snmp_event_severity') ? get_nfilter_request_var('snmp_event_severity') : 4;
    $save['snmp_event_warning_severity'] = isset_request_var('snmp_event_warning_severity') ? get_nfilter_request_var('snmp_event_warning_severity') : 3;
    /* Get the Data Template, Graph Template, and Graph */
    $rrdsql = db_fetch_row('SELECT id, data_template_id 
		FROM data_template_rrd 
		WHERE local_data_id=' . $save['local_data_id'] . ' 
		ORDER BY id');
    $rrdlookup = $rrdsql['id'];
    $grapharr = db_fetch_row("SELECT local_graph_id, graph_template_id \n\t\tFROM graph_templates_item \n\t\tWHERE task_item_id={$rrdlookup} \n\t\tAND local_graph_id <> '' \n\t\tLIMIT 1");
    $save['local_graph_id'] = $grapharr['local_graph_id'];
    $save['graph_template_id'] = $grapharr['graph_template_id'];
    $save['data_template_id'] = $rrdsql['data_template_id'];
    if (!thold_user_auth_threshold($save['local_data_id'])) {
        $banner = "<span class='textError'>Permission Denied</span>";
        $_SESSION['thold_message'] = $banner;
        raise_message('thold_message');
        return '';
    }
    $id = sql_save($save, 'thold_data');
    if (isset_request_var('notify_accounts') && is_array(get_nfilter_request_var('notify_accounts'))) {
        thold_save_threshold_contacts($id, get_nfilter_request_var('notify_accounts'));
    } elseif (!isset_request_var('notify_accounts')) {
        thold_save_threshold_contacts($id, array());
    }
    if ($id) {
        plugin_thold_log_changes($id, 'modified', $save);
        $thold = db_fetch_row_prepared('SELECT * FROM thold_data WHERE id= ?', array($id));
        if ($thold['thold_type'] == 1) {
            thold_check_threshold($thold);
        }
        set_request_var('id', $id);
    } else {
        set_request_var('id', '0');
    }
    $banner = "<span class='textInfo'>" . __('Record Updated') . "</span>";
    $_SESSION['thold_message'] = $banner;
    raise_message('thold_message');
    return $id;
}
Esempio n. 16
0
function thold_show_log()
{
    global $config, $item_rows, $thold_log_states, $thold_status, $thold_types, $thold_log_retention;
    $step = read_config_option('poller_interval');
    /* ================= input validation and session storage ================= */
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'time', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'DESC', 'options' => array('options' => 'sanitize_search_string')), 'threshold_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'));
    validate_store_request_vars($filters, 'sess_thold_log');
    /* ================= input validation ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $days = read_config_option('thold_log_storage');
    if (isset($thold_log_retention[$days])) {
        $days = $thold_log_retention[$days];
    } else {
        $days = __('%d Days', $days);
    }
    html_start_box(__('Threshold Log for [ %s ]', $days), '100%', '', '3', 'center', '');
    form_thold_log_filter();
    html_end_box();
    $sql_where = '';
    if (get_request_var('host_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' h.id IS NULL';
    } elseif (!isempty_request_var('host_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.host_id=' . get_request_var('host_id');
    }
    if (get_request_var('threshold_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('threshold_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' td.id IS NULL';
    } elseif (!isempty_request_var('threshold_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.threshold_id=' . get_request_var('threshold_id');
    }
    if (get_request_var('status') == '-1') {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.status=' . get_request_var('status');
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . " tl.description LIKE '%" . get_request_var('filter') . "%'";
    }
    $sortby = get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    $limit = $rows * (get_request_var('page') - 1) . ',' . $rows;
    $logs = get_allowed_threshold_logs($sql_where, $sortby, $limit, $total_rows);
    $nav = html_nav_bar('thold_graph.php?action=log', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('Log Entries'), 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('hdescription' => array('display' => __('Device'), 'sort' => 'ASC', 'align' => 'left'), 'time' => array('display' => __('Time'), 'sort' => 'ASC', 'align' => 'left'), 'type' => array('display' => __('Type'), 'sort' => 'DESC', 'align' => 'left'), 'description' => array('display' => __('Event Description'), 'sort' => 'ASC', 'align' => 'left'), 'threshold_value' => array('display' => __('Alert Value'), 'sort' => 'ASC', 'align' => 'right'), 'current' => array('display' => __('Measured Value'), 'sort' => 'ASC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=log');
    $i = 0;
    if (sizeof($logs)) {
        foreach ($logs as $l) {
            ?>
			<tr class='<?php 
            print $thold_log_states[$l['status']]['class'];
            ?>
'>
			<td class='left nowrap'><?php 
            print $l['hdescription'];
            ?>
</td>
			<td class='left nowrap'><?php 
            print date('Y-m-d H:i:s', $l['time']);
            ?>
</td>
			<td class='left nowrap'><?php 
            print $thold_types[$l['type']];
            ?>
</td>
			<td class='left nowrap'><?php 
            print strlen($l['description']) ? $l['description'] : __('Restoral Event');
            ?>
</td>
			<td class='right'><?php 
            print $l['threshold_value'] != '' ? thold_format_number($l['threshold_value']) : __('N/A');
            ?>
</td>
			<td class='right'><?php 
            print $l['current'] != '' ? thold_format_number($l['current']) : __('N/A');
            ?>
</td>
			<?php 
            form_end_row();
        }
    } else {
        print '<tr><td class="center" colspan="8">' . __('No Threshold Logs Found') . '</td></tr>';
    }
    html_end_box(false);
    if (sizeof($logs)) {
        print $nav;
    }
    log_legend();
}
Esempio n. 17
0
function template_save_edit()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('thold_type');
    get_filter_request_var('thold_hi');
    get_filter_request_var('thold_low');
    get_filter_request_var('thold_fail_trigger');
    get_filter_request_var('time_hi');
    get_filter_request_var('time_low');
    get_filter_request_var('time_fail_trigger');
    get_filter_request_var('time_fail_length');
    get_filter_request_var('thold_warning_type');
    get_filter_request_var('thold_warning_hi');
    get_filter_request_var('thold_warning_low');
    get_filter_request_var('thold_warning_fail_trigger');
    get_filter_request_var('time_warning_hi');
    get_filter_request_var('time_warning_low');
    get_filter_request_var('time_warning_fail_trigger');
    get_filter_request_var('time_warning_fail_length');
    get_filter_request_var('bl_ref_time_range');
    get_filter_request_var('bl_pct_down');
    get_filter_request_var('bl_pct_up');
    get_filter_request_var('bl_fail_trigger');
    get_filter_request_var('repeat_alert');
    get_filter_request_var('data_type');
    get_filter_request_var('cdef');
    get_filter_request_var('notify_warning');
    get_filter_request_var('notify_alert');
    get_filter_request_var('snmp_event_severity');
    get_filter_request_var('snmp_event_warning_severity');
    /* ==================================================== */
    /* clean up date1 string */
    if (isset_request_var('name')) {
        set_request_var('name', trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('name'))));
    }
    if (isset_request_var('snmp_trap_category')) {
        set_request_var('snmp_event_category', db_qstr(trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('snmp_event_category')))));
    }
    /* save: data_template */
    $save['id'] = get_nfilter_request_var('id');
    $save['hash'] = get_hash_thold_template($save['id']);
    $save['name'] = get_nfilter_request_var('name');
    $save['thold_type'] = get_nfilter_request_var('thold_type');
    // High / Low
    $save['thold_hi'] = get_nfilter_request_var('thold_hi');
    $save['thold_low'] = get_nfilter_request_var('thold_low');
    $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    // Time Based
    $save['time_hi'] = get_nfilter_request_var('time_hi');
    $save['time_low'] = get_nfilter_request_var('time_low');
    $save['time_fail_trigger'] = get_nfilter_request_var('time_fail_trigger');
    $save['time_fail_length'] = get_nfilter_request_var('time_fail_length');
    if (isset_request_var('thold_fail_trigger') && get_nfilter_request_var('thold_fail_trigger') != '') {
        $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_fail_trigger'] = 5;
        }
    }
    /***  Warnings  ***/
    // High / Low Warnings
    $save['thold_warning_hi'] = get_nfilter_request_var('thold_warning_hi');
    $save['thold_warning_low'] = get_nfilter_request_var('thold_warning_low');
    $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    // Time Based Warnings
    $save['time_warning_hi'] = get_nfilter_request_var('time_warning_hi');
    $save['time_warning_low'] = get_nfilter_request_var('time_warning_low');
    $save['time_warning_fail_trigger'] = get_nfilter_request_var('time_warning_fail_trigger');
    $save['time_warning_fail_length'] = get_nfilter_request_var('time_warning_fail_length');
    if (isset_request_var('thold_warning_fail_trigger') && get_nfilter_request_var('thold_warning_fail_trigger') != '') {
        $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_warning_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_warning_fail_trigger'] = 5;
        }
    }
    $save['thold_enabled'] = isset_request_var('thold_enabled') ? 'on' : 'off';
    $save['exempt'] = isset_request_var('exempt') ? 'on' : '';
    $save['restored_alert'] = isset_request_var('restored_alert') ? 'on' : '';
    if (isset_request_var('bl_ref_time_range') && get_nfilter_request_var('bl_ref_time_range') != '') {
        $save['bl_ref_time_range'] = get_nfilter_request_var('bl_ref_time_range');
    } else {
        $alert_bl_timerange_def = read_config_option('alert_bl_timerange_def');
        if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) {
            $save['bl_ref_time_range'] = $alert_bl_timerange_def;
        } else {
            $save['bl_ref_time_range'] = 10800;
        }
    }
    $save['bl_pct_down'] = get_nfilter_request_var('bl_pct_down');
    $save['bl_pct_up'] = get_nfilter_request_var('bl_pct_up');
    if (isset_request_var('bl_fail_trigger') && get_nfilter_request_var('bl_fail_trigger') != '') {
        $save['bl_fail_trigger'] = get_nfilter_request_var('bl_fail_trigger');
    } else {
        $alert_bl_trigger = read_config_option('alert_bl_trigger');
        if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) {
            $save['bl_fail_trigger'] = $alert_bl_trigger;
        } else {
            $save['bl_fail_trigger'] = 3;
        }
    }
    if (isset_request_var('repeat_alert') && get_nfilter_request_var('repeat_alert') != '') {
        $save['repeat_alert'] = get_nfilter_request_var('repeat_alert');
    } else {
        $alert_repeat = read_config_option('alert_repeat');
        if ($alert_repeat != '' && is_numeric($alert_repeat)) {
            $save['repeat_alert'] = $alert_repeat;
        } else {
            $save['repeat_alert'] = 12;
        }
    }
    if (isset_request_var('snmp_event_category')) {
        $save['snmp_event_category'] = get_nfilter_request_var('snmp_event_category');
        $save['snmp_event_severity'] = get_nfilter_request_var('snmp_event_severity');
    }
    if (isset_request_var('snmp_event_warning_severity')) {
        if (get_nfilter_request_var('snmp_event_warning_severity') > get_nfilter_request_var('snmp_event_severity')) {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_severity');
        } else {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_warning_severity');
        }
    }
    $save['notify_extra'] = get_nfilter_request_var('notify_extra');
    $save['notify_warning_extra'] = get_nfilter_request_var('notify_warning_extra');
    $save['notify_warning'] = get_nfilter_request_var('notify_warning');
    $save['notify_alert'] = get_nfilter_request_var('notify_alert');
    $save['cdef'] = get_nfilter_request_var('cdef');
    $save['data_type'] = get_nfilter_request_var('data_type');
    $save['percent_ds'] = get_nfilter_request_var('percent_ds');
    $save['expression'] = get_nfilter_request_var('expression');
    if (!is_error_message()) {
        $id = sql_save($save, 'thold_template');
        if ($id) {
            raise_message(1);
            if (isset_request_var('notify_accounts') && is_array(get_nfilter_request_var('notify_accounts'))) {
                thold_save_template_contacts($id, get_nfilter_request_var('notify_accounts'));
            } elseif (!isset_request_var('notify_accounts')) {
                thold_save_template_contacts($id, array());
            }
            thold_template_update_thresholds($id);
            plugin_thold_log_changes($id, 'modified_template', $save);
        } else {
            raise_message(2);
        }
    }
    if (is_error_message() || isempty_request_var('id')) {
        header('Location: thold_templates.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
    } else {
        header('Location: thold_templates.php?header=false');
    }
}
function mactrack_view_get_device_records(&$sql_where, $row_limit, $apply_limits = TRUE)
{
    $device_type_info = db_fetch_row_prepared('SELECT * FROM mac_track_device_types WHERE device_type_id = ?', array(get_request_var('device_type_id')));
    /* if the device type is not the same as the type_id, then reset it */
    if (sizeof($device_type_info) && get_request_var('type_id') != -1) {
        if ($device_type_info['device_type'] != get_request_var('type_id')) {
            $device_type_info = array();
        }
    } else {
        if (get_request_var('device_type_id') == 0) {
            $device_type_info = array('device_type_id' => 0, 'description' => __('Unknown Device Type'));
        }
    }
    /* form the 'where' clause for our main sql query */
    if (get_request_var('filter') != '') {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . "(mac_track_devices.hostname LIKE '%" . get_request_var('filter') . "%' OR " . "mac_track_devices.notes LIKE '%" . get_request_var('filter') . "%' OR " . "mac_track_devices.device_name LIKE '%" . get_request_var('filter') . "%' OR " . "mac_track_sites.site_name LIKE '%" . get_request_var('filter') . "%')";
    }
    if (sizeof($device_type_info)) {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.device_type_id=' . $device_type_info['device_type_id'] . ')';
    }
    if (get_request_var('status') == '-1') {
        /* Show all items */
    } elseif (get_request_var('status') == '-2') {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.disabled="on")';
    } elseif (get_request_var('status') == '5') {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.host_id=0)';
    } else {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.snmp_status=' . get_request_var('status') . ') AND (mac_track_devices.disabled = "")';
    }
    /* scan types matching */
    if (get_request_var('type_id') == '-1') {
        /* Show all items */
    } else {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.scan_type=' . get_request_var('type_id') . ')';
    }
    /* device types matching */
    if (get_request_var('device_type_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('device_type_id') == '-2') {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_device_types.description="")';
    } else {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.device_type_id=' . get_request_var('device_type_id') . ')';
    }
    if (get_request_var('site_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('site_id') == '-2') {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_sites.site_id IS NULL)';
    } elseif (!isempty_request_var('site_id')) {
        $sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . '(mac_track_devices.site_id=' . get_request_var('site_id') . ')';
    }
    $sql_query = "SELECT\n\t\tmac_track_devices.*,\n\t\tmac_track_device_types.description AS device_type,\n\t\tmac_track_sites.site_name\n\t\tFROM mac_track_sites\n\t\tRIGHT JOIN mac_track_devices ON (mac_track_devices.site_id=mac_track_sites.site_id)\n\t\tLEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id)\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    if ($apply_limits) {
        $sql_query .= ' LIMIT ' . $row_limit * (get_request_var('page') - 1) . ',' . $row_limit;
    }
    return db_fetch_assoc($sql_query);
}
Esempio n. 19
0
function mactrack_snmp_edit()
{
    global $config, $fields_mactrack_snmp_edit;
    include_once $config['base_path'] . '/plugins/mactrack/lib/mactrack_functions.php';
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('page');
    /* ==================================================== */
    /* clean up rule name */
    if (isset_request_var('name')) {
        set_request_var('name', sanitize_search_string(get_request_var('name')));
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('page', 'sess_mactrack_edit_current_page', '1');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    /* display the mactrack snmp option set */
    $snmp_group = array();
    if (!isempty_request_var('id')) {
        $snmp_group = db_fetch_row_prepared('SELECT * FROM mac_track_snmp where id = ?', array(get_request_var('id')));
        $header_label = __('SNMP Option Set [edit: %s]', $snmp_group['name']);
    } else {
        $header_label = __('SNMP Option Set [new]');
    }
    form_start('mactrack_snmp.php', 'mactrack_snmp_group');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_snmp_edit, $snmp_group)));
    html_end_box();
    form_hidden_box('id', isset_request_var('id') ? get_request_var('id') : '0', '');
    form_hidden_box('save_component_mactrack_snmp', '1', '');
    if (!isempty_request_var('id')) {
        $items = db_fetch_assoc_prepared('SELECT * FROM mac_track_snmp_items WHERE snmp_id= ? ORDER BY sequence', array(get_request_var('id')));
        html_start_box(__('Mactrack SNMP Options'), '100%', '', '3', 'center', 'mactrack_snmp.php?action=item_edit&id=' . get_request_var('id'));
        print "<tr class='tableHeader'>";
        DrawMatrixHeaderItem(__('Item'), '', 1);
        DrawMatrixHeaderItem(__('Version'), '', 1);
        DrawMatrixHeaderItem(__('Community'), '', 1);
        DrawMatrixHeaderItem(__('Port'), '', 1);
        DrawMatrixHeaderItem(__('Timeout'), '', 1);
        DrawMatrixHeaderItem(__('Retries'), '', 1);
        DrawMatrixHeaderItem(__('Max OIDs'), '', 1);
        DrawMatrixHeaderItem(__('Username'), '', 1);
        DrawMatrixHeaderItem(__('Auth Proto'), '', 1);
        DrawMatrixHeaderItem(__('Priv Proto'), '', 1);
        DrawMatrixHeaderItem(__('Actions'), '', 1);
        print '</tr>';
        $i = 1;
        if (sizeof($items)) {
            foreach ($items as $item) {
                form_alternate_row();
                $form_data = '<td><a class="linkEditMain" href="' . htmlspecialchars('mactrack_snmp.php?action=item_edit&item_id=' . $item['id'] . '&id=' . $item['snmp_id']) . '">Item#' . $i . '</a></td>';
                $form_data .= '<td>' . $item['snmp_version'] . '</td>';
                $form_data .= '<td>' . ($item['snmp_version'] == 3 ? __('N/A') : $item['snmp_readstring']) . '</td>';
                $form_data .= '<td>' . $item['snmp_port'] . '</td>';
                $form_data .= '<td>' . $item['snmp_timeout'] . '</td>';
                $form_data .= '<td>' . $item['snmp_retries'] . '</td>';
                $form_data .= '<td>' . $item['max_oids'] . '</td>';
                $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_username'] : __('N/A')) . '</td>';
                $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_auth_protocol'] : __('N/A')) . '</td>';
                $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_priv_protocol'] : __('N/A')) . '</td>';
                $form_data .= '<td class="right">' . ($i < sizeof($items) ? '<a class="remover fa fa-caret-down moveArrow" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_movedown&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' : '<span class="moveArrowNone"></span>') . ($i > 1 ? '<a class="remover fa fa-caret-up moveArrow" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_moveup&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' : '<span class="moveArrowNone"></span>');
                $form_data .= '<a class="delete deleteMarker fa fa-remove" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_remove&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' . '</td></tr>';
                print $form_data;
                $i++;
            }
        } else {
            print '<tr><td colspan="5"><em>' . __('No SNMP Items') . '</em></td></tr>';
        }
        html_end_box();
    }
    form_save_button('mactrack_snmp.php');
}
Esempio n. 20
0
function get_syslog_messages(&$sql_where, $row_limit, $tab)
{
    global $sql_where, $hostfilter, $current_tab, $syslog_incoming_config;
    include dirname(__FILE__) . '/config.php';
    $sql_where = '';
    /* form the 'where' clause for our main sql query */
    if (get_request_var('host') == -1 && $tab != 'syslog') {
        $sql_where .= "WHERE sl.host='N/A'";
    } else {
        if (!isempty_request_var('host')) {
            sql_hosts_where($tab);
            if (strlen($hostfilter)) {
                $sql_where .= 'WHERE ' . $hostfilter;
            }
        }
    }
    if (isset($_SESSION['sess_current_date1'])) {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "logtime BETWEEN '" . $_SESSION['sess_current_date1'] . "'\n\t\t\t\tAND '" . $_SESSION['sess_current_date2'] . "'";
    }
    if (isset_request_var('id') && $current_tab == 'current') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'sa.id=' . get_request_var('id');
    }
    if (!isempty_request_var('filter')) {
        if ($tab == 'syslog') {
            $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "message LIKE '%" . get_request_var('filter') . "%'";
        } else {
            $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "logmsg LIKE '%" . get_request_var('filter') . "%'";
        }
    }
    if (get_request_var('eprogram') != '-1') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "syslog.program_id='" . get_request_var('eprogram') . "'";
    }
    if (get_request_var('efacility') != '-1') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "syslog.facility_id='" . get_request_var('efacility') . "'";
    }
    if (isset_request_var('epriority') && get_request_var('epriority') != '-1') {
        $priorities = '';
        switch (get_request_var('epriority')) {
            case '0':
                $priorities = "=0";
                break;
            case '1o':
                $priorities = "=1";
                break;
            case '1':
                $priorities = "<1";
                break;
            case '2o':
                $priorities = "=2";
                break;
            case '2':
                $priorities = "<=2";
                break;
            case '3o':
                $priorities = "=3";
                break;
            case '3':
                $priorities = "<=3";
                break;
            case '4o':
                $priorities = "=4";
                break;
            case '4':
                $priorities = "<=4";
                break;
            case '5o':
                $priorities = "=5";
                break;
            case '5':
                $priorities = "<=5";
                break;
            case '6o':
                $priorities = "=6";
                break;
            case '6':
                $priorities = "<=6";
                break;
            case '7':
                $priorities = "=7";
                break;
        }
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'syslog.priority_id ' . $priorities;
    }
    $sql_where = api_plugin_hook_function('syslog_sqlwhere', $sql_where);
    if (!isset_request_var('export')) {
        $limit = ' LIMIT ' . $row_limit * (get_request_var('page') - 1) . ',' . $row_limit;
    } else {
        $limit = ' LIMIT 10000';
    }
    $sort = get_request_var('sort_column');
    if ($tab == 'syslog') {
        if (get_request_var('removal') == '-1') {
            $query_sql = "SELECT syslog.*, syslog_programs.program, 'main' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog` \n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        } elseif (get_request_var('removal') == '1') {
            $query_sql = "(SELECT syslog.*, syslog_programs.program, 'main' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\t) UNION (SELECT syslog.*, syslog_programs.program, 'remove' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_removed` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . ")\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        } else {
            $query_sql = "SELECT syslog.*, syslog_programs.program, 'remove' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_removed` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` AS syslog\n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        }
    } else {
        $query_sql = "SELECT syslog.*, sf.facility, sp.priority, spr.program, sa.name, sa.severity\n\t\t\tFROM `" . $syslogdb_default . "`.`syslog_logs` AS syslog\n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_facilities` AS sf\n\t\t\tON syslog.facility_id=sf.facility_id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_priorities` AS sp\n\t\t\tON syslog.priority_id=sp.priority_id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_alert` AS sa\n\t\t\tON syslog.alert_id=sa.id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_programs` AS spr\n\t\t\tON syslog.program_id=spr.program_id " . $sql_where . "\n\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
    }
    //echo $query_sql;
    return syslog_db_fetch_assoc($query_sql);
}
Esempio n. 21
0
function mactrack_site_edit()
{
    global $fields_mactrack_site_edit;
    /* ================= input validation ================= */
    get_filter_request_var('site_id');
    /* ==================================================== */
    display_output_messages();
    if (!isempty_request_var('site_id')) {
        $site = db_fetch_row('SELECT * FROM mac_track_sites WHERE site_id=' . get_request_var('site_id'));
        $header_label = __('MacTrack Site [edit: %s]', $site['site_name']);
    } else {
        $header_label = __('MacTrack Site [new]');
    }
    form_start('mactrack_sites.php');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_site_edit, isset($site) ? $site : array())));
    html_end_box();
    form_save_button('mactrack_sites.php', 'return', 'site_id');
}
Esempio n. 22
0
function hmib_host_type_edit()
{
    global $config;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    display_output_messages();
    /* file: mactrack_device_types.php, action: edit */
    $fields_host_type_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Device Scanning Function Options')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Name'), 'description' => __('Give this Host Type a meaningful name.'), 'value' => '|arg1:name|', 'max_length' => '250'), 'version' => array('method' => 'textbox', 'friendly_name' => __('Version'), 'description' => __('Fill in the name for the version of this Host Type.'), 'value' => '|arg1:version|', 'max_length' => '10', 'size' => '10'), 'sysDescrMatch' => array('method' => 'textbox', 'friendly_name' => __('System Description Match'), 'description' => __('Provide key information to help HMIB detect the type of Host.  SQL Where expressions are supported.  SQL Where wildcard character is the \'%\' sign. Regular Expressions have been removed due to compatibility issues.'), 'value' => '|arg1:sysDescrMatch|', 'max_length' => '250'), 'sysObjectID' => array('method' => 'textbox', 'friendly_name' => __('Vendor snmp Object ID'), 'description' => __('Provide key information to help HMIB detect the type of Host.  SQL Where expressions are supported.  SQL Where wildcard character is the \'%\' sign. Regular Expressions have been removed due to compatibility issues.'), 'value' => '|arg1:sysObjectID|', 'max_length' => '250'), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_host_type' => array('method' => 'hidden', 'value' => '1'));
    if (!isempty_request_var('id')) {
        $host_type = db_fetch_row('SELECT * FROM plugin_hmib_hrSystemTypes WHERE id=' . get_filter_request_var('id'));
        $header_label = __('Host MIB OS Types [edit: %s]', $host_type['name']);
    } else {
        $header_label = __('Host MIB OS Types [new]');
    }
    form_start('hmib_types.php');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_type_edit, isset($host_type) ? $host_type : array())));
    html_end_box();
    if (isset($host_type)) {
        form_save_button('hmib_types.php', 'save', '', 'id');
    } else {
        form_save_button('cancel', 'save', '', 'id');
    }
}