/*
+-------------------------------------------------------------------------+
| Copyright (C) 2002 Ian Berry |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| cacti: the rrdtool frontend [php-auth, php-tree, php-form] |
+-------------------------------------------------------------------------+
| This code is currently maintained and debugged by Ian Berry, any |
| questions or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/?>
$section = "User Administration"; include ('include/auth.php');
include_once ("include/form.php");
switch ($_REQUEST["action"]) {
case 'save':
$redirect_location = form_save();
header ("Location: $redirect_location"); exit;
break;
case 'user_remove':
user_remove();
header ("Location: user_auth.php");
break;
case 'graph_config_edit':
include_once ("include/top_header.php");
graph_config_edit();
include_once ("include/bottom_footer.php");
break;
case 'graph_perms_edit':
include_once ("include/top_header.php");
graph_perms_edit();
include_once ("include/bottom_footer.php");
break;
case 'user_edit':
include_once ("include/top_header.php");
user_edit();
include_once ("include/bottom_footer.php");
break;
default:
include_once ("include/top_header.php");
user();
include_once ("include/bottom_footer.php");
break;
}
/* --------------------------
Global Form Functions
-------------------------- */
function draw_user_form_select() {
global $colors; ?>
">
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
global $config;
if ((isset($_POST["save_component_user"])) && (isset($_POST["save_component_graph_perms"])) && (isset($_POST["save_component_graph_config"]))) {
user_save();
graph_perms_save();
/* graph_config_save(); */
return "user_admin.php?action=user_edit&id=" . $_POST["user_id"];
}elseif (isset($_POST["save_component_user"])) {
user_save();
return "user_admin.php";
}elseif (isset($_POST["save_component_graph_perms"])) {
graph_perms_save();
return "user_admin.php";
}elseif (isset($_POST["save_component_graph_config"])) {
/* graph_config_save(); */
return "user_admin.php";
}
}
/* --------------------------
Graph Permissions
-------------------------- */
function graph_perms_save() {
db_execute ("delete from auth_graph where userid=" . $_POST["user_id"]);
db_execute ("delete from auth_graph_hierarchy where userid=" . $_POST["user_id"]);
reset($_POST);
while (list($var, $val) = each($_POST)) {
if (eregi("^[graph|tree]", $var)) {
if (substr($var, 0, 5) == "graph") {
db_execute ("replace into auth_graph (userid,graphid) values(" . $_POST["user_id"] . "," . substr($var, 5) . ")");
}elseif (substr($var, 0, 4) == "tree") {
db_execute ("replace into auth_graph_hierarchy (userid,hierarchyid) values(" . $_POST["user_id"] . "," . substr($var, 4) . ")");
}
}
}
}
function graph_perms_edit() {
global $colors, $config;
if (isset($_GET["id"])) {
$graph_policy = db_fetch_cell("select GraphPolicy from auth_users where id=" . $_GET["id"]);
if ($graph_policy == "1") {
$graph_policy_text = "DENIED";
}elseif ($graph_policy == "2") {
$graph_policy_text = "ALLOWED";
}
}else{
unset($user);
}
if (read_config_option("full_view_user_admin") == "") {
start_box("User Management [edit]", "98%", $colors["header"], "3", "center", "");
draw_user_form_select();
end_box();
}
if ($graph_policy == "1") {
$graph_policy_text = "Select the graphs you want to DENY this user from.";
} elseif ($graph_policy == "2") {
$graph_policy_text = "Select the graphs you want ALLOW this user to view.";
}
start_box($graph_policy_text, "98%", $colors["header"], "3", "center", "");
$graphs = db_fetch_assoc("select
ag.UserID,
g.ID, g.Title
from rrd_graph g
left join auth_graph ag on (g.id=ag.graphid and ag.userid=" . $_GET["id"] . ")
order by g.title");
$rows = sizeof($graphs);
?>
end_box();
}
}
/* --------------------------
Per-User Graph Config
-------------------------- */
function graph_config_edit() {
include_once ("include/functions.php");
global $colors, $config;
if (isset($_GET["id"])) {
$graph_settings = LoadSettingsIntoArray($_SESSION["user_id"], read_config_option("guest_user"));
}else{
unset($user);
}
if (read_config_option("full_view_user_admin") == "") {
start_box("User Management [edit]", "98%", $colors["header"], "3", "center", "");
draw_user_form_select();
end_box();
}
start_box("Graph Preview Settings", "98%", $colors["header"], "3", "center", "");
?>
end_box();
}
/* --------------------------
User Administration
-------------------------- */
function user_save() {
/* only change password when user types one */
if ($_POST["Password"] != $_POST["Confirm"]) {
$passwords_do_not_match = true;
}elseif (($_POST["Password"] == "") && ($_POST["Confirm"] == "")) {
$password = $_POST["_password"];
}else{
$password = "PASSWORD('" . $_POST["Password"] . "')";
}
if ($passwords_do_not_match != true) {
$save["ID"] = $_POST["user_id"];
$save["Username"] = $_POST["Username"];
$save["FullName"] = $_POST["FullName"];
$save["Password"] = $password;
$save["MustChangePassword"] = $_POST["MustChangePassword"];
$save["ShowTree"] = $_POST["ShowTree"];
$save["ShowList"] = $_POST["ShowList"];
$save["ShowPreview"] = $_POST["ShowPreview"];
$save["GraphSettings"] = $_POST["GraphSettings"];
$save["LoginOpts"] = $_POST["LoginOpts"];
$save["GraphPolicy"] = $_POST["GraphPolicy"];
$id = sql_save($save, "auth_users");
reset($_POST);
db_execute("delete from auth_acl where userid=$id");
while (list($var, $val) = each($_POST)) {
if (eregi("^[section]", $var)) {
if (substr($var, 0, 7) == "section") {
db_execute ("replace into auth_acl (userid,sectionid) values($id," . substr($var, 7) . ")");
}
}
}
}
}
function user_remove() {
global $config;
if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) {
include ('include/top_header.php');
DrawConfirmForm("Are You Sure?", "Are you sure you want to delete the user '" . db_fetch_cell("select Username from auth_users where id=" . $_GET["id"]) . "'?", getenv("HTTP_REFERER"), "user_admin.php?action=user_remove&id=" . $_GET["id"]);
include ('include/bottom_footer.php');
exit;
}
if ((read_config_option("remove_verification") == "") || ($_GET["confirm"] == "yes")) {
db_execute("delete from auth_users where id=" . $_GET["id"]);
db_execute("delete from auth_acl where userid=" . $_GET["id"]);
db_execute("delete from auth_hosts where userid=" . $_GET["id"]);
db_execute("delete from auth_graph where userid=" . $_GET["id"]);
db_execute("delete from auth_graph_hierarchy where userid=" . $_GET["id"]);
db_execute("delete from settings_graphs where userid=" . $_GET["id"]);
db_execute("delete from settings_viewing_tree where userid=" . $_GET["id"]);
db_execute("delete from settings_graph_tree where userid=" . $_GET["id"]);
db_execute("delete from settings_ds_tree where userid=" . $_GET["id"]);
}
}
function user_edit() {
global $colors, $config;
if (isset($_GET["id"])) {
$user = db_fetch_row("select * from auth_users where id=" . $_GET["id"]);
}else{
unset($user);
}
if (read_config_option("full_view_user_admin") == "") {
start_box("User Management [edit]", "98%", $colors["header"], "3", "center", "");
draw_user_form_select();
end_box();
}
start_box("User Configuration", "98%", $colors["header"], "3", "center", "");
?>
end_box();
}
if (read_config_option("full_view_user_admin") == "on") {
graph_perms_edit();
graph_config_edit();
}
}
function user() {
global $colors;
start_box("User Management", "98%", $colors["header"], "3", "center", "user_admin.php?action=user_edit");
print "";
DrawMatrixHeaderItem("User Name",$colors["header_text"],1);
DrawMatrixHeaderItem("Full Name",$colors["header_text"],1);
DrawMatrixHeaderItem("Default Graph Policy",$colors["header_text"],2);
print "
";
$user_list = db_fetch_assoc("select ID,Username,FullName,GraphPolicy from auth_users order by Username");
if (sizeof($user_list) > 0) {
foreach ($user_list as $user) {
DrawMatrixRowAlternateColorBegin($colors["alternate"],$colors["light"],$i);
?>
">
|
|
|
">
|
$i++;
}
}
end_box();
}
?>