示例#1
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;
}
示例#2
0
function syslog_graph_buttons($graph_elements = array())
{
    global $config, $timespan, $graph_timeshifts;
    include dirname(__FILE__) . '/config.php';
    if (get_nfilter_request_var('action') == 'view') {
        return;
    }
    if (isset_request_var('graph_end') && strlen(get_filter_request_var('graph_end'))) {
        $date1 = date('Y-m-d H:i:s', get_filter_request_var('graph_start'));
        $date2 = date('Y-m-d H:i:s', get_filter_request_var('graph_end'));
    } else {
        $date1 = $timespan['current_value_date1'];
        $date2 = $timespan['current_value_date2'];
    }
    if (isset($graph_elements[1]['local_graph_id'])) {
        $graph_local = db_fetch_row("SELECT host_id FROM graph_local WHERE id='" . $graph_elements[1]['local_graph_id'] . "'");
        $sql_where = '';
        if (isset($graph_local['host_id'])) {
            $host = db_fetch_row("SELECT description, hostname FROM host WHERE id='" . $graph_local['host_id'] . "'");
            if (sizeof($host)) {
                if (!is_ipv4_address($host['description']) && strpos($host['description'], '.') !== false) {
                    $parts = explode('.', $host['description']);
                    $sql_where = "WHERE host LIKE '" . $parts[0] . ".%'";
                } else {
                    $sql_where = "WHERE host='" . $host['description'] . "'";
                }
                if (!is_ipv4_address($host['hostname']) && strpos($host['hostname'], '.') !== false) {
                    $parts = explode('.', $host['hostname']);
                    $sql_where .= ($sql_where != '' ? ' OR ' : 'WHERE ') . "host LIKE '" . $parts[0] . ".%'";
                } else {
                    $sql_where .= ($sql_where != '' ? ' OR ' : 'WHERE ') . "host='" . $host['hostname'] . "'";
                }
                if ($sql_where != '') {
                    $host = syslog_db_fetch_cell("SELECT host_id FROM `" . $syslogdb_default . "`.`syslog_hosts` {$sql_where}");
                    if (!empty($host)) {
                        print "<a href='" . htmlspecialchars($config['url_path'] . 'plugins/syslog/syslog.php?tab=syslog&reset=1&host=' . $host['host_id'] . '&date1=' . $date1 . '&date2=' . $date2) . "'><img src='" . $config['url_path'] . "plugins/syslog/images/view_syslog.png' border='0' alt='' title='" . __('Display Syslog in Range') . "'></a><br>";
                    }
                }
            }
        }
    }
}
示例#3
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();
}
示例#4
0
        break;
    case 'ajax_hosts_noany':
        get_allowed_ajax_hosts(false, false, 'h.id IN (SELECT host_id FROM thold_data)');
        break;
    case 'thold':
        general_header();
        thold_tabs();
        tholds();
        bottom_footer();
        break;
    case 'disable':
        thold_threshold_disable(get_filter_request_var('id'));
        header('Location: thold_graph.php');
        exit;
    case 'enable':
        thold_threshold_enable(get_filter_request_var('id'));
        header('Location: thold_graph.php');
        exit;
    case 'hoststat':
        general_header();
        thold_tabs();
        hosts();
        bottom_footer();
        break;
    default:
        general_header();
        thold_tabs();
        thold_show_log();
        bottom_footer();
        break;
}
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');
}
示例#6
0
function flowview_save_filter()
{
    if (isset_request_var('new_query') && get_nfilter_request_var('new_query') != '') {
        $queryname = get_nfilter_request_var('new_query');
        $save['id'] = '';
        $save['name'] = form_input_validate($queryname, 'queryname', '', false, 3);
    } else {
        $save['id'] = get_filter_request_var('query');
    }
    $save['device'] = get_nfilter_request_var('device_name');
    $save['timespan'] = get_nfilter_request_var('predefined_timespan');
    $save['startdate'] = get_nfilter_request_var('date1');
    $save['enddate'] = get_nfilter_request_var('date2');
    $save['tosfields'] = get_nfilter_request_var('tos_fields');
    $save['tcpflags'] = get_nfilter_request_var('tcp_flags');
    $save['protocols'] = get_nfilter_request_var('protocols');
    $save['sourceip'] = get_nfilter_request_var('source_address');
    $save['sourceport'] = get_nfilter_request_var('source_port');
    $save['sourceinterface'] = get_nfilter_request_var('source_if');
    $save['sourceas'] = get_nfilter_request_var('source_as');
    $save['destip'] = get_nfilter_request_var('dest_address');
    $save['destport'] = get_nfilter_request_var('dest_port');
    $save['destinterface'] = get_nfilter_request_var('desc_if');
    $save['destas'] = get_nfilter_request_var('desc_as');
    $save['statistics'] = get_nfilter_request_var('stat_report');
    $save['printed'] = get_nfilter_request_var('print_report');
    $save['includeif'] = get_nfilter_request_var('flow_select');
    $save['sortfield'] = get_nfilter_request_var('sort_field');
    $save['cutofflines'] = get_nfilter_request_var('cutoff_lines');
    $save['cutoffoctets'] = get_nfilter_request_var('cutoff_octets');
    $save['resolve'] = get_nfilter_request_var('resolve_addresses');
    $id = sql_save($save, 'plugin_flowview_queries', 'id', true);
    if (is_error_message() || $id == '') {
        print 'error';
    } else {
        print $id;
    }
}
示例#7
0
function lists()
{
    global $actions, $item_rows;
    /* ================= 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' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')));
    validate_store_request_vars($filters, 'sess_lists');
    /* ================= 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');
    }
    html_start_box(__('Notification Lists'), '100%', '', '3', 'center', 'notify_lists.php?action=edit');
    ?>
	<tr class='even'>
		<td>
		<form id='lists' 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'));
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Lists');
    ?>
					</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='button' value='<?php 
    print __('Go');
    ?>
' title='<?php 
    print __('Set/Refresh Filters');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input type='button' name='clear' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Clear Filters');
    ?>
' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'notify_lists.php?header=false';
			strURL += '&rows=' + $('#rows').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

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

		$(function() {
			$('#lists').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var('filter'))) {
        $sql_where = "WHERE (name LIKE '%" . get_request_var('filter') . "%' OR\n\t\tdescription LIKE '%" . get_request_var('filter') . "%' OR\n\t\temails LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}");
    $lists = db_fetch_assoc("SELECT id, name, description, emails\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows);
    $nav = html_nav_bar('notify_lists.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Lists'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('List Name'), 'ASC'), 'description' => array(__('Description'), 'ASC'), 'emails' => array(__('Emails'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    if (sizeof($lists)) {
        foreach ($lists as $item) {
            form_alternate_row('line' . $item['id'], true);
            form_selectable_cell(filter_value($item['name'], get_request_var('filter'), 'notify_lists.php?action=edit&id=' . $item['id']), $item['id'], '25%');
            form_selectable_cell(filter_value($item['description'], get_request_var('filter')), $item['id'], '35%');
            form_selectable_cell(filter_value($item['emails'], get_request_var('filter')), $item['id']);
            form_checkbox_cell($item['name'], $item['id']);
            form_end_row();
        }
    } else {
        print '<tr><td><em>' . __('No Notification Lists') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($lists)) {
        print $nav;
    }
    form_hidden_box('save_list', '1', '');
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($actions);
    form_end();
}
示例#8
0
function mikrotik_host_top()
{
    global $fields_host_edit;
    $id = get_filter_request_var('id');
    $template_id = db_fetch_cell('SELECT id FROM host_template WHERE hash="d364e2b9570f166ab33c8df8bd503887"');
    $is_tik = db_fetch_row_prepared('SELECT pmc.*, host.hostname
		FROM host 
		LEFT JOIN plugin_mikrotik_credentials AS pmc 
		ON host.id=pmc.host_id 
		WHERE host_template_id = ? AND host.id = ?', array($template_id, $id));
    if (sizeof($is_tik)) {
        $fields_host_edit += array('mikrotik_head' => array('method' => 'spacer', 'collapsible' => 'true', 'friendly_name' => __('MikroTik Credentials')), 'mikrotik_user' => array('method' => 'textbox', 'friendly_name' => __('Read Only User'), 'description' => __('Provide a read only username for the MikroTik.'), 'value' => $is_tik['user'], 'max_length' => '40', 'size' => '20'), 'mikrotik_password' => array('method' => 'textbox', 'friendly_name' => __('Password'), 'description' => __('Provide the read only username password for this MikroTik.'), 'value' => $is_tik['password'], 'max_length' => '40', 'size' => '30'));
        if ($is_tik['user'] != '') {
            include_once './plugins/mikrotik/RouterOS/routeros_api.class.php';
            $api = new RouterosAPI();
            $api->debug = false;
            if ($api->connect($is_tik['hostname'], $is_tik['user'], $is_tik['password'])) {
                $api->disconnect();
                $fields_host_edit += array('mikrotik_result' => array('method' => 'other', 'friendly_name' => __('Connection Result'), 'description' => __('Ok if Cacti can connect to the Mikrotik over its API port.'), 'value' => 'Connected Successfully'));
            } else {
                $fields_host_edit += array('mikrotik_result' => array('method' => 'other', 'friendly_name' => __('Connection Result'), 'description' => __('Ok if Cacti can connect to the Mikrotik over its API port.'), 'value' => 'Connection Failed'));
            }
        }
    }
}
示例#9
0
function template_edit()
{
    global $config;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    $id = get_request_var('id');
    $thold_data = db_fetch_row('SELECT * 
		FROM thold_template 
		WHERE id=' . $id . ' 
		LIMIT 1');
    $temp = db_fetch_assoc('SELECT id, name 
		FROM data_template 
		WHERE id=' . $thold_data['data_template_id']);
    foreach ($temp as $d) {
        $data_templates[$d['id']] = $d['name'];
    }
    $temp = db_fetch_row('SELECT id, data_source_name, data_input_field_id
		FROM data_template_rrd
		WHERE id=' . $thold_data['data_source_id'] . ' 
		LIMIT 1');
    $source_id = $temp['data_input_field_id'];
    if ($source_id != 0) {
        $temp2 = db_fetch_assoc('SELECT id, name FROM data_input_fields WHERE id=' . $source_id);
        foreach ($temp2 as $d) {
            $data_fields[$d['id']] = $d['name'];
        }
    } else {
        $data_fields[$temp['id']] = $temp['data_source_name'];
    }
    $send_notification_array = array();
    $users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data,\n\t\tplugin_thold_contacts.type, user_auth.full_name\n\t\tFROM plugin_thold_contacts, user_auth\n\t\tWHERE user_auth.id=plugin_thold_contacts.user_id\n\t\tAND plugin_thold_contacts.data!=''\n\t\tORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC");
    if (!empty($users)) {
        foreach ($users as $user) {
            $send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']);
        }
    }
    if (isset($thold_data['id'])) {
        $sql = 'SELECT contact_id as id FROM plugin_thold_template_contact WHERE template_id=' . $thold_data['id'];
    } else {
        $sql = 'SELECT contact_id as id FROM plugin_thold_template_contact WHERE template_id=0';
    }
    $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE data_template_id = ' . $thold_data['data_template_id'], FALSE);
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $rra_steps = db_fetch_assoc("SELECT dspr.steps\n\t\tFROM data_template_data AS dtd\n\t\tINNER JOIN data_source_profiles AS dsp\n\t    ON dsp.id=dtd.data_source_profile_id\n\t\tINNER JOIN data_source_profiles_rra AS dspr\n\t\tON dsp.id=dspr.data_source_profile_id\n\t    WHERE dspr.steps>1\n\t\tAND dtd.data_template_id=" . $thold_data['data_template_id'] . "\n\t    AND dtd.local_data_template_data_id=0\n\t\tORDER BY steps");
    $reference_types = array();
    foreach ($rra_steps as $rra_step) {
        $seconds = $step * $rra_step['steps'];
        $reference_types[$seconds] = $timearray[$rra_step['steps']] . " Average";
    }
    $data_fields2 = array();
    $temp = db_fetch_assoc('SELECT id, local_data_template_rrd_id, data_source_name,
		data_input_field_id
		FROM data_template_rrd
		WHERE local_data_template_rrd_id=0
		AND data_template_id=' . $thold_data['data_template_id']);
    foreach ($temp as $d) {
        if ($d['data_input_field_id'] != 0) {
            $temp2 = db_fetch_assoc('SELECT id, name, data_name
				FROM data_input_fields
				WHERE id=' . $d['data_input_field_id'] . '
				ORDER BY data_name');
            $data_fields2[$d['data_source_name']] = $temp2[0]['data_name'] . ' (' . $temp2[0]['name'] . ')';
        } else {
            $temp2[0]['name'] = $d['data_source_name'];
            $data_fields2[$d['data_source_name']] = $temp2[0]['name'];
        }
    }
    $replacements = db_fetch_assoc("SELECT DISTINCT field_name\n\t\tFROM data_local AS dl\n\t\tINNER JOIN (SELECT DISTINCT field_name, snmp_query_id FROM host_snmp_cache) AS hsc\n\t\tON dl.snmp_query_id=hsc.snmp_query_id\n\t\tWHERE dl.data_template_id=" . $thold_data['data_template_id']);
    $nr = array();
    if (sizeof($replacements)) {
        foreach ($replacements as $r) {
            $nr[] = "<span style='color:blue;'>|query_" . $r['field_name'] . "|</span>";
        }
    }
    $vhf = explode("|", trim(VALID_HOST_FIELDS, "()"));
    if (sizeof($vhf)) {
        foreach ($vhf as $r) {
            $nr[] = "<span style='color:blue;'>|" . $r . "|</span>";
        }
    }
    $replacements = "<br>Replacement Fields: " . implode(", ", $nr);
    $dss = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE data_template_id=" . $thold_data['data_template_id'] . " AND local_data_id=0");
    if (sizeof($dss)) {
        foreach ($dss as $ds) {
            $dsname[] = "<span style='color:blue;'>|ds:" . $ds["data_source_name"] . "|</span>";
        }
    }
    $datasources = "<br>Data Sources: " . implode(", ", $dsname);
    $form_array = array('general_header' => array('friendly_name' => __('General Settings'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Template Name'), 'method' => 'textbox', 'max_length' => 100, 'size' => '60', 'default' => $thold_data['data_template_name'] . ' [' . $thold_data['data_source_name'] . ']', 'description' => __('Provide the Threshold Template a meaningful name.  Device Substritution and Data Query Substitution variables can be used as well as |graph_title| for the Graph Title'), 'value' => isset($thold_data['name']) ? $thold_data['name'] : ''), 'data_template_name' => array('friendly_name' => __('Data Template'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Data Template that you are using. (This can not be changed)'), 'value' => $thold_data['data_template_id'], 'array' => $data_templates), 'data_field_name' => array('friendly_name' => __('Data Field'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Data Field that you are using. (This can not be changed)'), 'value' => $thold_data['id'], 'array' => $data_fields), 'thold_enabled' => array('friendly_name' => __('Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this Threshold will be checked and alerted upon.'), 'value' => isset($thold_data['thold_enabled']) ? $thold_data['thold_enabled'] : ''), 'exempt' => array('friendly_name' => __('Weekend Exemption'), 'description' => __('If this is checked, this Threshold will not alert on weekends.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['exempt']) ? $thold_data['exempt'] : ''), 'restored_alert' => array('friendly_name' => __('Disable Restoration Email'), 'description' => __('If this is checked, Thold will not send an alert when the Threshold has returned to normal status.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['restored_alert']) ? $thold_data['restored_alert'] : ''), 'thold_type' => array('friendly_name' => __('Threshold Type'), 'method' => 'drop_array', 'on_change' => 'changeTholdType()', 'array' => $thold_types, 'default' => read_config_option('thold_type'), 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($thold_data['thold_type']) ? $thold_data['thold_type'] : ''), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => read_config_option('alert_repeat'), 'description' => __('Repeat alert after this amount of time has pasted since the last alert.'), 'value' => isset($thold_data['repeat_alert']) ? $thold_data['repeat_alert'] : ''), 'thold_warning_header' => array('friendly_name' => __('Warning - High / Low Settings'), 'method' => 'spacer'), 'thold_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['thold_warning_hi']) ? $thold_data['thold_warning_hi'] : ''), 'thold_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['thold_warning_low']) ? $thold_data['thold_warning_low'] : ''), 'thold_warning_fail_trigger' => array('friendly_name' => __('Min Trigger Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in a breach condition for an alert to be raised.'), 'value' => isset($thold_data['thold_warning_fail_trigger']) ? $thold_data['thold_warning_fail_trigger'] : read_config_option('alert_trigger')), 'thold_header' => array('friendly_name' => __('Alert - High / Low Settings'), 'method' => 'spacer'), 'thold_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['thold_hi']) ? $thold_data['thold_hi'] : ''), 'thold_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['thold_low']) ? $thold_data['thold_low'] : ''), 'thold_fail_trigger' => array('friendly_name' => __('Min Trigger Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in a breach condition for an alert to be raised.'), 'value' => isset($thold_data['thold_fail_trigger']) ? $thold_data['thold_fail_trigger'] : read_config_option('alert_trigger')), 'time_warning_header' => array('friendly_name' => __('Warning - Time Based Settings'), 'method' => 'spacer'), 'time_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_hi']) ? $thold_data['time_warning_hi'] : ''), 'time_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_low']) ? $thold_data['time_warning_low'] : ''), 'time_warning_fail_trigger' => array('friendly_name' => __('Trigger Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'default' => read_config_option('thold_warning_time_fail_trigger'), 'description' => __('The number of times the data source must be in breach condition prior to issuing a warning.'), 'value' => isset($thold_data['time_warning_fail_trigger']) ? $thold_data['time_warning_fail_trigger'] : read_config_option('alert_trigger')), 'time_warning_fail_length' => array('friendly_name' => __('Time Period Length'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for Threshold breaches.'), 'value' => isset($thold_data['time_warning_fail_length']) ? $thold_data['time_warning_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1)), 'time_header' => array('friendly_name' => __('Alert - Time Based Settings'), 'method' => 'spacer'), 'time_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['time_hi']) ? $thold_data['time_hi'] : ''), 'time_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['time_low']) ? $thold_data['time_low'] : ''), 'time_fail_trigger' => array('friendly_name' => __('Trigger Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'description' => __('The number of times the data source must be in breach condition prior to issuing an alert.'), 'value' => isset($thold_data['time_fail_trigger']) ? $thold_data['time_fail_trigger'] : read_config_option('thold_time_fail_trigger')), 'time_fail_length' => array('friendly_name' => __('Time Period Length'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for Threshold breaches.'), 'value' => isset($thold_data['time_fail_length']) ? $thold_data['time_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_time_fail_length') : 2)), 'baseline_header' => array('friendly_name' => __('Baseline Monitoring'), 'method' => 'spacer'), 'bl_ref_time_range' => array('friendly_name' => __('Time reference in the past'), 'method' => 'drop_array', 'array' => $reference_types, 'description' => __('Specifies the point in the past (based on rrd resolution) that will be used as a reference'), 'value' => isset($thold_data['bl_ref_time_range']) ? $thold_data['bl_ref_time_range'] : read_config_option('alert_bl_timerange_def')), 'bl_pct_up' => array('friendly_name' => __('Baseline Deviation UP'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the upper bound Threshold. If not set, upper bound Threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_up']) ? $thold_data['bl_pct_up'] : read_config_option('alert_bl_percent_def')), 'bl_pct_down' => array('friendly_name' => __('Baseline Deviation DOWN'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the lower bound Threshold. If not set, lower bound Threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_down']) ? $thold_data['bl_pct_down'] : read_config_option('alert_bl_percent_def')), 'bl_fail_trigger' => array('friendly_name' => __('Baseline Trigger Count'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Number of consecutive times the data source must be in a breached condition for an alert to be raised.<br>Leave empty to use default value (Default: %s cycles', read_config_option('alert_bl_trigger')), 'value' => isset($thold_data['bl_fail_trigger']) ? $thold_data['bl_fail_trigger'] : read_config_option('alert_bl_trigger')), 'data_manipulation' => array('friendly_name' => __('Data Manipulation'), 'method' => 'spacer'), 'data_type' => array('friendly_name' => __('Data Type'), 'method' => 'drop_array', 'on_change' => 'changeDataType()', 'array' => $data_types, 'description' => __('Special formatting for the given data.'), 'value' => isset($thold_data['data_type']) ? $thold_data['data_type'] : read_config_option('data_type')), 'cdef' => array('friendly_name' => __('Threshold CDEF'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Apply this CDEF before returning the data.'), 'value' => isset($thold_data['cdef']) ? $thold_data['cdef'] : 0, 'array' => thold_cdef_select_usable_names()), 'percent_ds' => array('friendly_name' => __('Percent Datasource'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Second Datasource Item to use as total value to calculate percentage from.'), 'value' => isset($thold_data['percent_ds']) ? $thold_data['percent_ds'] : 0, 'array' => $data_fields2), 'expression' => array('friendly_name' => __('RPN Expression'), 'method' => 'textbox', 'default' => '', 'description' => __('An RPN Expression is an RRDtool Compatible RPN Expression.  Syntax includes all functions below in addition to both Device and Data Query replacement expressions such as <span style="color:blue;">|query_ifSpeed|</span>.  To use a Data Source in the RPN Expression, you must use the syntax: <span style="color:blue;">|ds:dsname|</span>.  For example, <span style="color:blue;">|ds:traffic_in|</span> will get the current value of the traffic_in Data Source for the RRDfile(s) associated with the Graph. Any Data Source for a Graph can be included.<br>Math Operators: <span style="color:blue;">+, -, /, *, &#37;, ^</span><br>Functions: <span style="color:blue;">SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG, ATAN, ADNAN</span><br>Flow Operators: <span style="color:blue;">UN, ISINF, IF, LT, LE, GT, GE, EQ, NE</span><br>Comparison Functions: <span style="color:blue;">MAX, MIN, INF, NEGINF, NAN, UNKN, COUNT, PREV</span>%s %s', $replacements, $datasources), 'value' => isset($thold_data['expression']) ? $thold_data['expression'] : '', 'max_length' => '255', 'size' => '80'), 'other_header' => array('friendly_name' => __('Other Settings'), 'method' => 'spacer'), 'notify_warning' => array('friendly_name' => __('Warning Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Warnings for this Data Source'), 'value' => isset($thold_data['notify_warning']) ? $thold_data['notify_warning'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'), 'notify_alert' => array('friendly_name' => __('Alert Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Alerts for this Data Source'), 'value' => isset($thold_data['notify_alert']) ? $thold_data['notify_alert'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'));
    if (read_config_option('thold_alert_snmp') == 'on') {
        $extra = array('snmp_event_category' => array('friendly_name' => __('SNMP Notification - Event Category'), 'method' => 'textbox', 'description' => __('To allow a NMS to categorize different SNMP notifications more easily please fill in the category SNMP notifications for this template should make use of. E.g.: "disk_usage", "link_utilization", "ping_test", "nokia_firewall_cpu_utilization" ...'), 'value' => isset($thold_data['snmp_event_category']) ? $thold_data['snmp_event_category'] : '', 'default' => '', 'max_length' => '255'), 'snmp_event_severity' => array('friendly_name' => __('SNMP Notification - Alert Event Severity'), 'method' => 'drop_array', 'default' => '3', 'description' => __('Severity to be used for alerts. (Low impact -> Critical impact)'), 'value' => isset($thold_data['snmp_event_severity']) ? $thold_data['snmp_event_severity'] : 3, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical'))));
        $form_array += $extra;
        if (read_config_option('thold_alert_snmp_warning') != 'on') {
            $extra = array('snmp_event_warning_severity' => array('friendly_name' => __('SNMP Notification - Warning Event Severity'), 'method' => 'drop_array', 'default' => '2', 'description' => __('Severity to be used for warnings. (Low impact -> Critical impact).<br>Note: The severity of warnings has to be equal or lower than the severity being defined for alerts.'), 'value' => isset($thold_data['snmp_event_warning_severity']) ? $thold_data['snmp_event_warning_severity'] : 2, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical'))));
        }
        $form_array += $extra;
    }
    if (read_config_option('thold_disable_legacy') != 'on') {
        $extra = array('notify_accounts' => array('friendly_name' => __('Notify accounts'), 'method' => 'drop_multi', 'description' => __('This is a listing of accounts that will be notified when this Threshold is breached.<br><br><br><br>'), 'array' => $send_notification_array, 'sql' => $sql), 'notify_extra' => array('friendly_name' => __('Alert Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive alerts for this data source (comma separated)'), 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('friendly_name' => __('Warning Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive warnings for this data source (comma separated)'), 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : ''));
        $form_array += $extra;
    } else {
        $extra = array('notify_accounts' => array('method' => 'hidden', 'value' => 'ignore'), 'notify_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : ''));
        $form_array += $extra;
    }
    form_start('thold_templates.php', 'thold');
    html_start_box('', '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
    form_hidden_box('save', 'edit', '');
    form_hidden_box('id', $id, '');
    html_end_box();
    form_save_button('thold_templates.php?id=' . $id);
    ?>
	<script type='text/javascript'>

	function changeTholdType() {
		switch($('#thold_type').val()) {
		case '0': // Hi/Low
			thold_toggle_hilow('');
			thold_toggle_baseline('none');
			thold_toggle_time('none');
			break;
		case '1': // Baseline
			thold_toggle_hilow('none');
			thold_toggle_baseline('');
			thold_toggle_time('none');
			break;
		case '2': // Time Based
			thold_toggle_hilow('none');
			thold_toggle_baseline('none');
			thold_toggle_time('');
			break;
		}
	}

	function changeDataType() {
		switch($('#data_type').val()) {
		case '0':
			$('#row_cdef, #row_percent_ds, #row_expression').hide();

			break;
		case '1':
			$('#row_cdef').show();
			$('#row_percent_ds, #row_expression').hide();

			break;
		case '2':
			$('#row_cdef').hide();
			$('#row_percent_ds, #row_expression').show();

			break;
		case '3':
			$('#row_cdef').hide();
			$('#row_percent_ds').hide();
			$('#row_expression').show();
			break;
		}
	}

	function thold_toggle_hilow(status) {
		if (status == '') {
			$('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').show();
			$('#row_thold_warning_header, #row_thold_warning_hi').show();
			$('#row_thold_warning_low, #row_thold_warning_fail_trigger').show();
		}else{
			$('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').hide();
			$('#row_thold_warning_header, #row_thold_warning_hi').hide();
			$('#row_thold_warning_low, #row_thold_warning_fail_trigger').hide();
		}
	}

	function thold_toggle_baseline(status) {
		if (status == '') {
			$('#row_baseline_header, #row_bl_ref_time_range').show();
			$('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').show();
		}else{
			$('#row_baseline_header, #row_bl_ref_time_range').hide();
			$('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').hide();
		}
	}

	function thold_toggle_time(status) {
		if (status == '') {
			$('#row_time_header, #row_time_hi, #row_time_low').show();
			$('#row_time_fail_trigger, #row_time_fail_length, #row_time_warning_header').show();
			$('#row_time_warning_hi, #row_time_warning_low').show();
			$('#row_time_warning_fail_trigger, #row_time_warning_fail_length').show();
		}else{
			$('#row_time_header, #row_time_hi, #row_time_low').hide();
			$('#row_time_fail_trigger, #row_time_fail_length, #row_time_warning_header').hide();
			$('#row_time_warning_hi, #row_time_warning_low').hide();
			$('#row_time_warning_fail_trigger, #row_time_warning_fail_length').hide();
		}
	}

	changeTholdType();
	changeDataType();

	if ($('#notify_accounts option').length == 0) {
		$('#row_notify_accounts').hide();
	}

	if ($('#notify_warning option').length == 0) {
		$('#row_notify_warning').hide();
	}

	if ($('#notify_alert option').length == 0) {
		$('#row_notify_alert').hide();
	}

	$('#notify_accounts').multiselect({
		minWidth: '400',
		noneSelectedText: 'Select Users(s)', 
		selectedText: function(numChecked, numTotal, checkedItems) {
			myReturn = numChecked + ' Users Selected';
			$.each(checkedItems, function(index, value) {
				if (value.value == '0') {
				myReturn='All Users Selected';
					return false;
				}
			});
			return myReturn;
		},
		checkAllText: 'All', 
		uncheckAllText: 'None',
		uncheckall: function() {
			$(this).multiselect('widget').find(':checkbox:first').each(function() {
				$(this).prop('checked', true);
			});
		},
		open: function() {
			size = $('#notify_accounts option').length * 20 + 20;
			if (size > 140) {
				size = 140;
			}
			$('ul.ui-multiselect-checkboxes').css('height', size + 'px');
		},
		click: function(event, ui) {
			checked=$(this).multiselect('widget').find('input:checked').length;

			if (ui.value == '0') {
				if (ui.checked == true) {
					$('#host').multiselect('uncheckAll');
					$(this).multiselect('widget').find(':checkbox:first').each(function() {
						$(this).prop('checked', true);
					});
				}
			}else if (checked == 0) {
				$(this).multiselect('widget').find(':checkbox:first').each(function() {
					$(this).click();
				});
			}else if ($(this).multiselect('widget').find('input:checked:first').val() == '0') {
				if (checked > 0) {
					$(this).multiselect('widget').find(':checkbox:first').each(function() {
						$(this).click();
						$(this).prop('disable', true);
					});
				}
			}
		}
	}).multiselectfilter( {
		label: 'Search', width: '150'
	});

	</script>
	<?php 
}
示例#10
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');
}
示例#11
0
function mikrotik_tabs()
{
    global $config;
    /* present a tabbed interface */
    $tabs['devices'] = __('Devices');
    if (mikrotik_users_exist()) {
        $tabs['users'] = __('Users');
    }
    if (mikrotik_queues_exist()) {
        $tabs['queues'] = __('Queues');
    }
    if (mikrotik_queue_trees_exist()) {
        $tabs['trees'] = __('Queue Trees');
    }
    if (mikrotik_interfaces_exist()) {
        $tabs['interfaces'] = __('Interfaces');
    }
    if (mikrotik_wireless_aps_exist()) {
        $tabs['wireless_aps'] = __('Wireless Aps');
    }
    if (mikrotik_hotspots_exist()) {
        $tabs['hotspots'] = __('Hot Spots');
    }
    if (mikrotik_wroutes_exist()) {
        $tabs['wireless'] = __('Wireless Routes');
    }
    $tabs['graphs'] = __('Graphs');
    /* set the default tab */
    $current_tab = get_request_var('action');
    print "<div class='tabs'><nav><ul>\n";
    if (sizeof($tabs)) {
        foreach (array_keys($tabs) as $tab_short_name) {
            print "<li><a class='pic" . ($tab_short_name == $current_tab ? ' selected' : '') . "' href='" . $config['url_path'] . 'plugins/mikrotik/mikrotik.php?' . 'action=' . $tab_short_name . (isset_request_var('host_id') ? '&host_id=' . get_filter_request_var('host_id') : '') . "'>" . $tabs[$tab_short_name] . "</a></li>\n";
        }
    }
    print "</ul></nav></div>\n";
}
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');
}
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');
}
示例#14
0
function thold_device_template_top()
{
    if (get_request_var('action') == 'item_remove_tt_confirm') {
        /* ================= input validation ================= */
        get_filter_request_var('id');
        get_filter_request_var('host_template_id');
        /* ==================================================== */
        form_start('host_templates.php?action=edit&id' . get_request_var('host_template_id'));
        html_start_box('', '100%', '', '3', 'center', '');
        $template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array(get_request_var('id')));
        ?>
		<tr>
			<td class='topBoxAlt'>
				<p><?php 
        print __('Click \'Continue\' to delete the following Threshold Template will be disassociated from the Device Template.');
        ?>
</p>
				<p><?php 
        print __('Threshold Template Name: %s', htmlspecialchars($template['name']));
        ?>
'<br>
			</td>
		</tr>
		<tr>
			<td align='right'>
				<input id='cancel' type='button' value='<?php 
        print __('Cancel');
        ?>
' onClick='$("#cdialog").dialog("close")' name='cancel'>
				<input id='continue' type='button' value='<?php 
        print __('Continue');
        ?>
' name='continue' title='<?php 
        print __('Remove Threshold Template');
        ?>
'>
			</td>
		</tr>
		<?php 
        html_end_box();
        form_end();
        ?>
		<script type='text/javascript'>
		$(function() {
			$('#cdialog').dialog();
		});

	    $('#continue').click(function(data) {
			$.post('host_templates.php?action=item_remove_tt', {
				__csrf_magic: csrfMagicToken,
				host_template_id: <?php 
        print get_request_var('host_template_id');
        ?>
,
				id: <?php 
        print get_request_var('id');
        ?>
			}, function(data) {
				$('#cdialog').dialog('close');
				loadPageNoHeader('host_templates.php?action=edit&header=false&id=<?php 
        print get_request_var('host_template_id');
        ?>
');
			});
		});
		</script>
		<?php 
        exit;
    } elseif (get_request_var('action') == 'item_remove_tt') {
        /* ================= input validation ================= */
        get_filter_request_var('id');
        get_filter_request_var('host_template_id');
        /* ==================================================== */
        db_execute_prepared('DELETE FROM plugin_thold_host_template WHERE thold_template_id = ? AND host_template_id = ?', array(get_request_var('id'), get_request_var('host_template_id')));
        header('Location: host_templates.php?header=false&action=edit&id=' . get_request_var('host_template_id'));
        exit;
    } elseif (get_request_var('action') == 'item_add_tt') {
        /* ================= input validation ================= */
        get_filter_request_var('host_template_id');
        get_filter_request_var('thold_template_id');
        /* ==================================================== */
        db_execute_prepared('REPLACE INTO plugin_thold_host_template
			(host_template_id, thold_template_id) VALUES (?, ?)', array(get_request_var('host_template_id'), get_request_var('thold_template_id')));
        header('Location: host_templates.php?header=false&action=edit&id=' . get_request_var('host_template_id'));
        exit;
    }
}
function form_aggregated_actions()
{
    global $config, $mactrack_view_agg_macs_actions;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_request_var('drp_action') == '01') {
                /* Delete */
                if (sizeof($selected_items)) {
                    db_execute('DELETE FROM mac_track_aggregated_ports WHERE row_id IN (' . implode(',', $selected_items) . ')');
                }
            }
            header('Location: mactrack_view_macs.php');
            exit;
        }
    }
    /* setup some variables */
    $row_array = array();
    $mac_address_list = '';
    $row_list = '';
    $i = 0;
    $row_ids = '';
    /* loop through each of the ports selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $row_array[] = $matches[1];
        }
    }
    if (sizeof($row_array)) {
        $row_ids = implode(',', $row_array);
        $rows_info = db_fetch_assoc('SELECT device_name, mac_address, ip_address, port_number, count_rec 
			FROM mac_track_aggregated_ports 
			WHERE row_id IN (' . implode(',', $row_array) . ')');
        if (isset($rows_info)) {
            foreach ($rows_info as $row_info) {
                $row_list .= '<li>' . __(' Dev.:%s IP.:%s MAC.:%s PORT.:%s Count.: [%s]', $row_info['device_name'], $row_info['ip_address'], $row_info['mac_address'], $row_info['port_number'], $row_info['count_rec']) . '</li>';
            }
        }
    }
    top_header();
    html_start_box($mactrack_view_agg_macs_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    form_start('mactrack_view_macs.php');
    if (!sizeof($row_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Row.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        if (!mactrack_check_user_realm(2122)) {
            print "<tr><td class='even'><span class='textError'>" . __('You are not permitted to delete rows.') . "</span></td></tr>\n";
            $save_html = "";
        } else {
            $save_html = "<input type='submit' name='save' value='" . __('Yes') . "'>";
            if (get_request_var('drp_action') == '1') {
                /* Delete Macs */
                print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Are you sure you want to Delete the following rows from Aggregated table?') . "</p>\n\t\t\t\t\t<p><ul>{$row_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
            }
        }
    }
    print "<tr>\n\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($row_array) ? serialize($row_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . (strlen($save_html) ? "\n\t\t\t<input type='submit' name='cancel_x' value='No'>\n\t\t\t{$save_html}" : "<input type='submit' name='cancel' value='Return'>") . "\n\t\t</td>\n\t</tr>";
    html_end_box();
    bottom_footer();
}
示例#16
0
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
$stat_report_array = array(0 => 'Statistics Reports', 99 => 'Summary', 5 => 'UDP/TCP Destination Port', 6 => 'UDP/TCP Source Port', 7 => 'UDP/TCP Port', 8 => 'Destination IP', 9 => 'Source IP', 10 => 'Source/Destination IP', 11 => 'Source or Destination IP', 12 => 'IP Protocol', 17 => 'Input Interface', 18 => 'Output Interface', 23 => 'Input/Output Interface', 19 => 'Source AS', 20 => 'Destination AS', 21 => 'Source/Destination AS', 22 => 'IP ToS', 24 => 'Source Prefix', 25 => 'Destination Prefix', 26 => 'Source/Destination Prefix');
$print_report_array = array(0 => 'Print Reports', 1 => 'Flow Times', 4 => 'AS Numbers', 5 => '132 Columns', 9 => '1 Line with Tags', 10 => 'AS Aggregation', 11 => 'Protocol Port Aggregation', 12 => 'Source Prefix Aggregation', 13 => 'Destination Prefix Aggregation', 14 => 'Prefix Aggregation', 24 => 'Full (Catalyst)');
$flow_select_array = array(1 => 'Any Part in Specified Time Span', 2 => 'End Time in Specified Time Span', 3 => 'Start Time in Specified Time Span', 4 => 'Entirely in Specified Time Span');
$ip_protocols_array = array('' => 'Select One', 6 => 'TCP', 17 => 'UDP', 1 => 'ICMP', 2 => 'IGMP', 3 => 'GGP', 4 => 'IPENCAP', 5 => 'ST', 7 => 'CBT', 8 => 'EGP', 9 => 'IGP', 10 => 'BBN-RCC-MON', 11 => 'NVP-II', 12 => 'PUP', 13 => 'ARGUS', 14 => 'EMCON', 15 => 'XNET', 16 => 'CHAOS', 18 => 'MUX', 19 => 'DCN-MEAS', 20 => 'HMP', 21 => 'PRM', 22 => 'XNS-IDP', 23 => 'TRUNK-1', 24 => 'TRUNK-2', 25 => 'LEAF-1', 26 => 'LEAF-2', 27 => 'RDP', 28 => 'IRTP', 29 => 'ISO-TP4', 30 => 'NETBLT', 31 => 'MFE-NSP', 32 => 'MERIT-INP', 33 => 'DCCP', 34 => '3PC', 35 => 'IDPR', 36 => 'XTP', 37 => 'DDP', 38 => 'IDPR-CMTP', 39 => 'TP++', 40 => 'IL', 41 => 'IPv6', 42 => 'SDRP', 43 => 'IPv6-Route', 44 => 'IPv6-Frag', 45 => 'IDRP', 46 => 'RSVP', 47 => 'GRE', 48 => 'DSR', 49 => 'BNA', 50 => 'IPSEC-ESP', 51 => 'IPSEC-AH', 58 => 'IPv6-ICMP', 59 => 'IPv6-NoNxt', 60 => 'IPv6-Opts', 73 => 'RSPF', 81 => 'VMTP', 88 => 'EIGRP', 89 => 'OSPF', 92 => 'MTP', 94 => 'IPIP', 98 => 'ENCAP');
$resolve_addresses_array = array('Y' => 'Yes', 'N' => 'No');
$devices_arr = db_fetch_assoc('SELECT folder, name FROM plugin_flowview_devices ORDER BY name');
$devices = array();
if (!empty($devices_arr)) {
    $ddevice = $devices_arr[0]['folder'];
    foreach ($devices_arr as $d) {
        $devices[$d['folder']] = $d['name'];
    }
} else {
    $ddevice = 0;
}
$query_newname_field = array('friendly_name' => '', 'name' => 'queryname', 'method' => 'textbox', 'max_length' => 255, 'default' => '', 'description' => '', 'value' => isset_request_var('queryname') ? get_nfilter_request_var('queryname') : '');
$query_name_field = array('friendly_name' => '', 'method' => 'drop_sql', 'default' => 0, 'description' => '', 'value' => isset_request_var('query') ? get_filter_request_var('query') : 0, 'none_value' => 'None', 'on_change' => 'applyFilter()', 'sql' => 'SELECT id, name FROM plugin_flowview_queries ORDER BY name');
$device_name_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 0, 'description' => '', 'value' => isset_request_var('device_name') ? get_nfilter_request_var('device_name') : $ddevice, 'none_value' => 'None', 'array' => $devices);
$cutoff_lines_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 20, 'description' => '', 'value' => isset_request_var('cutoff_lines') ? get_nfilter_request_var('cutoff_lines') : 0, 'array' => array('999999' => 'All', '5' => 'Top 5', '10' => 'Top 10', '20' => 'Top 20', '30' => 'Top 30', '40' => 'Top 40', '50' => 'Top 50', '100' => 'Top 100', '200' => 'Top 200'));
$cutoff_octets_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 0, 'description' => '', 'value' => isset_request_var('cutoff_octets') ? get_nfilter_request_var('cutoff_octets') : '', 'array' => array('0' => 'No Limit', '1024' => '1K   Bytes', '10240' => '10K  Bytes', '20480' => '20K  Bytes', '102400' => '100K Bytes', '512000' => '500K Bytes', '1024000' => '1M   Bytes', '10240000' => '10M  Bytes', '20480000' => '20M  Bytes', '51200000' => '50M  Bytes', '102400000' => '100M Bytes', '204800000' => '200M Bytes', '512000000' => '500M Bytes', '1024000000' => '1G   Bytes'));
$ip_protocol_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 0, 'description' => '', 'value' => isset_request_var('protocols') ? get_nfilter_request_var('protocols') : '', 'array' => $ip_protocols_array);
$stat_report_field = array('friendly_name' => '', 'name' => 'stat_report', 'method' => 'drop_array', 'default' => 10, 'description' => '', 'value' => isset_request_var('stat_report') ? get_nfilter_request_var('stat_report') : 10, 'array' => $stat_report_array);
$flow_select_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 1, 'description' => '', 'value' => isset_request_var('flow_select') ? get_nfilter_request_var('flow_select') : 1, 'array' => $flow_select_array);
$print_report_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 0, 'description' => '', 'value' => isset_request_var('print_report') ? get_nfilter_request_var('print_report') : 0, 'array' => $print_report_array);
$resolve_addresses_field = array('friendly_name' => '', 'method' => 'drop_array', 'default' => 'Y', 'description' => '', 'value' => isset_request_var('resolve_addresses') ? get_nfilter_request_var('resolve_addresses') : 'Y', 'array' => $resolve_addresses_array);
$stat_columns_array = array(5 => array(1, 2, '-1', '-1', '0', 'Port', 'Flows', 'Bytes', 'Packets'), 6 => array(1, 2, '-1', '-1', '0', 'Port', 'Flows', 'Bytes', 'Packets'), 7 => array(1, 2, '-1', '-1', '0', 'Port', 'Flows', 'Bytes', 'Packets'), 8 => array(1, 2, 0, '-1', '-1', 'Dest IP', 'Flows', 'Bytes', 'Packets'), 9 => array(1, 2, 0, '-1', '-1', 'Src IP', 'Flows', 'Bytes', 'Packets'), 10 => array(1, 3, '0,1', '-1', '-1', 'Src IP', 'Dest IP', 'Flows', 'Bytes', 'Packets'), 11 => array(1, 2, 0, '-1', '-1', 'Src/Dest IP', 'Flows', 'Bytes', 'Packets'), 12 => array(1, 2, '-1', '0', '-1', 'Protocol', 'Flows', 'Bytes', 'Packets'), 17 => array(1, 2, '-1', '-1', '-1', 'Input IF', 'Flows', 'Bytes', 'Packets'), 18 => array(1, 2, '-1', '-1', '-1', 'Output IF', 'Flows', 'Bytes', 'Packets'), 19 => array(1, 2, '-1', '-1', '-1', 'Src AS', 'Flows', 'Bytes', 'Packets'), 20 => array(1, 2, '-1', '-1', '-1', 'Dest AS', 'Flows', 'Bytes', 'Packets'), 21 => array(1, 3, '-1', '-1', '-1', 'Src AS', 'Dest AS', 'Flows', 'Bytes', 'Packets'), 22 => array(1, 2, '-1', '-1', '-1', 'TOS', 'Flows', 'Bytes', 'Packets'), 23 => array(1, 3, '-1', '-1', '-1', 'Input IF', 'Output IF', 'Flows', 'Bytes', 'Packets'), 24 => array(1, 2, '0', '-1', '-1', 'Src Prefix', 'Flows', 'Bytes', 'Packets'), 25 => array(1, 2, '0', '-1', '-1', 'Dest Prefix', 'Flows', 'Bytes', 'Packets'), 26 => array(1, 3, '0,1', '-1', '-1', 'Src Prefix', 'Dest Prefix', 'Flows', 'Bytes', 'Packets'));
$print_columns_array = array(1 => array(2, 8, '1,3', '1', '4', '1', '5,6', 'Src IF', 'Src IP', 'Dest IF', 'Dest IP', 'Protocol', 'Src Port', 'Dest Port', 'Packets', 'Bytes', 'Start Time', 'End Time', 'Active', 'B/Pk', 'Ts', 'Fl'), 4 => array(1, 5, '', '0', '2', '0', '', 'Src IP', 'Dest IP', 'Protocol', 'Src AS', 'Dest AS', 'Bytes', 'Packets'), 5 => array(1, 11, '3,6', '0', '8', '0', '4,7', 'Start Time', 'End Time', 'Src IF', 'Src IP', 'Src Port', 'Dest IF', 'Dest IP', 'Dest Port', 'Protocol', 'Flags', 'Packets', 'Bytes'));
示例#17
0
function thold_edit()
{
    global $config;
    if (isset_request_var('id')) {
        $thold_data = db_fetch_row_prepared('SELECT * 
			FROM thold_data 
			WHERE id = ?', array(get_request_var('id')));
    } elseif (isset_request_var('local_data_id') && isset_request_var('local_graph_id') && isset_request_var('host_id') && isset_request_var('data_template_id') && isset_request_var('data_template_rrd_id')) {
        $thold_data['id'] = '0';
        $thold_data['local_data_id'] = get_filter_request_var('local_data_id');
        $thold_data['local_graph_id'] = get_filter_request_var('local_graph_id');
        $thold_data['data_template_id'] = get_filter_request_var('data_template_id');
        $thold_data['host_id'] = get_filter_request_var('host_id');
        $thold_data['data_template_rrd_id'] = get_filter_request_var('data_template_rrd_id');
        $thold_data['thold_template_id'] = get_filter_request_var('thold_template_id');
    } else {
        exit;
    }
    $desc = db_fetch_cell_prepared('SELECT name_cache 
		FROM data_template_data 
		WHERE local_data_id = ? 
		LIMIT 1', array($thold_data['local_data_id']));
    $rrdsql = array_rekey(db_fetch_assoc_prepared("SELECT id \n\t\tFROM data_template_rrd \n\t\tWHERE local_data_id = ? ORDER BY id", array($thold_data['local_data_id'])), 'id', 'id');
    $grapharr = db_fetch_assoc('SELECT DISTINCT local_graph_id 
		FROM graph_templates_item 
		WHERE task_item_id IN (' . implode(', ', $rrdsql) . ') AND graph_template_id>0');
    if (empty($thold_data['local_graph_id'])) {
        $thold_data['local_graph_id'] = db_fetch_cell_prepared('SELECT gl.id
			FROM graph_local AS gl
			INNER JOIN graph_templates_item AS gti
			ON gl.id=gti.local_graph_id
			INNER JOIN data_template_rrd AS dtr
			ON gti.task_item_id=dtr.id
			WHERE dtr.local_data_id = ?
			LIMIT 1', array($thold_data['local_data_id']));
    }
    if (empty($thold_data['data_template_rrd_id'])) {
        $thold_data['data_template_rrd_id'] = db_fetch_cell_prepared('SELECT id
			FROM data_template_rrd AS dtr
			WHERE local_data_id = ? 
			LIMIT 1', array($thold_data['local_data_id']));
    }
    $dt_sql = 'SELECT DISTINCT dtr.local_data_id
		FROM data_template_rrd AS dtr
		LEFT JOIN graph_templates_item AS gti
		ON gti.task_item_id=dtr.id
		LEFT JOIN graph_local AS gl
		ON gl.id=gti.local_graph_id
		WHERE gl.id=' . $thold_data['local_graph_id'];
    $template_data_rrds = db_fetch_assoc("SELECT td.id AS thold_id, dtr.id, dtr.data_source_name, dtr.local_data_id \n\t\tFROM data_template_rrd AS dtr\n\t\tLEFT JOIN thold_data AS td\n\t\tON dtr.id=td.data_template_rrd_id\n\t\tWHERE dtr.local_data_id IN ({$dt_sql}) \n\t\tORDER BY dtr.id");
    form_start('thold.php', 'thold');
    html_start_box(__('Graph Data'), '100%', '', '3', 'center', '');
    ?>
	<tr>
		<td class='textArea'>
			<?php 
    if (isset($banner)) {
        echo $banner . '<br><br>';
    }
    ?>
			<?php 
    print __('Data Source Description:');
    ?>
 <br><?php 
    echo $desc;
    ?>
<br><br>
			<?php 
    print __('Associated Graph (graphs that use this RRD):');
    ?>
 <br>
			<select name='element'>
				<?php 
    foreach ($grapharr as $g) {
        $graph_desc = db_fetch_row_prepared('SELECT local_graph_id, title, title_cache
						FROM graph_templates_graph
						WHERE local_graph_id = ?', array($g['local_graph_id']));
        echo "<option value='" . $graph_desc['local_graph_id'] . "'";
        if ($graph_desc['local_graph_id'] == $thold_data['local_graph_id']) {
            echo ' selected';
        }
        echo '>' . $graph_desc['local_graph_id'] . ' - ' . $graph_desc['title_cache'] . " </option>\n";
    }
    ?>
			</select>
			<br>
			<br>
		</td>
		<td class='textArea'>
			<img id='graphimage' src='<?php 
    echo htmlspecialchars($config['url_path'] . 'graph_image.php?local_graph_id=' . $thold_data['local_graph_id'] . '&rra_id=0&graph_start=-32400&graph_height=140&graph_width=500');
    ?>
'>
		</td>
	</tr>
	<?php 
    html_end_box();
    $template_rrd = db_fetch_row_prepared('SELECT * 
		FROM data_template_rrd 
		WHERE id = ?', array($thold_data['data_template_rrd_id']));
    //-----------------------------
    // Tabs (if more than one item)
    //-----------------------------
    $i = 0;
    $ds = 0;
    if (isset($template_data_rrds)) {
        if (sizeof($template_data_rrds)) {
            /* draw the data source tabs on the top of the page */
            print "<br><div class='tabs'><nav><ul>\n";
            foreach ($template_data_rrds as $template_data_rrd) {
                if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) {
                    $ds = $template_data_rrd['data_source_name'];
                }
                if (!empty($template_data_rrd['thold_id'])) {
                    $td = db_fetch_row('SELECT * 
						FROM thold_data 
						WHERE id=' . $template_data_rrd['thold_id']);
                } else {
                    $td = array();
                }
                $cur_setting = '';
                if (!sizeof($td)) {
                    $cur_setting .= "<span style='padding-right:4px;'>" . __('N/A') . "</span>";
                } else {
                    $cur_setting = '<span style="padding-right:4px;">' . __('Last:') . '</span>' . ($td['lastread'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceDown'>" . thold_format_number($td['lastread'], 4) . "</span>");
                    if ($td['thold_type'] != 1) {
                        if ($td['thold_warning_fail_trigger'] != 0) {
                            if ($td['thold_warning_hi'] != '') {
                                $cur_setting .= '<span style="padding:4px">' . __('WHi:') . '</span>' . ($td['thold_warning_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_hi'], 2) . '</span>');
                            }
                            if ($td['thold_warning_low'] != '') {
                                $cur_setting .= '<span style="padding:4px">' . __('WLo:') . '</span>' . ($td['thold_warning_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_low'], 2) . '</span>');
                            }
                        }
                        if ($td['thold_fail_trigger'] != 0) {
                            if ($td['thold_hi'] != '') {
                                $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>');
                            }
                            if ($td['thold_low'] != '') {
                                $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>');
                            }
                        }
                    } else {
                        $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span clas='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>');
                        $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>');
                        $cur_setting .= '<span>' . __('BL: (Up %s %/Down %s %)', $td['bl_pct_up'], $td['bl_pct_down']) . '</span>';
                    }
                }
                if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) {
                    $selected = 'selected';
                } else {
                    $selected = '';
                }
                if (!empty($template_data_rrd['thold_id'])) {
                    echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&id=' . $template_data_rrd['thold_id']) . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>';
                } else {
                    echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&local_data_id=' . $template_data_rrd['local_data_id'] . '&data_template_rrd_id=' . $template_data_rrd['id']) . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id'] . '&data_template_id=' . $thold_data['data_template_id'] . '&thold_template_id=0' . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>';
                }
            }
            echo "<li class='textEditTitle'><a class='hyperLink' href='" . htmlspecialchars('thold.php?action=add' . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id']) . "'>new thold<br>n/a</a></li>";
            print "</ul></nav></div>\n";
        } elseif (sizeof($template_data_rrds) == 1) {
            set_request_var('data_template_rrd_id', $template_data_rrds[0]['id']);
        }
    }
    //----------------------
    // Data Source Item Form
    //----------------------
    $thold_data_cdef = isset($thold_data['cdef']) ? $thold_data['cdef'] : 0;
    if (isset($thold_data['template'])) {
        $thold_data['template_name'] = db_fetch_cell_prepared('SELECT name 
			FROM thold_template 
			WHERE id = ?', array($thold_data['thold_template_id']));
    }
    $header_text = __('Data Source Item [%s] ' . ' - Current value: [%s]', isset($template_rrd) ? $template_rrd['data_source_name'] : '', get_current_value($thold_data['local_data_id'], $ds, $thold_data_cdef));
    html_start_box($header_text, '100%', '', '3', 'center', '');
    $send_notification_array = array();
    $users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data,\n\t\tplugin_thold_contacts.type, user_auth.full_name\n\t\tFROM plugin_thold_contacts, user_auth\n\t\tWHERE user_auth.id=plugin_thold_contacts.user_id\n\t\tAND plugin_thold_contacts.data!=''\n\t\tORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC");
    if (!empty($users)) {
        foreach ($users as $user) {
            $send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']);
        }
    }
    if (isset($thold_data['id'])) {
        $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=' . $thold_data['id'];
        $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE);
    } else {
        $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=0';
        $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE);
    }
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $data_fields = array();
    $reference_types = get_reference_types($thold_data['local_data_id'], $step, $timearray);
    $temp = db_fetch_assoc('SELECT id, local_data_template_rrd_id, data_source_name, data_input_field_id
		FROM data_template_rrd
		WHERE local_data_id=' . $thold_data['local_data_id']);
    foreach ($temp as $d) {
        if ($d['data_input_field_id'] != 0) {
            $name = db_fetch_cell('SELECT name FROM data_input_fields WHERE id=' . $d['data_input_field_id']);
        } else {
            $name = $d['data_source_name'];
        }
        if ($d['id'] != $thold_data['data_template_rrd_id']) {
            $data_fields[$d['data_source_name']] = $name;
        }
    }
    $replacements = db_fetch_assoc_prepared('SELECT DISTINCT field_name
		FROM data_local AS dl
		INNER JOIN host_snmp_cache AS hsc
		ON dl.snmp_query_id=hsc.snmp_query_id
		AND dl.host_id=hsc.host_id
		WHERE dl.id = ?', array($thold_data['data_template_id']));
    $nr = array();
    if (sizeof($replacements)) {
        foreach ($replacements as $r) {
            $nr[] = "<span class='deviceUp'>|query_" . $r['field_name'] . "|</span>";
        }
    }
    $vhf = explode('|', trim(VALID_HOST_FIELDS, '()'));
    if (sizeof($vhf)) {
        foreach ($vhf as $r) {
            $nr[] = "<span class='deviceUp'>|" . $r . "|</span>";
        }
    }
    $replacements = "<br>" . __('Replacement Fields: %s', implode(", ", $nr));
    $dss = db_fetch_assoc_prepared('SELECT data_source_name FROM data_template_rrd WHERE local_data_id = ?', array($thold_data['local_data_id']));
    if (sizeof($dss)) {
        foreach ($dss as $ds) {
            $dsname[] = "<span class='deviceUp'>|ds:" . $ds["data_source_name"] . "|</span>";
        }
    }
    $datasources = "<br>" . __('Data Sources: %s', implode(", ", $dsname));
    $form_array = array('template_header' => array('friendly_name' => __('Template Settings'), 'method' => 'spacer'), 'template_enabled' => array('friendly_name' => __('Template Propagation Enabled'), 'method' => 'checkbox', 'default' => '', 'description' => __('Whether or not these settings will be propagates from the threshold template.'), 'value' => !empty($thold_data['template_enabled']) ? $thold_data['template_enabled'] : ''), 'template_name' => array('friendly_name' => __('Template Name'), 'method' => 'custom', 'default' => '', 'description' => __('Name of the Threshold Template the threshold was created from.'), 'value' => isset($thold_data['template_name']) ? $thold_data['template_name'] : 'N/A'), 'general_header' => array('friendly_name' => __('General Settings'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Threshold Name'), 'method' => 'textbox', 'max_length' => 100, 'size' => '70', 'default' => $desc . ' [' . $template_rrd['data_source_name'] . ']', 'description' => __('Provide the Thresholds a meaningful name'), 'value' => isset($thold_data['name']) ? $thold_data['name'] : ''), 'thold_enabled' => array('friendly_name' => __('Threshold Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this threshold will be checked and alerted upon.'), 'value' => isset($thold_data['thold_enabled']) ? $thold_data['thold_enabled'] : ''), 'exempt' => array('friendly_name' => __('Weekend Exemption'), 'description' => __('If this is checked, this Threshold will not alert on weekends.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['exempt']) ? $thold_data['exempt'] : ''), 'restored_alert' => array('friendly_name' => __('Disable Restoration Email'), 'description' => __('If this is checked, Thold will not send an alert when the threshold has returned to normal status.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['restored_alert']) ? $thold_data['restored_alert'] : ''), 'thold_type' => array('friendly_name' => __('Threshold Type'), 'method' => 'drop_array', 'on_change' => 'changeTholdType()', 'array' => $thold_types, 'default' => read_config_option('thold_type'), 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($thold_data['thold_type']) ? $thold_data['thold_type'] : ''), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => read_config_option('alert_repeat'), 'description' => __('Repeat alert after this amount of time has pasted since the last alert.'), 'value' => isset($thold_data['repeat_alert']) ? $thold_data['repeat_alert'] : ''), 'thold_warning_header' => array('friendly_name' => __('Warning - High / Low Settings'), 'method' => 'spacer'), 'thold_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_hi']) ? $thold_data['thold_warning_hi'] : ''), 'thold_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_low']) ? $thold_data['thold_warning_low'] : ''), 'thold_warning_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for a warning to be raised.'), 'value' => isset($thold_data['thold_warning_fail_trigger']) ? $thold_data['thold_warning_fail_trigger'] : read_config_option('alert_trigger')), 'thold_header' => array('friendly_name' => __('Alert - High / Low Settings'), 'method' => 'spacer'), 'thold_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['thold_hi']) ? $thold_data['thold_hi'] : ''), 'thold_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['thold_low']) ? $thold_data['thold_low'] : ''), 'thold_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for an alert to be raised.'), 'value' => isset($thold_data['thold_fail_trigger']) ? $thold_data['thold_fail_trigger'] : read_config_option('alert_trigger')), 'time_warning_header' => array('friendly_name' => __('Warning - Time Based Settings'), 'method' => 'spacer'), 'time_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_hi']) ? $thold_data['time_warning_hi'] : ''), 'time_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_low']) ? $thold_data['time_warning_low'] : ''), 'time_warning_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_warning_fail_trigger']) ? $thold_data['time_warning_fail_trigger'] : read_config_option('thold_warning_time_fail_trigger')), 'time_warning_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_warning_fail_length']) ? $thold_data['time_warning_fail_length'] : (read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1)), 'time_header' => array('friendly_name' => __('Alert - Time Based Settings'), 'method' => 'spacer'), 'time_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['time_hi']) ? $thold_data['time_hi'] : ''), 'time_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['time_low']) ? $thold_data['time_low'] : ''), 'time_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'default' => read_config_option('thold_time_fail_trigger'), 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_fail_trigger']) ? $thold_data['time_fail_trigger'] : read_config_option('thold_time_fail_trigger')), 'time_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_fail_length']) ? $thold_data['time_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_time_fail_length') : 1)), 'baseline_header' => array('friendly_name' => __('Baseline Settings'), 'method' => 'spacer'), 'bl_ref_time_range' => array('friendly_name' => __('Time range'), 'method' => 'drop_array', 'array' => $reference_types, 'description' => __('Specifies the point in the past (based on rrd resolution) that will be used as a reference'), 'value' => isset($thold_data['bl_ref_time_range']) ? $thold_data['bl_ref_time_range'] : read_config_option('alert_bl_timerange_def')), 'bl_pct_up' => array('friendly_name' => __('Deviation UP'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the upper bound threshold. If not set, upper bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_up']) ? $thold_data['bl_pct_up'] : ''), 'bl_pct_down' => array('friendly_name' => __('Deviation DOWN'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the lower bound threshold. If not set, lower bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_down']) ? $thold_data['bl_pct_down'] : ''), 'bl_fail_trigger' => array('friendly_name' => __('Baseline Trigger Count'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Number of consecutive times the data source must be in breach of the baseline threshold for an alert to be raised.<br>Leave empty to use default value (<b>Default: %s cycles</b>)', read_config_option('alert_bl_trigger')), 'value' => isset($thold_data['bl_fail_trigger']) ? $thold_data['bl_fail_trigger'] : read_config_option("alert_bl_trigger")), 'data_manipulation' => array('friendly_name' => __('Data Manipulation'), 'method' => 'spacer'), 'data_type' => array('friendly_name' => __('Data Type'), 'method' => 'drop_array', 'on_change' => 'changeDataType()', 'array' => $data_types, 'default' => read_config_option('data_type'), 'description' => __('Special formatting for the given data.'), 'value' => isset($thold_data['data_type']) ? $thold_data['data_type'] : ''), 'cdef' => array('friendly_name' => __('Threshold CDEF'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Apply this CDEF before returning the data.'), 'value' => isset($thold_data['cdef']) ? $thold_data['cdef'] : 0, 'array' => thold_cdef_select_usable_names()), 'percent_ds' => array('friendly_name' => __('Percent Datasource'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Second Datasource Item to use as total value to calculate percentage from.'), 'value' => isset($thold_data['percent_ds']) ? $thold_data['percent_ds'] : 0, 'array' => $data_fields), 'expression' => array('friendly_name' => __('RPN Expression'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 80, 'default' => '', 'description' => __('An RPN Expression is an RRDtool Compatible RPN Expression.  Syntax includes all functions below in addition to both Device and Data Query replacement expressions such as <span class="deviceUp">|query_ifSpeed|</span>.  To use a Data Source in the RPN Expression, you must use the syntax: <span class="deviceUp">|ds:dsname|</span>.  For example, <span class="deviceUp">|ds:traffic_in|</span> will get the current value of the traffic_in Data Source for the RRDfile(s) associated with the Graph. Any Data Source for a Graph can be included.<br><br>Math Operators: <span class="deviceUp">+, -, /, *, &#37;, ^</span><br>Functions: <span class="deviceUp">SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG, ATAN, ADNAN</span><br>Flow Operators: <span class="deviceUp">UN, ISINF, IF, LT, LE, GT, GE, EQ, NE</span><br>Comparison Functions: <span class="deviceUp">MAX, MIN, INF, NEGINF, NAN, UNKN, COUNT, PREV</span>%s %s', $replacements, $datasources), 'value' => isset($thold_data['expression']) ? $thold_data['expression'] : '', 'max_length' => '255', 'size' => '80'), 'other_header' => array('friendly_name' => __('Other Settings'), 'method' => 'spacer'), 'notify_warning' => array('friendly_name' => __('Warning Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Warnings for this Data Source'), 'value' => isset($thold_data['notify_warning']) ? $thold_data['notify_warning'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'), 'notify_alert' => array('friendly_name' => __('Alert Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Alerts for this Data Source'), 'value' => isset($thold_data['notify_alert']) ? $thold_data['notify_alert'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'));
    if (read_config_option("thold_alert_snmp") == 'on') {
        $extra = array('snmp_event_category' => array('friendly_name' => __('SNMP Notification - Event Category'), 'method' => 'textbox', 'description' => __('To allow a NMS to categorize different SNMP notifications more easily please fill in the category SNMP notifications for this template should make use of. E.g.: "disk_usage", "link_utilization", "ping_test", "nokia_firewall_cpu_utilization" ...'), 'value' => isset($thold_data['snmp_event_category']) ? $thold_data['snmp_event_category'] : '', 'default' => '', 'max_length' => '255'), 'snmp_event_severity' => array('friendly_name' => __('SNMP Notification - Alert Event Severity'), 'method' => 'drop_array', 'default' => '3', 'description' => __('Severity to be used for alerts. (low impact -> critical impact)'), 'value' => isset($thold_data['snmp_event_severity']) ? $thold_data['snmp_event_severity'] : 3, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical'))));
        $form_array += $extra;
        if (read_config_option('thold_alert_snmp_warning') != 'on') {
            $extra = array('snmp_event_warning_severity' => array('friendly_name' => __('SNMP Notification - Warning Event Severity'), 'method' => 'drop_array', 'default' => '2', 'description' => __('Severity to be used for warnings. (Low impact -> Critical impact).<br>Note: The severity of warnings has to be equal or lower than the severity being defined for alerts.'), 'value' => isset($thold_data['snmp_event_warning_severity']) ? $thold_data['snmp_event_warning_severity'] : 2, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical'))));
        }
        $form_array += $extra;
    }
    if (read_config_option('thold_disable_legacy') != 'on') {
        $extra = array('notify_accounts' => array('friendly_name' => __('Notify accounts'), 'method' => 'drop_multi', 'description' => __('This is a listing of accounts that will be notified when this threshold is breached.<br><br><br><br>'), 'array' => $send_notification_array, 'sql' => $sql), 'notify_extra' => array('friendly_name' => __('Alert Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive alerts for this data source (comma separated)'), 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('friendly_name' => __('Warning Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive warnings for this data source (comma separated)'), 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : ''));
        $form_array += $extra;
    } else {
        $extra = array('notify_accounts' => array('method' => 'hidden', 'value' => 'ignore'), 'notify_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : ''));
        $form_array += $extra;
    }
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array + array('id' => array('method' => 'hidden', 'value' => !empty($thold_data['id']) ? $thold_data['id'] : '0'), 'data_template_rrd_id' => array('method' => 'hidden', 'value' => isset($template_rrd) ? $template_rrd['id'] : '0'), 'host_id' => array('method' => 'hidden', 'value' => $thold_data['host_id']), 'local_data_id' => array('method' => 'hidden', 'value' => $thold_data['local_data_id']))));
    html_end_box();
    if (isset($_SESSION['data_return'])) {
        $ajax = false;
    } else {
        $ajax = true;
    }
    form_save_button('thold.php' . (!empty($thold_data['id']) ? '?id=' . $thold_data['id'] : ''), 'return', 'id', $ajax);
    ?>

	<script type='text/javascript'>

	function templateEnableDisable() {
		var status = $('#template_enabled').is(':checked');

		$('#name').prop('disabled', status);
		$('#thold_type').prop('disabled', status);
		$('#thold_hi').prop('disabled', status);
		$('#thold_low').prop('disabled', status);
		$('#thold_fail_trigger').prop('disabled', status);
		$('#thold_warning_hi').prop('disabled', status);
		$('#thold_warning_low').prop('disabled', status);
		$('#thold_warning_fail_trigger').prop('disabled', status);
		$('#repeat_alert').prop('disabled', status);
		$('#notify_extra').prop('disabled', status);
		$('#notify_warning_extra').prop('disabled', status);
		$('#notify_warning').prop('disabled', status);
		$('#notify_alert').prop('disabled', status);
		$('#cdef').prop('disabled', status);
		$('#thold_enabled').prop('disabled', status);

		if ($('#notify_accounts')) $('#notify_accounts').prop('disabled', status);

		$('#time_hi').prop('disabled', status);
		$('#time_low').prop('disabled', status);
		$('#time_fail_trigger').prop('disabled', status);
		$('#time_fail_length').prop('disabled', status);
		$('#time_warning_hi').prop('disabled', status);
		$('#time_warning_low').prop('disabled', status);
		$('#time_warning_fail_trigger').prop('disabled', status);
		$('#time_warning_fail_length').prop('disabled', status);
		$('#data_type').prop('disabled', status);
		$('#percent_ds').prop('disabled', status);
		$('#expression').prop('disabled', status);
		$('#exempt').prop('disabled', status);
		$('#restored_alert').prop('disabled', status);

		if ($('#snmp_event_category')) $('#snmp_event_category').prop('disabled', status);
		if ($('#snmp_event_severity')) $('#snmp_event_severity').prop('disabled', status);
		if ($('#snmp_event_warning_severity')) $('#snmp_event_warning_severity').prop('disabled', status);
	}

	function changeTholdType() {
		switch($('#thold_type').val()) {
		case '0':
			thold_toggle_hilow('');
			thold_toggle_baseline('none');
			thold_toggle_time('none');
			break;
		case '1':
			thold_toggle_hilow('none');
			thold_toggle_baseline('');
			thold_toggle_time('none');
			break;
		case '2':
			thold_toggle_hilow('none');
			thold_toggle_baseline('none');
			thold_toggle_time('');
			break;
		}
	}

	function changeDataType () {
		switch($('#data_type').val()) {
		case '0':
			$('#row_cdef').hide();
			$('#row_percent_ds').hide();
			$('#row_expression').hide();
			break;
		case '1':
			$('#row_cdef').show();
			$('#row_percent_ds').hide();
			$('#row_expression').hide();
			break;
		case '2':
			$('#row_cdef').hide()
			$('#row_percent_ds').show();
			$('#row_expression').hide();
			break;
		case '3':
			$('#row_expression').show();
			$('#row_cdef').hide();
			$('#row_percent_ds').hide();
			break;
		}
	}

	function thold_toggle_hilow (status) {
		if (status == '') {
			$('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').show();
			$('#row_thold_warning_header, #row_thold_warning_hi').show();
			$('#row_thold_warning_low, #row_thold_warning_fail_trigger').show();
		}else{
			$('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').hide();
			$('#row_thold_warning_header, #row_thold_warning_hi').hide();
			$('#row_thold_warning_low, #row_thold_warning_fail_trigger').hide();
		}
	}

	function thold_toggle_baseline(status) {
		if (status == '') {
			$('#row_baseline_header, #row_bl_ref_time_range').show();
			$('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').show();
		}else{
			$('#row_baseline_header, #row_bl_ref_time_range').hide();
			$('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').hide();
		}
	}

	function thold_toggle_time(status) {
		if (status == '') {
			$('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').show();
			$('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').show();
			$('#row_time_warning_fail_trigger, #row_time_warning_fail_length').show();
		}else{
			$('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').hide();
			$('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').hide();
			$('#row_time_warning_fail_trigger, #row_time_warning_fail_length').hide();
		}
	}

	function graphImage() {
		var id = $('#element').val();
		$('#graphimage').attr(src, '../../graph_image.php?local_graph_id=' + id + '&rra_id=0&graph_start=-32400&graph_height=100&graph_width=300&graph_nolegend=true').change();
	}

	$(function() {
		if ('<?php 
    print $thold_data['thold_template_id'];
    ?>
' == '0') {
			$('#template_enabled').prop('disabled', true);
		}

		if ($('#notify_accounts option').length == 0) {
			$('#row_notify_accounts').hide();
		}

		if ($('#notify_warning option').length == 0) {
			$('#row_notify_warning').hide();
		}

		if ($('#notify_alert option').length == 0) {
			$('#row_notify_alert').hide();
		}

		$('#notify_accounts').multiselect({
			minWidth: '400',
			noneSelectedText: '<?php 
    print __('Select Users(s)');
    ?>
', 
			selectedText: function(numChecked, numTotal, checkedItems) {
				myReturn = numChecked + ' <?php 
    print __('Users Selected');
    ?>
';
				$.each(checkedItems, function(index, value) {
					if (value.value == '0') {
						myReturn='<?php 
    print __('All Users Selected');
    ?>
';
						return false;
					}
				});
				return myReturn;
			},
			checkAllText: 'All', 
			uncheckAllText: 'None',
			uncheckall: function() {
				$(this).multiselect('widget').find(':checkbox:first').each(function() {
					$(this).prop('checked', true);
				});
			},
			open: function() {
				size = $('#notify_accounts option').length * 18 + 20;
				if (size > 100) {
					size = 100;
				}
				$('ul.ui-multiselect-checkboxes').css('height', size + 'px');
			},
			click: function(event, ui) {
				checked=$(this).multiselect('widget').find('input:checked').length;

				if (ui.value == '0') {
					if (ui.checked == true) {
						$('#host').multiselect('uncheckAll');
						$(this).multiselect('widget').find(':checkbox:first').each(function() {
							$(this).prop('checked', true);
						});
					}
				}else if (checked == 0) {
					$(this).multiselect('widget').find(':checkbox:first').each(function() {
						$(this).click();
					});
				}else if ($(this).multiselect('widget').find('input:checked:first').val() == '0') {
					if (checked > 0) {
						$(this).multiselect('widget').find(':checkbox:first').each(function() {
							$(this).click();
							$(this).prop('disable', true);
						});
					}
				}
			}
		}).multiselectfilter( {
			label: 'Search', width: '150'
		});

		templateEnableDisable();

		$('#template_enabled').click(function() {
			templateEnableDisable();
		});

		<?php 
    if (!isset($thold_data['thold_template_id']) || $thold_data['thold_template_id'] == '') {
        ?>
		$('#templated_enabled').prop('disabled', true);
		<?php 
    }
    ?>

		changeTholdType ();
		changeDataType ();

		$('#element').change(function() {
			graphImage;
		});
	});

	</script>
	<?php 
}
function mactrack_get_records(&$sql_where, $apply_limits = TRUE, $row_limit = '30')
{
    global $timespan, $group_function, $summary_stats;
    $match = read_config_option('mt_ignorePorts', TRUE);
    if ($match == '') {
        $match = '(Vlan|Loopback|Null)';
        db_execute_prepared('REPLACE INTO settings SET name="mt_ignorePorts", value = ?', array($match));
    }
    $ignore = "(ifName NOT REGEXP '" . $match . "' AND ifDescr NOT REGEXP '" . $match . "')";
    /* issues sql where */
    if (get_request_var('issues') == '-2') {
        // All Interfaces
        /* do nothing all records */
    } elseif (get_request_var('issues') == '-3') {
        // Non Ignored Interfaces
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . $ignore;
    } elseif (get_request_var('issues') == '-4') {
        // Ignored Interfaces
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' NOT ' . $ignore;
    } elseif (get_request_var('issues') == '-1') {
        // With Issues
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "((int_errors_present=1 OR int_discards_present=1) AND {$ignore})";
    } elseif (get_request_var('issues') == '0') {
        // Up Interfaces
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(ifOperStatus=1 AND {$ignore})";
    } elseif (get_request_var('issues') == '1') {
        // Up w/o Alias
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(ifOperStatus=1 AND ifAlias='' AND {$ignore})";
    } elseif (get_request_var('issues') == '2') {
        // Errors Up
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(int_errors_present=1 AND {$ignore})";
    } elseif (get_request_var('issues') == '3') {
        // Discards Up
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . "(int_discards_present=1 AND {$ignore})";
    } elseif (get_request_var('issues') == '7') {
        // Change < 24 Hours
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_interfaces.sysUptime-ifLastChange < 8640000) AND ifLastChange > 0 AND (mac_track_interfaces.sysUptime-ifLastChange > 0)';
    } elseif (get_request_var('issues') == '9' && get_filter_request_var('bwusage') != '-1') {
        // In/Out over 70%
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '((inBound>' . get_request_var('bwusage') . ' OR outBound>' . get_request_var('bwusage') . ") AND {$ignore})";
    } elseif (get_request_var('issues') == '10' && get_filter_request_var('bwusage') != '-1') {
        // In over 70%
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(inBound>' . get_request_var('bwusage') . " AND {$ignore})";
    } elseif (get_request_var('issues') == '11' && get_filter_request_var('bwusage') != '-1') {
        // Out over 70%
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(outBound>' . get_request_var('bwusage') . " AND {$ignore})";
    } else {
    }
    /* filter sql where */
    $filter_where = mactrack_create_sql_filter(get_request_var('filter'), array('ifAlias', 'hostname', 'ifName', 'ifDescr'));
    if (strlen($filter_where)) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . $filter_where;
    }
    /* device_id sql where */
    if (get_filter_request_var('device_id') == '-1') {
        /* do nothing all states */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_interfaces.device_id=' . get_request_var('device_id');
    }
    /* site sql where */
    if (get_filter_request_var('site_id') == '-1') {
        /* do nothing all sites */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_interfaces.site_id=' . get_request_var('site_id');
    }
    /* type sql where */
    if (get_filter_request_var('device_type_id') == '-1') {
        /* do nothing all states */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(mac_track_devices.device_type_id=' . get_request_var('device_type_id');
    }
    $sql_query = "SELECT mac_track_interfaces.*,\n\t\tmac_track_device_types.description AS device_type,\n\t\tmac_track_devices.device_name,\n\t\tmac_track_devices.host_id,\n\t\tmac_track_devices.disabled,\n\t\tmac_track_devices.last_rundate\n\t\tFROM mac_track_interfaces\n\t\tINNER JOIN mac_track_devices\n\t\tON mac_track_interfaces.device_id=mac_track_devices.device_id\n\t\tINNER JOIN mac_track_device_types\n\t\tON 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;
    }
    //echo $sql_query;
    return db_fetch_assoc($sql_query);
}
示例#19
0
function form_actions()
{
    global $colors, $user_actions, $fields_user_edit;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        $selected_items = unserialize(stripslashes(get_request_var('selected_items')));
        if (get_request_var('drp_action') == '1') {
            /* delete */
            if (!isset_request_var('delete_type')) {
                set_request_var('delete_type', 2);
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                $selected_items[$i] = sanitize_search_string($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                $graphs = db_fetch_assoc('SELECT
					graph_local.id AS local_graph_id
					FROM graph_local
					WHERE ' . array_to_sql_or($selected_items, 'graph_local.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($graphs) > 0) {
                    foreach ($graphs as $graph) {
                        $graphs_to_act_on[] = $graph['local_graph_id'];
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            api_data_source_remove_multi($data_sources_to_act_on);
            api_graph_remove_multi($graphs_to_act_on);
            db_execute("DELETE FROM plugin_mikrotik_users WHERE name IN ('" . implode("','", $devices_to_act_on) . "')");
        }
        header('Location: mikrotik_users.php?header=false');
        exit;
    }
    /* setup some variables */
    $user_list = '';
    /* loop through each of the user templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([A-Z0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            $matches[1] = sanitize_search_string($matches[1]);
            /* ==================================================== */
            $user_list .= '<li>' . $matches[1] . '</li>';
            $user_array[] = $matches[1];
        }
    }
    top_header();
    html_start_box('<strong>' . $user_actions[get_request_var('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='mikrotik_users.php' autocomplete='off' method='post'>\n";
    if (isset($user_array) && sizeof($user_array)) {
        if (get_request_var('drp_action') == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete the following Users(s) and their Graph(s).') . "</p>\n\t\t\t\t\t\t<ul>" . $user_list . "</ul>";
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Device(s)') . "'>";
        }
    } else {
        print "<tr><td><span class='textError'>" . __('You must select at least one User.') . "</span></td></tr>\n";
        $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
    }
    print "<tr class='saveRow'>\n\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($user_array) ? serialize($user_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var("drp_action") . "'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>\n";
    html_end_box();
    bottom_footer();
}
示例#20
0
function syslog_stats_filter()
{
    global $config, $item_rows;
    ?>
	<tr class='even'>
		<td>
		<form id='stats_form' action='syslog.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Facility');
    ?>
					</td>
					<td>
						<select id='facility' onChange='applyFilter(document.stats)'>
							<option value='-1'<?php 
    if (get_request_var('facility') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='-2'<?php 
    if (get_request_var('facility') == '-2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('None');
    ?>
</option>
							<?php 
    $facilities = syslog_db_fetch_assoc('SELECT DISTINCT facility_id, facility 
								FROM syslog_facilities AS sf
								WHERE facility_id IN (SELECT DISTINCT facility_id FROM syslog_statistics)
								ORDER BY facility');
    if (sizeof($facilities)) {
        foreach ($facilities as $r) {
            print '<option value="' . $r['facility_id'] . '"';
            if (get_request_var('facility') == $r['facility_id']) {
                print ' selected';
            }
            print '>' . ucfirst($r['facility']) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Priority');
    ?>
					</td>
					<td>
						<select id='priority' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('priority') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='-2'<?php 
    if (get_request_var('priority') == '-2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('None');
    ?>
</option>
							<?php 
    $priorities = syslog_db_fetch_assoc('SELECT DISTINCT priority_id, priority 
								FROM syslog_priorities AS sp
								WHERE priority_id IN (SELECT DISTINCT priority_id FROM syslog_statistics)
								ORDER BY priority');
    if (sizeof($priorities)) {
        foreach ($priorities as $r) {
            print '<option value="' . $r['priority_id'] . '"';
            if (get_request_var('priority') == $r['priority_id']) {
                print ' selected';
            }
            print '>' . ucfirst($r['priority']) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Entries');
    ?>
					</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 '>' . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input id='go' type='button' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input id='clear' type='button' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
				</tr>
			</table>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='30' value='<?php 
    print get_request_var('filter');
    ?>
' onChange='applyFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		</td>
		<script type='text/javascript'>

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

		$(function() {
			$('#go').click(function() {
				applyFilter();
			});

			$('#clear').click(function() {
				clearFilter();
			});
		});

		function applyFilter() {
			strURL  = 'syslog.php?header=false&facility=' + $('#facility').val();
			strURL += '&priority=' + $('#priority').val();
			strURL += '&filter=' + $('#filter').val();
			strURL += '&rows=' + $('#rows').val();
			loadPageNoHeader(strURL);
		}

		</script>
	</tr>
	<?php 
}
        break;
    case 'mactrack_utilities_purge_aggregated_data':
        mactrack_utilities_purge_aggregated_data();
        break;
    case 'mactrack_utilities_recreate_aggregated_data':
        mactrack_utilities_recreate_aggregated_data();
        break;
    case 'mactrack_refresh_oui_database':
        top_header();
        include_once './plugins/mactrack/lib/mactrack_functions.php';
        import_oui_database('web');
        bottom_footer();
        break;
    case 'mactrack_proc_status':
        /* ================= input validation ================= */
        get_filter_request_var('refresh');
        /* ==================================================== */
        load_current_session_value('refresh', 'sess_mactrack_utilities_refresh', '30');
        $refresh['seconds'] = get_request_var('refresh');
        $refresh['page'] = 'mactrack_utilities.php?action=mactrack_proc_status';
        top_header();
        mactrack_display_run_status();
        bottom_footer();
        break;
    default:
        top_header();
        mactrack_utilities();
        bottom_footer();
        break;
}
/* -----------------------
function mactrack_redirect()
{
    /* set the default tab */
    get_filter_request_var('report', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z]+)$/')));
    load_current_session_value('report', 'sess_mactrack_view_report', 'devices');
    $current_tab = get_nfilter_request_var('report');
    $current_page = str_replace('mactrack_', '', str_replace('view_', '', str_replace('.php', '', basename($_SERVER['PHP_SELF']))));
    $current_dir = dirname($_SERVER['PHP_SELF']);
    if ($current_page != $current_tab) {
        header('Location: ' . $current_dir . '/mactrack_view_' . $current_tab . '.php');
    }
}
示例#23
0
function syslog_filter()
{
    global $config, $item_rows;
    ?>
	<tr class='even'>
		<td>
		<form id='removal' action='syslog_removal.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='30' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Enabled');
    ?>
					</td>
					<td>
						<select id='enabled' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('enabled') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('enabled') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Yes');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('enabled') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('No');
    ?>
</option>
						</select>
					</td>
					<td>
						Rules
					</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 '>' . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input id='refresh' type='button' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input id='clear' type='button' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL = 'syslog_removal.php?filter='+$('#filter').val()+'&enabled='+$('#enabled').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&header=false';
			loadPageNoHeader(strURL);
		}

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

		$(function() {
			$('#refresh').click(function() {
                    applyFilter();
			});

			$('#clear').click(function() {
                    clearFilter();
			});

			$('#removal').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});

		</script>
		</td>
	</tr>
	<?php 
}
示例#24
0
function hmib_summary()
{
    global $device_actions, $item_rows, $config;
    /* ================= input validation ================= */
    get_filter_request_var('htop');
    get_filter_request_var('ptop');
    /* ==================================================== */
    /* clean up sort string */
    if (isset_request_var('sort_column')) {
        set_request_var('sort_column', sanitize_search_string(get_nfilter_request_var('sort_column')));
    }
    /* clean up sort string */
    if (isset_request_var('sort_direction')) {
        set_request_var('sort_direction', sanitize_search_string(get_nfilter_request_var('sort_direction')));
    }
    /* clean up search string */
    if (isset_request_var('filter')) {
        set_request_var('filter', sanitize_search_string(get_nfilter_request_var('filter')));
    }
    /* remember these search fields in session vars so we don't have
     * to keep passing them around
     */
    if (isset_request_var('area') && get_nfilter_request_var('area') == 'processes') {
        if (isset_request_var('clear')) {
            kill_session_var('sess_hmib_proc_top');
            kill_session_var('sess_hmib_proc_filter');
            kill_session_var('sess_hmib_proc_sort_column');
            kill_session_var('sess_hmib_proc_sort_direction');
            unset_request_var('filter');
            unset_request_var('ptop');
            unset_request_var('sort_column');
            unset_request_var('sort_direction');
        }
        if (isset_request_var('sort_column')) {
            $_SESSION['sess_hmib_proc_sort_column'] = get_request_var('sort_column');
            $_SESSION['sess_hmib_proc_sort_direction'] = get_request_var('sort_direction');
        } elseif (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
    } elseif (isset_request_var('area') && get_nfilter_request_var('area') == 'hosts') {
        if (isset_request_var('clear')) {
            kill_session_var('sess_hmib_host_top');
            kill_session_var('sess_hmib_host_sort_column');
            kill_session_var('sess_hmib_host_sort_direction');
            unset_request_var('htop');
            unset_request_var('sort_column');
            unset_request_var('sort_direction');
        }
        if (isset_request_var('sort_column')) {
            $_SESSION['sess_hmib_host_sort_column'] = get_request_var('sort_column');
            $_SESSION['sess_hmib_host_sort_direction'] = get_request_var('sort_direction');
        } elseif (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
    } else {
        if (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
    }
    load_current_session_value('ptop', 'sess_hmib_proc_top', read_config_option('hmib_top_processes'));
    load_current_session_value('htop', 'sess_hmib_host_top', read_config_option('hmib_top_types'));
    load_current_session_value('filter', 'sess_hmib_proc_filter', '');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/hmib/hmib.php';
    $proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
    $host = $config['url_path'] . 'plugins/hmib/images/server.png';
    $hardw = $config['url_path'] . 'plugins/hmib/images/view_hardware.gif';
    $inven = $config['url_path'] . 'plugins/hmib/images/view_inventory.gif';
    $storage = $config['url_path'] . 'plugins/hmib/images/drive.png';
    $htdq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query\n\t\tWHERE hash='137aeab842986a76cf5bdef41b96c9a3'");
    $hcpudq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query\n\t\tWHERE hash='0d1ab53fe37487a5d0b9e1d3ee8c1d0d'");
    $hugt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='e8462bbe094e4e9e814d4e681671ea82'");
    $hpgt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='62205afbd4066e5c4700338841e3901e'");
    $htsd = db_fetch_cell("SELECT id\n\t\tFROM host_template\n\t\tWHERE hash='7c13344910097cc599f0d0485305361d'");
    if ($htdq == 0 || $hcpudq == 0 || $hugt == 0 || $hpgt == 0 || $htsd == 0) {
        $templates_missing = true;
    } else {
        $templates_missing = false;
    }
    ?>
	<script type='text/javascript'>
	function applyFilter(objForm) {
		strURL  = '?action=summary&area=hosts&header=false';
		strURL += '&htop=' + $('#htop').val();
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = '?area=hosts&clear=true&header=false';
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    html_start_box(__('Summary Filter'), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
			<form name='host_summary'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Top');
    ?>
					</td>
					<td>
						<select id='htop' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('htop') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Records');
    ?>
</option>
							<option value='5'<?php 
    if (get_request_var('htop') == '5') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 5);
    ?>
</option>
							<option value='10'<?php 
    if (get_request_var('htop') == '10') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Record', 10);
    ?>
s</option>
							<option value='15'<?php 
    if (get_request_var('htop') == '15') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Record', 15);
    ?>
s</option>
							<option value='20'<?php 
    if (get_request_var('htop') == '20') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Record', 20);
    ?>
s</option>
						</select>
					</td>
					<td>
						<input type='button' onClick='applyFilter()' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input type='button' onClick='clearFilter()' value='<?php 
    print __('Clear');
    ?>
' name='clear'>
					</td>
					<td>
						&nbsp;&nbsp;<?php 
    print $templates_missing ? '<strong>' . __('WARNING: You need to import your Host MIB Host Template to view Graphs.  See the README for more information.') . '</strong>' : '';
    ?>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box(false);
    html_start_box(__('Device Type Summary Statistics'), '100%', '', '3', 'center', '');
    if (!isset($_SESSION['sess_hmib_host_top'])) {
        $limit = 'LIMIT ' . read_config_option('hmib_top_types');
    } elseif ($_SESSION['sess_hmib_host_top'] == '-1') {
        $limit = '';
    } else {
        $limit = 'LIMIT ' . $_SESSION['sess_hmib_host_top'];
    }
    $sql = 'SELECT
		hrst.id AS id,
		hrst.name AS name,
		hrst.version AS version,
		hrs.host_type AS host_type,
		SUM(CASE WHEN host_status=3 THEN 1 ELSE 0 END) AS upHosts,
		SUM(CASE WHEN host_status=2 THEN 1 ELSE 0 END) AS recHosts,
		SUM(CASE WHEN host_status=1 THEN 1 ELSE 0 END) AS downHosts,
		SUM(CASE WHEN host_status=0 THEN 1 ELSE 0 END) AS disabledHosts,
		SUM(users) AS users,
		SUM(numCpus) AS cpus,
		AVG(memUsed) AS avgMem,
		MAX(memUsed) AS maxMem,
		AVG(swapUsed) AS avgSwap,
		MAX(swapUsed) AS maxSwap,
		AVG(cpuPercent) AS avgCpuPercent,
		MAX(cpuPercent) AS maxCpuPercent,
		AVG(processes) AS avgProcesses,
		MAX(processes) AS maxProcesses
		FROM plugin_hmib_hrSystem AS hrs
		LEFT JOIN plugin_hmib_hrSystemTypes AS hrst
		ON hrs.host_type=hrst.id
		GROUP BY name, version
		ORDER BY ' . $_SESSION['sess_hmib_host_sort_column'] . ' ' . $_SESSION['sess_hmib_host_sort_direction'] . ' ' . $limit;
    $rows = db_fetch_assoc($sql);
    $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => 'ASC', 'align' => 'left'), 'name' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'left'), '(version/1)' => array('display' => __('Version'), 'sort' => 'ASC', 'align' => 'right'), 'upHosts' => array('display' => __('Up'), 'sort' => 'DESC', 'align' => 'right'), 'recHosts' => array('display' => __('Recovering'), 'sort' => 'DESC', 'align' => 'right'), 'downHosts' => array('display' => __('Down'), 'sort' => 'DESC', 'align' => 'right'), 'disabledHosts' => array('display' => __('Disabled'), 'sort' => 'DESC', 'align' => 'right'), 'users' => array('display' => __('Logins'), 'sort' => 'DESC', 'align' => 'right'), 'cpus' => array('display' => __('CPUS'), 'sort' => 'DESC', 'align' => 'right'), 'avgCpuPercent' => array('display' => __('Avg CPU'), 'sort' => 'DESC', 'align' => 'right'), 'maxCpuPercent' => array('display' => __('Max CPU'), 'sort' => 'DESC', 'align' => 'right'), 'avgMem' => array('display' => __('Avg Mem'), 'sort' => 'DESC', 'align' => 'right'), 'maxMem' => array('display' => __('Max Mem'), 'sort' => 'DESC', 'align' => 'right'), 'avgSwap' => array('display' => __('Avg Swap'), 'sort' => 'DESC', 'align' => 'right'), 'maxSwap' => array('display' => __('Max Swap'), 'sort' => 'DESC', 'align' => 'right'), 'avgProcesses' => array('display' => __('Avg Proc'), 'sort' => 'DESC', 'align' => 'right'), 'maxProcesses' => array('display' => __('Max Proc'), 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, $_SESSION['sess_hmib_host_sort_column'], $_SESSION['sess_hmib_host_sort_direction'], false, 'hmib.php?action=summary&area=hosts');
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            if (!$templates_missing) {
                $host_id = db_fetch_cell("SELECT id FROM host WHERE host_template_id={$htsd}");
                $graph_url = hmib_get_graph_url($htdq, 0, $host_id, $row['id']);
                $graph_ncpu = hmib_get_graph_url($hcpudq, $row['id'], 0, '', $row['cpus'], false);
                $graph_acpu = hmib_get_graph_url($hcpudq, $row['id'], 0, '', round($row['avgCpuPercent'], 2), false);
                $graph_mcpu = hmib_get_graph_url($hcpudq, $row['id'], 0, '', round($row['maxCpuPercent'], 2), false);
                $graph_users = hmib_get_graph_template_url($hugt, $row['id'], 0, $row['users'], false);
                $graph_aproc = hmib_get_graph_template_url($hpgt, $row['id'], 0, number_format_i18n($row['avgProcesses'], 0), false);
                $graph_mproc = hmib_get_graph_template_url($hpgt, $row['id'], 0, number_format_i18n($row['maxProcesses'], 0), false);
            } else {
                $graph_url = '';
                $graph_ncpu = '';
                $graph_acpu = '';
                $graph_mcpu = '';
                $graph_users = '';
                $graph_aproc = '';
                $graph_mproc = '';
            }
            form_alternate_row();
            echo "<td style='white-space:nowrap;' width='120'>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=devices&type=" . $row['id']) . "'><img src='{$host}' title='" . __('View Devices') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=storage&ostype=" . $row['id']) . "'><img src='{$storage}' title='" . __('View Storage') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=hardware&ostype=" . $row['id']) . "'><img src='{$hardw}' title='" . __('View Hardware') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=running&type=" . $row['id']) . "'><img src='{$proc}' title='" . __('View Processes') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=software&ostype=" . $row['id']) . "'><img src='{$inven}' title='" . __('View Software Inventory') . "' align='absmiddle' alt=''></a>";
            echo $graph_url;
            echo '</td>';
            $upHosts = hmib_get_device_status_url($row['upHosts'], $row['host_type'], 3);
            $recHosts = hmib_get_device_status_url($row['recHosts'], $row['host_type'], 2);
            $downHosts = hmib_get_device_status_url($row['downHosts'], $row['host_type'], 1);
            $disaHosts = hmib_get_device_status_url($row['disabledHosts'], $row['host_type'], 0);
            echo "<td class='nowrap left'>" . ($row['name'] != '' ? $row['name'] : 'Unknown') . '</td>';
            echo "<td class='nowrap right'>" . $row['version'] . '</td>';
            echo "<td class='nowrap right'>" . $upHosts . '</td>';
            echo "<td class='nowrap right'>" . $recHosts . '</td>';
            echo "<td class='nowrap right'>" . $downHosts . '</td>';
            echo "<td class='nowrap right'>" . $disaHosts . '</td>';
            echo "<td class='nowrap right'>" . $graph_users . '</td>';
            echo "<td class='nowrap right'>" . $graph_ncpu . '</td>';
            echo "<td class='nowrap right'>" . $graph_acpu . ' %</td>';
            echo "<td class='nowrap right'>" . $graph_mcpu . ' %</td>';
            echo "<td class='nowrap right'>" . round($row['avgMem'], 2) . ' %</td>';
            echo "<td class='nowrap right'>" . round($row['maxMem'], 2) . ' %</td>';
            echo "<td class='nowrap right'>" . round($row['avgSwap'], 2) . ' %</td>';
            echo "<td class='nowrap right'>" . round($row['maxSwap'], 2) . ' %</td>';
            echo "<td class='nowrap right'>" . $graph_aproc . '</td>';
            echo "<td class='nowrap right'>" . $graph_mproc . '</td>';
        }
        echo '</tr>';
    } else {
        print '<tr><td colspan="8"><em>' . __('No Device Types') . '</em></td></tr>';
    }
    html_end_box();
    html_start_box(__('Process Summary Filter'), '100%', '', '3', 'center', '');
    ?>
	<script type='text/javascript'>
	function applyProcFilter(objForm) {
		strURL  = '?action=summary&area=processes';
		strURL += '&filter='  + $('#filter').val();
		strURL += '&ptop='    + $('#ptop').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearProc() {
		strURL = '?action=summary&area=processes&clear=true&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#proc_summary').submit(function(event) {
			event.preventDefault();
			applyProcFilter();
		});
	});
	</script>
	<?php 
    ?>
	<tr class='even'>
		<td>
			<form id='proc_summary'>
			<table class='filterTable'>
				<tr>
					<td style='width:55px;'>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='textbox' size='25' id='filter' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Top');
    ?>
					</td>
					<td>
						<select id='ptop' onChange='applyProcFilter()'>
							<option value='-1'<?php 
    if (get_request_var('ptop') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Records');
    ?>
</option>
							<option value='5'<?php 
    if (get_request_var('ptop') == '5') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 5);
    ?>
</option>
							<option value='10'<?php 
    if (get_request_var('ptop') == '10') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 10);
    ?>
</option>
							<option value='15'<?php 
    if (get_request_var('ptop') == '15') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 15);
    ?>
</option>
							<option value='20'<?php 
    if (get_request_var('ptop') == '20') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 20);
    ?>
</option>
						</select>
					</td>
					<td>
						<input type='button' onClick='applyProcFilter(document.proc_summary)' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input type='button' onClick='clearProc()' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
					<td>
						&nbsp;&nbsp;<?php 
    print $templates_missing ? '<strong>' . __('WARNING: You need to import your Host MIB Host Template to view Graphs.  See the README for more information.') . '</strong>' : '';
    ?>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box(false);
    html_start_box(__('Process Summary Statistics'), '100%', '', '3', 'center', '');
    if (!isset($_SESSION['sess_hmib_proc_top'])) {
        $limit = 'LIMIT ' . read_config_option('hmib_top_processes');
    } elseif ($_SESSION['sess_hmib_proc_top'] == '-1') {
        $limit = '';
    } else {
        $limit = 'LIMIT ' . $_SESSION['sess_hmib_proc_top'];
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where = "AND (hrswr.name LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thrswr.path LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thrswr.parameters LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    $sql = "SELECT\n\t\thrswr.name AS name,\n\t\tCOUNT(DISTINCT hrswr.path) AS paths,\n\t\tCOUNT(DISTINCT hrswr.host_id) AS numHosts,\n\t\tCOUNT(hrswr.host_id) AS numProcesses,\n\t\tAVG(hrswr.perfCPU) AS avgCpu,\n\t\tMAX(hrswr.perfCPU) AS maxCpu,\n\t\tAVG(hrswr.perfMemory) AS avgMemory,\n\t\tMAX(hrswr.perfMemory) AS maxMemory\n\t\tFROM plugin_hmib_hrSWRun AS hrswr\n\t\tWHERE hrswr.name!='System Idle Process' AND hrswr.name!=''\n\t\t{$sql_where}\n\t\tGROUP BY hrswr.name\n\t\tORDER BY " . $_SESSION['sess_hmib_proc_sort_column'] . ' ' . $_SESSION['sess_hmib_proc_sort_direction'] . ' ' . $limit;
    $rows = db_fetch_assoc($sql);
    //echo $sql;
    $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => 'ASC', 'align' => 'left'), 'name' => array('display' => __('Process Name'), 'sort' => 'ASC', 'align' => 'left'), 'paths' => array('display' => __('Num Paths'), 'sort' => 'DESC', 'align' => 'right'), 'numHosts' => array('display' => __('Hosts'), 'sort' => 'DESC', 'align' => 'right'), 'numProcesses' => array('display' => __('Processes'), 'sort' => 'DESC', 'align' => 'right'), 'avgCpu' => array('display' => __('Avg CPU'), 'sort' => 'DESC', 'align' => 'right'), 'maxCpu' => array('display' => __('Max CPU'), 'sort' => 'DESC', 'align' => 'right'), 'avgMemory' => array('display' => __('Avg Memory'), 'sort' => 'DESC', 'align' => 'right'), 'maxMemory' => array('display' => __('Max Memory'), 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, $_SESSION['sess_hmib_proc_sort_column'], $_SESSION['sess_hmib_proc_sort_direction'], false, 'hmib.php?action=summary&area=processes');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/hmib/hmib.php';
    $proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
    $host = $config['url_path'] . 'plugins/hmib/images/server.png';
    /* get the data query for the application use */
    $adq = db_fetch_cell("SELECT id\n\t\tFROM snmp_query\n\t\tWHERE hash='6b0ef0fe7f1d85bbb6812801ca15a7c5'");
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $graph_url = hmib_get_graph_url($adq, 0, 0, $row['name']);
            form_alternate_row();
            echo "<td width='70'>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=devices&process=" . $row['name']) . "'><img src='{$host}' title='" . __('View Devices') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=running&process=" . $row['name']) . "'><img src='{$proc}' title='" . __('View Processes') . "' align='absmiddle' alt=''></a>";
            echo $graph_url;
            echo '</td>';
            echo "<td class='left' width='140'>" . $row['name'] . '</td>';
            echo "<td class='right'>" . $row['paths'] . '</td>';
            echo "<td class='right'>" . $row['numHosts'] . '</td>';
            echo "<td class='right'>" . $row['numProcesses'] . '</td>';
            echo "<td class='right'>" . number_format_i18n($row['avgCpu'] / 3600, 0) . ' Hrs</td>';
            echo "<td class='right'>" . number_format_i18n($row['maxCpu'] / 3600, 0) . ' Hrs</td>';
            echo "<td class='right'>" . number_format_i18n($row['avgMemory'] / 1024, 2) . ' MB</td>';
            echo "<td class='right'>" . number_format_i18n($row['maxMemory'] / 1024, 2) . ' MB</td>';
        }
        echo '</tr>';
    } else {
        print '<tr><td><em>' . __('No Processes') . '</em></td></tr>';
    }
    html_end_box();
}
示例#25
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');
}
示例#26
0
function mactrack_device_edit()
{
    global $config, $fields_mactrack_device_edit;
    /* ================= input validation ================= */
    get_filter_request_var('device_id');
    /* ==================================================== */
    if (!isempty_request_var('device_id')) {
        $device = db_fetch_row_prepared('SELECT * FROM mac_track_devices WHERE device_id = ?', array(get_request_var('device_id')));
        $header_label = __('MacTrack Devices [edit: %s]', $device['device_name']);
    } else {
        $device = array();
        $header_label = __('MacTrack Devices [new]');
    }
    if (!empty($device['device_id'])) {
        ?>
		<table width='100%' align='center'>
			<tr>
				<td class='textInfo' colspan='2'>
					<?php 
        print $device['device_name'];
        ?>
 (<?php 
        print $device['hostname'];
        ?>
)
				</td>
			</tr>
			<tr>
				<td class='textHeader'>
					SNMP Information<br>

					<span style='font-size: 10px; font-weight: normal; font-family: monospace;'>
					<?php 
        /* force php to return numeric oid's */
        cacti_oid_numeric_format();
        $snmp_system = cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.1.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries'], SNMP_WEBUI);
        if ($snmp_system == '') {
            print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
        } else {
            $snmp_uptime = cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.3.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries'], SNMP_WEBUI);
            $snmp_hostname = cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.5.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries'], SNMP_WEBUI);
            $snmp_objid = cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.2.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries'], SNMP_WEBUI);
            $snmp_objid = str_replace('enterprises', '.1.3.6.1.4.1', $snmp_objid);
            $snmp_objid = str_replace('OID: ', '', $snmp_objid);
            $snmp_objid = str_replace('.iso', '.1', $snmp_objid);
            print "<strong>System:</strong> {$snmp_system}<br>\n";
            print "<strong>Uptime:</strong> {$snmp_uptime}<br>\n";
            print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n";
            print "<strong>ObjectID:</strong> {$snmp_objid}<br>\n";
        }
        ?>
					</span>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    form_start('mactrack_devices.php');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    /* preserve the devices site id between refreshes via a GET variable */
    if (!isempty_request_var('site_id')) {
        $fields_host_edit['site_id']['value'] = get_request_var('site_id');
    }
    draw_edit_form(array('config' => array('no_form_tab' => true), 'fields' => inject_form_variables($fields_mactrack_device_edit, isset($device) ? $device : array())));
    html_end_box();
    form_save_button('mactrack_devices.php', 'return');
}
示例#27
0
function thold_add_select_host()
{
    global $config;
    $host_id = get_filter_request_var('host_id');
    $local_graph_id = get_filter_request_var('local_graph_id');
    $data_template_rrd_id = get_filter_request_var('data_template_rrd_id');
    $hosts = get_allowed_devices();
    top_header();
    form_start('thold.php?action=save', 'tholdform');
    html_start_box(__('Threshold Creation Wizard'), '50%', '', '3', 'center', '');
    if ($host_id == '') {
        print '<tr><td class="center">' . __('Please select a Device') . '</td></tr>';
    } else {
        if ($local_graph_id == '') {
            print '<tr><td class="center">' . __('Please select a Graph') . '</td></tr>';
        } else {
            if ($data_template_rrd_id == '') {
                print '<tr><td class="center">' . __('Please select a Data Source') . '</td></tr>';
            } else {
                print '<tr><td class="center">' . __('Please press \'Create\' to activate your Threshold') . '</td></tr>';
            }
        }
    }
    html_end_box();
    html_start_box('', '50%', '', '3', 'center', '');
    /* display the host dropdown */
    ?>
	<tr><td><table class='filterTable' align='center'>
		<tr>
			<?php 
    print html_host_filter(get_request_var('host_id'));
    ?>
		</tr><?php 
    if ($host_id != '') {
        $graphs = get_allowed_graphs('gl.host_id=' . $host_id);
        ?>
		<tr>
			<td>
				<?php 
        print __('Graph');
        ?>
			</td>
			<td>
				<select id='local_graph_id' name='local_graph_id' onChange='applyFilter("graph")'>
					<option value=''></option><?php 
        foreach ($graphs as $row) {
            echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $local_graph_id ? ' selected' : '') . '>' . htmlspecialchars($row['title_cache'], ENT_QUOTES) . '</option>';
        }
        ?>
				</select>
			</td>
		</tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type='hidden' id='local_graph_id' name='local_graph_id' value=''>
			</td>
		</tr><?php 
    }
    if ($local_graph_id != '') {
        $dt_sql = 'SELECT DISTINCT dtr.local_data_id
			FROM data_template_rrd AS dtr
			LEFT JOIN graph_templates_item AS gti
			ON gti.task_item_id=dtr.id
			LEFT JOIN graph_local AS gl
			ON gl.id=gti.local_graph_id
			WHERE gl.id = ' . $local_graph_id;
        $local_data_id = db_fetch_cell($dt_sql);
        $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name
			FROM data_template_rrd
			WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name');
        /* show the data source options */
        ?>
		<tr>
			<td>
				<?php 
        print __('Data Source');
        ?>
			</td>
			<td>
				<input type='hidden' id='local_data_id' name='local_data_id' value='<?php 
        print $local_data_id;
        ?>
'>
				<select id='data_template_rrd_id' name='data_template_rrd_id' onChange='applyFilter("ds")'>
					<option value=''></option><?php 
        foreach ($dss as $row) {
            echo "<option value='" . $row['id'] . "'" . ($row['id'] == $data_template_rrd_id ? ' selected' : '') . '>' . htmlspecialchars($row['data_source_name'], ENT_QUOTES) . '</option>';
        }
        ?>
				</select>
			</td>
		</tr></table></td></tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type='hidden' id='data_template_rrd_id' name='data_template_rrd_id' value=''>
			</td>
		</tr></table></td></tr><?php 
    }
    if ($data_template_rrd_id != '') {
        echo "<tr><td class='center' colspan='2'><input type='hidden' name='save' id='save' value='save'><input id='go' type='button' value='" . __('Create') . "' title='" . __('Create Threshold') . "'></td></tr>";
    } else {
        echo "<tr><td class='center' colspan='2'></td></tr>";
    }
    html_end_box();
    form_end();
    html_start_box('', '50%', '', '3', 'center', '');
    if ($local_graph_id != '') {
        print "<tr><td style='text-align:center'><img id='graphi' src='../../graph_image.php?local_graph_id={$local_graph_id}&rra_id=0'></td></tr>";
    }
    html_end_box();
    ?>
	<script type='text/javascript'>

	function applyFilter(target) {
		strURL = 'thold.php?action=add&header=false&host_id=' + $('#host_id').val();
		if (target != 'host_id') {
			strURL += '&local_graph_id=' + $('#local_graph_id').val();
		}
		if (target == 'ds') {
			strURL += '&data_template_rrd_id=' + $('#data_template_rrd_id').val();
		}
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#go').button().click(function() {
            strURL = $('#tholdform').attr('action');
            json   = $('input, select').serializeObject();
            $.post(strURL, json).done(function(data) {
                $('#main').html(data);
                applySkin();
                window.scrollTo(0, 0);
            });
		});
	});

	</script>
	<?php 
}
示例#28
0
/** flowview_viewchart()
 *
 *  This function is taken from Slowlog.  Given
 *  a title, chart type and chart data, it will
 *  echo the required syntax for the Callback
 *  from the chart page to operate corectly.
 */
function flowview_viewchart()
{
    global $colors, $config;
    include $config['base_path'] . '/plugins/flowview/lib/open-flash-chart-object.php';
    include $config['base_path'] . '/plugins/flowview/lib/open-flash-chart.php';
    $title = get_nfilter_request_var('title');
    $chart_type = 'bar';
    $column = get_nfilter_request_var('type');
    $sessionid = get_nfilter_request_var('session');
    /* get the chart data from the session */
    if (isset($_SESSION['flowview_flows'][$sessionid]['data'])) {
        $data = $_SESSION['flowview_flows'][$sessionid]['data'];
    } else {
        $filter = createfilter($sessionid);
        $data = $_SESSION['flowview_flows'][$sessionid]['data'];
    }
    switch ($column) {
        case 'flows':
            $unit = ucfirst($column);
            $suffix = 'Total Flows';
            $_SESSION['sess_flows_flows'] = 'on';
            break;
        case 'bytes':
            $unit = ucfirst($column);
            $suffix = 'Bytes Exchanged';
            $_SESSION['sess_flows_bytes'] = 'on';
            break;
        case 'packets':
            $unit = ucfirst($column);
            $suffix = 'Packets Examined';
            $_SESSION['sess_flows_packets'] = 'on';
            break;
    }
    $columns = $_SESSION['flowview_flows'][$sessionid]['columns'];
    foreach ($columns as $key => $cdata) {
        if (strtolower($cdata) == $column) {
            $column = $key;
        }
    }
    if (sizeof($data)) {
        $elements = array();
        $legend = array();
        $maxvalue = 0;
        if (isset_request_var('exclude') && get_filter_request_var('exclude') > 0) {
            for ($i = 0; $i < get_request_var('exclude'); $i++) {
                array_shift($data);
            }
        }
        foreach ($data as $row) {
            if ($maxvalue < $row[$column]) {
                $maxvalue = $row[$column];
                $scaling = flowview_autoscale($row[$column]);
            }
        }
        $maxvalue = flowview_getmax($maxvalue);
        $autorange = flowview_autoscale($maxvalue);
        $maxvalue = $maxvalue / $autorange[0];
        $i = 0;
        foreach ($data as $row) {
            $elements[$i] = new bar_value(round($row[$column] / $autorange[0], 3));
            $elements[$i]->set_colour(flowview_get_color());
            $elements[$i]->set_tooltip($unit . ': #val# ' . $autorange[1]);
            if (sizeof($row) == 4) {
                $legend[] = $row[0];
            } else {
                $legend[] = $row[0] . " -\n" . $row[1];
            }
            $i++;
        }
        $bar = new bar_glass();
        $bar->set_values($elements);
        $title = new title($title . ' (' . $suffix . ')');
        $title->set_style('{font-size: 18px; color: #444444; text-align: center;}');
        $x_axis_labels = new x_axis_labels();
        $x_axis_labels->set_size(10);
        $x_axis_labels->rotate(45);
        $x_axis_labels->set_labels($legend);
        $x_axis = new x_axis();
        //$x_axis->set_3d( 3 );
        $x_axis->set_colours('#909090', '#909090');
        $x_axis->set_labels($x_axis_labels);
        $y_axis = new y_axis();
        $y_axis->set_offset(true);
        $y_axis->set_colours('#909090', '#909090');
        $y_axis->set_range(0, $maxvalue, $maxvalue / 10);
        $y_axis->set_label_text('#val# ' . $autorange[1]);
        $chart = new open_flash_chart();
        $chart->set_title($title);
        $chart->add_element($bar);
        $chart->set_x_axis($x_axis);
        $chart->add_y_axis($y_axis);
        $chart->set_bg_colour('#FEFEFE');
        echo $chart->toString();
    }
}
示例#29
0
function mactrack_site()
{
    global $site_actions, $config, $item_rows;
    mactrack_site_validate_req_vars();
    if (get_request_var('rows') == -1) {
        $row_limit = read_config_option('num_rows_table');
    } elseif (get_request_var('rows') == -2) {
        $row_limit = 999999;
    } else {
        $row_limit = get_request_var('rows');
    }
    html_start_box(__('MacTrack Site Filters'), '100%', '', '3', 'center', 'mactrack_sites.php?action=edit');
    mactrack_site_filter();
    html_end_box();
    $sql_where = '';
    $sites = mactrack_site_get_site_records($sql_where, $row_limit);
    if (get_request_var('detail') == 'false') {
        $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(mac_track_sites.site_id)\n\t\t\tFROM mac_track_sites\n\t\t\t{$sql_where}");
    } else {
        $total_rows = db_fetch_cell("SELECT count(*)\n\t\t\tFROM (mac_track_device_types\n\t\t\tRIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))\n\t\t\tRIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id");
    }
    if (get_request_var('detail') == 'false') {
        $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 9, __('Sites'));
        print $nav;
        html_start_box('', '100%', '', '3', 'center', '');
        $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'total_devices' => array(__('Devices'), 'DESC'), 'total_ips' => array(__('Total IP\'s'), 'DESC'), 'total_user_ports' => array(__('User Ports'), 'DESC'), 'total_oper_ports' => array(__('User Ports Up'), 'DESC'), 'total_macs' => array(__('MACS Found'), 'DESC'), 'total_device_errors' => array(__('Device Errors'), 'DESC'));
        html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        $i = 0;
        if (sizeof($sites)) {
            foreach ($sites as $site) {
                form_alternate_row('line' . $site['site_id'], true);
                form_selectable_cell("<a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=" . $site['site_id'] . "'>" . (get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name']) . '</a>', $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_devices']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_ips']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_user_ports']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_oper_ports']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_macs']), $site['site_id']);
                form_selectable_cell($site['total_device_errors'], $site['site_id']);
                form_checkbox_cell($site['site_name'], $site['site_id']);
                form_end_row();
            }
        } else {
            print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
        }
    } else {
        $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 10, __('Sites'));
        print $nav;
        html_start_box('', '100%', '', '3', 'center', '');
        $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'vendor' => array(__('Vendor'), 'ASC'), 'description' => array(__('Device Type'), 'DESC'), 'total_devices' => array(__('Total Devices'), 'DESC'), 'sum_ips_total' => array(__('Total IP\'s'), 'DESC'), 'sum_ports_total' => array(__('Total User Ports'), 'DESC'), 'sum_ports_active' => array(__('Total Oper Ports'), 'DESC'), 'sum_ports_trunk' => array(__('Total Trunks'), 'DESC'), 'sum_macs_active' => array(__('MACS Found'), 'DESC'));
        html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        if (sizeof($sites)) {
            foreach ($sites as $site) {
                form_alternate_row();
                ?>
					<td width=200>
						<a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=<?php 
                print $site['site_id'];
                ?>
'><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name'];
                ?>
</a>
					</td>
					<td><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['vendor']) : $site['vendor'];
                ?>
</td>
					<td><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['description']) : $site['description'];
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_devices']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ips_total']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_total']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_active']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_trunk']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_macs_active']);
                ?>
</td>
				</tr>
				<?php 
            }
        } else {
            print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
        }
    }
    /* draw the dropdown containing a list of available actions for this form */
    if (get_request_var('detail') == 'false') {
        draw_actions_dropdown($site_actions);
    }
}
示例#30
0
    $_POST['cutoff_octets'] = $cutoff_octets = $q['cutoffoctets'];
    $_POST['action'] = $action = $_REQUEST['action'];
    $_POST['stat_report'] = $stat_report = $q['statistics'];
    $_POST['flow_select'] = $flow_select = $q['includeif'];
    $_POST['print_report'] = $print_report = $q['printed'];
    $_POST['resolve_addresses'] = $resolve_addresses = $q['resolve'];
} else {
    $device = '';
    if (isset_request_var('device_name')) {
        $device = get_nfilter_request_var('device_name');
    } else {
        $device = db_fetch_cell("SELECT folder FROM plugin_flowview_devices ORDER BY id LIMIT 1");
        $_POST['device_name'] = $device;
    }
    $timespan = 0;
    if (isset_request_var('predefined_timespan') && get_filter_request_var('predefined_timespan') > 0) {
        $timespan = get_request_var('predefined_timespan');
        set_request_var('predefined_timespan', $timespan);
        $span = array();
        get_timespan($span, time(), $timespan, read_user_setting('first_weekdayid'));
        $_POST['date1'] = $date1 = $span['current_value_date1'];
        $_POST['date2'] = $date2 = $span['current_value_date2'];
    } else {
        set_request_var('predefined_timespan', '0');
        $timespan = 0;
        $date1 = date('Y-m-d H:i:s', time() - 8 * 3600);
        if (isset_request_var('date1')) {
            $date1 = get_nfilter_request_var('date1');
        }
        $date2 = date('Y-m-d H:i:s');
        if (isset_request_var('date2')) {