From 8cf255072cab8250cc576b47b341d6d266b4339e Mon Sep 17 00:00:00 2001
From: laf
Date: Mon, 10 Mar 2014 23:50:16 +0000
Subject: [PATCH] Updated edit user screen so you can now update details
---
.../includes/authentication/http-auth.inc.php | 16 ++
html/includes/authentication/ldap.inc.php | 18 ++
html/includes/authentication/mysql.inc.php | 16 ++
html/pages/edituser.inc.php | 212 +++++++++++++++---
4 files changed, 233 insertions(+), 29 deletions(-)
diff --git a/html/includes/authentication/http-auth.inc.php b/html/includes/authentication/http-auth.inc.php
index 9b0f511072..651785966d 100644
--- a/html/includes/authentication/http-auth.inc.php
+++ b/html/includes/authentication/http-auth.inc.php
@@ -79,4 +79,20 @@ function get_userlist()
return dbFetchRows("SELECT * FROM `users`");
}
+function can_update_users()
+{
+ # supported so return 1
+ return 1;
+}
+
+function get_user($user_id)
+{
+ return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id));
+}
+
+function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
+{
+ dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
+}
+
?>
diff --git a/html/includes/authentication/ldap.inc.php b/html/includes/authentication/ldap.inc.php
index d640097d70..2ae73110e2 100644
--- a/html/includes/authentication/ldap.inc.php
+++ b/html/includes/authentication/ldap.inc.php
@@ -163,4 +163,22 @@ function get_userlist()
return $userlist;
}
+function can_update_usesr()
+{
+ # not supported so return 0
+ return 0;
+}
+
+function get_user($user_id)
+{
+ # not supported
+ return 0;
+}
+
+function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
+{
+ # not supported
+ return 0;
+}
+
?>
diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php
index 67b2c5990a..151830d702 100644
--- a/html/includes/authentication/mysql.inc.php
+++ b/html/includes/authentication/mysql.inc.php
@@ -145,4 +145,20 @@ function get_userlist()
return dbFetchRows("SELECT * FROM `users`");
}
+function can_update_users()
+{
+ # supported so return 1
+ return 1;
+}
+
+function get_user($user_id)
+{
+ return dbFetchRow("SELECT * FROM `users` WHERE `user_id` = ?", array($user_id));
+}
+
+function update_user($user_id,$realname,$level,$can_modify_passwd,$email)
+{
+ dbUpdate(array('realname' => $realname, 'level' => $level, 'can_modify_passwd' => $can_modify_passwd, 'email' => $email), 'users', '`user_id` = ?', array($user_id));
+}
+
?>
diff --git a/html/pages/edituser.inc.php b/html/pages/edituser.inc.php
index d4203a35ee..4f6106b455 100644
--- a/html/pages/edituser.inc.php
+++ b/html/pages/edituser.inc.php
@@ -8,7 +8,7 @@ $pagetitle[] = "Edit user";
if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php"); } else
{
- if ($vars['user_id'])
+ if ($vars['user_id'] && !$vars['edit'])
{
$user_data = dbFetchRow("SELECT * FROM users WHERE user_id = ?", array($vars['user_id']));
echo("
" . $user_data['realname'] . " Change...
");
@@ -57,28 +57,41 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
}
}
- echo("");
+ echo('
+
');
// Display devices this users has access to
echo("
Device Access ");
+ echo("
+
+
+ Device
+ Action
+ ");
+
$device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id']));
foreach ($device_perms as $device_perm)
{
- echo("" . $device_perm['hostname'] . " ");
+ echo("" . $device_perm['hostname'] . " ");
$access_list[] = $device_perm['device_id'];
$permdone = "yes";
}
+ echo("
+
");
+
if (!$permdone) { echo("None Configured"); }
// Display devices this user doesn't have access to
echo("
Grant access to new device ");
- echo("
");
- echo("
");
+ echo("
+ ");
echo("
Interface Access ");
$interface_perms = dbFetchRows("SELECT * from ports_perms as P, ports as I, devices as D WHERE `user_id` = ? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($vars['user_id']));
+ echo("
+
+
+ Interface name
+ Action
+ ");
foreach ($interface_perms as $interface_perm)
{
- echo("".$interface_perm['hostname']." - ".$interface_perm['ifDescr']." ".
- "" . $interface_perm['ifAlias'] . "
");
+ echo("
+
+ ".$interface_perm['hostname']." - ".$interface_perm['ifDescr']." ".
+ "" . $interface_perm['ifAlias'] . "
+
+
+
+
+ ");
$ipermdone = "yes";
}
+ echo("
+
");
if (!$ipermdone) { echo("None Configured"); }
// Display devices this user doesn't have access to
echo("
Grant access to new interface ");
- echo("
");
+ echo("
+
+
+
+
+ ");
- echo(" ");
+ echo("
+ ");
echo("
Bill Access ");
$bill_perms = dbFetchRows("SELECT * from bills AS B, bill_perms AS P WHERE P.user_id = ? AND P.bill_id = B.bill_id", array($vars['user_id']));
+ echo("
+
+
+ Bill name
+ Action
+ ");
+
foreach ($bill_perms as $bill_perm)
{
- echo("".$bill_perm['bill_name']."
");
+ echo("
+
+ ".$bill_perm['bill_name']."
+
+ ");
$bill_access_list[] = $bill_perm['bill_id'];
$bpermdone = "yes";
}
+ echo("
+
");
+
if (!$bpermdone) { echo("None Configured"); }
// Display devices this user doesn't have access to
echo("
Grant access to new bill ");
- echo("
");
+ echo("
+
+ Add
+
+ ");
+ } elseif ($vars['user_id'] && $vars['edit']) {
+
+ if(!empty($vars['new_level']))
+ {
+ if($vars['can_modify_passwd'] == 'on') {
+ $vars['can_modify_passwd'] = '1';
+ }
+ update_user($vars['user_id'],$vars['new_realname'],$vars['new_level'],$vars['can_modify_passwd'],$vars['new_email']);
+ print_message("User has been updated");
+ }
+
+ if(can_update_users() == '1') {
+
+ $users_details = get_user($vars['user_id']);
+ if(!empty($users_details))
+ {
+
+ if(empty($vars['new_realname']))
+ {
+ $vars['new_realname'] = $users_details['realname'];
+ }
+ if(empty($vars['new_level']))
+ {
+ $vars['new_level'] = $users_details['level'];
+ }
+ if(empty($vars['can_modify_passwd']))
+ {
+ $vars['can_modify_passwd'] = $users_details['can_modify_passwd'];
+ } elseif($vars['can_modify_passwd'] == 'on') {
+ $vars['can_modify_passwd'] = '1';
+ }
+ if(empty($vars['new_email']))
+ {
+ $vars['new_email'] = $users_details['email'];
+ }
+
+ echo("");
+ } else {
+ echo print_error("Error getting user details");
+ }
+ } else {
+ echo print_error("Authentication method doesn't support updating users");
+ }
} else {
$user_list = get_userlist();
@@ -177,18 +328,21 @@ if ($_SESSION['userlevel'] != '10') { include("includes/error-no-perm.inc.php");
echo("