Example #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);
}
function form_actions()
{
    global $config, $macw_actions, $fields_mactrack_macw_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 = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_request_var('drp_action') == '1') {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_mactrack_macw_remove($selected_items[$i]);
                }
            }
            header('Location: mactrack_macwatch.php');
            exit;
        }
    }
    /* setup some variables */
    $macw_list = '';
    $i = 0;
    /* loop through each of the mac watch items 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]);
            /* ==================================================== */
            $macw_info = db_fetch_cell_prepared('SELECT name FROM mac_track_macwatch WHERE mac_id = ?', array($matches[1]));
            $macw_list .= '<li>' . $macw_info . '</li>';
            $macw_array[$i] = $matches[1];
        }
        $i++;
    }
    top_header();
    html_start_box($macw_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    form_start('mactrack_macwatch.php');
    if (!isset($macw_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one watched Mac to delete.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='submit' name='save' value='" . __('Yes') . "'>";
        if (get_request_var('drp_action') == '1') {
            /* delete */
            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 watched Mac\'s?') . "</p>\n\t\t\t\t\t<p><ul>{$macw_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($macw_array) ? serialize($macw_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='button' name='cancel' onClick='cactiReturnTo()' value='" . __('No') . "'>\n\t\t\t{$save_html}" : "<input type='button' onClick='cactiReturnTo()' name='cancel' value='" . __('Return') . "'>") . "\n\t\t</td>\n\t</tr>";
    html_end_box();
    form_end();
    bottom_footer();
}
function form_mactrack_actions()
{
    global $config, $device_actions, $fields_mactrack_device_edit, $fields_mactrack_snmp_item;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    include_once $config['base_path'] . '/lib/functions.php';
    /* 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') == '2') {
                /* Enable Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute_prepared("UPDATE mac_track_devices SET disabled='' WHERE device_id = ?", array($selected_items[$i]));
                }
            } elseif (get_request_var('drp_action') == '3') {
                /* Disable Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute_prepared("UPDATE mac_track_devices SET disabled='on' WHERE device_id = ?", array($selected_items[$i]));
                }
            } elseif (get_request_var('drp_action') == '4') {
                /* change snmp options */
                for ($i = 0; $i < count($selected_items); $i++) {
                    reset($fields_mactrack_device_edit);
                    while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                        if (isset_request_var("t_{$field_name}")) {
                            db_execute_prepared("UPDATE mac_track_devices \n\t\t\t\t\t\t\t\tSET {$field_name} = ?\n\t\t\t\t\t\t\t\tWHERE device_id = ?", array(get_request_var($field_name), $selected_items[$i]));
                        }
                    }
                }
            } elseif (get_request_var('drp_action') == '5') {
                /* change port settings for multiple devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    reset($fields_mactrack_device_edit);
                    while (list($field_name, $field_array) = each($fields_host_edit)) {
                        if (isset_request_var("t_{$field_name}")) {
                            db_execute_prepared("UPDATE mac_track_devices \n\t\t\t\t\t\t\t\tSET {$field_name} = ? WHERE id = ?", array(get_request_var($field_name), $selected_items[$i]));
                        }
                    }
                }
            } elseif (get_request_var('drp_action') == '6') {
                /* Connect Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    $cacti_host = db_fetch_row_prepared('SELECT host.id, host.description FROM mac_track_devices 
						LEFT JOIN host ON (mac_track_devices.hostname=host.hostname) 
						WHERE mac_track_devices.device_id=?', array($selected_items[$i]));
                    if (sizeof($cacti_host)) {
                        db_execute_prepared('UPDATE mac_track_devices SET host_id = ?, device_name = ? WHERE device_id = ?', array($cacti_host['id'], $cacti_host['description'], $selected_items[$i]));
                    }
                }
            } elseif (get_request_var('drp_action') == '7') {
                /* Copy SNMP Settings */
                for ($i = 0; $i < count($selected_items); $i++) {
                    $cacti_host = db_fetch_row_prepared("SELECT host.*, \n\t\t\t\t\t\thost.snmp_community as snmp_readstring, \n\t\t\t\t\t\thost.ping_retries as snmp_retries\n\t\t\t\t\t\tFROM mac_track_devices \n\t\t\t\t\t\tLEFT JOIN host ON (mac_track_devices.hostname=host.hostname) \n\t\t\t\t\t\tWHERE mac_track_devices.device_id = ?", array($selected_items[$i]));
                    if (isset($cacti_host['id'])) {
                        reset($fields_mactrack_snmp_item);
                        $updates = '';
                        while (list($field_name, $field_array) = each($fields_mactrack_snmp_item)) {
                            if (isset($cacti_host[$field_name])) {
                                $updates .= ($updates != '' ? ', ' : '') . $field_name . "='" . $cacti_host[$field_name] . "'";
                            }
                        }
                        if (strlen($updates)) {
                            db_execute('UPDATE mac_track_devices SET ' . $updates . ' WHERE device_id=' . $selected_items[$i]);
                        }
                    } else {
                        # skip silently; possible enhacement: tell the user what we did
                    }
                }
            } elseif (get_request_var('drp_action') == '1') {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_mactrack_device_remove($selected_items[$i]);
                }
            }
            header('Location: mactrack_devices.php');
            exit;
        }
    }
    /* setup some variables */
    $device_list = '';
    $i = 0;
    /* loop through each of the host templates 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]);
            /* ==================================================== */
            $device_info = db_fetch_row_prepared('SELECT hostname, device_name FROM mac_track_devices WHERE device_id = ?', array($matches[1]));
            $device_list .= '<li>' . $device_info['device_name'] . ' (' . $device_info['hostname'] . ')</li>';
            $device_array[] = $matches[1];
        }
    }
    top_header();
    form_start('mactrack_devices.php');
    html_start_box($device_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (!sizeof($device_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one device.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>";
        if (get_request_var('drp_action') == '2') {
            /* Enable Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To enable the following devices, press the "yes" button below.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '3') {
            /* Disable Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To disable the following devices, press the "yes" button below.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '4') {
            /* change snmp options */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                if (preg_match('/^snmp_/', $field_name)) {
                    $form_array += array($field_name => $fields_mactrack_device_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['device_name'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field<br/>', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        } elseif (get_request_var('drp_action') == '5') {
            /* change port settngs for multiple devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To change upper or lower port parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                if (preg_match('/^port_/', $field_name)) {
                    $form_array += array($field_name => $fields_mactrack_device_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['device_name'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        } elseif (get_request_var('drp_action') == '6') {
            /* Connect Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To connect the following devices to their respective Cacti Device, press the "yes" button below.  The relation will be built on equal hostnames. Description will be updated as well.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '7') {
            /* Copy SNMP Settings */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To copy SNMP Settings from connected Cacti Device to MacTrack Device, press the "yes" button below.  All not connected Devices will silently be skipped. SNMP retries will be taken from Ping retries.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '1') {
            /* delete */
            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 devices?') . "</p>\n\t\t\t\t\t<p><ul>{$device_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($device_array) ? serialize($device_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='button' name='cancel' onClick='cactiReturnTo()' value='" . __('No') . "'>\n\t\t\t{$save_html}" : "<input type='button' onClick='cactiReturnTo()' name='cancel' value='" . __('Return') . "'>") . "\n\t\t</td>\n\t</tr>";
    html_end_box();
    form_end();
    bottom_footer();
}
Example #4
0
        $sort_field = get_nfilter_request_var('sort_field');
    }
    $cutoff_lines = 100;
    if (isset_request_var('cutoff_lines')) {
        $cutoff_lines = get_nfilter_request_var('cutoff_lines');
    }
    $cutoff_octets = '';
    if (isset_request_var('cutoff_octets')) {
        $cutoff_octets = get_nfilter_request_var('cutoff_octets');
    }
    $action = '';
    if (isset_request_var('action')) {
        $action = get_nfilter_request_var('action');
    }
    $stat_report = '0';
    if (isset_request_var('stat_report')) {
        $stat_report = get_nfilter_request_var('stat_report');
    }
    $flow_select = '1';
    if (isset_request_var('flow_select')) {
        $flow_select = get_nfilter_request_var('flow_select');
    }
    $print_report = '0';
    if (isset_request_var('print_report')) {
        $print_report = get_nfilter_request_var('print_report');
    }
    $resolve_addresses = 'Y';
    if (isset_request_var('resolve_addresses')) {
        $resolve_addresses = get_nfilter_request_var('resolve_addresses');
    }
}
Example #5
0
function form_actions()
{
    global $actions, $assoc_actions;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
    /* ================= input validation ================= */
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        if (isset_request_var('save_list')) {
            if (get_request_var('drp_action') == '2') {
                /* delete */
                schedule_delete();
            } elseif (get_request_var('drp_action') == '1') {
                /* update */
                schedule_update();
            }
            header('Location: maint.php?header=false');
            exit;
        } elseif (isset_request_var('save_hosts')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        db_execute('REPLACE INTO plugin_maint_hosts (type, host, schedule) VALUES (1, ' . $selected_items[$i] . ', ' . get_request_var('id') . ')');
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        db_execute('DELETE FROM plugin_maint_hosts WHERE type=1 AND host=' . $selected_items[$i] . ' AND schedule=' . get_request_var('id'));
                    }
                }
            }
            header('Location: maint.php?action=edit&tab=hosts&header=false&id=' . get_request_var('id'));
            exit;
        } elseif (isset_request_var('save_webseer')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        db_execute('REPLACE INTO plugin_maint_hosts (type, host, schedule) VALUES (2, ' . $selected_items[$i] . ', ' . get_request_var('id') . ')');
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        db_execute('DELETE FROM plugin_maint_hosts WHERE type=2 AND host=' . $selected_items[$i] . ' AND schedule=' . get_request_var('id'));
                    }
                }
            }
            header('Location: maint.php?action=edit&tab=webseer&header=false&id=' . get_request_var('id'));
            exit;
        } else {
            api_plugin_hook_function('maint_actions_execute');
        }
    }
    /* setup some variables */
    $list = '';
    $array = array();
    $list_name = '';
    if (isset_request_var('id')) {
        $list_name = db_fetch_cell('SELECT name FROM plugin_maint_schedules WHERE id=' . get_request_var('id'));
    }
    if (isset_request_var('save_list')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM plugin_maint_schedules WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('maint.php');
        html_start_box($actions[get_request_var('drp_action')] . " {$list_name}", '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* update */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Update the following Maintenance Schedule(s).') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Update Maintenance Schedule(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* delete */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete the following Maintenance Schedule(s).  Any Devices(s) Associated with this Schedule will be Disassociated.') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Maintenance Schedule(s)') . "'>";
            }
        } else {
            print "<tr><td><span class='textError'>" . __('You must select at least one Maintenance Schedule.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr class='saveRow'>\n\t\t\t<td>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='save_list' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_hosts')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT description FROM host WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('maint.php');
        html_start_box($assoc_actions[get_request_var('drp_action')] . ' ' . __('Device(s)'), '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to associate the following Device(s) with the Maintenance Schedule \'<b>%s</b>\'.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Maintenance Schedule(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to disassociate the following Device(s) with the Maintenance Schedule \'<b>%s</b>\'.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Maintenance Schedule(s)') . "'>";
            }
        } else {
            print "<tr><td><span class='textError'>" . __('You must select at least one Device.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr class='saveRow'>\n\t\t\t<td>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_hosts' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_webseer')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT description FROM host WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        html_start_box($assoc_actions[get_request_var('drp_action')] . ' ' . __('Device(s)'), '60%', '', '3', 'center', '');
        form_start('maint.php');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to associate the Device(s) below with the Maintenance Schedule \'<b>%s</b>\'.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Maintenance Schedule(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to disassociate the Devices(s) below with the Maintenance Schedule \'<b>%s</b>\'.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Maintenance Schedule(s)') . "'>";
            }
        } else {
            print "<tr><td><span class='textError'>" . __('You must select at least one Device.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr class='saveRow'>\n\t\t\t<td>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_webseer' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        form_end();
        html_end_box();
        bottom_footer();
    } else {
        api_plugin_hook_function('maint_actions_prepare');
    }
}
Example #6
0
function form_mactrack_snmp_actions()
{
    global $config, $mactrack_snmp_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_nfilter_request_var('drp_action') == '1') {
                /* delete */
                db_execute('DELETE FROM mac_track_snmp WHERE ' . array_to_sql_or($selected_items, 'id'));
                db_execute('DELETE FROM mac_track_snmp_items WHERE ' . str_replace('id', 'snmp_id', array_to_sql_or($selected_items, 'id')));
            } elseif (get_nfilter_request_var('drp_action') == '2') {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_mactrack($selected_items[$i], get_nfilter_request_var('name_format'));
                }
            }
            header('Location: mactrack_snmp.php?header=false');
            exit;
        }
    }
    /* setup some variables */
    $snmp_groups = '';
    $i = 0;
    /* loop through each of the graphs 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]);
            /* ==================================================== */
            $snmp_groups .= '<li>' . db_fetch_cell_prepared('SELECT name FROM mac_track_snmp WHERE id = ?', array($matches[1])) . '</li>';
            $mactrack_array[$i] = $matches[1];
            $i++;
        }
    }
    general_header();
    display_output_messages();
    ?>
	<script type='text/javascript'>
	function goTo(strURL) {
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    form_start('mactrack_snmp.php', 'mactrack');
    html_start_box($mactrack_snmp_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (!isset($mactrack_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one SNMP Option.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>";
        if (get_nfilter_request_var("drp_action") == '1') {
            /* delete */
            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 SNMP Options?') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_nfilter_request_var("drp_action") == '2') {
            /* duplicate */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('When you click save, the following SNMP Options will be duplicated. You can optionally change the title format for the new SNMP Options.') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t\t<p>" . __('Name Format:') . "<br>";
            form_text_box('name_format', '<name> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        }
    }
    print "\t<tr>\n\t\t<td 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($mactrack_array) ? serialize($mactrack_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_nfilter_request_var("drp_action") . "'>\n\t\t\t<input type='button' onClick='goTo(\"" . "mactrack_snmp.php" . "\")' value='" . ($save_html == '' ? 'Return' : 'No') . "' name='cancel'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>";
    html_end_box();
    bottom_footer();
}
Example #7
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 
}
Example #8
0
function do_thold()
{
    global $host_id;
    $tholds = array();
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_(.*)\$/", $var, $matches)) {
            $del = $matches[1];
            $rra = db_fetch_cell("SELECT local_data_id FROM thold_data WHERE id={$del}");
            input_validate_input_number($del);
            $tholds[$del] = $rra;
        }
    }
    switch (get_nfilter_request_var('drp_action')) {
        case 1:
            // Delete
            foreach ($tholds as $del => $rra) {
                if (thold_user_auth_threshold($rra)) {
                    plugin_thold_log_changes($del, 'deleted', array('id' => $del));
                    db_execute("DELETE FROM thold_data WHERE id={$del}");
                    db_execute('DELETE FROM plugin_thold_threshold_contact WHERE thold_id=' . $del);
                    db_execute('DELETE FROM plugin_thold_log WHERE threshold_id=' . $del);
                }
            }
            break;
        case 2:
            // Disabled
            foreach ($tholds as $del => $rra) {
                if (thold_user_auth_threshold($rra)) {
                    plugin_thold_log_changes($del, 'disabled_threshold', array('id' => $del));
                    db_execute("UPDATE thold_data SET thold_enabled='off' WHERE id={$del}");
                }
            }
            break;
        case 3:
            // Enabled
            foreach ($tholds as $del => $rra) {
                if (thold_user_auth_threshold($rra)) {
                    plugin_thold_log_changes($del, 'enabled_threshold', array('id' => $del));
                    db_execute("UPDATE thold_data SET thold_enabled='on' WHERE id={$del}");
                }
            }
            break;
        case 4:
            // Reapply Suggested Name
            foreach ($tholds as $del => $rra) {
                if (thold_user_auth_threshold($rra)) {
                    $thold = db_fetch_row("SELECT * FROM thold_data WHERE id={$del}");
                    /* check if thold templated */
                    if ($thold['template_enabled'] == "on") {
                        $template = db_fetch_row_prepared("SELECT * FROM thold_template WHERE id = ?", array($thold["template"]));
                        $name = thold_format_name($template, $thold["local_graph_id"], $thold["data_template_rrd_id"], $template['data_source_name']);
                        plugin_thold_log_changes($del, 'reapply_name', array('id' => $del));
                        db_execute("UPDATE thold_data SET name='{$name}' WHERE id={$del}");
                    }
                }
            }
            break;
        case 5:
            // Propagate Template
            foreach ($tholds as $thold_id => $rra) {
                if (thold_user_auth_threshold($rra)) {
                    $template = db_fetch_row("SELECT td.template id, td.template_enabled enabled\n\t\t\t\t\t\tFROM thold_data td\n\t\t\t\t\t\tINNER JOIN thold_template tt ON tt.id = td.template\n\t\t\t\t\t\tWHERE td.id = {$thold_id}");
                    if (isset($template['id']) && $template['id'] != 0 && $template['enabled'] != 'on') {
                        thold_template_update_threshold($thold_id, $template['id']);
                        plugin_thold_log_changes($thold_id, 'modified', array('id' => $thold_id, 'template_enabled' => 'on'));
                    }
                }
            }
            break;
    }
    if (isset($host_id) && $host_id != '') {
        header('Location:thold.php?header=false&host_id=' . $host_id);
    } else {
        header('Location:thold.php?header=false');
    }
    exit;
}
Example #9
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;
}
Example #10
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 
}
function form_actions()
{
    global $config, $device_types_actions, $fields_mactrack_device_types_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 = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_request_var('drp_action') == '1') {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_mactrack_device_type_remove($selected_items[$i]);
                }
            } elseif (get_nfilter_request_var('drp_action') == '2') {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_mactrack_duplicate_device_type($selected_items[$i], $i, get_request_var('title_format'));
                }
            }
            header('Location: mactrack_device_types.php');
            exit;
        }
    }
    /* setup some variables */
    $device_types_list = '';
    $i = 0;
    /* loop through each of the device types 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]);
            /* ==================================================== */
            $device_types_info = db_fetch_row_prepared('SELECT description FROM mac_track_device_types WHERE device_type_id = ?', array($matches[1]));
            $device_types_list .= '<li>' . $device_types_info['description'] . '</li>';
            $device_types_array[] = $matches[1];
        }
    }
    top_header();
    form_start('mactrack_device_types.php');
    html_start_box($device_types_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (!isset($device_types_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one device type.') . "</span></td></tr>\n";
        $save_html = '';
    } else {
        $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>";
        if (get_request_var('drp_action') == '1') {
            /* delete */
            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 device types?') . "</p>\n\t\t\t\t\t<p><ul>{$device_types_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '2') {
            /* duplicate */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('When you click save, the following device types will be duplicated. You may optionally change the description for the new device types.  Otherwise, do not change value below and the original name will be replicated with a new suffix.') . "</p>\n\t\t\t\t\t<p><ul>{$device_types_list}</ul></p>\n\t\t\t\t\t<p>" . __('Device Type Prefix:') . '<br>';
            form_text_box('title_format', '<description> (1)', '', '255', '30', 'text');
            print "</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($device_types_array) ? serialize($device_types_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_nfilter_request_var('drp_action') . "'>" . (strlen($save_html) ? "\n\t\t\t<input type='button' onClick='cactiReturnTo()' name='cancel' value='" . __('No') . "'>\n\t\t\t{$save_html}" : "<input type='submit' onClick='cactiReturnTo()' name='cancel' value='" . __('Return') . "'>") . "\n\t\t</td>\n\t</tr>";
    html_end_box();
    form_end();
    bottom_footer();
}
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;
}
Example #13
0
function thold_graphs_action_execute($action)
{
    global $config, $form_array;
    include_once $config['base_path'] . '/plugins/thold/thold_functions.php';
    if ($action == 'plugin_thold_create') {
        $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            $message = '';
            get_filter_request_var('thold_template_id');
            $template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array(get_request_var('thold_template_id')));
            for ($i = 0; $i < count($selected_items); $i++) {
                $graph = $selected_items[$i];
                $temp = db_fetch_row("SELECT dtr.*\n\t\t\t\t\t FROM data_template_rrd AS dtr\n\t\t\t\t\t LEFT JOIN graph_templates_item AS gti\n\t\t\t\t\t ON gti.task_item_id=dtr.id\n\t\t\t\t\t LEFT JOIN graph_local AS gl\n\t\t\t\t\t ON gl.id=gti.local_graph_id\n\t\t\t\t\t WHERE gl.id={$graph}");
                $data_template_id = $temp['data_template_id'];
                $local_data_id = $temp['local_data_id'];
                $data_source = db_fetch_row('SELECT * FROM data_local WHERE id=' . $local_data_id);
                $data_template_id = $data_source['data_template_id'];
                $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE local_data_id=' . $local_data_id . ' AND data_template_rrd_id=' . $data_template_id);
                if (count($existing) == 0 && count($template)) {
                    if ($graph) {
                        $rrdlookup = db_fetch_cell("SELECT id \n\t\t\t\t\t\t\tFROM data_template_rrd\n\t\t\t\t\t\t\tWHERE local_data_id={$local_data_id}\n\t\t\t\t\t\t\tORDER BY id\n\t\t\t\t\t\t\tLIMIT 1");
                        $grapharr = db_fetch_row("SELECT graph_template_id\n\t\t\t\t\t\t\tFROM graph_templates_item\n\t\t\t\t\t\t\tWHERE task_item_id={$rrdlookup}\n\t\t\t\t\t\t\tAND local_graph_id={$graph}");
                        $data_source_name = $template['data_source_name'];
                        $insert = array();
                        $name = thold_format_name($template, $graph, $local_data_id, $data_source_name);
                        $insert['name'] = $name;
                        $insert['host_id'] = $data_source['host_id'];
                        $insert['local_data_id'] = $local_data_id;
                        $insert['local_graph_id'] = $graph;
                        $insert['data_template_id'] = $data_template_id;
                        $insert['graph_template_id'] = $grapharr['graph_template_id'];
                        $insert['thold_hi'] = $template['thold_hi'];
                        $insert['thold_low'] = $template['thold_low'];
                        $insert['thold_fail_trigger'] = $template['thold_fail_trigger'];
                        $insert['thold_enabled'] = $template['thold_enabled'];
                        $insert['bl_ref_time_range'] = $template['bl_ref_time_range'];
                        $insert['bl_pct_down'] = $template['bl_pct_down'];
                        $insert['bl_pct_up'] = $template['bl_pct_up'];
                        $insert['bl_fail_trigger'] = $template['bl_fail_trigger'];
                        $insert['bl_alert'] = $template['bl_alert'];
                        $insert['repeat_alert'] = $template['repeat_alert'];
                        $insert['notify_extra'] = $template['notify_extra'];
                        $insert['cdef'] = $template['cdef'];
                        $insert['thold_template_id'] = $template['id'];
                        $insert['template_enabled'] = 'on';
                        $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id FROM data_template_rrd where local_data_id='{$local_data_id}' and data_source_name='{$data_source_name}'");
                        $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef');
                        foreach ($rrdlist as $rrdrow) {
                            $data_rrd_id = $rrdrow['id'];
                            $insert['data_id'] = $data_rrd_id;
                            $existing = db_fetch_assoc("SELECT id FROM thold_data WHERE local_data_id='{$local_data_id}' AND data_template_rrd_id='{$data_rrd_id}'");
                            if (count($existing) == 0) {
                                $insert['id'] = 0;
                                $id = sql_save($insert, 'thold_data');
                                if ($id) {
                                    thold_template_update_threshold($id, $insert['template']);
                                    $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}");
                                    $tname = $l[0]['name'];
                                    $name = $data_source_name;
                                    if ($rrdrow['data_input_field_id'] != 0) {
                                        $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']);
                                        $name = $l[0]['name'];
                                    }
                                    plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]");
                                    $message .= __('Created threshold for the Graph \'<i>%s</i>\' using the Data Source \'<i>%s</i>\'', $tname, $name) . "<br>";
                                }
                            }
                        }
                    }
                }
            }
            if (strlen($message)) {
                $_SESSION['thold_message'] = "<font size=-2>{$message}</font>";
            } else {
                $_SESSION['thold_message'] = "<font size=-2>" . __('Threshold(s) Already Exist - No Thresholds Created') . "</font>";
            }
            raise_message('thold_message');
        }
    }
    return $action;
}
Example #14
0
function thold_mandatory_field_ok($name, $friendly_name)
{
    global $banner;
    if (!isset_request_var($name) || isset_request_var($name) && (trim(get_nfilter_request_var($name)) == '' || get_nfilter_request_var($name) <= 0)) {
        $banner .= __('&quot;%s&quot; must be set to positive integer value!<br>RECORD NOT UPDATED!</span>', $friendly_name);
        return false;
    }
    return true;
}
Example #15
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();
    }
}
Example #16
0
function template_import()
{
    include_once './lib/xml.php';
    if (trim(get_nfilter_request_var('import_text') != '')) {
        /* textbox input */
        $xml_data = get_nfilter_request_var('import_text');
    } elseif ($_FILES['import_file']['tmp_name'] != 'none' && $_FILES['import_file']['tmp_name'] != '') {
        /* file upload */
        $fp = fopen($_FILES['import_file']['tmp_name'], 'r');
        $xml_data = fread($fp, filesize($_FILES['import_file']['tmp_name']));
        fclose($fp);
    } else {
        header('Location: thold_templates.php?header=false');
        exit;
    }
    /* obtain debug information if it's set */
    $xml_array = xml2array($xml_data);
    $debug_data = array();
    if (sizeof($xml_array)) {
        foreach ($xml_array as $template => $contents) {
            $error = false;
            $save = array();
            if (sizeof($contents)) {
                foreach ($contents as $name => $value) {
                    switch ($name) {
                        case 'data_template_id':
                            // See if the hash exists, if it doesn't, Error Out
                            $found = db_fetch_cell_prepared('SELECT id FROM data_template WHERE hash = ?', array($value));
                            if (!empty($found)) {
                                $save['data_template_id'] = $found;
                            } else {
                                $error = true;
                                $debug_data[] = "<span style='font-weight:bold;color:red;'>" . __('ERROR:') . "</span> " . __('Threshold Template Subordinate Data Template Not Found!');
                            }
                            break;
                        case 'data_source_id':
                            // See if the hash exists, if it doesn't, Error Out
                            $found = db_fetch_cell_prepared('SELECT id FROM data_template_rrd WHERE hash = ?', array($value));
                            if (!empty($found)) {
                                $save['data_source_id'] = $found;
                            } else {
                                $error = true;
                                $debug_data[] = "<span style='font-weight:bold;color:red;'>" . __('ERROR:') . "</span> " . __('Threshold Template Subordinate Data Source Not Found!');
                            }
                            break;
                        case 'hash':
                            // See if the hash exists, if it does, update the thold
                            $found = db_fetch_cell_prepared('SELECT id FROM thold_template WHERE hash = ?', array($value));
                            if (!empty($found)) {
                                $save['hash'] = $value;
                                $save['id'] = $found;
                            } else {
                                $save['hash'] = $value;
                                $save['id'] = 0;
                            }
                            break;
                        case 'name':
                            $tname = $value;
                            $save['name'] = $value;
                            break;
                        default:
                            $save[$name] = $value;
                            break;
                    }
                }
            }
            if (!$error) {
                $id = sql_save($save, 'thold_template');
                if ($id) {
                    $debug_data[] = "<span style='font-weight:bold;color:green;'>" . __('NOTE:') . "</span> " . __('Threshold Template \'%s\' %s!', $tname, $save['id'] > 0 ? __('Updated') : __('Imported'));
                } else {
                    $debug_data[] = "<span style='font-weight:bold;color:red;'>" . __('ERROR:') . "</span> " . __('Threshold Template \'%s\' %s Failed!', $tname, $save['id'] > 0 ? __('Update') : __('Import'));
                }
            }
        }
    }
    if (sizeof($debug_data) > 0) {
        $_SESSION['import_debug_info'] = $debug_data;
    }
    header('Location: thold_templates.php?action=import');
}
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();
}
Example #18
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'));
Example #19
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;
    }
}
Example #20
0
function form_actions()
{
    global $colors, $config, $syslog_actions, $fields_syslog_action_edit;
    include dirname(__FILE__) . '/config.php';
    get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
    /* 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') == '1') {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_syslog_report_remove($selected_items[$i]);
                }
            } else {
                if (get_request_var('drp_action') == '2') {
                    /* disable */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        api_syslog_report_disable($selected_items[$i]);
                    }
                } else {
                    if (get_request_var('drp_action') == '3') {
                        /* enable */
                        for ($i = 0; $i < count($selected_items); $i++) {
                            api_syslog_report_enable($selected_items[$i]);
                        }
                    }
                }
            }
        }
        header('Location: syslog_reports.php?header=false');
        exit;
    }
    top_header();
    form_start('syslog_reports.php');
    html_start_box($syslog_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    /* setup some variables */
    $report_array = array();
    $report_list = '';
    /* loop through each of the clusters 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]);
            /* ==================================================== */
            $report_info = syslog_db_fetch_cell('SELECT name FROM `' . $syslogdb_default . '`.`syslog_reports` WHERE id=' . $matches[1]);
            $report_list .= '<li>' . $report_info . '</li>';
            $report_array[] = $matches[1];
        }
    }
    if (sizeof($report_array)) {
        if (get_request_var('drp_action') == '1') {
            /* delete */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete the following Syslog Report(s).') . "</p>\n\t\t\t\t\t<ul>{$report_list}</ul>";
            print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
            $title = __('Delete Syslog Report(s)');
        } else {
            if (get_request_var('drp_action') == '2') {
                /* disable */
                print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Click \'Continue\' to Disable the following Syslog Report(s).') . "</p>\n\t\t\t\t\t<ul>{$report_list}</ul>";
                print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
                $title = __('Disable Syslog Report(s)');
            } else {
                if (get_request_var('drp_action') == '3') {
                    /* enable */
                    print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Click \'Continue\' to Enable the following Syslog Report(s).') . "</p>\n\t\t\t\t\t<ul>{$report_list}</ul>";
                    print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
                    $title = __('Enable Syslog Report(s)');
                }
            }
        }
        $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='{$title}'";
    } else {
        print "<tr><td class='odd'><span class='textError'>" . __('You must select at least one Syslog Report.') . "</span></td></tr>\n";
        $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
    }
    print "<tr>\n\t\t<td 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($report_array) ? serialize($report_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();
    form_end();
    bottom_footer();
}
Example #21
0
function form_actions()
{
    global $actions, $assoc_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')) {
        if (isset_request_var('save_list')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                if (get_request_var('drp_action') == '1') {
                    /* delete */
                    db_execute('DELETE FROM plugin_notification_lists WHERE ' . array_to_sql_or($selected_items, 'id'));
                    db_execute('UPDATE host SET thold_send_email=0 WHERE thold_send_email=2 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
                    db_execute('UPDATE host SET thold_send_email=1 WHERE thold_send_email=3 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
                    db_execute('UPDATE host SET thold_host_email=0 WHERE ' . array_to_sql_or($selected_items, 'thold_host_email'));
                } elseif (get_request_var('drp_action') == '2') {
                    /* duplicate */
                    // To Do
                }
            }
            header('Location: notify_lists.php?header=false');
            exit;
        } elseif (isset_request_var('save_associate')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        /* set the notification list */
                        db_execute('UPDATE host SET thold_host_email=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                        /* set the global/list election */
                        db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        /* set the notification list */
                        db_execute('UPDATE host SET thold_host_email=0 WHERE id=' . $selected_items[$i]);
                        /* set the global/list election */
                        db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=hosts&id=' . get_request_var('id'));
            exit;
        } elseif (isset_request_var('save_templates')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_warning_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_template SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_alert_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_template SET notify_extra='' WHERE id=" . $selected_items[$i]);
                                db_execute('DELETE FROM plugin_thold_template_contact WHERE template_id=' . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_template SET notify_warning=0 WHERE id=' . $selected_items[$i] . ' AND notify_warning=' . get_request_var('id'));
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_template SET notify_alert=0 WHERE id=' . $selected_items[$i] . ' AND notify_alert=' . get_request_var('id'));
                        }
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=templates&id=' . get_request_var('id'));
            exit;
        } elseif (isset_request_var('save_tholds')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_warning_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_data SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_alert_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_data SET notify_extra='' WHERE id=" . $selected_items[$i]);
                                db_execute('DELETE FROM plugin_thold_threshold_contact WHERE thold_id=' . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_data SET notify_warning=0 WHERE id=' . $selected_items[$i] . ' AND notify_warning=' . get_request_var('id'));
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_data SET notify_alert=0 WHERE id=' . $selected_items[$i] . ' AND notify_alert=' . get_request_var('id'));
                        }
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=tholds&id=' . get_request_var('id'));
            exit;
        }
    }
    /* setup some variables */
    $list = '';
    $array = array();
    $list_name = '';
    if (isset_request_var('id')) {
        $list_name = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . get_filter_request_var('id'));
    }
    if (isset_request_var('save_list')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box($actions[get_request_var('drp_action')] . " {$list_name}", '60%', '', '3', 'center', '');
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* delete */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete Notification Lists(s).  Any Device(s) or Threshold(s) associated with the List(s) will be reverted to the default.') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* duplicate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Duplicate the following Notification List(s).') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Duplicate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Notification List.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='save_list' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_templates')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM thold_template WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box(__('%s Threshold Template(s)', $assoc_actions[get_request_var('drp_action')]), '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Association the Notification List \'<b>%s</b>\' with the Threshold Template(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Thresholds Template(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Threshold Template.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "\t<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_templates' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_tholds')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM thold_data WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box(__('%s Threshold(s)', $assoc_actions[get_request_var('drp_action')]), '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Associate the Notification List \'<b>%s</b>\' with the Threshold(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Thresholds(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Threshold.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "\t<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_tholds' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } else {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li>' . db_fetch_cell('SELECT description FROM host WHERE id=' . $matches[1]) . '</li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box($assoc_actions[get_request_var('drp_action')] . ' Device(s)', '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Associate the Notification List \'<b>%s</b>\' with the Device(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Resulting Membership:') . "<br>";
                form_dropdown('notification_action', array(2 => __('Notification List Only'), 3 => __('Notification and Global Lists')), '', '', 2, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Device(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Resulting Membership:') . "</b><br>";
                form_dropdown('notification_action', array(1 => __('Global List'), 0 => __('Disabled')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Device.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_associate' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    }
}
Example #22
0
function syslog_filter($sql_where, $tab)
{
    global $config, $graph_timespans, $graph_timeshifts, $reset_multi, $page_refresh_interval, $item_rows, $trimvals;
    include dirname(__FILE__) . '/config.php';
    $unprocessed = syslog_db_fetch_cell("SELECT COUNT(*) FROM `" . $syslogdb_default . "`.`syslog_incoming`");
    if (isset($_SESSION['sess_current_date1'])) {
        $filter_text = __(' [ Start: \'%s\' to End: \'%s\', Unprocessed Messages: %s ]', $_SESSION['sess_current_date1'], $_SESSION['sess_current_date2'], $unprocessed);
    } else {
        $filter_text = __('[ Unprocessed Messages: %s ]', $unprocessed);
    }
    ?>
	<script type='text/javascript'>

	var date1Open = false;
	var date2Open = false;

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

		$('#host').multiselect({
			noneSelectedText: '<?php 
    print __('Select Device(s)');
    ?>
', 
			selectedText: function(numChecked, numTotal, checkedItems) {
				myReturn = numChecked + ' <?php 
    print __('Devices Selected');
    ?>
';
				$.each(checkedItems, function(index, value) {
					if (value.value == '0') {
						myReturn='<?php 
    print __('All Devices Selected');
    ?>
';
						return false;
					}
				});
				return myReturn;
			},
			checkAllText: '<?php 
    print __('All');
    ?>
', 
			uncheckAllText: '<?php 
    print __('None');
    ?>
',
			uncheckall: function() {
				$(this).multiselect('widget').find(':checkbox:first').each(function() {
					$(this).prop('checked', true);
				});
			},
			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: '<?php 
    print __('Search');
    ?>
', width: '150'
		});

		$('#save').click(function() {
			saveSettings();
		});

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

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

		$('#startDate').click(function() {
			if (date1Open) {
				date1Open = false;
				$('#date1').datetimepicker('hide');
			}else{
				date1Open = true;
				$('#date1').datetimepicker('show');
			}
		});

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

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

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

		$(window).resize(function() {
			resizeHostSelect();
		});

		resizeHostSelect();
	});

	function resizeHostSelect() {
		position = $('#host').offset();
		$('#host').css('height', ($(window).height()-position.top)+'px');
	}

	function applyTimespan() {
		strURL  = urlPath+'plugins/syslog/syslog.php?header=false&predefined_timespan=' + $('#predefined_timespan').val();
		strURL += '&predefined_timeshift=' + $('#predefined_timeshift').val();
		loadPageNoHeader(strURL);
	}

	function applyFilter() {
		strURL = 'syslog.php?header=false'+
			'&date1='+$('#date1').val()+
			'&date2='+$('#date2').val()+
			'&host='+$('#host').val()+
			'&filter='+$('#filter').val()+
			'&efacility='+$('#efacility').val()+
			'&epriority='+$('#epriority').val()+
			'&eprogram='+$('#eprogram').val()+
			'&rows='+$('#rows').val()+
			'&trimval='+$('#trimval').val()+
			'&removal='+$('#removal').val()+
			'&refresh='+$('#refresh').val();

		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = 'syslog.php?header=false&clear=true';

		loadPageNoHeader(strURL);
	}

	function saveSettings() {
		strURL = 'syslog.php?action=save'+
			'&trimval='+$('#trimval').val()+
			'&rows='+$('#rows').val()+
			'&removal='+$('#removal').val()+
			'&refresh='+$('#refresh').val()+
			'&efacility='+$('#efacility').val()+
			'&epriority='+$('#epriority').val()+
			'&eprogram='+$('#eprogram').val();

		$.get(strURL, function() {
			$('#text').show().text('Filter Settings Saved').fadeOut(2000);
		});
	}

	function timeshiftFilterLeft() {
		var json = { 
			move_left_x: 1, 
			move_left_y: 1, 
			date1: $('#date1').val(), 
			date2: $('#date2').val(), 
			predefined_timespan: $('#predefined_timespan').val(), 
			predefined_timeshift: $('#predefined_timeshift').val(),
			__csrf_magic: csrfMagicToken
		};
	
		var href = urlPath+'plugins/syslog/syslog.php?action='+pageAction+'&header=false';
		$.post(href, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function timeshiftFilterRight() {
		var json = { 
			move_right_x: 1, 
			move_right_y: 1, 
			date1: $('#date1').val(), 
			date2: $('#date2').val(), 
			predefined_timespan: $('#predefined_timespan').val(), 
			predefined_timeshift: $('#predefined_timeshift').val(),
			__csrf_magic: csrfMagicToken
		};
	
		var href = urlPath+'plugins/syslog/syslog.php?action='+pageAction+'&header=false';
		$.post(href, json).done(function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	</script>
	<?php 
    html_start_box(__('Syslog Message Filter %s', $filter_text), '100%', '', '3', 'center', '');
    ?>
		<tr class='even noprint'>
			<td class='noprint'>
			<form id='syslog_form' action='syslog.php'>
				<table class='filterTable'>
					<tr>
						<td>
							<select id='predefined_timespan' onChange='applyTimespan()'>
								<?php 
    if ($_SESSION['custom']) {
        $graph_timespans[GT_CUSTOM] = __('Custom');
        set_request_var('predefined_timespan', GT_CUSTOM);
        $start_val = 0;
        $end_val = sizeof($graph_timespans);
    } else {
        if (isset($graph_timespans[GT_CUSTOM])) {
            asort($graph_timespans);
            array_shift($graph_timespans);
        }
        $start_val = 1;
        $end_val = sizeof($graph_timespans) + 1;
    }
    if (sizeof($graph_timespans) > 0) {
        for ($value = $start_val; $value < $end_val; $value++) {
            print "<option value='{$value}'";
            if (get_request_var('predefined_timespan') == $value) {
                print ' selected';
            }
            print '>' . title_trim($graph_timespans[$value], 40) . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<?php 
    print __('From');
    ?>
						</td>
						<td>
							<input type='text' id='date1' size='15' value='<?php 
    print isset($_SESSION['sess_current_date1']) ? $_SESSION['sess_current_date1'] : '';
    ?>
'>
						</td>
						<td>
							<i title='<?php 
    print __('Start Date Selector');
    ?>
' class='calendar fa fa-calendar' id='startDate'></i>
						</td>
						<td>
							<?php 
    print __('To');
    ?>
						</td>
						<td>
							<input type='text' id='date2' size='15' value='<?php 
    print isset($_SESSION['sess_current_date2']) ? $_SESSION['sess_current_date2'] : '';
    ?>
'>
						</td>
						<td>
							<i title='<?php 
    print __('End Date Selector');
    ?>
' class='calendar fa fa-calendar' id='endDate'></i>
						</td>
						<td>
							<i title='<?php 
    print __('Shift Time Backward');
    ?>
' onclick='timeshiftFilterLeft()' class='shiftArrow fa fa-backward'></i>
						</td>
						<td>
							<select id='predefined_timeshift' title='<?php 
    print __('Define Shifting Interval');
    ?>
' onChange='applyTimespan()'>
								<?php 
    $start_val = 1;
    $end_val = sizeof($graph_timeshifts) + 1;
    if (sizeof($graph_timeshifts) > 0) {
        for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) {
            print "<option value='{$shift_value}'";
            if (get_request_var('predefined_timeshift') == $shift_value) {
                print ' selected';
            }
            print '>' . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<i title='<?php 
    print __('Shift Time Forward');
    ?>
' onclick='timeshiftFilterRight()' class='shiftArrow fa fa-forward'></i>
						</td>
						<td>
							<input id='go' type='button' value='<?php 
    print __('Go');
    ?>
'>
						</td>
						<td>
							<input id='clear' type='button' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Return filter values to their user defined defaults');
    ?>
'>
						</td>
						<td>
							<input id='export' type='button' value='<?php 
    print __('Export');
    ?>
' title='<?php 
    print __('Export Records to CSV');
    ?>
'>
						</td>
						<td>
							<input id='save' type='button' value='<?php 
    print __('Save');
    ?>
' title='<?php 
    print __('Save Default Settings');
    ?>
'>
						</td>
						<?php 
    if (api_plugin_user_realm_auth('syslog_alerts.php')) {
        ?>
						<td align='right' style='white-space:nowrap;'>
							<input type='button' value='<?php 
        print __('Alerts');
        ?>
' title='<?php 
        print __('View Syslog Alert Rules');
        ?>
' onClick='javascript:document.location="<?php 
        print $config['url_path'] . "plugins/syslog/syslog_alerts.php";
        ?>
"'>
						</td>
						<td>
							<input type='button' value='<?php 
        print __('Removals');
        ?>
' title='<?php 
        print __('View Syslog Removal Rules');
        ?>
' onClick='javascript:document.location="<?php 
        print $config['url_path'] . "plugins/syslog/syslog_removal.php";
        ?>
"'>
						</td>
						<td>
							<input type='button' value='<?php 
        print __('Reports');
        ?>
' title='<?php 
        print __('View Syslog Reports');
        ?>
' onClick='javascript:document.location="<?php 
        print $config['url_path'] . "plugins/syslog/syslog_reports.php";
        ?>
"'>
						</td>
						<?php 
    }
    ?>
						<td>
							<span id='text'></span>
							<input type='hidden' name='action' value='actions'>
							<input type='hidden' name='syslog_pdt_change' value='false'>
						</td>
					</tr>
				</table>
				<table class='filterTable'>
					<tr>
						<td>
							<input type='text' id='filter' size='30' value='<?php 
    print get_request_var('filter');
    ?>
' onChange='applyFilter()'>
						</td>
						<td class='even'>
							<select id='host' multiple style='width: 150px; overflow: scroll;'>
								<?php 
    if ($tab == 'syslog') {
        ?>
<option id='host_all' value='0'<?php 
        if (get_request_var('host') == 'null' || get_request_var('host') == '0' || $reset_multi) {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('Show All Hosts');
        ?>
</option><?php 
    } else {
        ?>
								<option id='host_all' value='0'<?php 
        if (get_request_var('host') == 'null' || get_request_var('host') == 0 || $reset_multi) {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('Show All Logs');
        ?>
</option>
								<option id='host_none' value='-1'<?php 
        if (get_request_var('host') == '-1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('Threshold Logs');
        ?>
</option><?php 
    }
    ?>
								<?php 
    $hosts_where = '';
    $hosts_where = api_plugin_hook_function('syslog_hosts_where', $hosts_where);
    $hosts = syslog_db_fetch_assoc("SELECT host_id, SUBSTRING_INDEX(host,'.',1) AS host FROM `" . $syslogdb_default . "`.`syslog_hosts` {$hosts_where} ORDER BY host");
    $selected = explode(' ', get_request_var('host'));
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["host_id"] . "'";
            if (sizeof($selected)) {
                if (in_array($host['host_id'], $selected)) {
                    print ' selected';
                }
            }
            print '>';
            print $host['host'] . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<select id='rows' onChange='applyFilter()' title='<?php 
    print __('Display Rows');
    ?>
'>
								<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
								<?php 
    foreach ($item_rows as $rows => $display_text) {
        print "<option value='" . $rows . "'";
        if (get_request_var('rows') == $rows) {
            print ' selected';
        }
        print '>' . __('%d Messages', $display_text) . "</option>\n";
    }
    ?>
							</select>
						</td>
						<td>
							<select id='trimval' onChange='applyFilter()' title='<?php 
    print __('Message Trim');
    ?>
'>
								<?php 
    foreach ($trimvals as $seconds => $display_text) {
        print "<option value='" . $seconds . "'";
        if (get_request_var('trimval') == $seconds) {
            print ' selected';
        }
        print '>' . $display_text . "</option>\n";
    }
    ?>
							</select>
						</td>
						<td>
							<select id='refresh' onChange='applyFilter()'>
								<?php 
    foreach ($page_refresh_interval as $seconds => $display_text) {
        print "<option value='" . $seconds . "'";
        if (get_request_var('refresh') == $seconds) {
            print ' selected';
        }
        print '>' . $display_text . "</option>\n";
    }
    ?>
							</select>
						</td>
					</tr>
				</table>
				<table class='filterTable'>
					<tr>
						<?php 
    api_plugin_hook('syslog_extend_filter');
    ?>
						<td>
							<select id='eprogram' onChange='applyFilter()' title='<?php 
    print __('Programs to filter on');
    ?>
'>
								<option value='-1'<?php 
    if (get_request_var('eprogram') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Programs');
    ?>
</option>
								<?php 
    $eprograms = syslog_db_fetch_assoc('SELECT program_id, program
									FROM `' . $syslogdb_default . '`.`syslog_programs` AS fh
									ORDER BY program');
    if (sizeof($eprograms)) {
        foreach ($eprograms as $eprogram) {
            if (trim($eprogram['program']) == '') {
                $eprogram['program'] = 'unspecified';
            }
            print "<option value='" . $eprogram['program_id'] . "'";
            if (get_request_var('eprogram') == $eprogram['program_id']) {
                print ' selected';
            }
            print '>' . $eprogram['program'] . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<select id='efacility' onChange='applyFilter()' title='<?php 
    print __('Facilities to filter on');
    ?>
'>
								<option value='-1'<?php 
    if (get_request_var('efacility') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Facilities');
    ?>
</option>
								<?php 
    if (!isset($hostfilter)) {
        $hostfilter = '';
    }
    $efacilities = syslog_db_fetch_assoc('SELECT DISTINCT f.facility_id, f.facility
									FROM `' . $syslogdb_default . '`.`syslog_host_facilities` AS fh
									INNER JOIN `' . $syslogdb_default . '`.`syslog_facilities` AS f
									ON f.facility_id=fh.facility_id ' . (strlen($hostfilter) ? 'WHERE ' : '') . $hostfilter . '
									ORDER BY facility');
    if (sizeof($efacilities)) {
        foreach ($efacilities as $efacility) {
            print "<option value='" . $efacility['facility_id'] . "'";
            if (get_request_var('efacility') == $efacility['facility_id']) {
                print ' selected';
            }
            print '>' . ucfirst($efacility['facility']) . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<select id='epriority' onChange='applyFilter()' title='<?php 
    print __('Priority Levels');
    ?>
'>
								<option value='-1'<?php 
    if (get_request_var('epriority') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Priorities');
    ?>
</option>
								<option value='0'<?php 
    if (get_request_var('epriority') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Emergency');
    ?>
</option>
								<option value='1'<?php 
    if (get_request_var('epriority') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Critical++');
    ?>
</option>
								<option value='1o'<?php 
    if (get_request_var('epriority') == '1o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Critical');
    ?>
</option>
								<option value='2'<?php 
    if (get_request_var('epriority') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Alert++');
    ?>
</option>
								<option value='2o'<?php 
    if (get_request_var('epriority') == '2o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Alert');
    ?>
</option>
								<option value='3'<?php 
    if (get_request_var('epriority') == '3') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Error++');
    ?>
</option>
								<option value='3o'<?php 
    if (get_request_var('epriority') == '3o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Error');
    ?>
</option>
								<option value='4'<?php 
    if (get_request_var('epriority') == '4') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Warning++');
    ?>
</option>
								<option value='4o'<?php 
    if (get_request_var('epriority') == '4o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Warning');
    ?>
</option>
								<option value='5'<?php 
    if (get_request_var('epriority') == '5') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Notice++');
    ?>
</option>
								<option value='5o'<?php 
    if (get_request_var('epriority') == '5o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Notice');
    ?>
</option>
								<option value='6'<?php 
    if (get_request_var('epriority') == '6') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Info++');
    ?>
</option>
								<option value='6o'<?php 
    if (get_request_var('epriority') == '6o') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Info');
    ?>
</option>
								<option value='7'<?php 
    if (get_request_var('epriority') == '7') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Debug');
    ?>
</option>
							</select>
						</td>
						<?php 
    if (get_nfilter_request_var('tab') == 'syslog') {
        ?>
						<td>
							<select id='removal' onChange='applyFilter()' title='<?php 
        print __('Removal Handling');
        ?>
'>
								<option value='1'<?php 
        if (get_request_var('removal') == '1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('All Records');
        ?>
</option>
								<option value='-1'<?php 
        if (get_request_var('removal') == '-1') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('Main Records');
        ?>
</option>
								<option value='2'<?php 
        if (get_request_var('removal') == '2') {
            ?>
 selected<?php 
        }
        ?>
><?php 
        print __('Removed Records');
        ?>
</option>
							</select>
						</td>
						<?php 
    } else {
        ?>
						<input type='hidden' id='removal' value='<?php 
        print get_request_var('removal');
        ?>
'>
						<?php 
    }
    ?>
					</tr>
				</table>
			</form>
			</td>
		</tr>
	<?php 
    html_end_box(false);
}
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;
}
function mactrack_redirect()
{
    /* set the default tab */
    get_filter_request_var('report', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z]+)$/')));
    load_current_session_value('report', 'sess_mactrack_view_report', 'devices');
    $current_tab = get_nfilter_request_var('report');
    $current_page = str_replace('mactrack_', '', str_replace('view_', '', str_replace('.php', '', basename($_SERVER['PHP_SELF']))));
    $current_dir = dirname($_SERVER['PHP_SELF']);
    if ($current_page != $current_tab) {
        header('Location: ' . $current_dir . '/mactrack_view_' . $current_tab . '.php');
    }
}
Example #25
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>";
                    }
                }
            }
        }
    }
}
Example #26
0
function hmib_summary()
{
    global $device_actions, $item_rows, $config;
    /* ================= input validation ================= */
    get_filter_request_var('htop');
    get_filter_request_var('ptop');
    /* ==================================================== */
    /* clean up sort string */
    if (isset_request_var('sort_column')) {
        set_request_var('sort_column', sanitize_search_string(get_nfilter_request_var('sort_column')));
    }
    /* clean up sort string */
    if (isset_request_var('sort_direction')) {
        set_request_var('sort_direction', sanitize_search_string(get_nfilter_request_var('sort_direction')));
    }
    /* clean up search string */
    if (isset_request_var('filter')) {
        set_request_var('filter', sanitize_search_string(get_nfilter_request_var('filter')));
    }
    /* remember these search fields in session vars so we don't have
     * to keep passing them around
     */
    if (isset_request_var('area') && get_nfilter_request_var('area') == 'processes') {
        if (isset_request_var('clear')) {
            kill_session_var('sess_hmib_proc_top');
            kill_session_var('sess_hmib_proc_filter');
            kill_session_var('sess_hmib_proc_sort_column');
            kill_session_var('sess_hmib_proc_sort_direction');
            unset_request_var('filter');
            unset_request_var('ptop');
            unset_request_var('sort_column');
            unset_request_var('sort_direction');
        }
        if (isset_request_var('sort_column')) {
            $_SESSION['sess_hmib_proc_sort_column'] = get_request_var('sort_column');
            $_SESSION['sess_hmib_proc_sort_direction'] = get_request_var('sort_direction');
        } elseif (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
    } elseif (isset_request_var('area') && get_nfilter_request_var('area') == 'hosts') {
        if (isset_request_var('clear')) {
            kill_session_var('sess_hmib_host_top');
            kill_session_var('sess_hmib_host_sort_column');
            kill_session_var('sess_hmib_host_sort_direction');
            unset_request_var('htop');
            unset_request_var('sort_column');
            unset_request_var('sort_direction');
        }
        if (isset_request_var('sort_column')) {
            $_SESSION['sess_hmib_host_sort_column'] = get_request_var('sort_column');
            $_SESSION['sess_hmib_host_sort_direction'] = get_request_var('sort_direction');
        } elseif (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
    } else {
        if (!isset($_SESSION['sess_hmib_host_sort_column'])) {
            $_SESSION['sess_hmib_host_sort_column'] = 'downHosts';
            $_SESSION['sess_hmib_host_sort_direction'] = 'DESC';
        }
        if (!isset($_SESSION['sess_hmib_proc_sort_column'])) {
            $_SESSION['sess_hmib_proc_sort_column'] = 'maxCpu';
            $_SESSION['sess_hmib_proc_sort_direction'] = 'DESC';
        }
    }
    load_current_session_value('ptop', 'sess_hmib_proc_top', read_config_option('hmib_top_processes'));
    load_current_session_value('htop', 'sess_hmib_host_top', read_config_option('hmib_top_types'));
    load_current_session_value('filter', 'sess_hmib_proc_filter', '');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/hmib/hmib.php';
    $proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
    $host = $config['url_path'] . 'plugins/hmib/images/server.png';
    $hardw = $config['url_path'] . 'plugins/hmib/images/view_hardware.gif';
    $inven = $config['url_path'] . 'plugins/hmib/images/view_inventory.gif';
    $storage = $config['url_path'] . 'plugins/hmib/images/drive.png';
    $htdq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query\n\t\tWHERE hash='137aeab842986a76cf5bdef41b96c9a3'");
    $hcpudq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query\n\t\tWHERE hash='0d1ab53fe37487a5d0b9e1d3ee8c1d0d'");
    $hugt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='e8462bbe094e4e9e814d4e681671ea82'");
    $hpgt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='62205afbd4066e5c4700338841e3901e'");
    $htsd = db_fetch_cell("SELECT id\n\t\tFROM host_template\n\t\tWHERE hash='7c13344910097cc599f0d0485305361d'");
    if ($htdq == 0 || $hcpudq == 0 || $hugt == 0 || $hpgt == 0 || $htsd == 0) {
        $templates_missing = true;
    } else {
        $templates_missing = false;
    }
    ?>
	<script type='text/javascript'>
	function applyFilter(objForm) {
		strURL  = '?action=summary&area=hosts&header=false';
		strURL += '&htop=' + $('#htop').val();
		loadPageNoHeader(strURL);
	}

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

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

	$(function() {
		$('#proc_summary').submit(function(event) {
			event.preventDefault();
			applyProcFilter();
		});
	});
	</script>
	<?php 
    ?>
	<tr class='even'>
		<td>
			<form id='proc_summary'>
			<table class='filterTable'>
				<tr>
					<td style='width:55px;'>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='textbox' size='25' id='filter' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Top');
    ?>
					</td>
					<td>
						<select id='ptop' onChange='applyProcFilter()'>
							<option value='-1'<?php 
    if (get_request_var('ptop') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All Records');
    ?>
</option>
							<option value='5'<?php 
    if (get_request_var('ptop') == '5') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 5);
    ?>
</option>
							<option value='10'<?php 
    if (get_request_var('ptop') == '10') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 10);
    ?>
</option>
							<option value='15'<?php 
    if (get_request_var('ptop') == '15') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 15);
    ?>
</option>
							<option value='20'<?php 
    if (get_request_var('ptop') == '20') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('%d Records', 20);
    ?>
</option>
						</select>
					</td>
					<td>
						<input type='button' onClick='applyProcFilter(document.proc_summary)' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input type='button' onClick='clearProc()' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
					<td>
						&nbsp;&nbsp;<?php 
    print $templates_missing ? '<strong>' . __('WARNING: You need to import your Host MIB Host Template to view Graphs.  See the README for more information.') . '</strong>' : '';
    ?>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box(false);
    html_start_box(__('Process Summary Statistics'), '100%', '', '3', 'center', '');
    if (!isset($_SESSION['sess_hmib_proc_top'])) {
        $limit = 'LIMIT ' . read_config_option('hmib_top_processes');
    } elseif ($_SESSION['sess_hmib_proc_top'] == '-1') {
        $limit = '';
    } else {
        $limit = 'LIMIT ' . $_SESSION['sess_hmib_proc_top'];
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where = "AND (hrswr.name LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thrswr.path LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thrswr.parameters LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    $sql = "SELECT\n\t\thrswr.name AS name,\n\t\tCOUNT(DISTINCT hrswr.path) AS paths,\n\t\tCOUNT(DISTINCT hrswr.host_id) AS numHosts,\n\t\tCOUNT(hrswr.host_id) AS numProcesses,\n\t\tAVG(hrswr.perfCPU) AS avgCpu,\n\t\tMAX(hrswr.perfCPU) AS maxCpu,\n\t\tAVG(hrswr.perfMemory) AS avgMemory,\n\t\tMAX(hrswr.perfMemory) AS maxMemory\n\t\tFROM plugin_hmib_hrSWRun AS hrswr\n\t\tWHERE hrswr.name!='System Idle Process' AND hrswr.name!=''\n\t\t{$sql_where}\n\t\tGROUP BY hrswr.name\n\t\tORDER BY " . $_SESSION['sess_hmib_proc_sort_column'] . ' ' . $_SESSION['sess_hmib_proc_sort_direction'] . ' ' . $limit;
    $rows = db_fetch_assoc($sql);
    //echo $sql;
    $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => 'ASC', 'align' => 'left'), 'name' => array('display' => __('Process Name'), 'sort' => 'ASC', 'align' => 'left'), 'paths' => array('display' => __('Num Paths'), 'sort' => 'DESC', 'align' => 'right'), 'numHosts' => array('display' => __('Hosts'), 'sort' => 'DESC', 'align' => 'right'), 'numProcesses' => array('display' => __('Processes'), 'sort' => 'DESC', 'align' => 'right'), 'avgCpu' => array('display' => __('Avg CPU'), 'sort' => 'DESC', 'align' => 'right'), 'maxCpu' => array('display' => __('Max CPU'), 'sort' => 'DESC', 'align' => 'right'), 'avgMemory' => array('display' => __('Avg Memory'), 'sort' => 'DESC', 'align' => 'right'), 'maxMemory' => array('display' => __('Max Memory'), 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, $_SESSION['sess_hmib_proc_sort_column'], $_SESSION['sess_hmib_proc_sort_direction'], false, 'hmib.php?action=summary&area=processes');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/hmib/hmib.php';
    $proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
    $host = $config['url_path'] . 'plugins/hmib/images/server.png';
    /* get the data query for the application use */
    $adq = db_fetch_cell("SELECT id\n\t\tFROM snmp_query\n\t\tWHERE hash='6b0ef0fe7f1d85bbb6812801ca15a7c5'");
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $graph_url = hmib_get_graph_url($adq, 0, 0, $row['name']);
            form_alternate_row();
            echo "<td width='70'>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=devices&process=" . $row['name']) . "'><img src='{$host}' title='" . __('View Devices') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?reset=1&action=running&process=" . $row['name']) . "'><img src='{$proc}' title='" . __('View Processes') . "' align='absmiddle' alt=''></a>";
            echo $graph_url;
            echo '</td>';
            echo "<td class='left' width='140'>" . $row['name'] . '</td>';
            echo "<td class='right'>" . $row['paths'] . '</td>';
            echo "<td class='right'>" . $row['numHosts'] . '</td>';
            echo "<td class='right'>" . $row['numProcesses'] . '</td>';
            echo "<td class='right'>" . number_format_i18n($row['avgCpu'] / 3600, 0) . ' Hrs</td>';
            echo "<td class='right'>" . number_format_i18n($row['maxCpu'] / 3600, 0) . ' Hrs</td>';
            echo "<td class='right'>" . number_format_i18n($row['avgMemory'] / 1024, 2) . ' MB</td>';
            echo "<td class='right'>" . number_format_i18n($row['maxMemory'] / 1024, 2) . ' MB</td>';
        }
        echo '</tr>';
    } else {
        print '<tr><td><em>' . __('No Processes') . '</em></td></tr>';
    }
    html_end_box();
}
/**
 * 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;
}
Example #28
0
function form_actions()
{
    global $config, $host_types_actions, $fields_hmib_host_types_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 = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_request_var('drp_action') == '1') {
                /* delete */
                foreach ($selected_items as $item) {
                    api_hmib_host_type_remove($item);
                }
            } elseif (get_request_var('drp_action') == '2') {
                /* duplicate */
                foreach ($selected_items as $item) {
                    hmib_duplicate_host_type($item, $i, get_request_var('title_format'));
                }
            }
        }
        header('Location: hmib_types.php?heder=false');
        exit;
    }
    /* setup some variables */
    $host_types_list = '';
    $i = 0;
    /* loop through each of the device types 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]);
            /* ==================================================== */
            $host_types_info = db_fetch_row('SELECT name FROM plugin_hmib_hrSystemTypes WHERE id=' . $matches[1]);
            $host_types_list .= '<li>' . $host_types_info['name'] . '</li>';
            $host_types_array[$i] = $matches[1];
        }
        $i++;
    }
    top_header();
    form_start('hmib_types.php');
    html_start_box($host_types_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (get_filter_request_var('drp_action') == '1') {
        /* delete */
        print "\t<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete the following Host Type(s)') . "</p>\n\t\t\t\t\t<p><ul>{$host_types_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
        $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Host Type(s)') . "'>";
    } elseif (get_filter_request_var('drp_action') == '2') {
        /* duplicate */
        print "\t<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Click \'Continue\' to Duplicate the following Host Type(s). You may optionally change the description for the new Host Type(s).  Otherwise, do not change value below and the original name will be replicated with a new suffix.') . "</p>\n\t\t\t\t\t<p><ul>{$host_types_list}</ul></p>\n\t\t\t\t\t<p><strong>" . __('Host Type Prefix:') . "</strong><br>";
        form_text_box('title_format', '<description> (1)', '', '255', '30', 'text');
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
        $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Duplicate Host Type(s)') . "'>";
    }
    if (!isset($host_types_array)) {
        print "<tr><td class='odd'><span class='textError'>" . __('You must select at least one Host Type.') . "</span></td></tr>\n";
        $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>";
    } else {
    }
    print "<tr class='even'>\n\t\t<td colspan='2' 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($host_types_array) ? serialize($host_types_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();
    form_end();
    bottom_footer();
}