コード例 #1
0
ファイル: gprint_presets.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $gprint_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            db_execute('DELETE FROM graph_templates_gprint WHERE ' . array_to_sql_or($selected_items, 'id'));
        }
        header('Location: gprint_presets.php');
        exit;
    }
    /* setup some variables */
    $gprint_list = '';
    $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]);
            /* ==================================================== */
            $gprint_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM graph_templates_gprint WHERE id = ?', array($matches[1]))) . '</li>';
            $gprint_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    print "<form action='gprint_presets.php' method='post'>\n";
    html_start_box('<strong>' . $gprint_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    if (isset($gprint_array) && sizeof($gprint_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the folling GPRINT Preset(s) will be deleted.</p>\n\t\t\t\t\t\t<ul>{$gprint_list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete GPRINT Preset(s)'>";
        }
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one GPRINT Preset.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($gprint_array) ? serialize($gprint_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
    html_end_box();
    bottom_footer();
}
コード例 #2
0
ファイル: host_templates.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $host_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            db_execute('DELETE FROM host_template WHERE ' . array_to_sql_or($selected_items, 'id'));
            db_execute('DELETE FROM host_template_snmp_query WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
            db_execute('DELETE FROM host_template_graph WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
            /* "undo" any device that is currently using this template */
            db_execute('UPDATE host SET host_template_id=0 WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
        } elseif ($_POST['drp_action'] == '2') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_host_template($selected_items[$i], $_POST['title_format']);
            }
        }
        header('Location: host_templates.php');
        exit;
    }
    /* setup some variables */
    $host_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]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?'), array($matches[1])) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    html_start_box('<strong>' . $host_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host_templates.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Are you sure you want to delete the following Device Template(s)? All Devices currently associated\n\t\t\t\t\t\twith these Device Template(s) will lose that assocation.</p>\n\t\t\t\t\t\t<p><ul>{$host_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device Template(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Device Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$host_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<template_title> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Device Template(s)'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one host template.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
コード例 #3
0
ファイル: data_templates.php プロジェクト: teddywen/cacti
function form_actions()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        if ($selected_items != false) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                $data_template_datas = db_fetch_assoc("select id from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                if (sizeof($data_template_datas) > 0) {
                    foreach ($data_template_datas as $data_template_data) {
                        db_execute("delete from data_template_data_rra where data_template_data_id=" . $data_template_data["id"]);
                    }
                }
                db_execute("delete from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                db_execute("delete from data_template_rrd where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                db_execute("delete from snmp_query_graph_rrd where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("delete from snmp_query_graph_rrd_sv where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("delete from data_template where " . array_to_sql_or($selected_items, "id"));
                /* "undo" any graph that is currently using this template */
                db_execute("update data_template_data set local_data_template_data_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("update data_template_rrd set local_data_template_rrd_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("update data_local set data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
            } elseif ($_POST["drp_action"] == "2") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_data_source(0, $selected_items[$i], $_POST["title_format"]);
                }
            }
        }
        header("Location: data_templates.php");
        exit;
    }
    /* setup some variables */
    $ds_list = "";
    $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]);
            /* ==================================================== */
            $ds_list .= "<li>" . htmlspecialchars(db_fetch_cell("select name from data_template where id=" . $matches[1])) . "</li>";
            $ds_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
    print "<form action='data_templates.php' method='post'>\n";
    if (isset($ds_array) && sizeof($ds_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Template(s) will be deleted.  Any data sources attached\n\t\t\t\t\t\tto these templates will become individual Data Source(s) and all Templating benefits will be removed.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Template(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Data Template(s)'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one data template.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
コード例 #4
0
ファイル: graph.php プロジェクト: songchin/Cacti
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = "view"; }
if (!isset($_REQUEST["view_type"])) { $_REQUEST["view_type"] = ""; }

$guest_account = true;
include("./include/auth.php");
include("./lib/rrd.php");
include("./lib/html_tree.php");
include("./include/top_graph_header.php");

/* ================= input validation ================= */
input_validate_input_regex(get_request_var("rra_id"), "^([0-9]+|all)$");
input_validate_input_number(get_request_var("local_graph_id"));
/* ==================================================== */

if ($_GET["rra_id"] == "all") {
	$sql_where = " where id is not null";
}else{
	$sql_where = " where id=" . $_GET["rra_id"];
}

/* make sure the graph requested exists (sanity) */
if (!(db_fetch_cell("select local_graph_id from graph_templates_graph where local_graph_id=" . $_GET["local_graph_id"]))) {
	print "<strong><font size='+1' color='FF0000'>GRAPH DOES NOT EXIST</font></strong>"; exit;
}

/* take graph permissions into account here, if the user does not have permission
コード例 #5
0
ファイル: plugins.php プロジェクト: teddywen/cacti
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
include "./include/auth.php";
define("MAX_DISPLAY_PAGES", 21);
$actions = array("install" => "Install", "enable" => "Enable", "disable" => "Disable", "uninstall" => "Uninstall");
$status_names = array(-2 => 'Disabled', -1 => 'Active', 0 => 'Not Installed', 1 => 'Active', 2 => 'Awaiting Configuration', 3 => 'Awaiting Upgrade', 4 => 'Installed');
/* get the comprehensive list of plugins */
$pluginslist = retrieve_plugin_list();
/* Check to see if we are installing, etc... */
$modes = array('installold', 'uninstallold', 'install', 'uninstall', 'disable', 'enable', 'check', 'moveup', 'movedown');
if (isset($_GET['mode']) && in_array($_GET['mode'], $modes) && isset($_GET['id'])) {
    input_validate_input_regex(get_request_var("id"), "^([a-zA-Z0-9]+)\$");
    $mode = $_GET['mode'];
    $id = sanitize_search_string($_GET['id']);
    switch ($mode) {
        case 'installold':
            api_plugin_install_old($id);
            header("Location: plugins.php");
            exit;
            break;
        case 'uninstallold':
            api_plugin_uninstall_old($id);
            header("Location: plugins.php");
            exit;
            break;
        case 'install':
            api_plugin_install($id);
コード例 #6
0
ファイル: data_queries.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $dq_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                data_query_remove($selected_items[$i]);
            }
        }
        header('Location: data_queries.php');
        exit;
    }
    /* setup some variables */
    $dq_list = '';
    $i = 0;
    /* loop through each of the data queries and process them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $dq_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT snmp_query.name FROM snmp_query WHERE id = ?', array($matches[1]))) . '<br>';
            $dq_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    html_start_box('<strong>' . $dq_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='data_queries.php' method='post'>\n";
    if (isset($dq_array) && sizeof($dq_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            $graphs = array();
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Data Querie(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$dq_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
        }
        $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Querie(s)'>";
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one data query.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($dq_array) ? serialize($dq_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
コード例 #7
0
ファイル: graph_view.php プロジェクト: resmon/resmon-cacti
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
$guest_account = true;
include "./include/auth.php";
include_once "./lib/html_tree.php";
include_once "./lib/timespan_settings.php";
/* ================= input validation ================= */
input_validate_input_number(get_request_var("branch_id"));
input_validate_input_number(get_request_var("hide"));
input_validate_input_number(get_request_var("tree_id"));
input_validate_input_number(get_request_var("leaf_id"));
input_validate_input_number(get_request_var("rra_id"));
input_validate_input_regex(get_request_var_request('graph_list'), "^([\\,0-9]+)\$");
input_validate_input_regex(get_request_var_request('graph_add'), "^([\\,0-9]+)\$");
input_validate_input_regex(get_request_var_request('graph_remove'), "^([\\,0-9]+)\$");
/* ==================================================== */
/* clean up action string */
if (isset($_REQUEST["action"])) {
    $_REQUEST["action"] = sanitize_search_string(get_request_var("action"));
}
/* use cached url if available and applicable */
if (isset($_SESSION["sess_graph_view_url_cache"]) && empty($_REQUEST["action"])) {
    if (preg_match("/action=(preview|list)/", $_SESSION["sess_graph_view_url_cache"])) {
        header("Location: " . $_SESSION["sess_graph_view_url_cache"]);
        exit;
    } elseif (preg_match("/action=tree/", $_SESSION["sess_graph_view_url_cache"]) && preg_match("/tree_id=/", $_SESSION["sess_graph_view_url_cache"])) {
        header("Location: " . $_SESSION["sess_graph_view_url_cache"]);
        exit;
    } elseif (isset($_SESSION["sess_graph_view_last_tree"])) {
        header("Location: " . $_SESSION["sess_graph_view_last_tree"]);
コード例 #8
0
ファイル: tree.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $tree_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        for ($i = 0; $i < count($selected_items); $i++) {
            /* ================= input validation ================= */
            input_validate_input_number($selected_items[$i]);
            /* ==================================================== */
        }
        if ($_POST['drp_action'] == '1') {
            /* delete */
            db_execute('DELETE FROM graph_tree WHERE ' . array_to_sql_or($selected_items, 'id'));
            db_execute('DELETE FROM graph_tree_items WHERE ' . array_to_sql_or($selected_items, 'graph_tree_id'));
        } elseif ($_POST['drp_action'] == '2') {
            /* publish */
            db_execute("UPDATE graph_tree \n\t\t\t\tSET enabled='on',\n\t\t\t\tlast_modified=NOW(),\n\t\t\t\tmodified_by=" . $_SESSION['sess_user_id'] . '
				WHERE ' . array_to_sql_or($selected_items, 'id'));
        } elseif ($_POST['drp_action'] == '3') {
            /* un-publish */
            db_execute("UPDATE graph_tree \n\t\t\t\tSET enabled='',\n\t\t\t\tlast_modified=NOW(),\n\t\t\t\tmodified_by=" . $_SESSION['sess_user_id'] . '
				WHERE ' . array_to_sql_or($selected_items, 'id'));
        }
        header('Location: tree.php');
        exit;
    }
    /* setup some variables */
    $tree_list = '';
    $i = 0;
    /* loop through each of the selected items */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $tree_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($matches[1]))) . '</li>';
            $tree_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    print "<form action='tree.php' method='post'>\n";
    html_start_box('<strong>' . $tree_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    if (isset($tree_array) && sizeof($tree_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the folling Tree(s) will be deleted.</p>\n\t\t\t\t\t\t<ul>{$tree_list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Tree(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* publish */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Tree(s) will be Published.</p>\n\t\t\t\t\t\t<ul>{$tree_list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Publish Tree(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* un-publish */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Tree(s) will be Un-Published.</p>\n\t\t\t\t\t\t<ul>{$tree_list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Un-Publish Tree(s)'>";
        }
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one Tree.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($tree_array) ? serialize($tree_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
    html_end_box();
    bottom_footer();
}
コード例 #9
0
ファイル: plugins.php プロジェクト: songchin/Cacti
	'uninstalled' => __('Uninstalled')
);

$ptabs = api_plugin_hook_function ('plugin_management_tabs', $ptabs);

$status_names = array(__('Not Installed'), __('Active'), __('Awaiting Configuration'), __('Awaiting Upgrade'), __('Installed'));

/* set the default settings category */
load_current_session_value('tab', 'sess_plugins_tab', 'all');
$current_tab = $_REQUEST['tab'];

$modes = array('all', 'install', 'uninstall', 'disable', 'enable', 'check');

// Check to see if we are installing, etc...
if (isset($_GET['mode']) && in_array($_GET['mode'], $modes)  && isset($_GET['id'])) {
	input_validate_input_regex(get_request_var('id'), '/^([a-zA-Z0-9]+)$/');

	$mode = $_GET['mode'];
	$id = sanitize_search_string($_GET['id']);

	switch ($mode) {
		case 'install':
			api_plugin_install($id);
			$plugins = plugins_retrieve_list();
			break;
		case 'uninstall':
			if (!in_array($id, $plugins))
				break;
			api_plugin_uninstall($id);
			Header("Location: plugins.php\n\n");
			exit;
コード例 #10
0
ファイル: data_sources.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 1;
            }
            switch ($_POST['delete_type']) {
                case '2':
                    /* delete all graph items tied to this data source */
                    $data_template_rrds = array_rekey(db_fetch_assoc('SELECT id FROM data_template_rrd WHERE ' . array_to_sql_or($selected_items, 'local_data_id')), 'id', 'id');
                    /* loop through each data source item */
                    if (sizeof($data_template_rrds) > 0) {
                        db_execute('DELETE FROM graph_templates_item WHERE task_item_id IN (' . implode(',', $data_template_rrds) . ') and local_graph_id > 0');
                    }
                    api_plugin_hook_function('graph_items_remove', $data_template_rrds);
                    break;
                case '3':
                    /* delete all graphs tied to this data source */
                    $graphs = array_rekey(db_fetch_assoc('SELECT
						graph_templates_graph.local_graph_id
						FROM (data_template_rrd,graph_templates_item,graph_templates_graph)
						WHERE graph_templates_item.task_item_id=data_template_rrd.id
						AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id
						AND ' . array_to_sql_or($selected_items, 'data_template_rrd.local_data_id') . '
						AND graph_templates_graph.local_graph_id > 0
						GROUP BY graph_templates_graph.local_graph_id'), 'local_graph_id', 'local_graph_id');
                    if (sizeof($graphs) > 0) {
                        api_graph_remove_multi($graphs);
                    }
                    api_plugin_hook_function('graphs_remove', $graphs);
                    break;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            api_data_source_remove_multi($selected_items);
            api_plugin_hook_function('data_source_remove', $selected_items);
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('data_template_id'));
                /* ==================================================== */
                change_data_template($selected_items[$i], $_POST['data_template_id']);
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* change host */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('host_id'));
                /* ==================================================== */
                db_execute_prepared('UPDATE data_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i]));
                push_out_host($_POST['host_id'], $selected_items[$i]);
                update_data_source_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_data_source($selected_items[$i], 0, $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* data source -> data template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                data_source_to_data_template($selected_items[$i], $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* data source enable */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_data_source_enable($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '7') {
            /* data source disable */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_data_source_disable($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '8') {
            /* reapply suggested data source naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_data_source_title($selected_items[$i]);
                update_data_source_title_cache($selected_items[$i]);
            }
        } else {
            api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_data_source_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: data_sources.php');
        exit;
    }
    /* setup some variables */
    $ds_list = '';
    $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]);
            /* ==================================================== */
            $ds_list .= '<li>' . htmlspecialchars(get_data_source_title($matches[1])) . '<br>';
            $ds_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    html_start_box('<strong>' . $ds_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='data_sources.php' method='post'>\n";
    if (isset($ds_array) && sizeof($ds_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            $graphs = array();
            /* find out which (if any) graphs are using this data source, so we can tell the user */
            if (isset($ds_array)) {
                $graphs = db_fetch_assoc('SELECT
					graph_templates_graph.local_graph_id,
					graph_templates_graph.title_cache
					FROM (data_template_rrd,graph_templates_item,graph_templates_graph)
					WHERE graph_templates_item.task_item_id=data_template_rrd.id
					AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id
					AND ' . array_to_sql_or($ds_array, 'data_template_rrd.local_data_id') . '
					AND graph_templates_graph.local_graph_id > 0
					GROUP BY graph_templates_graph.local_graph_id
					ORDER BY graph_templates_graph.title_cache');
            }
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>";
            if (sizeof($graphs) > 0) {
                print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n";
                print '<ul>';
                foreach ($graphs as $graph) {
                    print '<li><strong>' . $graph['title_cache'] . "</strong></li>\n";
                }
                print '</ul>';
                print '<br>';
                form_radio_button('delete_type', '3', '1', 'Leave the Graph(s) untouched.', '1');
                print '<br>';
                form_radio_button('delete_type', '3', '2', 'Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).', '1');
                print '<br>';
                form_radio_button('delete_type', '3', '3', 'Delete all <strong>Graph(s)</strong> that reference these Data Source(s).', '1');
                print '<br>';
                print '</td></tr>';
            }
            print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Source(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>";
            form_dropdown('data_template_id', db_fetch_assoc('SELECT data_template.id,data_template.name FROM data_template ORDER BY data_template.name'), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* change host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Device:</strong><br>";
            form_dropdown('host_id', db_fetch_assoc("SELECT id, CONCAT_WS('',description,' (',hostname,')') AS name FROM host ORDER BY description, hostname"), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<ds_title> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Data Source(s)'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* data source -> data template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<ds_title> Template', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* data source enable */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Data Source(s)'>";
        } elseif ($_POST['drp_action'] == '7') {
            /* data source disable */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Data Source(s)'>";
        } elseif ($_POST['drp_action'] == '8') {
            /* reapply suggested data source naming */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['ds_list'] = $ds_list;
            $save['ds_array'] = isset($ds_array) ? $ds_array : array();
            api_plugin_hook_function('data_source_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one data source.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
コード例 #11
0
ファイル: functions.php プロジェクト: songchin/Cacti
function draw_navigation_text() {
	global $config;
	$nav_level_cache = (isset($_SESSION["sess_nav_level_cache"]) ? $_SESSION["sess_nav_level_cache"] : array());

	$nav = array(
		"about.php:" => array("title" => __("About Cacti"), "mapping" => "index.php:", "url" => "about.php", "level" => "1"),
		"cdef.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,cdef.php:", "url" => "", "level" => "2"),
		"cdef.php:" => array("title" => __("CDEF's"), "mapping" => "index.php:", "url" => "cdef.php", "level" => "1"),
		"cdef.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,cdef.php:", "url" => "", "level" => "2"),
		"cdef.php:item_edit" => array("title" => __("CDEF Items"), "mapping" => "index.php:,cdef.php:,cdef.php:edit", "url" => "", "level" => "3"),
		"cdef.php:remove" => array("title" => __("(Remove)"), "mapping" => "index.php:,cdef.php:", "url" => "", "level" => "2"),
		"color.php:" => array("title" => __("Colors"), "mapping" => "index.php:", "url" => "color.php", "level" => "1"),
		"color.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,color.php:", "url" => "", "level" => "2"),
		"color.php:import" => array("title" => __("Colors"), "mapping" => "index.php:", "url" => "color.php", "level" => "1"),
		"data_input.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,data_input.php:", "url" => "", "level" => "2"),
		"data_input.php:" => array("title" => __("Data Input Methods"), "mapping" => "index.php:", "url" => "data_input.php", "level" => "1"),
		"data_input.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,data_input.php:", "url" => "", "level" => "2"),
		"data_input.php:field_edit" => array("title" => __("Data Input Fields"), "mapping" => "index.php:,data_input.php:,data_input.php:edit", "url" => "", "level" => "3"),
		"data_input.php:field_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,data_input.php:,data_input.php:edit", "url" => "", "level" => "3"),
		"data_input.php:remove" => array("title" => __("(Remove)"), "mapping" => "index.php:,data_input.php:", "url" => "", "level" => "2"),
		"data_queries.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,data_queries.php:", "url" => "", "level" => "2"),
		"data_queries.php:" => array("title" => __("Data Queries"), "mapping" => "index.php:", "url" => "data_queries.php", "level" => "1"),
		"data_queries.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,data_queries.php:", "url" => "", "level" => "2"),
		"data_queries.php:item_edit" => array("title" => __("Associated Graph Templates"), "mapping" => "index.php:,data_queries.php:,data_queries.php:edit", "url" => "", "level" => "3"),
		"data_queries.php:item_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,data_queries.php:,data_queries.php:edit", "url" => "", "level" => "3"),
		"data_sources.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"),
		"data_sources.php:" => array("title" => __("Data Sources"), "mapping" => "index.php:", "url" => "data_sources.php", "level" => "1"),
		"data_sources.php:data_source_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"),
		"data_sources.php:ds_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"),
		"data_sources.php:ds_toggle_status" => array("title" => "(Disable)", "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"),
		"data_sources_items.php:item_edit" => array("title" => __("Data Source Items"), "mapping" => "index.php:,data_sources.php:,data_sources.php:data_source_edit", "url" => "", "level" => "3"),
		"data_templates.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,data_templates.php:", "url" => "", "level" => "2"),
		"data_templates.php:" => array("title" => __("Data Source Templates"), "mapping" => "index.php:", "url" => "data_templates.php", "level" => "1"),
		"data_templates.php:template_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,data_templates.php:", "url" => "", "level" => "2"),
		"data_templates_items.php:item_edit" => array("title" => __("Data Template Items"), "mapping" => "index.php:,data_templates.php:,data_templates.php:template_edit", "url" => "", "level" => "3"),
		"gprint_presets.php:" => array("title" => __("GPRINT Presets"), "mapping" => "index.php:", "url" => "gprint_presets.php", "level" => "1"),
		"gprint_presets.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,gprint_presets.php:", "url" => "", "level" => "2"),
		"gprint_presets.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,gprint_presets.php:", "url" => "", "level" => "2"),
		"graph.php:" => array("title" => "|current_graph_title|", "mapping" => "graph_view.php:,?", "level" => "2"),
		"graph.php:properties" => array("title" => __("Properties"), "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
		"graph.php:view" => array("title" => "|current_graph_title|", "mapping" => "graph_view.php:,?", "level" => "2"),
		"graph.php:zoom" => array("title" => __("Zoom"), "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"),
		"graph_settings.php:" => array("title" => __("Settings"), "mapping" => "graph_view.php:", "url" => "graph_settings.php", "level" => "1"),
		"graphs_items.php:item_edit" => array("title" => __("Graph Items"), "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"),
		"graphs_new.php:" => array("title" => __("Create New Graphs"), "mapping" => "index.php:", "url" => "graphs_new.php", "level" => "1"),
		"graphs_new.php:save" => array("title" => __("Create Graphs from Data Query"), "mapping" => "index.php:,graphs_new.php:", "url" => "", "level" => "2"),
		"graphs.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"),
		"graphs.php:" => array("title" => __("Graph Management"), "mapping" => "index.php:", "url" => "graphs.php", "level" => "1"),
		"graphs.php:graph_diff" => array("title" => __("Change Graph Template"), "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"),
		"graphs.php:graph_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"),
		"graph_templates_inputs.php:input_edit" => array("title" => __("Graph Item Inputs"), "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"),
		"graph_templates_inputs.php:input_remove" => array("title" => __("(Remove)"), "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"),
		"graph_templates_items.php:item_edit" => array("title" => __("Graph Template Items"), "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"),
		"graph_templates.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"),
		"graph_templates.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"),
		"graph_templates.php:" => array("title" => __("Graph Templates"), "mapping" => "index.php:", "url" => "graph_templates.php", "level" => "1"),
		"graph_templates.php:template_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"),
		"graph_view.php:" => array("title" => __("Graphs"), "mapping" => "", "url" => "graph_view.php", "level" => "0"),
		"graph_view.php:list" => array("title" => __("List Mode"), "mapping" => "graph_view.php:", "url" => "graph_view.php?action=list", "level" => "1"),
		"graph_view.php:preview" => array("title" => __("Preview Mode"), "mapping" => "graph_view.php:", "url" => "graph_view.php?action=preview", "level" => "1"),
		"graph_view.php:tree" => array("title" => __("Tree Mode"), "mapping" => "graph_view.php:", "url" => "graph_view.php?action=tree", "level" => "1"),
		"sites.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,sites.php:", "url" => "", "level" => "2"),
		"sites.php:" => array("title" => __("Sites"), "mapping" => "index.php:", "url" => "sites.php", "level" => "1"),
		"sites.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,sites.php:", "url" => "", "level" => "2"),
		"devices.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,devices.php:", "url" => "", "level" => "2"),
		"devices.php:" => array("title" => __("Devices"), "mapping" => "index.php:", "url" => "devices.php", "level" => "1"),
		"devices.php:save" => array("title" => __("Devices"), "mapping" => "index.php:", "url" => "devices.php", "level" => "1"),
		"devices.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,devices.php:", "url" => "", "level" => "2"),
		"devices.php:create" => array("title" => __("Devices"), "mapping" => "index.php:", "url" => "devices.php", "level" => "1"),
		"pollers.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,pollers.php:", "url" => "", "level" => "2"),
		"pollers.php:" => array("title" => __("Pollers"), "mapping" => "index.php:", "url" => "pollers.php", "level" => "1"),
		"pollers.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,pollers.php:", "url" => "", "level" => "2"),
		"device_templates.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,device_templates.php:", "url" => "", "level" => "2"),
		"device_templates.php:save_dt" => array("title" => __("Actions"), "mapping" => "index.php:,device_templates.php:", "url" => "", "level" => "2"),
		"device_templates.php:save_dq" => array("title" => __("Actions"), "mapping" => "index.php:,device_templates.php:", "url" => "", "level" => "2"),
		"device_templates.php:" => array("title" => __("Device Templates"), "mapping" => "index.php:", "url" => "device_templates.php", "level" => "1"),
		"device_templates.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,device_templates.php:", "url" => "", "level" => "2"),
		"index.php:" => array("title" => __("Console"), "mapping" => "", "url" => CACTI_URL_PATH . "index.php", "level" => "0"),
		"index.php:login" => array("title" => __("Console"), "mapping" => "", "url" => CACTI_URL_PATH . "index.php", "level" => "0"),
		"rra.php:" => array("title" => __("Round Robin Archives"), "mapping" => "index.php:", "url" => "rra.php", "level" => "1"),
		"rra.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,rra.php:", "url" => "", "level" => "2"),
		"rra.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,rra.php:", "url" => "", "level" => "2"),
		"settings.php:" => array("title" => __("Cacti Settings"), "mapping" => "index.php:", "url" => "settings.php", "level" => "1"),
		"settings.php:shift" => array("title" => __("Cacti Settings"), "mapping" => "index.php:", "url" => "settings.php", "level" => "1"),
		"templates_export.php:" => array("title" => __("Export Templates"), "mapping" => "index.php:", "url" => "templates_export.php", "level" => "1"),
		"templates_export.php:create" => array("title" => __("Export Templates"), "mapping" => "index.php:,templates_export.php:", "url" => "templates_export.php", "level" => "2"),
		"templates_export.php:save" => array("title" => __("Export Results"), "mapping" => "index.php:,templates_export.php:", "url" => "templates_export.php", "level" => "2"),
		"templates_import.php" => array("title" => __("Import Templates"), "mapping" => "index.php:", "url" => "templates_import.php", "level" => "1"),
		"templates_import.php:" => array("title" => __("Import Templates"), "mapping" => "index.php:", "url" => "templates_import.php", "level" => "1"),
		"templates_import.php:create" => array("title" => __("Import Templates"), "mapping" => "index.php:,templates_import.php", "url" => "templates_import.php", "level" => "1"),
		"tree.php:" => array("title" => __("Graph Trees"), "mapping" => "index.php:", "url" => "tree.php", "level" => "1"),
		"tree.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,tree.php:", "url" => "", "level" => "2"),
		"tree.php:item_edit" => array("title" => __("Graph Tree Items"), "mapping" => "index.php:,tree.php:,tree.php:edit", "url" => "", "level" => "3"),
		"tree.php:item_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,tree.php:,tree.php:edit", "url" => "", "level" => "3"),
		"tree.php:remove" => array("title" => __("(Remove)"), "mapping" => "index.php:,tree.php:", "url" => "", "level" => "2"),
		"user_admin.php:actions" => array("title" => "(Action)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"),
		"user_admin.php:" => array("title" => __("User Management"), "mapping" => "index.php:", "url" => "user_admin.php", "level" => "1"),
		"user_admin.php:graph_perms_edit" => array("title" => __("Edit (Graph Permissions)"), "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"),
		"user_admin.php:graph_settings_edit" => array("title" => __("Edit (Graph Settings)"), "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"),
		"user_admin.php:user_edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"),
		"user_admin.php:user_realms_edit" => array("title" => __("Edit (Realm Permissions)"), "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"),
		"utilities.php:" => array("title" => __("Utilities"), "mapping" => "index.php:", "url" => "utilities.php", "level" => "1"),
		"utilities.php:clear_logfile" => array("title" => __("Clear Cacti Log File"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:clear_poller_cache" => array("title" => __("Clear Poller Cache"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:clear_user_log" => array("title" => __("Clear User Log File"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:view_logfile" => array("title" => __("View Cacti Log File"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:view_poller_cache" => array("title" => __("View Poller Cache"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:view_snmp_cache" => array("title" => __("View SNMP Cache"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:view_tech" => array("title" => __("Technical Support"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"utilities.php:view_user_log" => array("title" => __("View User Log File"), "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"),
		"vdef.php:" => array("title" => __("VDEF's"), "mapping" => "index.php:", "url" => "vdef.php", "level" => "1"),
		"vdef.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,vdef.php:", "url" => "", "level" => "2"),
		"vdef.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,vdef.php:", "url" => "", "level" => "2"),
		"vdef.php:remove" => array("title" => __("(Remove)"), "mapping" => "index.php:,vdef.php:", "url" => "", "level" => "2"),
		"vdef.php:item_edit" => array("title" => __("VDEF Items"), "mapping" => "index.php:,vdef.php:,vdef.php:edit", "url" => "", "level" => "3"),
		"xaxis_presets.php:" => array("title" => __("X-Axis Presets"), "mapping" => "index.php:", "url" => "xaxis_presets.php", "level" => "1"),
		"xaxis_presets.php:edit" => array("title" => __("(Edit)"), "mapping" => "index.php:,xaxis_presets.php:", "url" => "", "level" => "2"),
		"xaxis_presets.php:item_edit" => array("title" => __("X-Axis Items"), "mapping" => "index.php:,xaxis_presets.php:,xaxis_presets.php:edit", "url" => "", "level" => "3"),
		"xaxis_presets.php:actions" => array("title" => __("Actions"), "mapping" => "index.php:,xaxis_presets.php:", "url" => "", "level" => "2"),
	);

	$nav = api_plugin_hook_function('draw_navigation_text', $nav);

	$current_page = basename($_SERVER["PHP_SELF"]);

	input_validate_input_regex(get_request_var_request("action"), "/^([a-zA-Z0-9_-]+)$/");

	$current_action = (isset($_REQUEST["action"]) ? $_REQUEST["action"] : "");

	/* find the current page in the big array */
	$current_array = $nav{$current_page . ":" . $current_action};
	$current_mappings = explode(",", $current_array["mapping"]);
	$current_nav = "";

	/* resolve all mappings to build the navigation string */
	for ($i=0; ($i<count($current_mappings)); $i++) {
		if (empty($current_mappings[$i])) { continue; }

		if  ($i == 0) {
			/* always use the default for level == 0 */
			$url = $nav{$current_mappings[$i]}["url"];
		}elseif (!empty($nav_level_cache{$i}["url"])) {
			/* found a match in the url cache for this level */
			$url = $nav_level_cache{$i}["url"];
		}elseif (!empty($current_array["url"])) {
			/* found a default url in the above array */
			$url = $current_array["url"];
		}else{
			/* default to no url */
			$url = "";
		}

		if ($current_mappings[$i] == "?") {
			/* '?' tells us to pull title from the cache at this level */
			if (isset($nav_level_cache{$i})) {
				$current_nav .= (empty($url) ? "" : "<a href='" . htmlspecialchars($url) . "'>") . resolve_navigation_variables($nav{$nav_level_cache{$i}["id"]}["title"]) . (empty($url) ? "" : "</a>") . " -&gt; ";
			}
		}else{
			/* there is no '?' - pull from the above array */
			$current_nav .= (empty($url) ? "" : "<a href='" . htmlspecialchars($url) . "'>") . resolve_navigation_variables($nav{$current_mappings[$i]}["title"]) . (empty($url) ? "" : "</a>") . " -&gt; ";
		}
	}

	$current_nav .= resolve_navigation_variables($current_array["title"]);

	/* keep a cache for each level we encounter */
	$nav_level_cache{$current_array["level"]} = array("id" => $current_page . ":" . $current_action, "url" => get_browser_query_string());
	$_SESSION["sess_nav_level_cache"] = $nav_level_cache;

	print $current_nav;
}
コード例 #12
0
ファイル: user_admin.php プロジェクト: teddywen/cacti
function form_actions()
{
    global $user_actions, $auth_realms;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        if (get_request_var_post("drp_action") != "2") {
            $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        }
        if ($selected_items != false) {
            if (get_request_var_post("drp_action") == "1") {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    user_remove($selected_items[$i]);
                    api_plugin_hook_function('user_remove', $selected_items[$i]);
                }
            }
            if (get_request_var_post("drp_action") == "2") {
                /* copy */
                /* ================= input validation ================= */
                input_validate_input_number(get_request_var_post("selected_items"));
                input_validate_input_number(get_request_var_post("new_realm"));
                /* ==================================================== */
                $new_username = get_request_var_post("new_username");
                $new_realm = get_request_var_post("new_realm", 0);
                $template_user = db_fetch_row("SELECT username, realm FROM user_auth WHERE id = " . get_request_var_post("selected_items"));
                $overwrite = array("full_name" => get_request_var_post("new_fullname"));
                if (strlen($new_username)) {
                    if (sizeof(db_fetch_assoc("SELECT username FROM user_auth WHERE username = '******' AND realm = " . $new_realm))) {
                        raise_message(19);
                    } else {
                        if (user_copy($template_user["username"], $new_username, $template_user["realm"], $new_realm, false, $overwrite) === false) {
                            raise_message(2);
                        } else {
                            raise_message(1);
                        }
                    }
                }
            }
            if (get_request_var_post("drp_action") == "3") {
                /* enable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    user_enable($selected_items[$i]);
                }
            }
            if (get_request_var_post("drp_action") == "4") {
                /* disable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    user_disable($selected_items[$i]);
                }
            }
            if (get_request_var_post("drp_action") == "5") {
                /* batch copy */
                /* ================= input validation ================= */
                input_validate_input_number(get_request_var_post("template_user"));
                /* ==================================================== */
                $copy_error = false;
                $template = db_fetch_row("SELECT username, realm FROM user_auth WHERE id = " . get_request_var_post("template_user"));
                for ($i = 0; $i < count($selected_items); $i++) {
                    $user = db_fetch_row("SELECT username, realm FROM user_auth WHERE id = " . $selected_items[$i]);
                    if (isset($user) && isset($template)) {
                        if (user_copy($template["username"], $user["username"], $template["realm"], $user["realm"], true) === false) {
                            $copy_error = true;
                        }
                    }
                }
                if ($copy_error) {
                    raise_message(2);
                } else {
                    raise_message(1);
                }
            }
        }
        header("Location: user_admin.php");
        exit;
    }
    /* loop through each of the users and process them */
    $user_list = "";
    $user_array = array();
    $i = 0;
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            if (get_request_var_post("drp_action") != "2") {
                $user_list .= "<li>" . htmlspecialchars(db_fetch_cell("SELECT username FROM user_auth WHERE id=" . $matches[1])) . "</li>";
            }
            $user_array[$i] = $matches[1];
            $i++;
        }
    }
    /* Check for deleting of Graph Export User */
    if (get_request_var_post("drp_action") == "1" && isset($user_array) && sizeof($user_array)) {
        /* delete */
        $exportuser = read_config_option('export_user_id');
        if (in_array($exportuser, $user_array)) {
            raise_message(22);
            header("Location: user_admin.php");
            exit;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $user_actions[get_request_var_post("drp_action")] . "</strong>", "60%", "", "3", "center", "");
    print "<form action='user_admin.php' method='post'>\n";
    if (isset($user_array) && sizeof($user_array)) {
        if (get_request_var_post("drp_action") == "1" && sizeof($user_array)) {
            /* delete */
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the selected User(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$user_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete User(s)'>";
        }
        $user_id = "";
        if (get_request_var_post("drp_action") == "2" && sizeof($user_array)) {
            /* copy */
            $user_id = $user_array[0];
            $user_realm = db_fetch_cell("SELECT realm FROM user_auth WHERE id = " . $user_id);
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\tWhen you click \"Continue\" the selected User will be copied to the new User below<br><br>\n\t\t\t\t\t</td>\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\tTemplate Username: <i>" . db_fetch_cell("SELECT username FROM user_auth WHERE id=" . $user_id) . "</i>\n\t\t\t\t\t</td>\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\tNew Username: "******"new_username", "", "", 25);
            print "\t\t\t\t</td>\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\tNew Full Name: ";
            print form_text_box("new_fullname", "", "", 35);
            print "\t\t\t\t</td>\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\tNew Realm: \n";
            print form_dropdown("new_realm", $auth_realms, "", "", $user_realm, "", 0);
            print "\t\t\t\t</td>\n\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Copy User'>";
        }
        if (get_request_var_post("drp_action") == "3" && sizeof($user_array)) {
            /* enable */
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the selected User(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$user_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable User(s)'>";
        }
        if (get_request_var_post("drp_action") == "4" && sizeof($user_array)) {
            /* disable */
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the selected User(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$user_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable User(s)'>";
        }
        if (get_request_var_post("drp_action") == "5" && sizeof($user_array)) {
            /* batch copy */
            $usernames = db_fetch_assoc("SELECT id,username FROM user_auth WHERE realm = 0 ORDER BY username");
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>When you click \"Continue\" you will overwrite selected the User(s) settings with the selected template User settings and permissions?  Original user Full Name, Password, Realm and Enable status will be retained, all other fields will be overwritten from Template User.<br><br></td>\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\tTemplate User: \n";
            print form_dropdown("template_user", $usernames, "username", "id", "", "", 0);
            print "\t\t</td>\n\n\t\t\t\t</tr><tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>User(s) to update:\n\t\t\t\t\t\t<ul>{$user_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reset User(s) Settings'>";
        }
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one user.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print " <tr>\n\t\t\t<td align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>";
    if (get_request_var_post("drp_action") == "2") {
        /* copy */
        print "\t\t\t\t<input type='hidden' name='selected_items' value='" . $user_id . "'>\n";
    } else {
        print "\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($user_array) ? serialize($user_array) : '') . "'>\n";
    }
    print "\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var_post("drp_action") . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
コード例 #13
0
ファイル: graphs.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $graph_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 1;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            switch ($_POST['delete_type']) {
                case '2':
                    /* delete all data sources referenced by this graph */
                    $data_sources = array_rekey(db_fetch_assoc('SELECT data_template_data.local_data_id
						FROM (data_template_rrd, data_template_data, graph_templates_item)
						WHERE graph_templates_item.task_item_id=data_template_rrd.id
						AND data_template_rrd.local_data_id=data_template_data.local_data_id
						AND ' . array_to_sql_or($selected_items, 'graph_templates_item.local_graph_id') . '
						AND data_template_data.local_data_id > 0'), 'local_data_id', 'local_data_id');
                    if (sizeof($data_sources)) {
                        api_data_source_remove_multi($data_sources);
                        api_plugin_hook_function('data_source_remove', $data_sources);
                    }
                    break;
            }
            api_graph_remove_multi($selected_items);
            api_plugin_hook_function('graphs_remove', $selected_items);
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            input_validate_input_number(get_request_var_post('graph_template_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                change_graph_template($selected_items[$i], $_POST['graph_template_id'], true);
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph($selected_items[$i], 0, $_POST['title_format']);
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                graph_to_graph_template($selected_items[$i], $_POST['title_format']);
            }
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            input_validate_input_number(get_request_var_post('tree_id'));
            input_validate_input_number(get_request_var_post('tree_item_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_GRAPH, $_POST['tree_item_id'], '', $selected_items[$i], read_graph_config_option('default_rra_id'), 0, 0, 0, false);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* change host */
            input_validate_input_number(get_request_var_post('host_id'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared('UPDATE graph_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i]));
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_graph_title($selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '7') {
            /* resize graphs */
            input_validate_input_number(get_request_var_post('graph_width'));
            input_validate_input_number(get_request_var_post('graph_height'));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_resize_graphs($selected_items[$i], $_POST['graph_width'], $_POST['graph_height']);
            }
        } else {
            api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_graphs_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('graphs_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: graphs.php');
        exit;
    }
    /* setup some variables */
    $graph_list = '';
    $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]);
            /* ==================================================== */
            $graph_list .= '<li>' . htmlspecialchars(get_graph_title($matches[1])) . '</li>';
            $graph_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $graph_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='graphs.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            $graphs = array();
            /* find out which (if any) data sources are being used by this graph, so we can tell the user */
            if (isset($graph_array) && sizeof($graph_array)) {
                $data_sources = db_fetch_assoc('select
					data_template_data.local_data_id,
					data_template_data.name_cache
					from (data_template_rrd,data_template_data,graph_templates_item)
					where graph_templates_item.task_item_id=data_template_rrd.id
					and data_template_rrd.local_data_id=data_template_data.local_data_id
					and ' . array_to_sql_or($graph_array, 'graph_templates_item.local_graph_id') . '
					and data_template_data.local_data_id > 0
					group by data_template_data.local_data_id
					order by data_template_data.name_cache');
            }
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be deleted.  Please note, Data Source(s) should be deleted only if they are only used by these Graph(s)\n\t\t\t\t\t\tand not others.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>";
            if (isset($data_sources) && sizeof($data_sources)) {
                print "<tr><td class='textArea'><p>The following Data Source(s) are in use by these Graph(s):</p>\n";
                print '<ul>';
                foreach ($data_sources as $data_source) {
                    print '<li><strong>' . $data_source['name_cache'] . "</strong></li>\n";
                }
                print '</ul>';
                print '<br>';
                form_radio_button('delete_type', '1', '2', "Leave the Data Source(s) untouched.  Not applicable for Graphs created under 'New Graphs' or WHERE the Graphs were created automatically.", '2');
                print '<br>';
                form_radio_button('delete_type', '2', '2', 'Delete all <strong>Data Source(s)</strong> referenced by these Graph(s).', '2');
                print '<br>';
                print '</td></tr>';
            }
            print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* change graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Graph Template and click \"Continue\" to change the Graph Template for\n\t\t\t\t\t\tthe following Graph(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so Graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Graph Template:</strong><br>";
            form_dropdown('graph_template_id', db_fetch_assoc('SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Graph(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<graph_title> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* graph -> graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be converted into Graph Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Graph Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<graph_title> Template', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert to Graph Template'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be placed under the Tree Branch selected below.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Graph(s) on Tree'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* change host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Graph(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Device:</strong><br>";
            form_dropdown('host_id', db_fetch_assoc("SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname"), 'name', 'id', '', '', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph(s) Associated Device'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* reapply suggested naming to host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will have thier suggested naming convensions\n\t\t\t\t\t\trecalculated and applied to the Graph(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Graph(s)'>";
        } elseif ($_POST['drp_action'] == '7') {
            /* resize graphs */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph(s) will be resized per your specifications.</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
            form_text_box('graph_height', '', '', '255', '30', 'text');
            print '</p>
						<p><strong>Graph Width:</strong><br>';
            form_text_box('graph_width', '', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['graph_list'] = $graph_list;
            $save['graph_array'] = isset($graph_array) ? $graph_array : array();
            api_plugin_hook_function('graphs_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
コード例 #14
0
ファイル: auth_login.php プロジェクト: resmon/resmon-cacti
        $message = file_get_contents("./text/forgot_mail.txt") . "http://" . $_SERVER["SERVER_NAME"] . "/index.php?a=f3&u=" . $ldap_dn_search_response["uid"]["0"] . "&h=" . substr($ldap_dn_search_response["description"]["0"], 64);
        $message = str_replace("%USERNAME%", $ldap_dn_search_response["uid"]["0"], $message);
        $errors = send_mail($mailaddr, "", "Resmon reset password", $message);
        if ($errors == "") {
            $caution_msg = "Send mail for reset password. Please read mail.";
            cacti_log("SIGNUP: send mail for reset password", false, "AUTH");
        }
    } else {
        auth_display_custom_error_message("Sorry. can't find your mail address.");
        cacti_log("SIGNUP: can't find your mail address.", false, "AUTH");
    }
}
if ($action == 'f4') {
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_request("h"), "^([a-z0-9]{64})\$");
    input_validate_input_regex(get_request_var_request("login_password"), "^([\\w\\=\\+\\-\\*\\/\\%\\^\\~\\!\\?\\&\\|\\@\\#\$\\(\\)\\[\\]\\{\\}\\<\\>\\,\\.\\;\\:]{6,})\$");
    /* ==================================================== */
    $hash2 = get_request_var_request("h");
    $password = get_request_var_request("login_password");
    include_once "./lib/ldap.php";
    $ldap_dn_search_response = cacti_ldap_search_dn("dummy", "", "", "", "", "", "", "", "", "", "description=*{$hash2}", "", "", array("uid"));
    if ($ldap_dn_search_response["error_num"] == "0") {
        $hash1 = hash_hmac('sha256', $ldap_dn_search_response["uid"]["0"] . $_SERVER["REMOTE_ADDR"] . $_SERVER["HTTP_USER_AGENT"], FALSE);
        $hash2 = hash_hmac("sha256", $ldap_dn_search_response["uid"]["0"] . time() . $password, FALSE);
        $ldap_dn_add_response = cacti_ldap_mod_dn(2, $ldap_dn_search_response["uid"]["0"], array("description" => $hash1 . $hash2, "userPassword" => $password));
        if ($ldap_dn_add_response["error_num"] == "0") {
            $caution_msg = "Reset user password successed.";
            cacti_log("SIGNUP: reset user password successed", false, "AUTH");
            setcookie("stay_login", "", time() - 3600, "/");
        }
    } else {
コード例 #15
0
ファイル: functions.php プロジェクト: MrWnn/cacti
function draw_navigation_text($type = 'url')
{
    global $config;
    $nav_level_cache = isset($_SESSION['sess_nav_level_cache']) ? $_SESSION['sess_nav_level_cache'] : array();
    $nav = array('auth_profile.php:' => array('title' => 'User Profile (Edit)', 'mapping' => '', 'url' => '', 'level' => '0'), 'graph_view.php:' => array('title' => 'Graphs', 'mapping' => '', 'url' => 'graph_view.php', 'level' => '0'), 'graph_view.php:tree' => array('title' => 'Tree Mode', 'mapping' => 'graph_view.php:', 'url' => 'graph_view.php?action=tree', 'level' => '0'), 'graph_view.php:tree_content' => array('title' => 'Tree Mode', 'mapping' => 'graph_view.php:', 'url' => 'graph_view.php?action=tree', 'level' => '0'), 'graph_view.php:list' => array('title' => 'List Mode', 'mapping' => '', 'url' => 'graph_view.php?action=list', 'level' => '0'), 'graph_view.php:preview' => array('title' => 'Preview Mode', 'mapping' => '', 'url' => 'graph_view.php?action=preview', 'level' => '0'), 'graph.php:' => array('title' => '|current_graph_title|', 'mapping' => 'graph_view.php:,?', 'level' => '2'), 'graph.php:view' => array('title' => '|current_graph_title|', 'mapping' => 'graph_view.php:,?', 'level' => '2'), 'graph.php:zoom' => array('title' => 'Zoom', 'mapping' => 'graph_view.php:,?,graph.php:view', 'level' => '3'), 'graph.php:properties' => array('title' => 'Properties', 'mapping' => 'graph_view.php:,?,graph.php:view', 'level' => '3'), 'graph_settings.php:' => array('title' => 'Settings', 'mapping' => 'graph_view.php:', 'url' => 'graph_settings.php', 'level' => '1'), 'index.php:' => array('title' => 'Console', 'mapping' => '', 'url' => $config['url_path'] . 'index.php', 'level' => '0'), 'index.php:login' => array('title' => 'Console', 'mapping' => '', 'url' => $config['url_path'] . 'index.php', 'level' => '0'), 'graphs.php:' => array('title' => 'Graph Management', 'mapping' => 'index.php:', 'url' => 'graphs.php', 'level' => '1'), 'graphs.php:graph_edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,graphs.php:', 'url' => '', 'level' => '2'), 'graphs.php:graph_diff' => array('title' => 'Change Graph Template', 'mapping' => 'index.php:,graphs.php:,graphs.php:graph_edit', 'url' => '', 'level' => '3'), 'graphs.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,graphs.php:', 'url' => '', 'level' => '2'), 'graphs_items.php:item_edit' => array('title' => 'Graph Items', 'mapping' => 'index.php:,graphs.php:,graphs.php:graph_edit', 'url' => '', 'level' => '3'), 'graphs_new.php:' => array('title' => 'Create New Graphs', 'mapping' => 'index.php:', 'url' => 'graphs_new.php', 'level' => '1'), 'graphs_new.php:save' => array('title' => 'Create Graphs from Data Query', 'mapping' => 'index.php:,graphs_new.php:', 'url' => '', 'level' => '2'), 'gprint_presets.php:' => array('title' => 'GPRINT Presets', 'mapping' => 'index.php:', 'url' => 'gprint_presets.php', 'level' => '1'), 'gprint_presets.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,gprint_presets.php:', 'url' => '', 'level' => '2'), 'gprint_presets.php:remove' => array('title' => '(Remove)', 'mapping' => 'index.php:,gprint_presets.php:', 'url' => '', 'level' => '2'), 'cdef.php:' => array('title' => 'CDEFs', 'mapping' => 'index.php:', 'url' => 'cdef.php', 'level' => '1'), 'cdef.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,cdef.php:', 'url' => '', 'level' => '2'), 'cdef.php:remove' => array('title' => '(Remove)', 'mapping' => 'index.php:,cdef.php:', 'url' => '', 'level' => '2'), 'cdef.php:item_edit' => array('title' => 'CDEF Items', 'mapping' => 'index.php:,cdef.php:,cdef.php:edit', 'url' => '', 'level' => '3'), 'cdef.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,cdef.php:', 'url' => '', 'level' => '2'), 'clog.php:' => array('title' => 'View Cacti Log', 'mapping' => '', 'url' => 'clog.php', 'level' => '0'), 'clog.php:preview' => array('title' => 'View Cacti Log', 'mapping' => '', 'url' => 'clog.php', 'level' => '0'), 'clog_user.php:' => array('title' => 'View Cacti Log', 'mapping' => '', 'url' => 'clog_user.php', 'level' => '0'), 'clog_user.php:preview' => array('title' => 'View Cacti Log', 'mapping' => '', 'url' => 'clog_user.php', 'level' => '0'), 'tree.php:' => array('title' => 'Graph Trees', 'mapping' => 'index.php:', 'url' => 'tree.php', 'level' => '1'), 'tree.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,tree.php:', 'url' => '', 'level' => '2'), 'color.php:' => array('title' => 'Colors', 'mapping' => 'index.php:', 'url' => 'color.php', 'level' => '1'), 'color.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,color.php:', 'url' => '', 'level' => '2'), 'graph_templates.php:' => array('title' => 'Graph Templates', 'mapping' => 'index.php:', 'url' => 'graph_templates.php', 'level' => '1'), 'graph_templates.php:template_edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,graph_templates.php:', 'url' => '', 'level' => '2'), 'graph_templates.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,graph_templates.php:', 'url' => '', 'level' => '2'), 'graph_templates_items.php:item_edit' => array('title' => 'Graph Template Items', 'mapping' => 'index.php:,graph_templates.php:,graph_templates.php:template_edit', 'url' => '', 'level' => '3'), 'graph_templates_inputs.php:input_edit' => array('title' => 'Graph Item Inputs', 'mapping' => 'index.php:,graph_templates.php:,graph_templates.php:template_edit', 'url' => '', 'level' => '3'), 'graph_templates_inputs.php:input_remove' => array('title' => '(Remove)', 'mapping' => 'index.php:,graph_templates.php:,graph_templates.php:template_edit', 'url' => '', 'level' => '3'), 'host_templates.php:' => array('title' => 'Device Templates', 'mapping' => 'index.php:', 'url' => 'host_templates.php', 'level' => '1'), 'host_templates.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,host_templates.php:', 'url' => '', 'level' => '2'), 'host_templates.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,host_templates.php:', 'url' => '', 'level' => '2'), 'graph_templates.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,graph_templates.php:', 'url' => '', 'level' => '2'), 'data_templates.php:' => array('title' => 'Data Templates', 'mapping' => 'index.php:', 'url' => 'data_templates.php', 'level' => '1'), 'data_templates.php:template_edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,data_templates.php:', 'url' => '', 'level' => '2'), 'data_templates.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,data_templates.php:', 'url' => '', 'level' => '2'), 'data_sources.php:' => array('title' => 'Data Sources', 'mapping' => 'index.php:', 'url' => 'data_sources.php', 'level' => '1'), 'data_sources.php:ds_edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,data_sources.php:', 'url' => '', 'level' => '2'), 'data_sources.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,data_sources.php:', 'url' => '', 'level' => '2'), 'host.php:' => array('title' => 'Devices', 'mapping' => 'index.php:', 'url' => 'host.php', 'level' => '1'), 'host.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,host.php:', 'url' => '', 'level' => '2'), 'host.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,host.php:', 'url' => '', 'level' => '2'), 'rra.php:' => array('title' => 'Round Robin Archives', 'mapping' => 'index.php:', 'url' => 'rra.php', 'level' => '1'), 'rra.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,rra.php:', 'url' => '', 'level' => '2'), 'rra.php:remove' => array('title' => '(Remove)', 'mapping' => 'index.php:,rra.php:', 'url' => '', 'level' => '2'), 'data_input.php:' => array('title' => 'Data Input Methods', 'mapping' => 'index.php:', 'url' => 'data_input.php', 'level' => '1'), 'data_input.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,data_input.php:', 'url' => '', 'level' => '2'), 'data_input.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,data_input.php:', 'url' => '', 'level' => '2'), 'data_input.php:remove' => array('title' => '(Remove)', 'mapping' => 'index.php:,data_input.php:', 'url' => '', 'level' => '2'), 'data_input.php:field_edit' => array('title' => 'Data Input Fields', 'mapping' => 'index.php:,data_input.php:,data_input.php:edit', 'url' => '', 'level' => '3'), 'data_input.php:field_remove' => array('title' => '(Remove Item)', 'mapping' => 'index.php:,data_input.php:,data_input.php:edit', 'url' => '', 'level' => '3'), 'data_queries.php:' => array('title' => 'Data Queries', 'mapping' => 'index.php:', 'url' => 'data_queries.php', 'level' => '1'), 'data_queries.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,data_queries.php:', 'url' => '', 'level' => '2'), 'data_queries.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,data_queries.php:', 'url' => '', 'level' => '2'), 'data_queries.php:item_edit' => array('title' => 'Associated Graph Templates', 'mapping' => 'index.php:,data_queries.php:,data_queries.php:edit', 'url' => '', 'level' => '3'), 'data_queries.php:item_remove' => array('title' => '(Remove Item)', 'mapping' => 'index.php:,data_queries.php:,data_queries.php:edit', 'url' => '', 'level' => '3'), 'rrdcleaner.php:' => array('title' => 'RRD Cleaner', 'mapping' => 'index.php:', 'url' => 'rrdcleaner.php', 'level' => '1'), 'rrdcleaner.php:actions' => array('title' => 'Actions', 'mapping' => 'index.php:,rrdcleaner.php:', 'url' => 'rrdcleaner.php?action=actions', 'level' => '2'), 'rrdcleaner.php:restart' => array('title' => 'List unused Files', 'mapping' => 'rrdcleaner.php:', 'url' => 'rrdcleaner.php?action=restart', 'level' => '2'), 'utilities.php:' => array('title' => 'Utilities', 'mapping' => 'index.php:', 'url' => 'utilities.php', 'level' => '1'), 'utilities.php:view_poller_cache' => array('title' => 'View Poller Cache', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:view_snmp_cache' => array('title' => 'View SNMP Cache', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:clear_poller_cache' => array('title' => 'View Poller Cache', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:view_logfile' => array('title' => 'View Cacti Log File', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:clear_logfile' => array('title' => 'Clear Cacti Log File', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:view_user_log' => array('title' => 'View User Log File', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:clear_user_log' => array('title' => 'Clear User Log File', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:view_tech' => array('title' => 'Technical Support', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'utilities.php:view_boost_status' => array('title' => 'Boost Status', 'mapping' => 'index.php:,utilities.php:', 'url' => 'utilities.php', 'level' => '2'), 'settings.php:' => array('title' => 'Cacti Settings', 'mapping' => 'index.php:', 'url' => 'settings.php', 'level' => '1'), 'user_admin.php:' => array('title' => 'Users', 'mapping' => 'index.php:', 'url' => 'user_admin.php', 'level' => '1'), 'user_admin.php:user_edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,user_admin.php:', 'url' => '', 'level' => '2'), 'user_admin.php:actions' => array('title' => '(Action)', 'mapping' => 'index.php:,user_admin.php:', 'url' => '', 'level' => '2'), 'user_domains.php:' => array('title' => 'User Domains', 'mapping' => 'index.php:', 'url' => 'user_domains.php', 'level' => '1'), 'user_domains.php:edit' => array('title' => '(Edit)', 'mapping' => 'user_domains.php:,index.php:', 'url' => 'user_domains.php:edit', 'level' => '2'), 'user_group_admin.php:' => array('title' => 'User Groups', 'mapping' => 'index.php:', 'url' => 'user_group_admin.php', 'level' => '1'), 'user_group_admin.php:edit' => array('title' => '(Edit)', 'mapping' => 'index.php:,user_group_admin.php:', 'url' => '', 'level' => '2'), 'user_group_admin.php:actions' => array('title' => '(Action)', 'mapping' => 'index.php:,user_group_admin.php:', 'url' => '', 'level' => '2'), 'about.php:' => array('title' => 'About Cacti', 'mapping' => 'index.php:', 'url' => 'about.php', 'level' => '1'), 'templates_export.php:' => array('title' => 'Export Templates', 'mapping' => 'index.php:', 'url' => 'templates_export.php', 'level' => '1'), 'templates_export.php:save' => array('title' => 'Export Results', 'mapping' => 'index.php:,templates_export.php:', 'url' => 'templates_export.php', 'level' => '2'), 'templates_import.php:' => array('title' => 'Import Templates', 'mapping' => 'index.php:', 'url' => 'templates_import.php', 'level' => '1'), 'reports_admin.php:' => array('title' => 'Reporting', 'mapping' => '', 'url' => 'reports_admin.php', 'level' => '0'), 'reports_admin.php:actions' => array('title' => 'Report Add', 'mapping' => 'reports_admin.php:', 'url' => 'reports_admin.php', 'level' => '1'), 'reports_admin.php:delete' => array('title' => 'Report Delete', 'mapping' => 'reports_admin.php:', 'url' => 'reports_admin.php', 'level' => '1'), 'reports_admin.php:edit' => array('title' => 'Report Edit', 'mapping' => 'reports_admin.php:', 'url' => 'reports_admin.php?action=edit', 'level' => '1'), 'reports_admin.php:item_edit' => array('title' => 'Report Edit Item', 'mapping' => 'reports_admin.php:,reports_admin.php:edit', 'url' => '', 'level' => '2'), 'reports_user.php:' => array('title' => 'Reporting', 'mapping' => '', 'url' => 'reports_user.php', 'level' => '0'), 'reports_user.php:actions' => array('title' => 'Report Add', 'mapping' => 'reports_user.php:', 'url' => 'reports_user.php', 'level' => '1'), 'reports_user.php:delete' => array('title' => 'Report Delete', 'mapping' => 'reports_user.php:', 'url' => 'reports_user.php', 'level' => '1'), 'reports_user.php:edit' => array('title' => 'Report Edit', 'mapping' => 'reports_user.php:', 'url' => 'reports_user.php?action=edit', 'level' => '1'), 'reports_user.php:item_edit' => array('title' => 'Report Edit Item', 'mapping' => 'reports_user.php:,reports_user.php:edit', 'url' => '', 'level' => '2'));
    $nav = api_plugin_hook_function('draw_navigation_text', $nav);
    $current_page = basename($_SERVER['PHP_SELF']);
    input_validate_input_regex(get_request_var_request('action'), '^([a-zA-Z0-9_-]+)$');
    $current_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    /* find the current page in the big array */
    if (isset($nav[$current_page . ':' . $current_action])) {
        $current_array = $nav[$current_page . ':' . $current_action];
    } else {
        $current_array = array('mapping' => 'index.php:', 'title' => ucwords(str_replace('_', ' ', basename($_SERVER['PHP_SELF'], '.php'))), 'level' => 1);
    }
    $current_mappings = explode(',', $current_array['mapping']);
    $current_nav = "<ul id='breadcrumbs'>";
    $title = '';
    $nav_count = 0;
    /* resolve all mappings to build the navigation string */
    for ($i = 0; $i < count($current_mappings); $i++) {
        if (empty($current_mappings[$i])) {
            continue;
        }
        if ($i == 0) {
            /* always use the default for level == 0 */
            $url = $nav[$current_mappings[$i]]['url'];
            if (basename($url) == 'graph_view.php') {
                continue;
            }
        } elseif (isset($nav_level_cache[$i]) && !empty($nav_level_cache[$i]['url'])) {
            /* found a match in the url cache for this level */
            $url = $nav_level_cache[$i]['url'];
        } elseif (!empty($current_array['url'])) {
            /* found a default url in the above array */
            $url = $current_array['url'];
        } else {
            /* default to no url */
            $url = '';
        }
        if ($current_mappings[$i] == '?') {
            /* '?' tells us to pull title from the cache at this level */
            if (isset($nav_level_cache[$i])) {
                $current_nav .= (empty($url) ? '' : "<li><a id='nav_{$i}' href='" . htmlspecialchars($url) . "'>") . htmlspecialchars(resolve_navigation_variables($nav[$nav_level_cache[$i]['id']]['title'])) . (empty($url) ? '' : '</a>' . (read_config_option('selected_theme') == 'classic' ? ' -> ' : '') . '</li>');
                $title .= htmlspecialchars(resolve_navigation_variables($nav[$nav_level_cache[$i]['id']]['title'])) . ' -> ';
            }
        } else {
            /* there is no '?' - pull from the above array */
            $current_nav .= (empty($url) ? '' : "<li><a id='nav_{$i}' href='" . htmlspecialchars($url) . "'>") . htmlspecialchars(resolve_navigation_variables($nav[$current_mappings[$i]]['title'])) . (empty($url) ? '' : '</a>' . (read_config_option('selected_theme') == 'classic' ? ' -> ' : '') . '</li>');
            $title .= htmlspecialchars(resolve_navigation_variables($nav[$current_mappings[$i]]['title'])) . ' -> ';
        }
        $nav_count++;
    }
    if ($nav_count) {
        $current_nav .= "<li><a id='nav_{$i}' href=#>" . htmlspecialchars(resolve_navigation_variables($current_array['title'])) . '</a></li>';
    } else {
        $current_array = $nav[$current_page . ':' . $current_action];
        $url = isset($current_array['url']) ? $current_array['url'] : '';
        $current_nav .= "<li><a id='nav_{$i}' href='{$url}'>" . htmlspecialchars(resolve_navigation_variables($current_array['title'])) . '</a></li>';
    }
    if (isset($_REQUEST['tree_id']) || isset($_REQUEST['leaf_id'])) {
        $leaf_sub = '';
        $leaf_name = '';
        $tree_name = '';
        if (isset($_REQUEST['leaf_id']) && $_REQUEST['leaf_id'] != '') {
            $leaf = db_fetch_row_prepared('SELECT * FROM graph_tree_items WHERE id = ?', array($_REQUEST['leaf_id']));
            if (sizeof($leaf)) {
                if ($leaf['host_id'] > 0) {
                    $leaf_name = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($leaf['host_id']));
                } else {
                    $leaf_name = $leaf['title'];
                }
                $tree_name = db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($leaf['graph_tree_id']));
            } else {
                $leaf_name = 'Leaf';
            }
            if (isset($_REQUEST['host_group_data']) && $_REQUEST['host_group_data'] != '') {
                $parts = explode(':', $_REQUEST['host_group_data']);
                input_validate_input_number($parts[1]);
                if ($parts[0] == 'graph_template') {
                    $leaf_sub = db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($parts[1]));
                } else {
                    if ($parts[1] > 0) {
                        $leaf_sub = db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($parts[1]));
                    } else {
                        $leaf_sub = 'Non Query Based';
                    }
                }
            } else {
                $leaf_sub = '';
            }
        } else {
            $leaf_name = '';
            if (isset($_REQUEST['tree_id'])) {
                $tree_name = db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($_REQUEST['tree_id']));
            } else {
                $tree_name = '';
            }
        }
        $tree_title = $tree_name . ($leaf_name != '' ? ' (' . $leaf_name : '') . ($leaf_sub != '' ? ':' . $leaf_sub . ')' : ($leaf_name != '' ? ')' : ''));
        $current_nav .= "<li><a id='nav_title' href=#>" . htmlspecialchars($tree_title) . '</a></li></ul>';
    } else {
        $current_nav .= '</ul>';
        $tree_title = '';
    }
    $title .= htmlspecialchars(resolve_navigation_variables($current_array['title']) . ' ' . $tree_title);
    /* keep a cache for each level we encounter */
    $nav_level_cache[$current_array['level']] = array('id' => $current_page . ':' . $current_action, 'url' => get_browser_query_string());
    $_SESSION['sess_nav_level_cache'] = $nav_level_cache;
    if ($type == 'url') {
        return $current_nav;
    } else {
        return $title;
    }
}
コード例 #16
0
ファイル: graph_view_form.php プロジェクト: songchin/Cacti
function get_graph_list_content() {
	global $graphs_per_page;
	global $colors;
	require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php");

	/* Make sure nothing is cached */
	header("Cache-Control: must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Expires: ". gmdate("D, d M Y H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-1, date("d"), date("Y")))." GMT");
	header("Last-Modified: ". gmdate("D, d M Y H:i:s")." GMT");

	$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]);

	define("MAX_DISPLAY_PAGES", 21);

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("graph_template_id"));
	input_validate_input_regex(get_request_var_request('graph_list'), "/^([\,0-9]+)$/");
	input_validate_input_regex(get_request_var_request('graph_add'), "/^([\,0-9]+)$/");
	input_validate_input_regex(get_request_var_request('graph_remove'), "/^([\,0-9]+)$/");
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
	}

	if ((read_config_option("auth_method") != 0) && (empty($current_user["show_list"]))) {
		print "<strong><font size='+1' color='FF0000'>" . __("YOU DO NOT HAVE RIGHTS FOR LIST VIEW") . "</font></strong>"; exit;
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_view_list_current_page");
		kill_session_var("sess_graph_view_list_filter");
		kill_session_var("sess_graph_view_list_device");
		kill_session_var("sess_graph_view_list_graph_template");
		kill_session_var("sess_graph_view_list_graphs");
		kill_session_var("sess_graph_view_list_graph_list");
		kill_session_var("sess_graph_view_list_graph_add");
		kill_session_var("sess_graph_view_list_graph_remove");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["device_id"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graphs"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* save selected graphs into url, for backward compatibility */
	if (!empty($_REQUEST["graph_list"])) {
		foreach (explode(",",get_request_var_request("graph_list")) as $item) {
			$graph_list[$item] = 1;
		}
	}else{
		$graph_list = array();
	}

	load_current_session_value("device_id", "sess_graph_view_list_device", "0");
	load_current_session_value("graph_template_id", "sess_graph_view_list_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_list_filter", "");
	load_current_session_value("page", "sess_graph_view_list_current_page", "1");
	load_current_session_value("graphs", "sess_graph_view_list_graphs", read_graph_config_option("list_graphs_per_page"));
	load_current_session_value("graph_list", "sess_graph_view_list_graph_list", "");
	load_current_session_value("graph_add", "sess_graph_view_list_graph_add", "");
	load_current_session_value("graph_remove", "sess_graph_view_list_graph_remove", "");

	if (is_array(get_request_var_request("graph_list"))) {
		$graph_list = $_REQUEST["graph_list"];
	}

	if (!empty($_REQUEST["graph_add"])) {
		foreach (explode(",",get_request_var_request("graph_add")) as $item) {
			$graph_list[$item] = 1;
		}
	}
	/* remove items */
	if (!empty($_REQUEST["graph_remove"])) {
		foreach (explode(",",get_request_var_request("graph_remove")) as $item) {
			unset($graph_list[$item]);
		}
	}
	$_SESSION["sess_graph_view_list_graph_list"] = $graph_list;

	/* display graph view filter selector */
	html_start_box("", "100", $colors["header"], "0", "center", "");

	?>

	<tr class='rowGraphFilter noprint'>
		<td>
			<script type="text/javascript">
			<!--
			$().ready(function() {
				$("#device").autocomplete("./lib/ajax/get_devices_brief.php", { max: 12, highlight: false, scroll: true, scrollHeight: 300 });
				$("#device").result(function(event, data, formatted) {
					if (data) {
						$(this).parent().find("#device_id").val(data[1]);
						applyGraphListFilterChange(document.form_graph_list);
					}
				});
				SetSelections();
			});

			function applyGraphListFilterChange(objForm, strURL) {
				form_graph(document.chk, document.form_graph_list)

				if (!strURL || strURL == '') {
					strURL = "?action=ajax_preview&";
				}else{
					strURL = strURL + "&action=ajax_list&";
				}

				strURL = strURL + 'device_id=' + objForm.device_id.value;
				strURL = strURL + '&graph_template_id=' + objForm.graph_template_id.value;
				strURL = strURL + '&graphs=' + objForm.graphs.value;
				strURL = strURL + '&filter=' + objForm.filter.value;
				strURL = strURL + '&graph_remove=' + objForm.graph_remove.value;
				strURL = strURL + '&graph_add=' + objForm.graph_add.value;
				$.get("graph_view.php" + strURL, function (data) {
					$("#graph_content").html(data);
					SetSelections();
				});
			}

			function clearFilter(objForm) {
				strURL = '?clear_x=true';
				$.get("graph_view.php?action=ajax_list" + strURL, function (data) {
					$("#graph_content").html(data);
				});
			}

			function form_graph(objForm,objFormSubmit) {
				var strAdd = '';
				var strDel = '';
				for(var i = 0; i < objForm.elements.length; i++) {
					if (objForm.elements[i].name.substring(0,4) == 'chk_') {
						if (objForm.elements[i].checked) {
							strAdd = strAdd + objForm.elements[i].name.substring(4) + ',';
						} else {
							if (objForm.elements[i].value != '') {
								strDel = strDel + objForm.elements[i].name.substring(4) + ',';
							}
						}
					}
				}
				strAdd = strAdd.substring(0,strAdd.length - 1);
				strDel = strDel.substring(0,strDel.length - 1);
				objFormSubmit.graph_add.value = strAdd;
				objFormSubmit.graph_remove.value = strDel;
			}

			function pageChange(page) {
				strURL = '?page=' + page;
				applyGraphListFilterChange(document.form_graph_list, strURL);
			}

			function showGraphs(objForm) {
				form_graph(document.chk, document.form_graph_list)
				strURL = '?action=ajax_preview&list=true';
				strURL = strURL + '&graph_remove=' + objForm.graph_remove.value;
				strURL = strURL + '&graph_add=' + objForm.graph_add.value;
				$.get("graph_view.php" + strURL, function (data) {
					$("#graph_content").html(data);
				});
			}

			//-->
			</script>
			<form name="form_graph_list" action="graph_view.php" method="post">
			<input type='hidden' name='graph_add' value=''>
			<input type='hidden' name='graph_remove' value=''>
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class='w1'>
						&nbsp;<?php print __("Device:");?>&nbsp;
					</td>
					<td class="w1">
						<?php
						if (isset($_REQUEST["device_id"])) {
							$hostname = db_fetch_cell("SELECT description as name FROM device WHERE id=".$_REQUEST["device_id"]." ORDER BY description,hostname");
						} else {
							$hostname = "";
						}
						?>
						<input class="ac_field" type="text" id="device" size="30" value="<?php print $hostname; ?>">
						<input type="hidden" id="device_id">
					</td>
					<td class='w1'>
						&nbsp;<?php print __("Template:");?>&nbsp;
					</td>
					<td class='w1'>
						<select name="graph_template_id" onChange="applyGraphListFilterChange(document.form_graph_list)">
							<option value="0"<?php print get_request_var_request("filter");?><?php if (get_request_var_request("device_id") == "0") {?> selected<?php }?>><?php print __("Any");?></option>
							<?php
							if (read_config_option("auth_method") != 0) {
								$graph_templates = db_fetch_assoc("SELECT DISTINCT graph_templates.*
									FROM (graph_templates_graph,graph_local)
									LEFT JOIN device ON (device.id=graph_local.device_id)
									LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
									LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))
									WHERE graph_templates_graph.local_graph_id=graph_local.id " .
									"AND graph_templates_graph.graph_template_id > 0 " .
									(($_REQUEST["device_id"] > 0) ? " and graph_local.device_id=" . $_REQUEST["device_id"] :" and graph_local.device_id > 0 ") . "
									" . (empty($sql_where) ? "" : "and $sql_where") . "
									ORDER BY name");
							}else{
								$graph_templates = db_fetch_assoc("SELECT DISTINCT graph_templates.* " .
										"FROM graph_templates " .
										"INNER JOIN graph_local " .
										"ON graph_templates.id=graph_local.graph_template_id" .
										(($_REQUEST["device_id"] > 0) ? " WHERE device_id=" . $_REQUEST["device_id"] :"") .
										" GROUP BY graph_templates.name " .
										" ORDER BY name");
							}

							if (sizeof($graph_templates) > 0) {
							foreach ($graph_templates as $template) {
								print "<option value='" . $template["id"] . "'"; if (get_request_var_request("graph_template_id") == $template["id"]) { print " selected"; } print ">" . $template["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw100">
						&nbsp;<?php print __("Graphs/Page:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="graphs" onChange="applyGraphListFilterChange(document.form_graph_list)">
							<?php
							if (sizeof($graphs_per_page) > 0) {
							foreach ($graphs_per_page as $key => $value) {
								print "\t\t\t\t\t\t\t<option value='" . $key . "'"; if ((isset($_REQUEST["graphs"])) && ($_REQUEST["graphs"] == $key)) { print " selected"; } print ">" . $value . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class='w1'>
						&nbsp;<?php print __("Search:");?>&nbsp;
					</td>
					<td class="w1">
						<input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td>
						&nbsp;<input type="submit" value="<?php print __("Go");?>" name="go">
						<input type="button" value="<?php print __("Clear");?>" name="clear" onClick='clearFilter(document.form_graph_list)'>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php
	html_graph_end_box(TRUE);

	/* create filter for sql */
	$sql_filter = "";
	$sql_filter .= (empty($_REQUEST["filter"]) ? "" : " graph_templates_graph.title_cache like '%" . $_REQUEST["filter"] . "%'");
	$sql_filter .= (empty($_REQUEST["device_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.device_id=" . $_REQUEST["device_id"]);
	$sql_filter .= (empty($_REQUEST["graph_template_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]);

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		/* get policy information for the sql where clause */
		$sql_where = "where " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]);
		$sql_join = "left join device on (device.id=graph_local.device_id)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";

	}else{
		$sql_where = "";
		$sql_join = "";
	}

	$sql_base = "from (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "where" : "and") . " graph_templates_graph.local_graph_id > 0
		and graph_templates_graph.local_graph_id=graph_local.id
		and graph_templates_graph.title_cache like '%" . get_request_var_request("filter") . "%'
		" . (empty($_REQUEST["device_id"]) ? "" : " and graph_local.device_id=" . $_REQUEST["device_id"]) . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]);

	$total_rows = count(db_fetch_assoc("select
		graph_templates_graph.local_graph_id
		$sql_base"));
	$graphs = db_fetch_assoc("select
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache,
		graph_templates_graph.height,
		graph_templates_graph.width
		$sql_base
		group by graph_templates_graph.local_graph_id
		order by graph_templates_graph.title_cache
		limit " . (get_request_var_request("graphs")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graphs"));
	?>
	<form name='chk' id='chk' action='graph_view.php' method='get' onSubmit='form_graph(document.chk,document.chk)'>
	<?php

	html_start_box("", "100", $colors["header"], "0", "center", "");

	if ($total_rows > get_request_var_request("graphs")) {
		$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["graphs"], $total_rows, "pageChange");

		$nav = "\t\t\t<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' style='width:100px;' class='textHeaderDark'>";
		if ($_REQUEST["page"] > 1) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]-1) . ")'>&lt;&lt;&nbsp;Previous</a></strong>"; }
		$nav .= "</td>\n
							<td align='center' class='textHeaderDark'>
								Showing Graphs " . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("graphs")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
							</td>\n
							<td align='right' style='width:100px;' class='textHeaderDark'>";
		if (($_REQUEST["page"] * $_REQUEST["graphs"]) < $total_rows) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]+1) . ")'>Next &gt;&gt;</a></strong>"; }
		$nav .= "</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}else{
		$nav = "<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='center' class='textHeaderDark'>
								" . __("Showing All Graphs") . (strlen(get_request_var_request("filter")) ? " [ " . __("Filter") . " '" . get_request_var_request("filter") . "' " . __("Applied") . " ]" : "") . "
							</td>
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	print $nav;

	?>
	<tr class='rowSubHeader noprint'>
		<td colspan='3'>
			<table width='100%' cellspacing='0' cellpadding='0' style='border-width:0px;'>
				<tr>
					<?php
					print "<td width='1%' align='left' class='textHeaderDark' style='padding:2px;'><input type='checkbox' style='margin: 0px 0px 0px 1px;' name='all' title='Select All' onClick='SelectAll(\"chk_\",this.checked)'></td><td class='textSubHeaderDark'><strong>Select All</strong></td>\n";
					?>
				</tr>
			</table>
		</td>
	</tr>
	<?php

	if (sizeof($graphs) > 0) {
		foreach ($graphs as $graph) {
			form_alternate_row_color('line' . $graph["local_graph_id"], true);
			if (isset($graph_list[$graph["local_graph_id"]])) {
				$checked = true;
			}else{
				$checked = false;
			}
			form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"], $checked);
			form_selectable_cell("<strong><a href='" . htmlspecialchars("graph.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=all") . "'>" . $graph["title_cache"] . "</a></strong>", $graph["local_graph_id"]);
			form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]);
			form_end_row();
		}
	}
	?>
	<tr class='rowSubHeader'>
		<td colspan='3'>
			<table width='100%' cellspacing='0' cellpadding='0' style='border-width:0px'>
				<tr><?php
					print "<td width='1%' align='right' class='textHeaderDark' style='padding:2px;'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"chk_\",this.checked)'></td><td class='textSubHeaderDark'><strong>Select All</strong></td>\n";
					?>
				</tr>
			</table>
		</td>
	</tr>
	<?php html_graph_end_box(FALSE);?>
	<table align='center' style='background-color:#FFFFFF;' width='100%'>
		<tr>
			<td width='1'><img src='images/arrow.gif' alt='' align='middle'>&nbsp;</td>
			<td><input onClick='showGraphs(document.form_graph_list)' type='button' title='<?php print __("View Graphs");?>' value='<?php print __("View Graphs");?>' alt='<?php print __("View");?>'></td>
		</tr>
	</table>
	<input type='hidden' name='page' value='1'>
	<input type='hidden' name='style' value='selective'>
	<input type='hidden' name='action' value='preview'>
	<input type='hidden' name='graph_add' value=''>
	<input type='hidden' name='graph_remove' value=''>
	</form><?php
}
コード例 #17
0
ファイル: data_input.php プロジェクト: songchin/Cacti
function field_edit()
{
    global $colors, $registered_cacti_names, $fields_data_input_field_edit_1, $fields_data_input_field_edit_2, $fields_data_input_field_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    input_validate_input_number(get_request_var("data_input_id"));
    input_validate_input_regex(get_request_var("type"), "^(in|out)\$");
    /* ==================================================== */
    if (!empty($_GET["id"])) {
        $field = db_fetch_row("select * from data_input_fields where id=" . $_GET["id"]);
    }
    if (!empty($_GET["type"])) {
        $current_field_type = $_GET["type"];
    } else {
        $current_field_type = $field["input_output"];
    }
    if ($current_field_type == "out") {
        $header_name = "Output";
    } elseif ($current_field_type == "in") {
        $header_name = "Input";
    }
    $data_input = db_fetch_row("select type_id,name from data_input where id=" . $_GET["data_input_id"]);
    /* obtain a list of available fields for this given field type (input/output) */
    if ($current_field_type == "in" && preg_match_all("/<([_a-zA-Z0-9]+)>/", db_fetch_cell("select input_string from data_input where id=" . ($_GET["data_input_id"] ? $_GET["data_input_id"] : $field["data_input_id"])), $matches)) {
        for ($i = 0; $i < count($matches[1]); $i++) {
            if (in_array($matches[1][$i], $registered_cacti_names) == false) {
                $current_field_name = $matches[1][$i];
                $array_field_names[$current_field_name] = $current_field_name;
            }
        }
    }
    /* if there are no input fields to choose from, complain */
    if (!isset($array_field_names) && (isset($_GET["type"]) ? $_GET["type"] == "in" : false) && $data_input["type_id"] == "1") {
        display_custom_error_message("This script appears to have no input values, therefore there is nothing to add.");
        return;
    }
    html_start_box("<strong>{$header_name} Fields</strong> [edit: " . $data_input["name"] . "]", "100%", $colors["header"], "3", "center", "");
    $form_array = array();
    /* field name */
    if (($data_input["type_id"] == "1" || $data_input["type_id"] == "5") && $current_field_type == "in") {
        /* script */
        $form_array = inject_form_variables($fields_data_input_field_edit_1, $header_name, $array_field_names, isset($field) ? $field : array());
    } elseif ($data_input["type_id"] == "2" || $data_input["type_id"] == "3" || $data_input["type_id"] == "4" || $data_input["type_id"] == "6" || $data_input["type_id"] == "7" || $data_input["type_id"] == "8" || $current_field_type == "out") {
        /* snmp */
        $form_array = inject_form_variables($fields_data_input_field_edit_2, $header_name, isset($field) ? $field : array());
    }
    /* ONLY if the field is an input */
    if ($current_field_type == "in") {
        unset($fields_data_input_field_edit["update_rra"]);
    } elseif ($current_field_type == "out") {
        unset($fields_data_input_field_edit["regexp_match"]);
        unset($fields_data_input_field_edit["allow_nulls"]);
        unset($fields_data_input_field_edit["type_code"]);
    }
    draw_edit_form(array("config" => array(), "fields" => $form_array + inject_form_variables($fields_data_input_field_edit, isset($field) ? $field : array(), $current_field_type, $_GET)));
    html_end_box();
    form_save_button("data_input.php?action=edit&id=" . $_GET["data_input_id"]);
}
コード例 #18
0
ファイル: plugins.php プロジェクト: MrWnn/cacti
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
include './include/auth.php';
define('MAX_DISPLAY_PAGES', 21);
$actions = array('install' => 'Install', 'enable' => 'Enable', 'disable' => 'Disable', 'uninstall' => 'Uninstall');
$status_names = array(-2 => 'Disabled', -1 => 'Active', 0 => 'Not Installed', 1 => 'Active', 2 => 'Awaiting Configuration', 3 => 'Awaiting Upgrade', 4 => 'Installed');
/* get the comprehensive list of plugins */
$pluginslist = retrieve_plugin_list();
/* Check to see if we are installing, etc... */
$modes = array('installold', 'uninstallold', 'install', 'uninstall', 'disable', 'enable', 'check', 'moveup', 'movedown');
if (isset($_REQUEST['mode']) && in_array($_REQUEST['mode'], $modes) && isset($_REQUEST['id'])) {
    input_validate_input_regex(get_request_var_request('id'), '^([a-zA-Z0-9]+)$');
    $mode = $_REQUEST['mode'];
    $id = sanitize_search_string($_REQUEST['id']);
    switch ($mode) {
        case 'installold':
            if (!in_array($id, $plugins_integrated)) {
                api_plugin_install_old($id);
            }
            header('Location: plugins.php');
            exit;
            break;
        case 'uninstallold':
            api_plugin_uninstall_old($id);
            header('Location: plugins.php');
            exit;
            break;
コード例 #19
0
ファイル: graph_view.php プロジェクト: teddywen/cacti
*/
$guest_account = true;
include './include/auth.php';
include_once './lib/html_tree.php';
include_once './lib/timespan_settings.php';
define("MAX_DISPLAY_PAGES", 21);
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('branch_id'));
input_validate_input_number(get_request_var_request('hide'));
input_validate_input_number(get_request_var_request('tree_id'));
input_validate_input_number(get_request_var_request('leaf_id'));
input_validate_input_number(get_request_var_request('rra_id'));
input_validate_input_regex(get_request_var_request('graph_list'), '^([\\,0-9]+)$');
input_validate_input_regex(get_request_var_request('graph_add'), '^([\\,0-9]+)$');
input_validate_input_regex(get_request_var_request('graph_remove'), '^([\\,0-9]+)$');
input_validate_input_regex(get_request_var_request('nodeid'), '^([_a-z0-9]+)$');
/* ==================================================== */
/* clean up action string */
if (isset($_REQUEST['action'])) {
    $_REQUEST['action'] = sanitize_search_string(get_request_var_request('action'));
}
/* setup tree selection defaults if the user has not been here before */
if (!isset($_REQUEST['action'])) {
    if (!isset($_SESSION['sess_graph_view_action'])) {
        if (read_graph_config_option('default_view_mode') == '1') {
            $_REQUEST['action'] = 'tree';
        } elseif (read_graph_config_option('default_view_mode') == '2') {
            $_REQUEST['action'] = 'list';
        } elseif (read_graph_config_option('default_view_mode') == '3') {
            $_REQUEST['action'] = 'preview';
        }
コード例 #20
0
function mactrack_view_graphs() {
	global $current_user, $colors, $config;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("rra_id"));
	input_validate_input_regex(get_request_var_request('graph_list'), "^([\,0-9]+)$");
	input_validate_input_regex(get_request_var_request('graph_add'), "^([\,0-9]+)$");
	input_validate_input_regex(get_request_var_request('graph_remove'), "^([\,0-9]+)$");
	/* ==================================================== */

	define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("graph_template_id"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
	}

	$sql_or = ""; $sql_where = ""; $sql_join = "";

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_view_current_page");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_graph_template");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* reset the page counter to '1' if a search in initiated */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["page"] = "1";
	}

	load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("page", "sess_graph_view_current_page", "1");

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		$sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);

		$sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)
			LEFT JOIN graph_templates
			ON (graph_templates.id=graph_local.graph_template_id)
			LEFT JOIN user_auth_perms
			ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id
			AND user_auth_perms.type=1
			AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}else{
		$sql_where = "";
		$sql_join = "";
	}
	/* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
	if (isset($_REQUEST["style"])) {
		if ($_REQUEST["style"] == "selective") {

			/* process selected graphs */
			if (! empty($_REQUEST["graph_list"])) {
				foreach (explode(",",$_REQUEST["graph_list"]) as $item) {
					$graph_list[$item] = 1;
				}
			}else{
				$graph_list = array();
			}
			if (! empty($_REQUEST["graph_add"])) {
				foreach (explode(",",$_REQUEST["graph_add"]) as $item) {
					$graph_list[$item] = 1;
				}
			}
			/* remove items */
			if (! empty($_REQUEST["graph_remove"])) {
				foreach (explode(",",$_REQUEST["graph_remove"]) as $item) {
					unset($graph_list[$item]);
				}
			}

			$i = 0;
			foreach ($graph_list as $item => $value) {
				$graph_array[$i] = $item;
				$i++;
			}

			if ((isset($graph_array)) && (sizeof($graph_array) > 0)) {
				/* build sql string including each graph the user checked */
				$sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");

				/* clear the filter vars so they don't affect our results */
				$_REQUEST["filter"]  = "";

				$set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
			}
		}
	}

	$sql_base = "FROM (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0
		AND graph_templates_graph.local_graph_id=graph_local.id
		" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'":"") . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "
		$sql_or";

	$total_rows = count(db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id
		$sql_base"));

	/* reset the page if you have changed some settings */
	if (ROWS_PER_PAGE * ($_REQUEST["page"]-1) >= $total_rows) {
		$_REQUEST["page"] = "1";
	}

	$graphs = db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache
		$sql_base
		GROUP BY graph_templates_graph.local_graph_id
		ORDER BY graph_templates_graph.title_cache
		LIMIT " . (ROWS_PER_PAGE*($_REQUEST["page"]-1)) . "," . ROWS_PER_PAGE);

	?>
	<script type="text/javascript">
	<!--
	function applyGraphPreviewFilterChange(objForm) {
		strURL = '?report=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php

	/* include graph view filter selector */
	display_output_messages();
	mactrack_tabs();
	html_start_box("<strong>Network Device Graphs</strong>", "100%", $colors["header"], "1", "center", "");
	mactrack_graph_view_filter();

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		mactrack_timespan_selector();
	}
	html_end_box();

	/* do some fancy navigation url construction so we don't have to try and rebuild the url string */
	if (ereg("page=[0-9]+",basename($_SERVER["QUERY_STRING"]))) {
		$nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
	}else{
		$nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
	}

	$nav_url = ereg_replace("((\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);

	html_start_box("", "100%", $colors["header"], "3", "center", "");
	mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	if (read_graph_config_option("thumbnail_section_preview") == "on") {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	if ($total_rows) {
		mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	}
	html_end_box();
}
コード例 #21
0
ファイル: graph.php プロジェクト: nexusvista/cacti
}
if (!isset($_REQUEST["view_type"])) {
    $_REQUEST["view_type"] = "";
}
$guest_account = true;
include "./include/auth.php";
include_once "./lib/rrd.php";
api_plugin_hook_function('graph');
include_once "./lib/html_tree.php";
include_once "./include/top_graph_header.php";
/* ================= input validation ================= */
input_validate_input_regex(get_request_var("rra_id"), "^([0-9]+|all)\$");
input_validate_input_number(get_request_var("local_graph_id"));
input_validate_input_number(get_request_var("graph_end"));
input_validate_input_number(get_request_var("graph_start"));
input_validate_input_regex(get_request_var_request("view_type"), "^([a-zA-Z0-9]+)\$");
/* ==================================================== */
if (!isset($_GET['rra_id'])) {
    $_GET['rra_id'] = 'all';
}
if ($_GET["rra_id"] == "all") {
    $sql_where = " where id is not null";
} else {
    $sql_where = " where id=" . $_GET["rra_id"];
}
/* make sure the graph requested exists (sanity) */
if (!db_fetch_cell("select local_graph_id from graph_templates_graph where local_graph_id=" . $_GET["local_graph_id"])) {
    print "<strong><font size='+1' color='FF0000'>GRAPH DOES NOT EXIST</font></strong>";
    exit;
}
/* take graph permissions into account here, if the user does not have permission
コード例 #22
0
ファイル: index.php プロジェクト: resmon/resmon-cacti
     input_validate_input_regex(get_request_var_request("login_password"), "^([\\w\\=\\+\\-\\*\\/\\%\\^\\~\\!\\?\\&\\|\\@\\#\$\\(\\)\\[\\]\\{\\}\\<\\>\\,\\.\\;\\:]{6,})\$");
     $username = db_fetch_cell("SELECT user_auth.username FROM user_auth WHERE user_auth.id = '" . $_SESSION["sess_user_id"] . "'");
     if ($username) {
         for ($i = 1; $i <= 10; $i++) {
             $salt .= substr('0123456789abcdef', rand(0, 15), 1);
         }
         $password = "******" . base64_encode(pack("H*", sha1(get_request_var_request("login_password") . $salt)) . $salt);
         //$password = get_request_var_request("login_password");
         include_once "./lib/ldap.php";
         $ldap_dn_add_response = cacti_ldap_mod_dn(2, $username, array("userPassword" => $password));
         if ($ldap_dn_add_response["error_num"] == "0") {
             $message = "Change user password successed.";
         }
     }
 } elseif ($_REQUEST["action"] === "mail_address") {
     input_validate_input_regex(get_request_var_request("mail_address"), "^([A-Za-z0-9]+[\\w-]*@[\\w\\.-]+\\.\\w{2,})\$");
     $username = db_fetch_cell("SELECT user_auth.username FROM user_auth WHERE user_auth.id = '" . $_SESSION["sess_user_id"] . "'");
     if ($username) {
         $mailaddr = get_request_var_request("mail_address");
         include_once "./lib/ldap.php";
         $ldap_dn_search_response = cacti_ldap_search_dn("dummy", "", "", "", "", "", "", "", "", "", "mail={$mailaddr}");
         if ($ldap_dn_search_response["error_num"] == "0") {
             $message = "mail address is already in use.";
         } else {
             $ldap_dn_add_response = cacti_ldap_mod_dn(2, $username, array("mail" => $mailaddr));
             if ($ldap_dn_add_response["error_num"] == "0") {
                 $message = "Change mail address successed.";
             }
         }
     }
 } elseif ($_REQUEST["action"] === "deactivate") {
コード例 #23
0
ファイル: data_input.php プロジェクト: MrWnn/cacti
function field_edit()
{
    global $registered_cacti_names, $fields_data_input_field_edit_1, $fields_data_input_field_edit_2, $fields_data_input_field_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    input_validate_input_number(get_request_var_request('data_input_id'));
    input_validate_input_regex(get_request_var_request('type'), '^(in|out)$');
    /* ==================================================== */
    if (!empty($_REQUEST['id'])) {
        $field = db_fetch_row_prepared('SELECT * FROM data_input_fields WHERE id = ?', array(get_request_var_request('id')));
    }
    if (!empty($_REQUEST['type'])) {
        $current_field_type = $_REQUEST['type'];
    } else {
        $current_field_type = $field['input_output'];
    }
    if ($current_field_type == 'out') {
        $header_name = 'Output';
    } elseif ($current_field_type == 'in') {
        $header_name = 'Input';
    }
    $data_input = db_fetch_row_prepared('SELECT type_id, name FROM data_input WHERE id = ?', array(get_request_var_request('data_input_id')));
    /* obtain a list of available fields for this given field type (input/output) */
    if ($current_field_type == 'in' && preg_match_all('/<([_a-zA-Z0-9]+)>/', db_fetch_cell_prepared('SELECT input_string FROM data_input WHERE id = ?', array($_REQUEST['data_input_id'] ? $_REQUEST['data_input_id'] : $field['data_input_id'])), $matches)) {
        for ($i = 0; $i < count($matches[1]); $i++) {
            if (in_array($matches[1][$i], $registered_cacti_names) == false) {
                $current_field_name = $matches[1][$i];
                $array_field_names[$current_field_name] = $current_field_name;
            }
        }
    }
    /* if there are no input fields to choose from, complain */
    if (!isset($array_field_names) && (isset($_REQUEST['type']) ? $_REQUEST['type'] == 'in' : false) && $data_input['type_id'] == '1') {
        display_custom_error_message('This script appears to have no input values, therefore there is nothing to add.');
        return;
    }
    html_start_box("<strong>{$header_name} Fields</strong> [edit: " . htmlspecialchars($data_input['name']) . ']', '100%', '', '3', 'center', '');
    $form_array = array();
    /* field name */
    if (($data_input['type_id'] == '1' || $data_input['type_id'] == '5') && $current_field_type == 'in') {
        /* script */
        $form_array = inject_form_variables($fields_data_input_field_edit_1, $header_name, $array_field_names, isset($field) ? $field : array());
    } elseif ($data_input['type_id'] == '2' || $data_input['type_id'] == '3' || $data_input['type_id'] == '4' || $data_input['type_id'] == '6' || $data_input['type_id'] == '7' || $data_input['type_id'] == '8' || $current_field_type == 'out') {
        /* snmp */
        $form_array = inject_form_variables($fields_data_input_field_edit_2, $header_name, isset($field) ? $field : array());
    }
    /* ONLY if the field is an input */
    if ($current_field_type == 'in') {
        unset($fields_data_input_field_edit['update_rra']);
    } elseif ($current_field_type == 'out') {
        unset($fields_data_input_field_edit['regexp_match']);
        unset($fields_data_input_field_edit['allow_nulls']);
        unset($fields_data_input_field_edit['type_code']);
    }
    draw_edit_form(array('config' => array(), 'fields' => $form_array + inject_form_variables($fields_data_input_field_edit, isset($field) ? $field : array(), $current_field_type, $_REQUEST)));
    html_end_box();
    form_save_button('data_input.php?action=edit&id=' . $_REQUEST['data_input_id']);
}
コード例 #24
0
ファイル: cdef.php プロジェクト: teddywen/cacti
function form_actions()
{
    global $cdef_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        if ($selected_items != false) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                db_execute("delete from cdef where " . array_to_sql_or($selected_items, "id"));
                db_execute("delete from cdef_items where " . array_to_sql_or($selected_items, "cdef_id"));
            } elseif ($_POST["drp_action"] == "2") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_cdef($selected_items[$i], $_POST["title_format"]);
                }
            }
        }
        header("Location: cdef.php");
        exit;
    }
    /* setup some variables */
    $cdef_list = "";
    $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]);
            /* ==================================================== */
            $cdef_list .= "<li>" . htmlspecialchars(db_fetch_cell("select name from cdef where id=" . $matches[1])) . "</li>";
            $cdef_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    print "<form action='cdef.php' method='post'>\n";
    html_start_box("<strong>" . $cdef_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
    if (isset($cdef_array) && sizeof($cdef_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the folling CDEF(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$cdef_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete CDEF(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following CDEFs will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new CDEFs.</p>\n\t\t\t\t\t\t<p><ul>{$cdef_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<cdef_title> (1)", "", "255", "30", "text");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate CDEF(s)'>";
        }
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one CDEF.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($cdef_array) ? serialize($cdef_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
コード例 #25
0
ファイル: data_sources.php プロジェクト: teddywen/cacti
function form_actions()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        if ($selected_items != false) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 1;
                }
                switch ($_POST["delete_type"]) {
                    case '2':
                        /* delete all graph items tied to this data source */
                        $data_template_rrds = array_rekey(db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")), "id", "id");
                        /* loop through each data source item */
                        if (sizeof($data_template_rrds) > 0) {
                            db_execute("delete from graph_templates_item where task_item_id IN (" . implode(",", $data_template_rrds) . ") and local_graph_id > 0");
                        }
                        api_plugin_hook_function('graph_items_remove', $data_template_rrds);
                        break;
                    case '3':
                        /* delete all graphs tied to this data source */
                        $graphs = array_rekey(db_fetch_assoc("select\n\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"), "local_graph_id", "local_graph_id");
                        if (sizeof($graphs) > 0) {
                            api_graph_remove_multi($graphs);
                        }
                        api_plugin_hook_function('graphs_remove', $graphs);
                        break;
                }
                api_data_source_remove_multi($selected_items);
                api_plugin_hook_function('data_source_remove', $selected_items);
            } elseif ($_POST["drp_action"] == "2") {
                /* change graph template */
                input_validate_input_number(get_request_var_post("data_template_id"));
                for ($i = 0; $i < count($selected_items); $i++) {
                    change_data_template($selected_items[$i], $_POST["data_template_id"]);
                }
            } elseif ($_POST["drp_action"] == "3") {
                /* change host */
                input_validate_input_number(get_request_var_post("host_id"));
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute("update data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
                    push_out_host($_POST["host_id"], $selected_items[$i]);
                    update_data_source_title_cache($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "4") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]);
                }
            } elseif ($_POST["drp_action"] == "5") {
                /* data source -> data template */
                for ($i = 0; $i < count($selected_items); $i++) {
                    data_source_to_data_template($selected_items[$i], $_POST["title_format"]);
                }
            } elseif ($_POST["drp_action"] == "6") {
                /* data source enable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_data_source_enable($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "7") {
                /* data source disable */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_data_source_disable($selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "8") {
                /* reapply suggested data source naming */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_reapply_suggested_data_source_title($selected_items[$i]);
                    update_data_source_title_cache($selected_items[$i]);
                }
            } else {
                api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']);
            }
            api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items));
        }
        header("Location: data_sources.php");
        exit;
    }
    /* setup some variables */
    $ds_list = "";
    $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]);
            /* ==================================================== */
            $ds_list .= "<li>" . htmlspecialchars(get_data_source_title($matches[1])) . "</li>";
            $ds_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
    print "<form action='data_sources.php' method='post'>\n";
    if (isset($ds_array) && sizeof($ds_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            $graphs = array();
            /* find out which (if any) graphs are using this data source, so we can tell the user */
            if (isset($ds_array)) {
                $graphs = db_fetch_assoc("select\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\tand " . array_to_sql_or($ds_array, "data_template_rrd.local_data_id") . "\n\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\tgroup by graph_templates_graph.local_graph_id\n\t\t\t\t\torder by graph_templates_graph.title_cache");
            }
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>";
            if (sizeof($graphs) > 0) {
                print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n";
                print "<ul>";
                foreach ($graphs as $graph) {
                    print "<li><strong>" . $graph["title_cache"] . "</strong></li>\n";
                }
                print "</ul>";
                print "<br>";
                form_radio_button("delete_type", "3", "1", "Leave the Graph(s) untouched.", "1");
                print "<br>";
                form_radio_button("delete_type", "3", "2", "Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).", "1");
                print "<br>";
                form_radio_button("delete_type", "3", "3", "Delete all <strong>Graph(s)</strong> that reference these Data Source(s).", "1");
                print "<br>";
                print "</td></tr>";
            }
            print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Source(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>";
            form_dropdown("data_template_id", db_fetch_assoc("select data_template.id,data_template.name from data_template order by data_template.name"), "name", "id", "", "", "0");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* change host */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Host:</strong><br>";
            form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<ds_title> (1)", "", "255", "30", "text");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Data Source(s)'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* data source -> data template */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<ds_title> Template", "", "255", "30", "text");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* data source enable */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Data Source(s)'>";
        } elseif ($_POST["drp_action"] == "7") {
            /* data source disable */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Data Source(s)'>";
        } elseif ($_POST["drp_action"] == "8") {
            /* reapply suggested data source naming */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['ds_list'] = $ds_list;
            $save['ds_array'] = isset($ds_array) ? $ds_array : array();
            api_plugin_hook_function('data_source_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one data source.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
コード例 #26
0
ファイル: data_queries.php プロジェクト: teddywen/cacti
function form_actions()
{
    global $dq_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']);
        if ($selected_items != false) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    data_query_remove($selected_items[$i]);
                }
            }
        }
        header("Location: data_queries.php");
        exit;
    }
    /* setup some variables */
    $dq_list = "";
    $i = 0;
    /* loop through each of the data queries and process them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $dq_list .= "<li>" . htmlspecialchars(db_fetch_cell("SELECT snmp_query.name FROM snmp_query WHERE id='" . $matches[1] . "'")) . "</li>";
            $dq_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $dq_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
    print "<form action='data_queries.php' method='post'>\n";
    if (isset($dq_array) && sizeof($dq_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            $graphs = array();
            print "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='textArea' class='odd'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Data Querie(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$dq_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
        }
        $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Querie(s)'>";
    } else {
        print "<tr><td class='odd'><span class='textError'>You must select at least one data query.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($dq_array) ? serialize($dq_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
コード例 #27
0
ファイル: host.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
						FROM graph_local
						WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id'));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph['local_graph_id'];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST['delete_type']) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('tree_id'));
                input_validate_input_number(get_request_var_post('tree_item_id'));
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false);
            }
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: host.php');
        exit;
    }
    /* setup some variables */
    $host_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]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '2') {
            /* Enable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $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));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $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));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>';
            form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.', '1');
            print '<br>';
            form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1');
            print '<br>';
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
						<p><strong>Destination Branch:</strong><br>';
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } 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='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
コード例 #28
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config;
    if (file_exists("./lib/timespan_settings.php")) {
        include "./lib/timespan_settings.php";
    } else {
        include "./include/html/inc_timespan_settings.php";
    }
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("rra_id"));
    input_validate_input_number(get_request_var("host"));
    input_validate_input_number(get_request_var("cols"));
    input_validate_input_regex(get_request_var_request('graph_list'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_add'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_remove'), "^([\\,0-9]+)\$");
    /* ==================================================== */
    define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("graph_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["style"])) {
        $_REQUEST["style"] = sanitize_search_string(get_request_var_request("style"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["thumb"])) {
        $_REQUEST["thumb"] = sanitize_search_string(get_request_var_request("thumb"));
    }
    $sql_or = "";
    $sql_where = "";
    $sql_join = "";
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["reset"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
    } elseif (isset($_REQUEST["clear"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host"]);
        unset($_REQUEST["cols"]);
        unset($_REQUEST["thumb"]);
        unset($_REQUEST["graph_template_id"]);
        unset($_REQUEST["graph_list"]);
        unset($_REQUEST["graph_add"]);
        unset($_REQUEST["style"]);
        unset($_REQUEST["graph_remove"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed("fitler", "sess_mikrotik_graph_filter");
        $changed += mikrotik_check_changed("host", "sess_mikrotik_graph_host");
        $changed += mikrotik_check_changed("style", "sess_mikrotik_graph_style");
        $changed += mikrotik_check_changed("graph_add", "sess_mikrotik_graph_add");
        $changed += mikrotik_check_changed("graph_template_id", "sess_mikrotik_graph_graph_template");
        if ($changed) {
            $_REQUEST["page"] = "1";
            $_REQUEST["style"] = "";
            $_REQUEST["graph_add"] = "";
        }
    }
    load_current_session_value("graph_template_id", "sess_mikrotik_graph_graph_template", "0");
    load_current_session_value("host", "sess_mikrotik_graph_host", "0");
    load_current_session_value("cols", "sess_mikrotik_graph_cols", "2");
    load_current_session_value("thumb", "sess_mikrotik_graph_thumb", "true");
    load_current_session_value("graph_add", "sess_mikrotik_graph_add", "");
    load_current_session_value("style", "sess_mikrotik_graph_style", "");
    load_current_session_value("filter", "sess_mikrotik_graph_filter", "");
    load_current_session_value("page", "sess_mikrotik_graph_current_page", "1");
    if ($_REQUEST["graph_add"] != "") {
        $_REQUEST["style"] = "selective";
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        $sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates\n\t\t\tON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms\n\t\t\tON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id\n\t\t\tAND user_auth_perms.type=1\n\t\t\tAND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
    } else {
        $sql_where = "";
        $sql_join = "";
    }
    /* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
    if (isset($_REQUEST["style"])) {
        if ($_REQUEST["style"] == "selective") {
            /* process selected graphs */
            if (!empty($_REQUEST["graph_list"])) {
                foreach (explode(",", $_REQUEST["graph_list"]) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST["graph_add"])) {
                foreach (explode(",", $_REQUEST["graph_add"]) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST["graph_remove"])) {
                foreach (explode(",", $_REQUEST["graph_remove"]) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
                /* clear the filter vars so they don't affect our results */
                $_REQUEST["filter"] = "";
                $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
            }
        }
    }
    $sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" : "") . "\n\t\t" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "\n\t\t" . (empty($_REQUEST["host"]) ? "" : " and graph_local.host_id=" . $_REQUEST["host"]) . "\n\t\t{$sql_or}";
    $total_rows = count(db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
    /* reset the page if you have changed some settings */
    if (ROWS_PER_PAGE * ($_REQUEST["page"] - 1) >= $total_rows) {
        $_REQUEST["page"] = "1";
    }
    $graphs = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.title_cache\n\t\t{$sql_base}\n\t\tGROUP BY graph_templates_graph.local_graph_id\n\t\tORDER BY graph_templates_graph.title_cache\n\t\tLIMIT " . ROWS_PER_PAGE * ($_REQUEST["page"] - 1) . "," . ROWS_PER_PAGE);
    ?>
	<script type="text/javascript">
	<!--
	function applyGraphWReset(objForm) {
		strURL = '?action=graphs&reset=1&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	function applyGraphWOReset(objForm) {
		strURL = '?action=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Host MIB Graphs" . ($_REQUEST["style"] == "selective" ? " (Custom Selective Filter)" : "") . "</strong>", "100%", $colors["header"], "1", "center", "");
    mikrotik_graph_view_filter();
    /* include time span selector */
    if (read_graph_config_option("timespan_sel") == "on") {
        mikrotik_timespan_selector();
    }
    html_end_box();
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) {
        $nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
    } else {
        $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
    }
    $nav_url = ereg_replace("((\\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    mikrotik_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "", $_REQUEST["cols"], $_REQUEST["thumb"]);
    if ($total_rows) {
        mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    }
    html_end_box();
}
コード例 #29
0
ファイル: functions.php プロジェクト: songchin/Cacti
function draw_navigation_text()
{
    $nav_level_cache = isset($_SESSION["sess_nav_level_cache"]) ? $_SESSION["sess_nav_level_cache"] : array();
    $nav = array("graph_view.php:" => array("title" => "Graphs", "mapping" => "", "url" => "graph_view.php", "level" => "0"), "graph_view.php:tree" => array("title" => "Tree Mode", "mapping" => "graph_view.php:", "url" => "graph_view.php?action=tree", "level" => "1"), "graph_view.php:list" => array("title" => "List Mode", "mapping" => "graph_view.php:", "url" => "graph_view.php?action=list", "level" => "1"), "graph_view.php:preview" => array("title" => "Preview Mode", "mapping" => "graph_view.php:", "url" => "graph_view.php?action=preview", "level" => "1"), "graph.php:" => array("title" => "|current_graph_title|", "mapping" => "graph_view.php:,?", "level" => "2"), "graph.php:view" => array("title" => "|current_graph_title|", "mapping" => "graph_view.php:,?", "level" => "2"), "graph.php:zoom" => array("title" => "Zoom", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"), "graph.php:properties" => array("title" => "Properties", "mapping" => "graph_view.php:,?,graph.php:view", "level" => "3"), "graph_settings.php:" => array("title" => "Settings", "mapping" => "graph_view.php:", "url" => "graph_settings.php", "level" => "1"), "index.php:" => array("title" => "Console", "mapping" => "", "url" => "index.php", "level" => "0"), "graphs.php:" => array("title" => "Graph Management", "mapping" => "index.php:", "url" => "graphs.php", "level" => "1"), "graphs.php:graph_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"), "graphs.php:graph_diff" => array("title" => "Change Graph Template", "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"), "graphs.php:actions" => array("title" => "Actions", "mapping" => "index.php:,graphs.php:", "url" => "", "level" => "2"), "graphs_items.php:item_edit" => array("title" => "Graph Items", "mapping" => "index.php:,graphs.php:,graphs.php:graph_edit", "url" => "", "level" => "3"), "graphs_new.php:" => array("title" => "Create New Graphs", "mapping" => "index.php:", "url" => "graphs_new.php", "level" => "1"), "graphs_new.php:save" => array("title" => "Create Graphs from Data Query", "mapping" => "index.php:,graphs_new.php:", "url" => "", "level" => "2"), "gprint_presets.php:" => array("title" => "GPRINT Presets", "mapping" => "index.php:", "url" => "gprint_presets.php", "level" => "1"), "gprint_presets.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,gprint_presets.php:", "url" => "", "level" => "2"), "gprint_presets.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,gprint_presets.php:", "url" => "", "level" => "2"), "cdef.php:" => array("title" => "CDEF's", "mapping" => "index.php:", "url" => "cdef.php", "level" => "1"), "cdef.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,cdef.php:", "url" => "", "level" => "2"), "cdef.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,cdef.php:", "url" => "", "level" => "2"), "cdef.php:item_edit" => array("title" => "CDEF Items", "mapping" => "index.php:,cdef.php:,cdef.php:edit", "url" => "", "level" => "3"), "tree.php:" => array("title" => "Graph Trees", "mapping" => "index.php:", "url" => "tree.php", "level" => "1"), "tree.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,tree.php:", "url" => "", "level" => "2"), "tree.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,tree.php:", "url" => "", "level" => "2"), "tree.php:item_edit" => array("title" => "Graph Tree Items", "mapping" => "index.php:,tree.php:,tree.php:edit", "url" => "", "level" => "3"), "tree.php:item_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,tree.php:,tree.php:edit", "url" => "", "level" => "3"), "color.php:" => array("title" => "Colors", "mapping" => "index.php:", "url" => "color.php", "level" => "1"), "color.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,color.php:", "url" => "", "level" => "2"), "graph_templates.php:" => array("title" => "Graph Templates", "mapping" => "index.php:", "url" => "graph_templates.php", "level" => "1"), "graph_templates.php:template_edit" => array("title" => "(Edit)", "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"), "graph_templates.php:actions" => array("title" => "Actions", "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"), "graph_templates_items.php:item_edit" => array("title" => "Graph Template Items", "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"), "graph_templates_inputs.php:input_edit" => array("title" => "Graph Item Inputs", "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"), "graph_templates_inputs.php:input_remove" => array("title" => "(Remove)", "mapping" => "index.php:,graph_templates.php:,graph_templates.php:template_edit", "url" => "", "level" => "3"), "host_templates.php:" => array("title" => "Host Templates", "mapping" => "index.php:", "url" => "host_templates.php", "level" => "1"), "host_templates.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,host_templates.php:", "url" => "", "level" => "2"), "host_templates.php:actions" => array("title" => "Actions", "mapping" => "index.php:,host_templates.php:", "url" => "", "level" => "2"), "graph_templates.php:actions" => array("title" => "Actions", "mapping" => "index.php:,graph_templates.php:", "url" => "", "level" => "2"), "data_templates.php:" => array("title" => "Data Templates", "mapping" => "index.php:", "url" => "data_templates.php", "level" => "1"), "data_templates.php:template_edit" => array("title" => "(Edit)", "mapping" => "index.php:,data_templates.php:", "url" => "", "level" => "2"), "data_templates.php:actions" => array("title" => "Actions", "mapping" => "index.php:,data_templates.php:", "url" => "", "level" => "2"), "data_sources.php:" => array("title" => "Data Sources", "mapping" => "index.php:", "url" => "data_sources.php", "level" => "1"), "data_sources.php:ds_edit" => array("title" => "(Edit)", "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"), "data_sources.php:actions" => array("title" => "Actions", "mapping" => "index.php:,data_sources.php:", "url" => "", "level" => "2"), "host.php:" => array("title" => "Devices", "mapping" => "index.php:", "url" => "host.php", "level" => "1"), "host.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,host.php:", "url" => "", "level" => "2"), "host.php:actions" => array("title" => "Actions", "mapping" => "index.php:,host.php:", "url" => "", "level" => "2"), "rra.php:" => array("title" => "Round Robin Archives", "mapping" => "index.php:", "url" => "rra.php", "level" => "1"), "rra.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,rra.php:", "url" => "", "level" => "2"), "rra.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,rra.php:", "url" => "", "level" => "2"), "data_input.php:" => array("title" => "Data Input Methods", "mapping" => "index.php:", "url" => "data_input.php", "level" => "1"), "data_input.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,data_input.php:", "url" => "", "level" => "2"), "data_input.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,data_input.php:", "url" => "", "level" => "2"), "data_input.php:field_edit" => array("title" => "Data Input Fields", "mapping" => "index.php:,data_input.php:,data_input.php:edit", "url" => "", "level" => "3"), "data_input.php:field_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,data_input.php:,data_input.php:edit", "url" => "", "level" => "3"), "data_queries.php:" => array("title" => "Data Queries", "mapping" => "index.php:", "url" => "data_queries.php", "level" => "1"), "data_queries.php:edit" => array("title" => "(Edit)", "mapping" => "index.php:,data_queries.php:", "url" => "", "level" => "2"), "data_queries.php:remove" => array("title" => "(Remove)", "mapping" => "index.php:,data_queries.php:", "url" => "", "level" => "2"), "data_queries.php:item_edit" => array("title" => "Associated Graph Templates", "mapping" => "index.php:,data_queries.php:,data_queries.php:edit", "url" => "", "level" => "3"), "data_queries.php:item_remove" => array("title" => "(Remove Item)", "mapping" => "index.php:,data_queries.php:,data_queries.php:edit", "url" => "", "level" => "3"), "utilities.php:" => array("title" => "Utilities", "mapping" => "index.php:", "url" => "utilities.php", "level" => "1"), "utilities.php:view_poller_cache" => array("title" => "View Poller Cache", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:view_snmp_cache" => array("title" => "View SNMP Cache", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:clear_poller_cache" => array("title" => "Clear Poller Cache", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:view_logfile" => array("title" => "View Cacti Log File", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:clear_logfile" => array("title" => "Clear Cacti Log File", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:view_user_log" => array("title" => "View User Log File", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "utilities.php:clear_user_log" => array("title" => "Clear User Log File", "mapping" => "index.php:,utilities.php:", "url" => "utilities.php", "level" => "2"), "settings.php:" => array("title" => "Cacti Settings", "mapping" => "index.php:", "url" => "settings.php", "level" => "1"), "user_admin.php:" => array("title" => "User Management", "mapping" => "index.php:", "url" => "user_admin.php", "level" => "1"), "user_admin.php:user_edit" => array("title" => "(Edit)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"), "user_admin.php:user_remove" => array("title" => "(Remove)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"), "user_admin.php:graph_perms_edit" => array("title" => "Edit (Graph Permissions)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"), "user_admin.php:user_realms_edit" => array("title" => "Edit (Realm Permissions)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"), "user_admin.php:graph_settings_edit" => array("title" => "Edit (Graph Settings)", "mapping" => "index.php:,user_admin.php:", "url" => "", "level" => "2"), "about.php:" => array("title" => "About Cacti", "mapping" => "index.php:", "url" => "about.php", "level" => "1"), "templates_export.php:" => array("title" => "Export Templates", "mapping" => "index.php:", "url" => "templates_export.php", "level" => "1"), "templates_export.php:save" => array("title" => "Export Results", "mapping" => "index.php:,templates_export.php:", "url" => "templates_export.php", "level" => "2"), "templates_import.php:" => array("title" => "Import Templates", "mapping" => "index.php:", "url" => "templates_import.php", "level" => "1"));
    $current_page = basename($_SERVER["PHP_SELF"]);
    input_validate_input_regex(get_request_var_request("action"), "^([a-zA-Z0-9_-]+)\$");
    $current_action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "";
    /* find the current page in the big array */
    $current_array = $nav[$current_page . ":" . $current_action];
    $current_mappings = split(",", $current_array["mapping"]);
    $current_nav = "";
    /* resolve all mappings to build the navigation string */
    for ($i = 0; $i < count($current_mappings); $i++) {
        if (empty($current_mappings[$i])) {
            continue;
        }
        if ($i == 0) {
            /* always use the default for level == 0 */
            $url = $nav[$current_mappings[$i]]["url"];
        } elseif (!empty($nav_level_cache[$i]["url"])) {
            /* found a match in the url cache for this level */
            $url = $nav_level_cache[$i]["url"];
        } elseif (!empty($current_array["url"])) {
            /* found a default url in the above array */
            $url = $current_array["url"];
        } else {
            /* default to no url */
            $url = "";
        }
        if ($current_mappings[$i] == "?") {
            /* '?' tells us to pull title from the cache at this level */
            if (isset($nav_level_cache[$i])) {
                $current_nav .= (empty($url) ? "" : "<a href='{$url}'>") . resolve_navigation_variables($nav[$nav_level_cache[$i]["id"]]["title"]) . (empty($url) ? "" : "</a>") . " -> ";
            }
        } else {
            /* there is no '?' - pull from the above array */
            $current_nav .= (empty($url) ? "" : "<a href='{$url}'>") . resolve_navigation_variables($nav[$current_mappings[$i]]["title"]) . (empty($url) ? "" : "</a>") . " -> ";
        }
    }
    $current_nav .= resolve_navigation_variables($current_array["title"]);
    /* keep a cache for each level we encounter */
    $nav_level_cache[$current_array["level"]] = array("id" => $current_page . ":" . $current_action, "url" => get_browser_query_string());
    $_SESSION["sess_nav_level_cache"] = $nav_level_cache;
    print $current_nav;
}
コード例 #30
0
ファイル: graph_templates.php プロジェクト: MrWnn/cacti
function form_actions()
{
    global $graph_actions;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$");
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "1") {
            /* delete */
            db_execute("DELETE FROM graph_templates WHERE " . array_to_sql_or($selected_items, "id"));
            $graph_template_input = db_fetch_assoc("SELECT id FROM graph_template_input WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
            if (sizeof($graph_template_input) > 0) {
                foreach ($graph_template_input as $item) {
                    db_execute("DELETE FROM graph_template_input_defs WHERE graph_template_input_id=" . $item["id"]);
                }
            }
            db_execute("DELETE FROM graph_template_input WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("DELETE FROM graph_templates_graph WHERE " . array_to_sql_or($selected_items, "graph_template_id") . " AND local_graph_id=0");
            db_execute("DELETE FROM graph_templates_item WHERE " . array_to_sql_or($selected_items, "graph_template_id") . " AND local_graph_id=0");
            db_execute("DELETE FROM host_template_graph WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
            /* "undo" any graph that is currently using this template */
            db_execute("UPDATE graph_templates_graph SET local_graph_template_graph_id=0,graph_template_id=0 WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("UPDATE graph_templates_item SET local_graph_template_item_id=0,graph_template_id=0 WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("UPDATE graph_local SET graph_template_id=0 WHERE " . array_to_sql_or($selected_items, "graph_template_id"));
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph(0, $selected_items[$i], $_POST["title_format"]);
            }
        }
        header("Location: graph_templates.php");
        exit;
    }
    /* setup some variables */
    $graph_list = "";
    $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]);
            /* ==================================================== */
            $graph_list .= "<li>" . htmlspecialchars(db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . $matches[1])) . "<br>";
            $graph_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", "");
    print "<form action='graph_templates.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph Template(s) will be deleted.  Any Graph(s) associated with\n\t\t\t\t\t\tthe Template(s) will become individual Graph(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph Template(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Graph Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Graph Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text");
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph Template(s)'>";
        }
    } else {
        print "<tr><td class='even'><p><span class='textError'>ERROR: You must select at least one graph template.</span></p></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}