Exemplo n.º 1
0
function thold_config_insert()
{
    global $menu;
    $menu['Management']['plugins/thold/notify_lists.php'] = __('Notification Lists');
    $menu['Management']['plugins/thold/thold.php'] = __('Thresholds');
    $menu['Templates']['plugins/thold/thold_templates.php'] = __('Threshold');
    if (isset_request_var('thold_vrule')) {
        if (get_nfilter_request_var('thold_vrule') == 'on') {
            $_SESSION['sess_config_array']['thold_draw_vrules'] = 'on';
            $_SESSION['sess_config_array']['boost_png_cache_enable'] = false;
        } elseif (get_nfilter_request_var('thold_vrule') == '') {
            $_SESSION['sess_config_array']['thold_draw_vrules'] = '';
        }
    }
    define('ST_RESTORAL', 0);
    // Restoral
    define('ST_TRIGGERA', 1);
    // Trigger Alert
    define('ST_NOTIFYRA', 2);
    // Notify Alert Retrigger
    define('ST_NOTIFYWA', 3);
    // Notify Warning
    define('ST_NOTIFYAL', 4);
    // Notify Alert
    define('ST_NOTIFYRS', 5);
    // Notify Restoral
    define('ST_TRIGGERW', 6);
    // Trigger Warning
    define('ST_NOTIFYAW', 7);
    // Notify Restoral to Warning
    define('STAT_HI', 2);
    define('STAT_LO', 1);
    define('STAT_NORMAL', 0);
}
Exemplo n.º 2
0
function save_schedules()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('savedquery');
    get_filter_request_var('sendinterval');
    /* ==================================================== */
    $save['title'] = get_nfilter_request_var('title');
    $save['savedquery'] = get_nfilter_request_var('savedquery');
    $save['sendinterval'] = get_nfilter_request_var('sendinterval');
    $save['start'] = get_nfilter_request_var('start');
    $save['email'] = get_nfilter_request_var('email');
    $t = time();
    $d = strtotime(get_nfilter_request_var('start'));
    $i = $save['sendinterval'];
    if (isset_request_var('id')) {
        $save['id'] = get_request_var('id');
        $q = db_fetch_row('SELECT * FROM plugin_flowview_schedules WHERE id = ' . $save['id']);
        if (!isset($q['lastsent']) || $save['start'] != $q['start'] || $save['sendinterval'] != $q['sendinterval']) {
            while ($d < $t) {
                $d += $i;
            }
            $save['lastsent'] = $d - $i;
        }
    } else {
        $save['id'] = '';
        while ($d < $t) {
            $d += $i;
        }
        $save['lastsent'] = $d - $i;
    }
    if (isset_request_var('enabled')) {
        $save['enabled'] = 'on';
    } else {
        $save['enabled'] = 'off';
    }
    $id = sql_save($save, 'plugin_flowview_schedules', 'id', true);
    if (is_error_message()) {
        header('Location: flowview_schedules.php?tab=sched&header=false&action=edit&id=' . (empty($id) ? get_filter_request_var('id') : $id));
        exit;
    }
    header('Location: flowview_schedules.php?tab=sched&header=false');
    exit;
}
Exemplo n.º 3
0
function mactrack_site_remove()
{
    global $config;
    /* ================= input validation ================= */
    get_filter_request_var('site_id');
    /* ==================================================== */
    if (read_config_option('remove_verification') == 'on' && !isset_request_var('confirm')) {
        top_header();
        form_confirm(__('Are You Sure?'), __("Are you sure you want to delete the site <strong>'%s'</strong>?", db_fetch_cell('SELECT description FROM host WHERE id=' . get_request_var('device_id'))), 'mactrack_sites.php', 'mactrack_sites.php?action=remove&site_id=' . get_request_var('site_id'));
        bottom_footer();
        exit;
    }
    if (read_config_option('remove_verification') == '' || isset_request_var('confirm')) {
        api_mactrack_site_remove(get_request_var('site_id'));
    }
}
Exemplo n.º 4
0
function schedule_edit()
{
    global $plugins, $config, $tabs, $maint_types, $maint_intervals;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    maint_tabs();
    if (isset_request_var('id')) {
        $id = get_request_var('id');
        $maint_item_data = db_fetch_row('SELECT * FROM plugin_maint_schedules WHERE id = ' . $id);
    } else {
        $id = 0;
        $maint_item_data = array('id' => 0, 'name' => __('New Maintenance Schedule'), 'enabled' => 'on', 'mtype' => 1, 'stime' => time(), 'etime' => time() + 3600, 'minterval' => 0);
    }
    $header_label = get_header_label();
    if (get_request_var('tab') == 'general') {
        form_start('maint.php', 'maint');
        html_start_box(htmlspecialchars($header_label), '100%', '', '3', 'center', '');
        $form_array = array('general_header' => array('friendly_name' => __('Schedule'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Schedule Name'), 'method' => 'textbox', 'max_length' => 100, 'default' => $maint_item_data['name'], 'description' => __('Provide the Maintenance Schedule a meaningful name'), 'value' => isset($maint_item_data['name']) ? $maint_item_data['name'] : ''), 'enabled' => array('friendly_name' => __('Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this threshold will be checked and alerted upon.'), 'value' => isset($maint_item_data['enabled']) ? $maint_item_data['enabled'] : ''), 'mtype' => array('friendly_name' => __('Schedule Type'), 'method' => 'drop_array', 'on_change' => 'changemaintType()', 'array' => $maint_types, 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($maint_item_data['mtype']) ? $maint_item_data['mtype'] : ''), 'minterval' => array('friendly_name' => __('Interval'), 'method' => 'drop_array', 'array' => $maint_intervals, 'default' => 86400, 'description' => __('This is the interval in which the start / end time will repeat.'), 'value' => isset($maint_item_data['minterval']) ? $maint_item_data['minterval'] : '1'), 'stime' => array('friendly_name' => __('Start Time'), 'method' => 'textbox', 'max_length' => 100, 'description' => __('The start date / time for this schedule. Most date / time formats accepted.'), 'default' => date('F j, Y, G:i', time()), 'value' => isset($maint_item_data['stime']) ? date('F j, Y,  G:i', $maint_item_data['stime']) : ''), 'etime' => array('friendly_name' => __('End Time'), 'method' => 'textbox', 'max_length' => 100, 'default' => date('F j, Y, G:i', time() + 3600), 'description' => __('The end date / time for this schedule. Most date / time formats accepted.'), 'value' => isset($maint_item_data['etime']) ? date('F j, Y,  G:i', $maint_item_data['etime']) : ''), 'save_component' => array('method' => 'hidden', 'value' => '1'), 'save' => array('method' => 'hidden', 'value' => 'edit'), 'id' => array('method' => 'hidden', 'value' => $id));
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        html_end_box();
        form_save_button('maint.php', 'return');
        ?>
		<script type='text/javascript'>

		var date1Open = false;
		var date2Open = false;

		function changemaintType () {
			type = $('#mtype').val();
			switch(type) {
			case '1':
				$('#row_minterval').hide();
				break;
			case '2':
				$('#row_minterval').show();
				break;
			}
		}
	
		$(function() {
			$('#stime').after('<i id="startDate" class="calendar fa fa-calendar" title="<?php 
        print __('Start Date/Time Selector');
        ?>
"></i>');
			$('#etime').after('<i id="endDate" class="calendar fa fa-calendar" title="<?php 
        print __('End Date/Time Selector');
        ?>
"></i>');
			$('#startDate').click(function() {
				if (date1Open) {
					date1Open = false;
					$('#stime').datetimepicker('hide');
				}else{
					date1Open = true;
					$('#stime').datetimepicker('show');
				}
			});

			$('#endDate').click(function() {
				if (date2Open) {
					date2Open = false;
					$('#etime').datetimepicker('hide');
				}else{
					date2Open = true;
					$('#etime').datetimepicker('show');
				}
			});

			changemaintType ();

			$('#stime').datetimepicker({
				minuteGrid: 10,
				stepMinute: 1,
				showAnim: 'slideDown',
				numberOfMonths: 1,
				timeFormat: 'HH:mm',
				dateFormat: 'MM d, yy, ',
				showButtonPanel: false
			});

			$('#etime').datetimepicker({
				minuteGrid: 10,
				stepMinute: 1,
				showAnim: 'slideDown',
				numberOfMonths: 1,
				timeFormat: 'HH:mm',
				dateFormat: 'MM d, yy, ',
				showButtonPanel: false
			});
		});
		</script>
		<?php 
    } elseif (get_request_var('tab') == 'hosts') {
        thold_hosts($header_label);
    } elseif (get_request_var('tab') == 'webseer') {
        webseer_urls($header_label);
    } else {
        api_plugin_hook_function('maint_show_tab', $header_label);
    }
}
Exemplo n.º 5
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>";
                    }
                }
            }
        }
    }
}
Exemplo n.º 6
0
function save_devices()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('version');
    get_filter_request_var('rotation');
    get_filter_request_var('expire');
    get_filter_request_var('port');
    get_filter_request_var('compression');
    /* ==================================================== */
    if (isset_request_var('id')) {
        $save['id'] = get_request_var('id');
    } else {
        $save['id'] = '';
    }
    $save['name'] = get_nfilter_request_var('name');
    $save['folder'] = get_nfilter_request_var('folder');
    $save['allowfrom'] = get_nfilter_request_var('allowfrom');
    $save['port'] = get_nfilter_request_var('port');
    $save['nesting'] = get_nfilter_request_var('nesting');
    $save['version'] = get_nfilter_request_var('version');
    $save['rotation'] = get_nfilter_request_var('rotation');
    $save['expire'] = get_nfilter_request_var('expire');
    $save['compression'] = get_nfilter_request_var('compression');
    $id = sql_save($save, 'plugin_flowview_devices', 'id', true);
    if (is_error_message()) {
        header('Location: flowview_devices.php?tab=listeners&header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
        exit;
    }
    header('Location: flowview_devices.php?tab=listeners&header=false');
    exit;
}
Exemplo n.º 7
0
function mactrack_utilities_recreate_aggregated_data()
{
    global $config;
    if (read_config_option('remove_verification') == 'on' && !isset_request_var('confirm')) {
        top_header();
        form_confirm(__('Are You Sure?'), __('Are you sure you want to delete and recreate all the Aggregated Port to MAC to IP results from the system?'), 'mactrack_utilities.php', 'mactrack_utilities.php?action=mactrack_utilities_recreate_aggregated_data');
        bottom_footer();
        exit;
    }
    if (read_config_option('remove_verification') == '' || isset_request_var('confirm')) {
        $old_rows = db_fetch_cell('SELECT COUNT(*) FROM mac_track_aggregated_ports');
        db_execute('TRUNCATE TABLE mac_track_aggregated_ports');
        db_execute('INSERT INTO mac_track_aggregated_ports
			(site_id, device_id, hostname, device_name,
			vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname,
			port_number, port_name, date_last, first_scan_date, count_rec, authorized)
			SELECT site_id, device_id, hostname, device_name,
			vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname,
			port_number, port_name, max(scan_date), min(scan_date), count(*), authorized
			FROM mac_track_ports
			GROUP BY site_id,device_id, mac_address, port_number, ip_address, vlan_id, authorized');
        $new_rows = db_fetch_cell('SELECT COUNT(*) FROM mac_track_aggregated_ports');
        top_header();
        mactrack_utilities();
        html_start_box('Device Tracking Database Results', '100%', '', '3', 'center', '');
        ?>
		<td>
			The following number of records have been removed from the aggergated table: <?php 
        print $old_rows;
        ?>
. And <?php 
        print $new_rows;
        ?>
 number of record will be added.
		</td>
		<?php 
        html_end_box();
    }
}
Exemplo n.º 8
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'));
Exemplo n.º 9
0
function syslog_action_edit()
{
    global $colors, $message_types, $syslog_freqs, $syslog_times;
    include dirname(__FILE__) . '/config.php';
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('type');
    /* ==================================================== */
    if (isset_request_var('id')) {
        $report = syslog_db_fetch_row('SELECT *
			FROM `' . $syslogdb_default . '`.`syslog_reports`
			WHERE id=' . get_request_var('id'));
        if (sizeof($report)) {
            $header_label = __('Report Edit [edit: %s]', $report['name']);
        } else {
            $header_label = __('Report Edit [new]');
            $report['name'] = __('New Report Record');
        }
    } else {
        $header_label = __('Report Edit [new]');
        $report['name'] = __('New Report Record');
    }
    $fields_syslog_report_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Report Details')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Report Name'), 'description' => __('Please describe this Report.'), 'value' => '|arg1:name|', 'max_length' => '250'), 'enabled' => array('method' => 'drop_array', 'friendly_name' => __('Enabled?'), 'description' => __('Is this Report Enabled?'), 'value' => '|arg1:enabled|', 'array' => array('on' => __('Enabled'), '' => __('Disabled')), 'default' => 'on'), 'type' => array('method' => 'drop_array', 'friendly_name' => __('String Match Type'), 'description' => __('Define how you would like this string matched.'), 'value' => '|arg1:type|', 'array' => $message_types, 'default' => 'matchesc'), 'message' => array('method' => 'textbox', 'friendly_name' => __('Syslog Message Match String'), 'description' => __('The matching component of the syslog message.'), 'value' => '|arg1:message|', 'default' => '', 'max_length' => '255'), 'timespan' => array('method' => 'drop_array', 'friendly_name' => __('Report Frequency'), 'description' => __('How often should this Report be sent to the distribution list?'), 'value' => '|arg1:timespan|', 'array' => $syslog_freqs, 'default' => 'del'), 'timepart' => array('method' => 'drop_array', 'friendly_name' => __('Send Time'), 'description' => __('What time of day should this report be sent?'), 'value' => '|arg1:timepart|', 'array' => $syslog_times, 'default' => 'del'), 'message' => array('friendly_name' => __('Syslog Message Match String'), 'description' => __('The matching component of the syslog message.'), 'method' => 'textbox', 'max_length' => '255', 'value' => '|arg1:message|', 'default' => ''), 'body' => array('friendly_name' => __('Report Body Text'), 'textarea_rows' => '5', 'textarea_cols' => '60', 'description' => __('The information that will be contained in the body of the report.'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:body|', 'default' => ''), 'email' => array('friendly_name' => __('Report e-mail Addresses'), 'textarea_rows' => '3', 'textarea_cols' => '60', 'description' => __('Comma delimited list of e-mail addresses to send the report to.'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:email|', 'default' => ''), 'notes' => array('friendly_name' => __('Report Notes'), 'textarea_rows' => '3', 'textarea_cols' => '60', 'description' => __('Space for Notes on the Report'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:notes|', 'default' => ''), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_report' => array('method' => 'hidden', 'value' => '1'));
    form_start('syslog_reports.php');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_syslog_report_edit, isset($report) ? $report : array())));
    html_end_box();
    form_save_button('syslog_reports.php', '', 'id');
    form_end();
}
Exemplo n.º 10
0
function mikrotik_host_save($data)
{
    $id = $data['host_id'];
    if (isset_request_var('mikrotik_user')) {
        db_execute_prepared('REPLACE INTO plugin_mikrotik_credentials (host_id, user, password) VALUES (?,?,?)', array($id, get_nfilter_request_var('mikrotik_user'), get_nfilter_request_var('mikrotik_password')));
    }
    return $data;
}
Exemplo n.º 11
0
function template_save_edit()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('thold_type');
    get_filter_request_var('thold_hi');
    get_filter_request_var('thold_low');
    get_filter_request_var('thold_fail_trigger');
    get_filter_request_var('time_hi');
    get_filter_request_var('time_low');
    get_filter_request_var('time_fail_trigger');
    get_filter_request_var('time_fail_length');
    get_filter_request_var('thold_warning_type');
    get_filter_request_var('thold_warning_hi');
    get_filter_request_var('thold_warning_low');
    get_filter_request_var('thold_warning_fail_trigger');
    get_filter_request_var('time_warning_hi');
    get_filter_request_var('time_warning_low');
    get_filter_request_var('time_warning_fail_trigger');
    get_filter_request_var('time_warning_fail_length');
    get_filter_request_var('bl_ref_time_range');
    get_filter_request_var('bl_pct_down');
    get_filter_request_var('bl_pct_up');
    get_filter_request_var('bl_fail_trigger');
    get_filter_request_var('repeat_alert');
    get_filter_request_var('data_type');
    get_filter_request_var('cdef');
    get_filter_request_var('notify_warning');
    get_filter_request_var('notify_alert');
    get_filter_request_var('snmp_event_severity');
    get_filter_request_var('snmp_event_warning_severity');
    /* ==================================================== */
    /* clean up date1 string */
    if (isset_request_var('name')) {
        set_request_var('name', trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('name'))));
    }
    if (isset_request_var('snmp_trap_category')) {
        set_request_var('snmp_event_category', db_qstr(trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('snmp_event_category')))));
    }
    /* save: data_template */
    $save['id'] = get_nfilter_request_var('id');
    $save['hash'] = get_hash_thold_template($save['id']);
    $save['name'] = get_nfilter_request_var('name');
    $save['thold_type'] = get_nfilter_request_var('thold_type');
    // High / Low
    $save['thold_hi'] = get_nfilter_request_var('thold_hi');
    $save['thold_low'] = get_nfilter_request_var('thold_low');
    $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    // Time Based
    $save['time_hi'] = get_nfilter_request_var('time_hi');
    $save['time_low'] = get_nfilter_request_var('time_low');
    $save['time_fail_trigger'] = get_nfilter_request_var('time_fail_trigger');
    $save['time_fail_length'] = get_nfilter_request_var('time_fail_length');
    if (isset_request_var('thold_fail_trigger') && get_nfilter_request_var('thold_fail_trigger') != '') {
        $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_fail_trigger'] = 5;
        }
    }
    /***  Warnings  ***/
    // High / Low Warnings
    $save['thold_warning_hi'] = get_nfilter_request_var('thold_warning_hi');
    $save['thold_warning_low'] = get_nfilter_request_var('thold_warning_low');
    $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    // Time Based Warnings
    $save['time_warning_hi'] = get_nfilter_request_var('time_warning_hi');
    $save['time_warning_low'] = get_nfilter_request_var('time_warning_low');
    $save['time_warning_fail_trigger'] = get_nfilter_request_var('time_warning_fail_trigger');
    $save['time_warning_fail_length'] = get_nfilter_request_var('time_warning_fail_length');
    if (isset_request_var('thold_warning_fail_trigger') && get_nfilter_request_var('thold_warning_fail_trigger') != '') {
        $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_warning_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_warning_fail_trigger'] = 5;
        }
    }
    $save['thold_enabled'] = isset_request_var('thold_enabled') ? 'on' : 'off';
    $save['exempt'] = isset_request_var('exempt') ? 'on' : '';
    $save['restored_alert'] = isset_request_var('restored_alert') ? 'on' : '';
    if (isset_request_var('bl_ref_time_range') && get_nfilter_request_var('bl_ref_time_range') != '') {
        $save['bl_ref_time_range'] = get_nfilter_request_var('bl_ref_time_range');
    } else {
        $alert_bl_timerange_def = read_config_option('alert_bl_timerange_def');
        if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) {
            $save['bl_ref_time_range'] = $alert_bl_timerange_def;
        } else {
            $save['bl_ref_time_range'] = 10800;
        }
    }
    $save['bl_pct_down'] = get_nfilter_request_var('bl_pct_down');
    $save['bl_pct_up'] = get_nfilter_request_var('bl_pct_up');
    if (isset_request_var('bl_fail_trigger') && get_nfilter_request_var('bl_fail_trigger') != '') {
        $save['bl_fail_trigger'] = get_nfilter_request_var('bl_fail_trigger');
    } else {
        $alert_bl_trigger = read_config_option('alert_bl_trigger');
        if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) {
            $save['bl_fail_trigger'] = $alert_bl_trigger;
        } else {
            $save['bl_fail_trigger'] = 3;
        }
    }
    if (isset_request_var('repeat_alert') && get_nfilter_request_var('repeat_alert') != '') {
        $save['repeat_alert'] = get_nfilter_request_var('repeat_alert');
    } else {
        $alert_repeat = read_config_option('alert_repeat');
        if ($alert_repeat != '' && is_numeric($alert_repeat)) {
            $save['repeat_alert'] = $alert_repeat;
        } else {
            $save['repeat_alert'] = 12;
        }
    }
    if (isset_request_var('snmp_event_category')) {
        $save['snmp_event_category'] = get_nfilter_request_var('snmp_event_category');
        $save['snmp_event_severity'] = get_nfilter_request_var('snmp_event_severity');
    }
    if (isset_request_var('snmp_event_warning_severity')) {
        if (get_nfilter_request_var('snmp_event_warning_severity') > get_nfilter_request_var('snmp_event_severity')) {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_severity');
        } else {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_warning_severity');
        }
    }
    $save['notify_extra'] = get_nfilter_request_var('notify_extra');
    $save['notify_warning_extra'] = get_nfilter_request_var('notify_warning_extra');
    $save['notify_warning'] = get_nfilter_request_var('notify_warning');
    $save['notify_alert'] = get_nfilter_request_var('notify_alert');
    $save['cdef'] = get_nfilter_request_var('cdef');
    $save['data_type'] = get_nfilter_request_var('data_type');
    $save['percent_ds'] = get_nfilter_request_var('percent_ds');
    $save['expression'] = get_nfilter_request_var('expression');
    if (!is_error_message()) {
        $id = sql_save($save, 'thold_template');
        if ($id) {
            raise_message(1);
            if (isset_request_var('notify_accounts') && is_array(get_nfilter_request_var('notify_accounts'))) {
                thold_save_template_contacts($id, get_nfilter_request_var('notify_accounts'));
            } elseif (!isset_request_var('notify_accounts')) {
                thold_save_template_contacts($id, array());
            }
            thold_template_update_thresholds($id);
            plugin_thold_log_changes($id, 'modified_template', $save);
        } else {
            raise_message(2);
        }
    }
    if (is_error_message() || isempty_request_var('id')) {
        header('Location: thold_templates.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
    } else {
        header('Location: thold_templates.php?header=false');
    }
}
Exemplo n.º 12
0
function syslog_action_edit()
{
    global $message_types, $severities;
    include dirname(__FILE__) . '/config.php';
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('type');
    get_filter_request_var('date');
    /* ==================================================== */
    if (!isempty_request_var('id') && get_nfilter_request_var('action') == 'edit') {
        $alert = syslog_db_fetch_row('SELECT *
			FROM `' . $syslogdb_default . '`.`syslog_alert`
			WHERE id=' . get_request_var('id'));
        if (sizeof($alert)) {
            $header_label = __('Alert Edit [edit: %s]' . $alert['name']);
        } else {
            $header_label = __('Alert Edit [new]');
        }
    } else {
        if (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') {
            $syslog_rec = syslog_db_fetch_row("SELECT * FROM `" . $syslogdb_default . "`.`syslog` WHERE seq=" . get_request_var("id") . (isset_request_var('date') ? " AND logtime='" . get_request_var("date") . "'" : ""));
            $header_label = __('Alert Ednt [new]');
            if (sizeof($syslog_rec)) {
                $alert['message'] = $syslog_rec['message'];
            }
            $alert['name'] = __('New Alert Rule');
        } else {
            $header_label = __('Alert Edit [new]');
            $alert['name'] = __('New Alert Rule');
        }
    }
    $alert_retention = read_config_option('syslog_alert_retention');
    if ($alert_retention != '' && $alert_retention > 0 && $alert_retention < 365) {
        $repeat_end = $alert_retention * 24 * 60 / 5;
    }
    $repeatarray = array(0 => __('Not Set'), 1 => __('%d Minutes', 5), 2 => __('%d Minutes', 10), 3 => __('%d Minutes', 15), 4 => __('%d Minutes', 20), 6 => __('%d Minutes', 30), 8 => __('%d Minutes', 45), 12 => __('%d Hour', 1), 24 => __('%d Hours', 2), 36 => __('%d Hours', 3), 48 => __('%d Hours', 4), 72 => __('%d Hours', 6), 96 => __('%d Hours', 8), 144 => __('%d Hours', 12), 288 => __('%d Day', 1), 576 => __('%d Days', 2), 2016 => __('%d Week', 1), 4032 => __('%d Weeks', 2), 8640 => __('Month'));
    if ($repeat_end) {
        foreach ($repeatarray as $i => $value) {
            if ($i > $repeat_end) {
                unset($repeatarray[$i]);
            }
        }
    }
    $fields_syslog_alert_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Alert Details')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Alert Name'), 'description' => __('Please describe this Alert.'), 'value' => '|arg1:name|', 'max_length' => '250', 'size' => 80), 'severity' => array('method' => 'drop_array', 'friendly_name' => __('Severity'), 'description' => __('What is the Severity Level of this Alert?'), 'value' => '|arg1:severity|', 'array' => $severities, 'default' => '1'), 'report_method' => array('method' => 'drop_array', 'friendly_name' => __('Reporting Method'), 'description' => __('Define how to Alert on the syslog messages.'), 'value' => '|arg1:method|', 'array' => array('0' => __('Individual'), '1' => __('Threshold')), 'default' => '0'), 'num' => array('method' => 'textbox', 'friendly_name' => __('Threshold'), 'description' => __('For the \'Threshold\' method, If the number seen is above this value an Alert will be triggered.'), 'value' => '|arg1:num|', 'size' => '4', 'max_length' => '10', 'default' => '1'), 'type' => array('method' => 'drop_array', 'friendly_name' => __('String Match Type'), 'description' => __('Define how you would like this string matched.  If using the SQL Expression type you may use any valid SQL expression
			to generate the alarm.  Available fields include \'message\', \'facility\', \'priority\', and \'host\'.'), 'value' => '|arg1:type|', 'array' => $message_types, 'on_change' => 'changeTypes()', 'default' => 'matchesc'), 'message' => array('friendly_name' => __('Syslog Message Match String'), 'description' => __('Enter the matching component of the syslog message, the facility or host name, or the SQL where clause if using the SQL Expression Match Type.'), 'textarea_rows' => '2', 'textarea_cols' => '70', 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:message|', 'default' => ''), 'enabled' => array('method' => 'drop_array', 'friendly_name' => __('Alert Enabled'), 'description' => __('Is this Alert Enabled?'), 'value' => '|arg1:enabled|', 'array' => array('on' => __('Enabled'), '' => __('Disabled')), 'default' => 'on'), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => '0', 'description' => __('Do not resend this alert again for the same host, until this amount of time has elapsed. For threshold based alarms, this applies to all hosts.'), 'value' => '|arg1:repeat_alert|'), 'notes' => array('friendly_name' => __('Alert Notes'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Space for Notes on the Alert'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:notes|', 'default' => ''), 'spacer1' => array('method' => 'spacer', 'friendly_name' => __('Alert Actions')), 'open_ticket' => array('method' => 'drop_array', 'friendly_name' => __('Open Ticket'), 'description' => __('Should a Help Desk Ticket be opened for this Alert'), 'value' => '|arg1:open_ticket|', 'array' => array('on' => __('Yes'), '' => __('No')), 'default' => ''), 'email' => array('method' => 'textarea', 'friendly_name' => __('E-Mails to Notify'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Please enter a comma delimited list of e-mail addresses to inform.  If you
			wish to send out e-mail to a recipient in SMS format, please prefix that recipient\'s e-mail address
			with <b>\'sms@\'</b>.  For example, if the recipients SMS address is <b>\'2485551212@mycarrier.net\'</b>, you would
			enter it as <b>\'sms@2485551212@mycarrier.net\'</b> and it will be formatted as an SMS message.'), 'class' => 'textAreaNotes', 'value' => '|arg1:email|', 'max_length' => '255'), 'command' => array('friendly_name' => __('Alert Command'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('When an Alert is triggered, run the following command.  The following replacement variables
			are available <b>\'&lt;HOSTNAME&gt;\'</b>, <b>\'&lt;ALERTID&gt;\'</b>, <b>\'&lt;MESSAGE&gt;\'</b>,
			<b>\'&lt;FACILITY&gt;\'</b>, <b>\'&lt;PRIORITY&gt;\'</b>, <b>\'&lt;SEVERITY&gt;\'</b>.  Please
			note that <b>\'&lt;HOSTNAME&gt;\'</b> is only available on individual thresholds.'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:command|', 'default' => ''), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_alert' => array('method' => 'hidden', 'value' => '1'));
    form_start('syslog_alerts.php', 'syslog_edit');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_syslog_alert_edit, sizeof($alert) ? $alert : array())));
    html_end_box();
    form_save_button('syslog_alerts.php', '', 'id');
    ?>
	<script type='text/javascript'>

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

	<?php 
}
Exemplo n.º 13
0
function mikrotik_view_graphs()
{
    global $current_user, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    /* include graph view filter selector */
    html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")');
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset_request_var('style')) {
        if (get_request_var('style') == 'selective') {
            /* process selected graphs */
            if (!isempty_request_var('graph_list')) {
                foreach (explode(',', get_request_var('graph_list')) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!isempty_request_var('graph_add')) {
                foreach (explode(',', get_request_var('graph_add')) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!isempty_request_var('graph_remove')) {
                foreach (explode(',', get_request_var('graph_remove')) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id');
                $set_rra_id = empty($rra_id) ? read_user_setting('default_rra_id') : get_request_var('rra_id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if (get_request_var('host_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id');
    } else {
        $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes);
        if (sizeof($host_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    // Graph Template Id sql_where
    if (get_request_var('graph_template_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN(' . get_request_var('graph_template_id') . ')';
    } else {
        $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes);
        if (sizeof($graph_template_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs');
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), __('Graphs'), 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    }
    html_end_box();
    if ($total_graphs > 0) {
        print $nav;
    }
    bottom_footer();
}
Exemplo n.º 14
0
function mactrack_macw_remove()
{
    global $config;
    /* ================= input validation ================= */
    get_filter_request_var('mac_id');
    /* ==================================================== */
    if (read_config_option('remove_verification') == 'on' && !isset_request_var('confirm')) {
        top_header();
        form_confirm(__('Are You Sure?'), __('Are you sure you want to delete the watched Mac Address %s?', db_fetch_cell_prepared('SELECT name FROM mac_track_macwatch WHERE mac_id=?', array(get_request_var('mac_id')))), 'mactrack_macwatch.php', 'mactrack_macwatch.php?action=remove&mac_id=' . get_request_var('mac_id'));
        bottom_footer();
        exit;
    }
    if (read_config_option('remove_verification') == '' || isset_request_var('confirm')) {
        api_mactrack_macw_remove(get_request_var('mac_id'));
    }
}
Exemplo n.º 15
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;
    }
}
function mactrack_filter_table()
{
    global $config, $rows_selector;
    ?>
	<tr class='even'>
		<td>
		<form id='mactrack'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Site');
    ?>
					</td>
					<td>
						<select id='site_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('site_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $sites = db_fetch_assoc('SELECT site_id, site_name FROM mac_track_sites ORDER BY site_name');
    if (sizeof($sites) > 0) {
        foreach ($sites as $site) {
            print '<option value="' . $site['site_id'] . '"';
            if (get_request_var('site_id') == $site['site_id']) {
                print ' selected';
            }
            print '>' . $site['site_name'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Filters');
    ?>
					</td>
					<td>
						<select id='issues' onChange='applyFilter()'>
							<option value='-2'<?php 
    if (get_request_var('issues') == '-2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Interfaces');
    ?>
</option>
							<option value='-3'<?php 
    if (get_request_var('issues') == '-3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Non-Ignored Interfaces');
    ?>
</option>
							<option value='-4'<?php 
    if (get_request_var('issues') == '-4') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Ignored Interfaces');
    ?>
</option>
							<?php 
    if (get_request_var('bwusage') != '-1') {
        ?>
<option value='9'<?php 
        if (get_request_var('issues') == '9' && get_request_var('bwusage') != '-1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('High In/Out Utilization > %d &#37;', get_request_var('bwusage'));
        ?>
</option><?php 
    }
    ?>
							<?php 
    if (get_request_var('bwusage') != '-1') {
        ?>
<option value='10'<?php 
        if (get_request_var('issues') == '10' && get_request_var('bwusage') != '-1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('High In Utilization > %d &#37;', get_request_var('bwusage'));
        ?>
</option><?php 
    }
    ?>
							<?php 
    if (get_request_var('bwusage') != '-1') {
        ?>
<option value='11'<?php 
        if (get_request_var('issues') == '11' && get_request_var('bwusage') != '-1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('High Out Utilization > %d &#37;', get_request_var('bwusage'));
        ?>
</option><?php 
    }
    ?>
							<option value='-1'<?php 
    if (get_request_var('issues') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('With Issues');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('issues') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Up Interfaces');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('issues') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Up Interfaces No Alias');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('issues') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Errors Accumulating');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('issues') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Discards Accumulating');
    ?>
</option>
							<option value='7'<?php 
    if (get_request_var('issues') == '7') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Changed in Last Day');
    ?>
</option>
						</select><BR>
					<td>
						<?php 
    print __('Bandwidth');
    ?>
					</td>
					<td>
						<select id='bwusage' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('bwusage') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('N/A');
    ?>
</option>
							<?php 
    for ($bwpercent = 10; $bwpercent < 100; $bwpercent += 10) {
        ?>
<option value='<?php 
        print $bwpercent;
        ?>
' <?php 
        if (isset_request_var('bwusage') and get_request_var('bwusage') == $bwpercent) {
            ?>
 selected<?php 
        }
        ?>
> >=<?php 
        print $bwpercent;
        ?>
%</option><?php 
    }
    ?>
						</select>
					</td>
					<td>
						<input type='submit' id='go' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input type='button' id='clear' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
					<td>
						<input type='button' id='export' value='<?php 
    print __('Export');
    ?>
'>
					</td>
				</tr>
			</table>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Type');
    ?>
					</td>
					<td>
						<select id='device_type_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('device_type_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    if (get_request_var('site_id') != -1) {
        $sql_where .= ' WHERE (mac_track_devices.site_id=' . get_request_var('site_id');
    } else {
        $sql_where = '';
    }
    $types = db_fetch_assoc("SELECT DISTINCT mac_track_device_types.device_type_id, \n\t\t\t\t\t\t\t\tmac_track_device_types.description AS device_type\n\t\t\t\t\t\t\t\tFROM mac_track_device_types\n\t\t\t\t\t\t\t\tINNER JOIN mac_track_devices\n\t\t\t\t\t\t\t\tON mac_track_device_types.device_type_id=mac_track_devices.device_type_id\n\t\t\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\t\t\tORDER BY device_type");
    if (sizeof($types)) {
        foreach ($types as $type) {
            print '<option value="' . $type['device_type_id'] . '"';
            if (get_request_var('device_type_id') == $type['device_type_id']) {
                print ' selected';
            }
            print '>' . $type['device_type'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Device');
    ?>
					</td>
					<td>
						<select id='device_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('device_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $sql_where = '';
    if (get_request_var('site_id') != -1) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(site_id=' . get_request_var('site_id');
    }
    if (get_request_var('device_type_id') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . '(device_type_id=' . get_request_var('device_type_id');
    }
    $devices = array_rekey(db_fetch_assoc("SELECT device_id, device_name FROM mac_track_devices {$sql_where} ORDER BY device_name"), "device_id", "device_name");
    if (sizeof($devices)) {
        foreach ($devices as $device_id => $device_name) {
            print '<option value="' . $device_id . '"';
            if (get_request_var('device_id') == $device_id) {
                print " selected";
            }
            print ">" . $device_name . "</option>";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Interfaces');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<?php 
    if (sizeof($rows_selector)) {
        foreach ($rows_selector as $key => $value) {
            print '<option value="' . $key . '"';
            if (get_request_var('rows') == $key) {
                print 'selected';
            }
            print '>' . $value . '</option>';
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<input type='checkbox' id='totals' onChange='applyFilter()' <?php 
    print get_request_var('totals') == 'true' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='totals'><?php 
    print __('Show Totals');
    ?>
</label>
					</td>
				</tr>
			</table>
			</form>
			<script type='text/javascript'>

			function applyFilter() {
				strURL  = urlPath+'plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&header=false';
				strURL += '&filter=' + $('#filter').val();
				strURL += '&rows=' + $('#rows').val();
				strURL += '&site_id=' + $('#site_id').val();
				strURL += '&device_id=' + $('#device_id').val();
				strURL += '&issues=' + $('#issues').val();
				strURL += '&bwusage=' + $('#bwusage').val();
				strURL += '&device_type_id=' + $('#device_type_id').val();
				strURL += '&totals=' + $('#totals').is(':checked');
				loadPageNoHeader(strURL);
			}

			function clearFilter() {
				strURL  = urlPath+'plugins/mactrack/mactrack_view_interfaces.php?header=false&clear=true';
				loadPageNoHeader(strURL);
			}

			function exportRows() {
				strURL  = urlPath+'plugins/mactrack/mactrack_view_interfaces.php?export=true';
				document.location = strURL;
			}

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

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

				$('#export').click(function() {
					exportRows();
				});
			});

			</script>
		</td>
	</tr><?php 
}
Exemplo n.º 17
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();
}
Exemplo n.º 18
0
function get_syslog_messages(&$sql_where, $row_limit, $tab)
{
    global $sql_where, $hostfilter, $current_tab, $syslog_incoming_config;
    include dirname(__FILE__) . '/config.php';
    $sql_where = '';
    /* form the 'where' clause for our main sql query */
    if (get_request_var('host') == -1 && $tab != 'syslog') {
        $sql_where .= "WHERE sl.host='N/A'";
    } else {
        if (!isempty_request_var('host')) {
            sql_hosts_where($tab);
            if (strlen($hostfilter)) {
                $sql_where .= 'WHERE ' . $hostfilter;
            }
        }
    }
    if (isset($_SESSION['sess_current_date1'])) {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "logtime BETWEEN '" . $_SESSION['sess_current_date1'] . "'\n\t\t\t\tAND '" . $_SESSION['sess_current_date2'] . "'";
    }
    if (isset_request_var('id') && $current_tab == 'current') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'sa.id=' . get_request_var('id');
    }
    if (!isempty_request_var('filter')) {
        if ($tab == 'syslog') {
            $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "message LIKE '%" . get_request_var('filter') . "%'";
        } else {
            $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "logmsg LIKE '%" . get_request_var('filter') . "%'";
        }
    }
    if (get_request_var('eprogram') != '-1') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "syslog.program_id='" . get_request_var('eprogram') . "'";
    }
    if (get_request_var('efacility') != '-1') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "syslog.facility_id='" . get_request_var('efacility') . "'";
    }
    if (isset_request_var('epriority') && get_request_var('epriority') != '-1') {
        $priorities = '';
        switch (get_request_var('epriority')) {
            case '0':
                $priorities = "=0";
                break;
            case '1o':
                $priorities = "=1";
                break;
            case '1':
                $priorities = "<1";
                break;
            case '2o':
                $priorities = "=2";
                break;
            case '2':
                $priorities = "<=2";
                break;
            case '3o':
                $priorities = "=3";
                break;
            case '3':
                $priorities = "<=3";
                break;
            case '4o':
                $priorities = "=4";
                break;
            case '4':
                $priorities = "<=4";
                break;
            case '5o':
                $priorities = "=5";
                break;
            case '5':
                $priorities = "<=5";
                break;
            case '6o':
                $priorities = "=6";
                break;
            case '6':
                $priorities = "<=6";
                break;
            case '7':
                $priorities = "=7";
                break;
        }
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'syslog.priority_id ' . $priorities;
    }
    $sql_where = api_plugin_hook_function('syslog_sqlwhere', $sql_where);
    if (!isset_request_var('export')) {
        $limit = ' LIMIT ' . $row_limit * (get_request_var('page') - 1) . ',' . $row_limit;
    } else {
        $limit = ' LIMIT 10000';
    }
    $sort = get_request_var('sort_column');
    if ($tab == 'syslog') {
        if (get_request_var('removal') == '-1') {
            $query_sql = "SELECT syslog.*, syslog_programs.program, 'main' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog` \n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        } elseif (get_request_var('removal') == '1') {
            $query_sql = "(SELECT syslog.*, syslog_programs.program, 'main' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\t) UNION (SELECT syslog.*, syslog_programs.program, 'remove' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_removed` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` \n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . ")\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        } else {
            $query_sql = "SELECT syslog.*, syslog_programs.program, 'remove' AS mtype\n\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_removed` AS syslog\n\t\t\t\tLEFT JOIN  `" . $syslogdb_default . "`.`syslog_programs` AS syslog\n\t\t\t\tON syslog.program_id=syslog_programs.program_id " . $sql_where . "\n\t\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
        }
    } else {
        $query_sql = "SELECT syslog.*, sf.facility, sp.priority, spr.program, sa.name, sa.severity\n\t\t\tFROM `" . $syslogdb_default . "`.`syslog_logs` AS syslog\n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_facilities` AS sf\n\t\t\tON syslog.facility_id=sf.facility_id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_priorities` AS sp\n\t\t\tON syslog.priority_id=sp.priority_id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_alert` AS sa\n\t\t\tON syslog.alert_id=sa.id \n\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_programs` AS spr\n\t\t\tON syslog.program_id=spr.program_id " . $sql_where . "\n\t\t\tORDER BY " . $sort . " " . get_request_var('sort_direction') . $limit;
    }
    //echo $query_sql;
    return syslog_db_fetch_assoc($query_sql);
}
Exemplo n.º 19
0
function tholds($header_label)
{
    global $item_rows, $config;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $thold_actions = array(1 => __('Associate'), 2 => __('Disassociate'));
    thold_request_validation();
    $statefilter = '';
    if (isset_request_var('state')) {
        if (get_request_var('state') == '-1') {
            $statefilter = '';
        } else {
            if (get_request_var('state') == '0') {
                $statefilter = "td.thold_enabled='off'";
            }
            if (get_request_var('state') == '2') {
                $statefilter = "td.thold_enabled='on'";
            }
            if (get_request_var('state') == '1') {
                $statefilter = '(td.thold_alert!=0 OR td.bl_alert>0)';
            }
            if (get_request_var('state') == '3') {
                $statefilter = '(td.thold_alert!=0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert>0 AND td.bl_fail_count >= td.bl_fail_trigger)';
            }
        }
    }
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    $sql_where = '';
    $sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    $limit = $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (!isempty_request_var('template') && get_request_var('template') != '-1') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template');
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . "td.name LIKE '%" . get_request_var('filter') . "%'";
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . $statefilter;
    }
    if (get_request_var('associated') == 'true') {
        $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . '(td.notify_warning=' . get_request_var('id') . ' OR td.notify_alert=' . get_request_var('id') . ')';
    }
    cacti_log($sql_where);
    $result = get_allowed_thresholds($sql_where, $sort, $limit, $total_rows);
    $data_templates = db_fetch_assoc('SELECT DISTINCT dt.id, dt.name
		FROM data_template AS dt
		INNER JOIN thold_data AS td
		ON td.data_template_id = dt.id
		ORDER BY dt.name');
    html_start_box(__('Associated Thresholds') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' method='get' action='notify_lists.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='template' onChange='applyFilter()'>
							<option value='-1'><?php 
    print __('Any');
    ?>
</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset_request_var('template') && $row['id'] == get_request_var('template') ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('State');
    ?>
					</td>
					<td>
						<select id='state' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('state') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('state') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Breached');
    ?>
</option>
							<option value='3'<?php 
    if (get_request_var('state') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Triggered');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('state') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Enabled');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('state') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Disabled');
    ?>
</option>
						</select>
					</td>
					<td>
						<?php 
    print __('Thresholds');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' name='clearf' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
			<input type='hidden' id='tab' value='tholds'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		<script type='text/javascript'>

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

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

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('notify_lists.php?action=edit&tab=tholds', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Thresholds'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array(__('Name'), 'ASC'), 'id' => array(__('ID'), 'ASC'), 'nosort1' => array(__('Warning Lists'), 'ASC'), 'nosort2' => array(__('Alert Lists'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'thold_alert' => array(__('Triggered'), 'ASC'), 'thold_enabled' => array(__('Enabled'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=tholds&id=' . get_filter_request_var('id'));
    $c = 0;
    $i = 0;
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] != 1) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                }
            }
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell('SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=' . $row['id']);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>" . __('Select Users') . "</span>";
            }
            if (strlen($row['notify_extra'])) {
                $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_alert'])) {
                if (get_request_var('id') == $row['notify_alert']) {
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $alert_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_alert']);
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $alert_list . '</span>';
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row['notify_warning_extra'])) {
                $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_warning'])) {
                if (get_request_var('id') == $row['notify_warning']) {
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $warn_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_warning']);
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $warn_list . '</span>';
                }
            }
            if (!strlen($warn_stat) && ($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '' || $row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>" . __('None') . "</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            if ($row['name'] != '') {
                $name = $row['name'];
            } else {
                $name = $row['name_cache'] . ' [' . $row['data_source_name'] . ']';
            }
            form_alternate_row('line' . $row['id'], true);
            form_selectable_cell(filter_value($name, get_request_var('filter')), $row['id']);
            form_selectable_cell($row['id'], $row['id']);
            form_selectable_cell($warn_stat, $row['id']);
            form_selectable_cell($alert_stat, $row['id']);
            form_selectable_cell($thold_types[$row['thold_type']], $row['id']);
            form_selectable_cell($alertstat, $row['id']);
            form_selectable_cell($row['thold_enabled'] == 'off' ? __('Disabled') : __('Enabled'), $row['id']);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        print "<tr class='even' <td colspan='8'><i>" . __('No Thresholds') . "</i></td></tr>\n";
    }
    html_end_box(false);
    if (count($result)) {
        print $nav;
    }
    form_hidden_box('tab', 'tholds', '');
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_tholds', '1', '');
    draw_actions_dropdown($thold_actions);
    form_end();
}
Exemplo n.º 20
0
function hmib_view_graphs()
{
    global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    if (!isset($_SESSION['sess_hmib_gt'])) {
        $_SESSION['sess_hmib_gt'] = implode(',', array_rekey(db_fetch_assoc('SELECT DISTINCT gl.graph_template_id 
			FROM graph_local AS gl 
			WHERE gl.host_id IN(
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			)'), 'graph_template_id', 'graph_template_id'));
    }
    $gt = $_SESSION['sess_hmib_gt'];
    if (!isset($_SESSION['sess_hmib_hosts'])) {
        $_SESSION['sess_hmib_hosts'] = implode(',', array_rekey(db_fetch_assoc('SELECT h.id 
			FROM host AS h 
			WHERE h.id IN (
				SELECT host_id 
				FROM plugin_hmib_hrSystem
			) 
			UNION 
			SELECT h.id 
			FROM host AS h
			INNER JOIN host_template AS ht
			ON h.host_template_id=ht.id
			WHERE hash="7c13344910097cc599f0d0485305361d" ORDER BY id DESC'), 'id', 'id'));
    }
    $hosts = $_SESSION['sess_hmib_hosts'];
    /* include graph view filter selector */
    html_start_box(__('Graph Preview Filters') . (isset_request_var('style') && strlen(get_request_var('style')) ? ' [ ' . __('Custom Graph List Applied - Filtering from List') . ' ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('hmib.php', 'graphs', "h.id IN ({$hosts})", "gt.id IN ({$gt})");
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset_request_var('style')) {
        if (get_request_var('style') == 'selective') {
            /* process selected graphs */
            if (!isempty_request_var('graph_list')) {
                foreach (explode(',', get_request_var('graph_list')) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!isempty_request_var('graph_add')) {
                foreach (explode(',', get_request_var('graph_add')) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!isempty_request_var('graph_remove')) {
                foreach (explode(',', get_request_var('graph_remove')) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $graph_array = array_keys($graph_list);
            if (sizeof($graph_array)) {
                $sql_or = array_to_sql_or($graph_array, 'gl.id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen(get_request_var('filter')) ? "gtg.title_cache LIKE '%" . get_request_var('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if (get_request_var('host_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . get_request_var('host_id');
    }
    // Graph Template Id sql_where
    if (get_request_var('graph_template_id') > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . get_request_var('graph_template_id');
    }
    $limit = get_request_var('graphs') * (get_request_var('page') - 1) . ',' . get_request_var('graphs');
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var('page'), get_request_var('graphs'), $total_graphs, get_request_var('columns'), 'Graphs', 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var('columns'));
    }
    html_end_box();
    if ($total_graphs > 0) {
        print $nav;
    }
    bottom_footer();
}
Exemplo n.º 21
0
function syslog_action_edit()
{
    global $message_types;
    include dirname(__FILE__) . '/config.php';
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('type');
    get_filter_request_var('date');
    /* ==================================================== */
    if (isset_request_var('id') && get_nfilter_request_var('action') == 'edit') {
        $removal = syslog_db_fetch_row('SELECT *
			FROM `' . $syslogdb_default . '`.`syslog_remove`
			WHERE id=' . get_request_var('id'));
        if (sizeof($removal)) {
            $header_label = __('Removal Rule Edit [edit: %s]', $removal['name']);
        } else {
            $header_label = __('Removal Rule Edit [new]');
            $removal['name'] = __('New Removal Record');
        }
    } else {
        if (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') {
            $syslog_rec = syslog_db_fetch_row('SELECT * FROM `' . $syslogdb_default . '`.`syslog` WHERE seq=' . get_request_var('id') . (isset_request_var('date') ? " AND logtime='" . get_request_var('date') . "'" : ""));
            $header_label = __('Removal Rule Edit [new]');
            if (sizeof($syslog_rec)) {
                $removal['message'] = $syslog_rec['message'];
            }
            $removal['name'] = __('New Removal Rule');
        } else {
            $header_label = '[new]';
            $removal['name'] = __('New Removal Record');
        }
    }
    $fields_syslog_removal_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Removel Rule Details')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Removal Rule Name'), 'description' => __('Please describe this Removal Rule.'), 'value' => '|arg1:name|', 'max_length' => '250', 'size' => 80), 'enabled' => array('method' => 'drop_array', 'friendly_name' => __('Enabled?'), 'description' => __('Is this Removal Rule Enabled?'), 'value' => '|arg1:enabled|', 'array' => array('on' => __('Enabled'), '' => __('Disabled')), 'default' => 'on'), 'type' => array('method' => 'drop_array', 'friendly_name' => __('String Match Type'), 'description' => __('Define how you would like this string matched.  If using the SQL Expression type you may use any valid SQL expression
			to generate the alarm.  Available fields include \'message\', \'facility\', \'priority\', and \'host\'.'), 'value' => '|arg1:type|', 'array' => $message_types, 'on_change' => 'changeTypes()', 'default' => 'matchesc'), 'message' => array('friendly_name' => __('Syslog Message Match String'), 'description' => __('Enter the matching component of the syslog message, the facility or host name, or the SQL where clause if using the SQL Expression Match Type.'), 'method' => 'textarea', 'textarea_rows' => '2', 'textarea_cols' => '70', 'class' => 'textAreaNotes', 'value' => '|arg1:message|', 'default' => ''), 'rmethod' => array('method' => 'drop_array', 'friendly_name' => __('Method of Removal'), 'value' => '|arg1:method|', 'array' => array('del' => __('Deletion'), 'trans' => __('Transferal')), 'default' => 'del'), 'notes' => array('friendly_name' => __('Removal Rule Notes'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Space for Notes on the Removal rule'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:notes|', 'default' => ''), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_removal' => array('method' => 'hidden', 'value' => '1'));
    form_start('syslog_removal.php', 'syslog_edit');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_syslog_removal_edit, isset($removal) ? $removal : array())));
    html_end_box();
    form_save_button('syslog_removal.php', '', 'id');
    ?>
	<script type='text/javascript'>
	function changeTypes() {
		if ($('#type').val == 'sql') {
			$('#message').prop('rows', 5);
		}else{
			$('#message').prop('rows', 2);
		}
	}
	</script>
	<?php 
}
Exemplo n.º 22
0
function mactrack_device_remove()
{
    global $config;
    /* ================= input validation ================= */
    get_filter_request_var('device_id');
    get_filter_request_var('type_id');
    /* ==================================================== */
    if (read_config_option('remove_verification') == 'on' && !isset_request_var('confirm')) {
        top_header();
        form_confirm(__('Are You Sure?'), __('Are you sure you want to delete the host %s', db_fetch_cell_prepared('SELECT device_name FROM host WHERE id = ?', array(get_request_var('device_id')))), 'mactrack_devices.php', 'mactrack_devices.php?action=remove&id=' . get_request_var('device_id'));
        bottom_footer();
        exit;
    }
    if (read_config_option('remove_verification') == '' || isset_request_var('confirm')) {
        api_mactrack_device_remove(get_request_var('device_id'));
    }
}
Exemplo n.º 23
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');
}
Exemplo n.º 24
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();
    }
}
Exemplo n.º 25
0
function thold_add_graphs_action_prepare()
{
    global $config;
    $local_graph_id = get_filter_request_var('local_graph_id');
    top_header();
    html_start_box(__('Create Threshold from Template'), '60%', '', '3', 'center', '');
    form_start('thold.php?action=add');
    /* get the valid thold templates
     * remove those hosts that do not have any valid templates
     */
    $templates = '';
    $found_list = '';
    $not_found = '';
    $data_template_id = db_fetch_cell("SELECT dtr.data_template_id\n\t\t FROM data_template_rrd AS dtr\n\t\t LEFT JOIN graph_templates_item AS gti\n\t\t ON gti.task_item_id=dtr.id\n\t\t LEFT JOIN graph_local AS gl\n\t\t ON gl.id=gti.local_graph_id\n\t\t WHERE gl.id={$local_graph_id}");
    if ($data_template_id != '') {
        if (sizeof(db_fetch_assoc("SELECT id FROM thold_template WHERE data_template_id={$data_template_id}"))) {
            $found_list .= '<li>' . get_graph_title($local_graph_id) . '</li>';
            if (strlen($templates)) {
                $templates .= ", {$data_template_id}";
            } else {
                $templates = "{$data_template_id}";
            }
        } else {
            $not_found .= '<li>' . get_graph_title($local_graph_id) . '</li>';
        }
    } else {
        $not_found .= '<li>' . get_graph_title($local_graph_id) . '</li>';
    }
    if (strlen($templates)) {
        $sql = 'SELECT id, name FROM thold_template WHERE data_template_id IN (' . $templates . ') ORDER BY name';
    } else {
        $sql = 'SELECT id, name FROM thold_template ORDER BY name';
    }
    print "<tr><td colspan='2' class='textArea'>\n";
    if (strlen($found_list)) {
        if (strlen($not_found)) {
            print '<p>' . __('The following Graph has no Threshold Templates associated with them.') . '</p>';
            print '<ul>' . $not_found . '</ul>';
        }
        print '<p>' . __('Are you sure you wish to create Thresholds for this Graph?') . '
			<ul>' . $found_list . "</ul>\n\t\t\t</td>\n\t\t</tr>\n";
        if (isset_request_var('tree_id')) {
            get_filter_request_var('tree_id');
        } else {
            set_request_var('tree_id', '');
        }
        if (isset_request_var('leaf_id')) {
            get_filter_request_var('leaf_id');
        } else {
            set_request_var('leaf_id', '');
        }
        $form_array = array('general_header' => array('friendly_name' => __('Available Threshold Templates'), 'method' => 'spacer'), 'thold_template_id' => array('method' => 'drop_sql', 'friendly_name' => __('Select a Threshold Template'), 'description' => '', 'none_value' => __('None'), 'value' => __('None'), 'sql' => $sql), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'local_graph_id' => array('method' => 'hidden', 'value' => $local_graph_id));
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
    } else {
        if (strlen($not_found)) {
            print '<p>' . __('There are no Threshold Templates associated with the following Graph.') . '</p>';
            print '<ul>' . $not_found . '</ul>';
        }
        $form_array = array('general_header' => array('friendly_name' => __('Please select an action'), 'method' => 'spacer'), 'doaction' => array('method' => 'drop_array', 'friendly_name' => __('Threshold Action'), 'description' => __('You may either create a new Threshold Template, or an non-templated Threshold from this screen.'), 'value' => 'None', 'array' => array(1 => __('Create a new Threshold'), 2 => __('Create a Threshold Template'))), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'local_graph_id' => array('method' => 'hidden', 'value' => $local_graph_id));
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
    }
    if (!strlen($not_found)) {
        $save_html = "<input type='submit' value='" . __('Continue') . "'>";
        print "<tr>\n\t\t\t<td colspan='2' class='saveRow'>\n\t\t\t\t<input type='hidden' id='action' value='actions'>\n\t\t\t\t<input type='button' onClick='cactiReturnTo()' value='" . __('Cancel') . "' title='" . __('Cancel') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
    } else {
        $save_html = "<input type='submit' value='" . __('Continue') . "'>";
        print "<tr>\n\t\t\t<td colspan='2' class='saveRow'>\n\t\t\t\t<input type='button' onClick='cactiReturnTo()' value='" . __('Cancel') . "' title='" . __('Cancel') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
    }
    html_end_box();
    print "<script type='text/javascript'>\$(function() { applySkin() ;});</script>";
    bottom_footer();
}
Exemplo n.º 26
0
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();
}
Exemplo n.º 27
0
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
$guest_account = true;
chdir('../../');
include './include/auth.php';
include_once './include/global_arrays.php';
include_once './plugins/mactrack/lib/mactrack_functions.php';
$title = __('Device Tracking - Site Report View');
if (isset_request_var('export')) {
    mactrack_view_export_sites();
} else {
    mactrack_redirect();
    general_header();
    mactrack_view_sites();
    bottom_footer();
}
function mactrack_view_export_sites()
{
    mactrack_sites_request_validation();
    $sql_where = '';
    $sites = mactrack_view_get_site_records($sql_where, 0, FALSE);
    $xport_array = array();
    if (get_request_var('detail') == 'false') {
        array_push($xport_array, '"site_id","site_name","total_devices",' . '"total_device_errors","total_macs","total_ips","total_oper_ports",' . '"total_user_ports"');
Exemplo n.º 28
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 
}
Exemplo n.º 29
0
/**
 * perform mactrack_device execute action
 * @arg $action				action to be performed
 * return				-
 *  */
function mactrack_device_action_execute($action)
{
    global $config;
    # it's our turn
    if ($action == 'plugin_mactrack_device') {
        /* mactrack */
        /* find out which (if any) hosts have been checked, so we can tell the user */
        if (isset_request_var('selected_items')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                /* work on all selected hosts */
                for ($i = 0; $i < count($selected_items); $i++) {
                    # fetch row from host table
                    $device = db_fetch_row_prepared('SELECT * from host WHERE id = ?', array($selected_items[$i]));
                    # now fetch the related device from mac_track_devices, if any
                    $mt_device = db_fetch_row_prepared('SELECT * from mac_track_devices WHERE host_id = ?', array($device['id']));
                    if (is_array($device)) {
                        # update mac_track_device
                        $device_id = api_mactrack_device_save(isset($mt_device['device_id']) ? $mt_device['device_id'] : '0', $device['id'], get_request_var('site_id'), $device['hostname'], $device['description'], get_request_var('scan_type'), get_request_var('snmp_options'), $device['snmp_community'], $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_engine_id'], $device['snmp_port'], $device['snmp_timeout'], get_request_var('snmp_retries'), $device['max_oids'], get_request_var('ignorePorts'), $device['notes'], get_request_var('user_name'), get_request_var('user_password'), get_request_var('term_type'), get_request_var('private_key_path'), isset_request_var('disabled') ? get_request_var('disabled') : '');
                    }
                }
            }
        }
    }
    return $action;
}
Exemplo n.º 30
0
function thold_user_admin_setup_sql_save($save)
{
    global $database_default, $database_type, $database_port, $database_password, $database_username, $database_hostname, $config;
    if (is_error_message()) {
        return $save;
    }
    if (isset_request_var('email')) {
        $email = form_input_validate(get_nfilter_request_var('email'), 'email', '', true, 3);
        if ($save['id'] == 0) {
            $save['id'] = sql_save($save, 'user_auth');
        }
        $cid = db_fetch_cell("SELECT id FROM plugin_thold_contacts WHERE type = 'email' AND user_id = " . $save['id'], false);
        if ($cid) {
            db_execute("REPLACE INTO plugin_thold_contacts (id, user_id, type, data) VALUES ({$cid}, " . $save['id'] . ", 'email', '{$email}')");
        } else {
            db_execute("REPLACE INTO plugin_thold_contacts (user_id, type, data) VALUES (" . $save['id'] . ", 'email', '{$email}')");
        }
    }
    return $save;
}