/*
+-------------------------------------------------------------------------+
| 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/ |
+-------------------------------------------------------------------------+
*/?>
header("Cache-control: no-cache");
$section = "User Administration";
include ('include/auth.php');
include_once ("include/form.php");
if ($form[action]) { $action = $form[action]; } else { $action = $args[action]; }
if ($form[ID]) { $id = $form[ID]; } else { $id = $args[id]; }
switch ($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, $args; ?>
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
global $form, $config;
if ((isset($form[save_component_user])) && (isset($form[save_component_graph_perms])) && (isset($form[save_component_graph_config]))) {
user_save();
graph_perms_save();
/* graph_config_save(); */
return "user_admin.php?action=user_edit&id=$form[user_id]";
}elseif (isset($form[save_component_user])) {
user_save();
return "user_admin.php";
}elseif (isset($form[save_component_graph_perms])) {
graph_perms_save();
return "user_admin.php";
}elseif (isset($form[save_component_graph_config])) {
/* graph_config_save(); */
return "user_admin.php";
}
}
/* --------------------------
Graph Permissions
-------------------------- */
function graph_perms_save() {
global $form;
db_execute ("delete from auth_graph where userid=$form[user_id]");
db_execute ("delete from auth_graph_hierarchy where userid=$form[user_id]");
reset($form);
while (list($var, $val) = each($form)) {
if (eregi("^[graph|tree]", $var)) {
if (substr($var, 0, 5) == "graph") {
db_execute ("replace into auth_graph (userid,graphid) values($form[user_id]," . substr($var, 5) . ")");
}elseif (substr($var, 0, 4) == "tree") {
db_execute ("replace into auth_graph_hierarchy (userid,hierarchyid) values($form[user_id]," . substr($var, 4) . ")");
}
}
}
}
function graph_perms_edit() {
global $colors, $args, $config;
if (isset($args[id])) {
$graph_policy = db_fetch_cell("select GraphPolicy from auth_users where id=$args[id]");
if ($graph_policy == "1") {
$graph_policy_text = "DENIED";
}elseif ($graph_policy == "2") {
$graph_policy_text = "ALLOWED";
}
}else{
unset($user);
}
if ($config[full_view_user_admin][value] == "") {
start_box("User Management [edit]", "", "");
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", "", "");
$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=$args[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, $args, $config, $HTTP_SESSION_VARS;
if (isset($args[id])) {
$graph_settings = LoadSettingsIntoArray($HTTP_SESSION_VARS["user_id"], $config["guest_user"]["value"]);
}else{
unset($user);
}
if ($config[full_view_user_admin][value] == "") {
start_box("User Management [edit]", "", "");
draw_user_form_select();
end_box();
}
start_box("Graph Preview Settings", "", "");
?>
end_box();
}
/* --------------------------
User Administration
-------------------------- */
function user_save() {
global $form;
/* only change password when user types one */
if ($form[Password] != $form[Confirm]) {
$passwords_do_not_match = true;
}elseif (($form[Password] == "") && ($form[Confirm] == "")) {
$password = $form[_password];
}else{
$password = "PASSWORD('$form[Password]')";
}
if ($passwords_do_not_match != true) {
$save["ID"] = $form["user_id"];
$save["Username"] = $form["Username"];
$save["FullName"] = $form["FullName"];
$save["Password"] = $password;
$save["MustChangePassword"] = $form["MustChangePassword"];
$save["ShowTree"] = $form["ShowTree"];
$save["ShowList"] = $form["ShowList"];
$save["ShowPreview"] = $form["ShowPreview"];
$save["GraphSettings"] = $form["GraphSettings"];
$save["LoginOpts"] = $form["LoginOpts"];
$save["GraphPolicy"] = $form["GraphPolicy"];
$id = sql_save($save, "auth_users");
reset($form);
db_execute("delete from auth_acl where userid=$id");
while (list($var, $val) = each($form)) {
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, $args;
if (($config["remove_verification"]["value"] == "on") && ($args[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=$args[id]") . "'?", getenv("HTTP_REFERER"), "user_admin.php?action=user_remove&id=$args[id]");
include ('include/bottom_footer.php');
exit;
}
if (($config["remove_verification"]["value"] == "") || ($args[confirm] == "yes")) {
db_execute("delete from auth_users where id=$args[id]");
db_execute("delete from auth_acl where userid=$args[id]");
db_execute("delete from auth_hosts where userid=$args[id]");
db_execute("delete from auth_graph where userid=$args[id]");
db_execute("delete from auth_graph_hierarchy where userid=$args[id]");
db_execute("delete from settings_graphs where userid=$args[id]");
db_execute("delete from settings_viewing_tree where userid=$args[id]");
db_execute("delete from settings_graph_tree where userid=$args[id]");
db_execute("delete from settings_ds_tree where userid=$args[id]");
}
}
function user_edit() {
global $args, $colors, $config;
if (isset($args[id])) {
$user = db_fetch_row("select * from auth_users where id=$args[id]");
}else{
unset($user);
}
if ($config[full_view_user_admin][value] == "") {
start_box("User Management [edit]", "", "");
draw_user_form_select();
end_box();
}
start_box("User Configuration", "", "");
?>
end_box();
}
if ($config[full_view_user_admin][value] == "on") {
graph_perms_edit();
graph_config_edit();
}
}
function user() {
global $colors;
start_box("User Management", "", "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();
}
?>