]> git.gsnw.org Git - m0n0chwall.git/commitdiff
Modified user and group manager code to use a more standard XML format.
authorptaylor <ptaylor@e36fee2c-cc09-0410-a7cc-ebac5c6737de>
Wed, 8 Feb 2006 21:25:46 +0000 (21:25 +0000)
committerptaylor <ptaylor@e36fee2c-cc09-0410-a7cc-ebac5c6737de>
Wed, 8 Feb 2006 21:25:46 +0000 (21:25 +0000)
git-svn-id: https://svn.m0n0.ch/wall/trunk@63 e36fee2c-cc09-0410-a7cc-ebac5c6737de

phpconf/inc/system.inc
phpconf/inc/xmlparse.inc
webgui/auth.inc
webgui/fbegin.inc
webgui/guiconfig.inc
webgui/system_groupmanager.php
webgui/system_usermanager.php

index 63c9df494e08e81bf04c71edc9a8ee02891d8571..9a4758d0e3ca08fdd6f687011d86e9efc2f253e8 100644 (file)
@@ -386,10 +386,10 @@ function system_password_configure() {
        
        fwrite($fd, $username . ":" . $config['system']['password'] . "\n");
 
-       if (is_array($config['system']['users'])) {
-               foreach ($config['system']['users'] as $user => $userdata) {
-                           fwrite($fd, $user . ":" 
-                             . $userdata['password'] . "\n");
+       if (is_array($config['system']['user'])) {
+               foreach ($config['system']['user'] as $userent) {
+                           fwrite($fd, $userent['name'] . ":" 
+                             . $userent['password'] . "\n");
                }
        }
        
index 229f333d45cd114ff1f977dc1b16163654fa5e59..42489ec550d4c31a7e2ca9488ac590fb376973a9 100644 (file)
@@ -30,7 +30,7 @@
 */
 
 /* tags that are always to be handled as lists */
-$listtags = explode(" ", "rule user key dnsserver winsserver pages " .
+$listtags = explode(" ", "rule user group key dnsserver winsserver pages " .
        "encryption-algorithm-option hash-algorithm-option hosts tunnel onetoone " .
        "staticmap route alias pipe queue shellcmd cacert earlyshellcmd mobilekey " .
        "servernat proxyarpnet passthrumac allowedip wolentry vlan domainoverrides element");
index 7cda0a1ca1ca72cf2262220606d20b3c22f96de5..9cb2f257b456104bed7284d90bf39ccac4b81c58 100644 (file)
        POSSIBILITY OF SUCH DAMAGE.
 */
 
+function index_groups() {
+    global $g, $config;
+    
+    if (isset($config['system']['group'])) {
+        $i = 0; 
+           foreach($config['system']['group'] as $groupent) {
+               $groupindex[$groupent['name']] = $i;
+               $i++;
+           }
+       }
+       return ($groupindex);
+}
+
+function index_users() {
+    global $g, $config;
+    
+    if (isset($config['system']['user'])) {
+        $i = 0; 
+       foreach($config['system']['user'] as $userent) {
+              $userindex[$userent['name']] = $i;
+              $i++;
+          }
+    }
+    return ($userindex);
+}
+
+$groupindex = index_groups();
+$userindex = index_users();
+
 // Once here, the user has authenticated with the web server.  
 // Now, we give them access only to the appropriate pages for their group.
 if (!($_SERVER['REMOTE_USER'] === $config['system']['username'])) {
        $allowed[] = '';
-       if (isset($config['system']['groups'][$config['system']['users'][$_SERVER['REMOTE_USER']]['group']]['pages'])) {
-               $allowed = &$config['system']['groups'][$config['system']['users'][$_SERVER['REMOTE_USER']]['group']]['pages'];
+       if (isset($config['system']['group'][$groupindex[$config['system']['user'][$userindex[$_SERVER['REMOTE_USER']]]['groupname']]]['pages'])) {
+               $allowed = &$config['system']['group'][$groupindex[$config['system']['user'][$userindex[$_SERVER['REMOTE_USER']]]['groupname']]]['pages'];
        } 
 
        // If the user is attempting to hit the default page, set it to specifically look for /index.php.
index cbcb73d9789072e3b21636cd4fe549d1ab4cde6c..34bb3169bceccc0f097c0f611102d3d235220402 100644 (file)
@@ -160,8 +160,6 @@ $menu['Diagnostics']['IPsec']                       = array('diag_ipsec_sad.php',
 $menu['Diagnostics']['Ping/Traceroute'] = array('diag_ping.php',
                                                                                                'diag_traceroute.php');
 $menu['Diagnostics']['ARP Table']              = array('diag_arp.php');
-$menu['Diagnostics']['NS Lookup']              = array('diag_nslookup.php');
-$menu['Diagnostics']['Whois']                  = array('diag_whois.php');
 $menu['Diagnostics']['Firewall states'] = array('diag_ipfstat.php');
 $menu['Diagnostics']['Reset state']    = array('diag_resetstate.php');
 $menu['Diagnostics']['Backup/Restore']         = array('diag_backup.php');
index 77d125aebf50d77e4b5730c7e03de7c23e495442..2eaed9b8a070c082eea0f8ae993460dfbba1b468 100644 (file)
@@ -342,6 +342,26 @@ function captiveportal_users_sort() {
        usort($config['captiveportal']['user'], "cpusercmp");
 }
 
+function admin_groups_sort() {
+       global $g, $config;
+       
+       function cpusercmp($a, $b) {
+               return strcasecmp($a['name'], $b['name']);
+       }
+       
+       usort($config['system']['group'], "cpusercmp");
+}
+
+function admin_users_sort() {
+       global $g, $config;
+       
+       function cpusercmp($a, $b) {
+               return strcasecmp($a['name'], $b['name']);
+       }
+       
+       usort($config['system']['user'], "cpusercmp");
+}
+
 function staticroutes_sort() {
        global $g, $config;
 
index 42da0c7b22e749fd1aa6178ce8dee59cbeaca730..8b3d1ab836e113fa94759b221ee1e8d815afcfef 100644 (file)
@@ -94,108 +94,93 @@ function getAdminPageList() {
     }
 }
 
-?>
-<?php include("fbegin.inc"); ?>
-
-<?php 
 // Get a list of all admin pages & Descriptions
 $pages = getAdminPageList();
 
-if ($_GET['act']=="new" || $_GET['act']=="edit") {
-       if (isset($_GET['groupname'])) {
-               $group=$config['system']['groups'][$_GET['groupname']];
+if (!is_array($config['system']['group'])) {
+       $config['system']['group'] = array();
+}
+admin_groups_sort();
+$a_group = &$config['system']['group'];
+
+$id = $_GET['id'];
+if (isset($_POST['id']))
+       $id = $_POST['id'];
+       
+if ($_GET['act'] == "del") {
+       if ($a_group[$_GET['id']]) {
+           $ok_to_delete = true;
+           if (isset($config['system']['user'])) {
+           foreach ($config['system']['user'] as $userent) {
+               if ($userent['groupname'] == $a_group[$_GET['id']]['name']) {
+                               $ok_to_delete = false;
+                               $input_errors[] = "users still exist who are members of this group!";
+                               break;      
+               }
+           }
+           }
+        if ($ok_to_delete) {
+               unset($a_group[$_GET['id']]);
+               write_config();
+                   header("Location: system_groupmanager.php");
+                   exit;
+           }
        }
 }      
+       
+if ($_POST) {
 
-if (($_GET['act']=='delete') && (isset($_GET['groupname']))) {
+       unset($input_errors);
+       $pconfig = $_POST;
 
-       // See if there are any users who are members of this group. 
-       $ok_to_delete = true;
-       if (is_array($config['system']['users'])) {
-               foreach ($config['system']['users'] as $key => $user) {
-                       if ($user['group'] == $_GET['groupname']) {
-                               $ok_to_delete = false;
-                               $input_errors[] = "users still exist who are members of this group!";
+       /* input validation */
+       $reqdfields = explode(" ", "groupname");
+       $reqdfieldsn = explode(",", "Group Name");
+       
+       do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+       
+       if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname']))
+               $input_errors[] = "The group name contains invalid characters.";
+               
+       if (!$input_errors && !(isset($id) && $a_group[$id])) {
+               /* make sure there are no dupes */
+               foreach ($a_group as $group) {
+                       if ($group['name'] == $_POST['groupname']) {
+                               $input_errors[] = "Another entry with the same group name already exists.";
                                break;
                        }
                }
        }
        
-       if ($ok_to_delete) {
-               unset($config['system']['groups'][$_GET['groupname']]);
-               write_config();
-               $retval = system_password_configure();
-               $savemsg = get_std_save_message($retval);
-               $savemsg="Group ".$_GET['groupname']." successfully deleted<br>";               
-       }
-}
-
-if(isset($_POST['save'])) {
-       //value-checking
-       if($_POST['groupname']==""){
-               $input_errors[] = "group name must not be empty!";
-       }
-       if($_POST['old_groupname'] != $_POST['groupname']) {
-               // Either a new group, or one with a group name change
-               if (isset($config['system']['groups'][$_POST['groupname']])) {
-                       $input_errors[] = "group name can not match an existing group!";
-               }
-       }
+       if (!$input_errors) {
        
-       //check groupname: only allow letters from A-Z and a-z, _, -, . and numbers from 0-9 (note: groupname can
-       //not contain characters which are not allowed in an xml-token. i.e. if you'd use @ in a groupname, config.xml
-       //could not be parsed anymore!
-       if(!preg_match('/^[a-zA-Z0-9_\-\.]*$/',$_POST['groupname'])){
-               $input_errors[] = "groupname contains illegal characters, only letters from A-Z and a-z, _, -, . and numbers are allowed";
-       }
-       if(!empty($input_errors)){
-               //there are illegal inputs --> print out error message and show formula again 
-               //and fill in all recently entered values except passwords
-               $_GET['act']="new";
-               $_POST['old_groupname']=($_POST['old_groupname'] ? $_POST['old_groupname'] : $_POST['groupname']);
-               $_GET['groupname']=$_POST['old_groupname'];
-
-               $group['description']=$_POST['description'];
-
+               if (isset($id) && $a_group[$id])
+                       $group = $a_group[$id];
+               
+               $group['name'] = $_POST['groupname'];
+               $group['description'] = $_POST['description'];
+               unset($group['pages']);
                foreach ($pages as $fname => $title) {
-                       $id = str_replace('.php','',$fname);
-                       if ($_POST[$id] == 'yes') {
+                       $identifier = str_replace('.php','',$fname);
+                       if ($_POST[$identifier] == 'yes') {
                                $group['pages'][] = $fname;
                        }                       
-               }
+               }               
+               
+               if (isset($id) && $a_group[$id])
+                       $a_group[$id] = $group;
+               else
+                       $a_group[] = $group;
                
-       } else {
-               //all values are okay --> saving changes
-               $_POST['groupname']=trim($_POST['groupname']);
-               if($_POST['old_groupname']!="" && $_POST['old_groupname']!=$_POST['groupname']){
-                       //change the groupname (which is used as array-index)
-                       $config['system']['groups'][$_POST['groupname']]=$config['system']['groups'][$_POST['old_groupname']];
-                       unset($config['system']['groups'][$_POST['old_groupname']]);
-
-                       // Group name was changed.  Update all users that are members of this group to point to the new groupname.
-                       foreach ($config['system']['users'] as $key => $user) {
-                               if ($user['group'] == $_POST['old_groupname']) 
-                                       $config['system']['users'][$key]['group'] = $_POST['groupname'];                                
-                       }
-               }
-               $config['system']['groups'][$_POST['groupname']]['description']=trim($_POST['description']);
-               // Clear pages info and read pages from POST
-               if (isset($config['system']['groups'][$_POST['groupname']]['pages']))
-                       unset($config['system']['groups'][$_POST['groupname']]['pages']);
-               foreach ($pages as $fname => $title) {
-                       $id = str_replace('.php','',$fname);
-                       if ($_POST[$id] == 'yes') {
-                               $config['system']['groups'][$_POST['groupname']]['pages'][] = $fname;
-                       }
-               }
                write_config();
-               $retval = system_password_configure();
-               $savemsg = get_std_save_message($retval);
-               $savemsg="Group ".$_POST['groupname']." successfully saved<br>";
+               
+               header("Location: system_groupmanager.php");
+               exit;
        }
 }
 
 ?>
+<?php include("fbegin.inc"); ?>
 <?php if ($input_errors) print_input_errors($input_errors); ?>
 <?php if ($savemsg) print_info_box($savemsg); ?>
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
@@ -212,8 +197,12 @@ if(isset($_POST['save'])) {
   <td class="tabcont">
 <?php
 if($_GET['act']=="new" || $_GET['act']=="edit"){
-       if($_GET['act']=="edit" && isset($_GET['groupname'])){
-               $group=$config['system']['groups'][$_GET['groupname']];
+       if($_GET['act']=="edit"){
+               if (isset($id) && $a_group[$id]) {
+              $pconfig['name'] = $a_group[$id]['name'];
+              $pconfig['description'] = $a_group[$id]['description'];
+              $pconfig['pages'] = $a_group[$id]['pages'];
+        }
        }
 ?>
 <form action="system_groupmanager.php" method="post" name="iform" id="iform">
@@ -221,13 +210,13 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
             <tr> 
               <td width="22%" valign="top" class="vncellreq">Group name</td>
               <td width="78%" class="vtable"> 
-                <input name="groupname" type="text" class="formfld" id="groupname" size="20" value="<?=$_GET['groupname'];?>"> 
+                <input name="groupname" type="text" class="formfld" id="groupname" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"> 
                 </td>
             </tr>
             <tr> 
               <td width="22%" valign="top" class="vncell">Description</td>
               <td width="78%" class="vtable"> 
-                <input name="description" type="text" class="formfld" id="description" size="20" value="<?=htmlspecialchars($group['description']);?>">
+                <input name="description" type="text" class="formfld" id="description" size="20" value="<?=htmlspecialchars($pconfig['description']);?>">
                 <br>
                 Group description, for your own information only</td>
             </tr>
@@ -247,10 +236,10 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
               </tr>
               <?php 
               foreach ($pages as $fname => $title) {
-               $id = str_replace('.php','',$fname);
+               $identifier = str_replace('.php','',$fname);
                ?>
                <tr><td class="listlr">
-               <input name="<?=$id?>" type="checkbox" id="<?=$id?>" value="yes" <?php if (in_array($fname,$group['pages'])) echo "checked"; ?>></td>
+               <input name="<?=$identifier?>" type="checkbox" id="<?=$identifier?>" value="yes" <?php if (in_array($fname,$pconfig['pages'])) echo "checked"; ?>></td>
                <td class="listr"><?=$title?></td>
                <td class="listr"><?=$fname?></td>
                </tr>
@@ -263,7 +252,9 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
               <td width="22%" valign="top">&nbsp;</td>
               <td width="78%"> 
                 <input name="save" type="submit" class="formbtn" value="Save"> 
-                <input name="old_groupname" type="hidden" value="<?=$_GET['groupname'];?>">
+                       <?php if (isset($id) && $a_group[$id]): ?>
+                       <input name="id" type="hidden" value="<?=$id;?>">
+                       <?php endif; ?>                
               </td>
             </tr>
           </table>
@@ -278,26 +269,21 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
        <td width="20%" class="listhdrr">Pages Accessible</td>                  
        <td width="10%" class="list"></td>
        </tr>
-<?php
-       if(is_array($config['system']['groups'])){
-               foreach($config['system']['groups'] as $groupname => $group){
-?>
+       <?php $i = 0; foreach($a_group as $group): ?>
                <tr>
-           <td class="listlr">
-              <?=$groupname; ?>&nbsp;
-           </td>
-           <td class="listr">
-              <?=htmlspecialchars($group['description']);?>&nbsp;
-           </td>
-              <td class="listr">
-              <?=count($group['pages']);?>
-              </td>
-           <td valign="middle" nowrap class="list"> <a href="system_groupmanager.php?act=edit&groupname=<?=$groupname; ?>"><img src="e.gif" title="edit group" width="17" height="17" border="0"></a>
-              &nbsp;<a href="system_groupmanager.php?act=delete&groupname=<?=$groupname; ?>" onclick="return confirm('Do you really want to delete this Group?')"><img src="x.gif" title="delete group" width="17" height="17" border="0"></a></td>
+                  <td class="listlr">
+                    <?=htmlspecialchars($group['name']); ?>&nbsp;
+                  </td>
+                  <td class="listr">
+                    <?=htmlspecialchars($group['description']);?>&nbsp;
+                  </td>
+                  <td class="listbg">
+                    <?=count($group['pages']);?>&nbsp;
+                  </td>
+                  <td valign="middle" nowrap class="list"> <a href="system_groupmanager.php?act=edit&id=<?=$i; ?>"><img src="e.gif" title="edit group" width="17" height="17" border="0"></a>
+                     &nbsp;<a href="system_groupmanager.php?act=del&id=<?=$i; ?>" onclick="return confirm('Do you really want to delete this group?')"><img src="x.gif" title="delete group" width="17" height="17" border="0"></a></td>
                </tr>
-<?php
-               }
-       } ?>
+       <?php $i++; endforeach; ?>
            <tr> 
                        <td class="list" colspan="3"></td>
                        <td class="list"> <a href="system_groupmanager.php?act=new"><img src="plus.gif" title="add group" width="17" height="17" border="0"></a></td>
index b26ee93119eef69a0e83d395502884c6508b7903..fb59ff48fa669e5fe8023202adf8f52f9543ba4d 100644 (file)
@@ -36,113 +36,100 @@ require("guiconfig.inc");
 
 // The page title for non-admins
 $pgtitle = array("System", "User password");
-if ($_SERVER['REMOTE_USER'] === $config['system']['username']) {
-       $pgtitle = array("System", "User manager");
-}
 
-?>
-<?php include("fbegin.inc"); ?>
-<?php 
 if ($_SERVER['REMOTE_USER'] === $config['system']['username']) { 
+    
+    // Page title for main admin
+    $pgtitle = array("System", "User manager");
+
+    $id = $_GET['id'];
+    if (isset($_POST['id']))
+          $id = $_POST['id'];
+       
+    if (!is_array($config['system']['user'])) {
+       $config['system']['user'] = array();
+    }
+    admin_users_sort();
+    $a_user = &$config['system']['user'];
+    
+    if ($_GET['act'] == "del") {
+       if ($a_user[$_GET['id']]) {
+           $userdeleted = $a_user[$_GET['id']]['name'];
+               unset($a_user[$_GET['id']]);
+               write_config();
+                       $retval = system_password_configure();
+                       $savemsg = get_std_save_message($retval);
+                       $savemsg = "User ".$userdeleted." successfully deleted<br>";                    
+       }
+    }
        
-       if ($_GET['act']=="new" || $_GET['act']=="edit") {
-               if (isset($_GET['username'])) {
-                       $user=$config['system']['users'][$_GET['username']];
-               }
-       }       
-       
-       if (($_GET['act']=='delete') && (isset($_GET['username']))) {
-               unset($config['system']['users'][$_GET['username']]);
-               write_config();
-               $retval = system_password_configure();
-               $savemsg = get_std_save_message($retval);
-               $savemsg="User ".$_GET['username']." successfully deleted<br>";         
-       }
-       
-       if(isset($_POST['save'])) {
-               //value-checking
-               if(trim($_POST['password1'])!="********" && 
-                  trim($_POST['password1'])!="" && 
-                  trim($_POST['password1'])!=trim($_POST['password2'])){
-                       //passwords are to be changed but don't match
-                       $input_errors[]="passwords don't match";
-               }
-               if((trim($_POST['password1'])=="" || trim($_POST['password1'])=="********") && 
-                  (trim($_POST['password2'])=="" || trim($_POST['password2'])=="********")){
-                       //assume password should be left as is if a password is set already.
-                       if(!empty($config['system']['users'][$_POST['old_username']]['password'])){
-                               $_POST['password1']="********";
-                               $_POST['password2']="********";
-                       } else {
-                               $input_errors[]="password must not be empty";
-                       }
-               } else {
-                       if(trim($_POST['password1'])!=trim($_POST['password2'])){
-                               //passwords are to be changed or set but don't match
-                               $input_errors[]="passwords don't match";
-                       } else {
-                               //check password for invalid characters
-                               if(!preg_match('/^[a-zA-Z0-9_\-\.@\~\(\)\&\*\+§?!\$£°\%;:]*$/',$_POST['username'])){
-                                       $input_errors[] = "password contains illegal characters, only  letters from A-Z and a-z, _, -, .,@,~,(,),&,*,+,§,?,!,$,£,°,%,;,: and numbers are allowed";
-                                       //test pw: AZaz_-.@~()&*+§?!$£°%;:
-                               }
-                       }
-               }
-               if($_POST['username']==""){
-                       $input_errors[] = "username must not be empty!";
-               }
+    if ($_POST) {
+       
+       unset($input_errors);
+       $pconfig = $_POST;
+    
+       /* input validation */
+       if (isset($id) && ($a_user[$id])) {
+               $reqdfields = explode(" ", "username");
+               $reqdfieldsn = explode(",", "Username");
+       } else {
+               $reqdfields = explode(" ", "username password");
+               $reqdfieldsn = explode(",", "Username,Password");
+       }
+       
+       do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+       
+       if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['username']))
+               $input_errors[] = "The username contains invalid characters.";
+
                if($_POST['username']==$config['system']['username']) {
                        $input_errors[] = "username can not match the administrator username!";
-               }
-               if($_POST['old_username'] != $_POST['username']) {
-                       // Either a new user, or one with a username change
-                       if (isset($config['system']['users'][$_POST['username']])) {
-                               $input_errors[] = "username can not match an existing user!";
-                       }
-               }
-               if(!isset($config['system']['groups'][$_POST['group']])) {
+               }               
+               
+       if (($_POST['password']) && ($_POST['password'] != $_POST['password2']))
+               $input_errors[] = "The passwords do not match.";
+               
+               if (!$input_errors && !(isset($id) && $a_user[$id])) {
+               /* make sure there are no dupes */
+               foreach ($a_user as $userent) {
+                       if ($userent['name'] == $_POST['username']) {
+                               $input_errors[] = "Another entry with the same username already exists.";
+                               break;
+                       }
+               }
+       }
+
+               if(!isset($groupindex[$_POST['groupname']])) {
                        $input_errors[] = "group does not exist, please define the group before assigning users.";
                }
-               
-               //check username: only allow letters from A-Z and a-z, _, -, . and numbers from 0-9 (note: username can
-               //not contain characters which are not allowed in an xml-token. i.e. if you'd use @ in a username, config.xml
-               //could not be parsed anymore!
-               if(!preg_match('/^[a-zA-Z0-9_\-\.]*$/',$_POST['username'])){
-                       $input_errors[] = "username contains illegal characters, only letters from A-Z and a-z, _, -, . and numbers are allowed";
-               }
-               if(!empty($input_errors)){
-                       //there are illegal inputs --> print out error message and show formula again 
-                       //and fill in all recently entered values except passwords
-                       $_GET['act']="new";
-                       $_POST['old_username']=($_POST['old_username'] ? $_POST['old_username'] : $_POST['username']);
-                       $_GET['username']=$_POST['old_username'];
-
-                       $user['fullname']=$_POST['fullname'];
-
-               } else {
-                       //all values are okay --> saving changes
-                       $_POST['username']=trim($_POST['username']);
-                       if($_POST['old_username']!="" && $_POST['old_username']!=$_POST['username']){
-                               //change the username (which is used as array-index)
-                               $config['system']['users'][$_POST['username']]=$config['system']['users'][$_POST['old_username']];
-                               unset($config['system']['users'][$_POST['old_username']]);
-                       }
-                       $config['system']['users'][$_POST['username']]['fullname']=trim($_POST['fullname']);
-                       if(trim($_POST['password1'])!="********" && trim($_POST['password1'])!=""){
-                               $config['system']['users'][$_POST['username']]['password']=crypt(trim($_POST['password1']));
-                       }
-                       $config['system']['users'][$_POST['username']]['group']=trim($_POST['group']);
-                       // Remove config information from old way of handling sub-admin users.
-                       if (isset($config['system']['users'][$_POST['username']]['pages'])) 
-                         unset($config['system']['users'][$_POST['username']]['pages']);
-                       write_config();
+       
+       if (!$input_errors) {
+       
+               if (isset($id) && $a_user[$id])
+                       $userent = $a_user[$id];
+               
+               $userent['name'] = $_POST['username'];
+               $userent['fullname'] = $_POST['fullname'];
+               $userent['groupname'] = $_POST['groupname'];
+               
+               if ($_POST['password'])
+                       $userent['password'] = crypt($_POST['password']);
+               
+               if (isset($id) && $a_user[$id])
+                       $a_user[$id] = $userent;
+               else
+                       $a_user[] = $userent;
+               
+               write_config();
                        $retval = system_password_configure();
                        $savemsg = get_std_save_message($retval);
-                       $savemsg="User ".$_POST['username']." successfully saved<br>";
-               }
-       }
+                       
+                       header("Location: system_usermanager.php");
+       }
+    }
 
 ?>
+<?php include("fbegin.inc"); ?>
 <?php if ($input_errors) print_input_errors($input_errors); ?>
 <?php if ($savemsg) print_info_box($savemsg); ?>
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
@@ -158,41 +145,44 @@ if ($_SERVER['REMOTE_USER'] === $config['system']['username']) {
 <tr>
   <td class="tabcont">
 <?php
-if($_GET['act']=="new" || $_GET['act']=="edit"){
-       if($_GET['act']=="edit" && isset($_GET['username'])){
-               $user=$config['system']['users'][$_GET['username']];
-       }
+if($_GET['act']=="new" || $_GET['act']=="edit" || $input_errors){
+       if($_GET['act']=="edit"){
+               if (isset($id) && $a_user[$id]) {
+              $pconfig['username'] = $a_user[$id]['name'];
+              $pconfig['fullname'] = $a_user[$id]['fullname'];
+              $pconfig['groupname'] = $a_group[$id]['groupname'];
+        }
+       }       
 ?>
        <form action="system_usermanager.php" method="post" name="iform" id="iform">
               <table width="100%" border="0" cellpadding="6" cellspacing="0">
                 <tr> 
                   <td width="22%" valign="top" class="vncellreq">Username</td>
                   <td width="78%" class="vtable"> 
-                    <input name="username" type="text" class="formfld" id="username" size="20" value="<?=$_GET['username'];?>"> 
+                    <input name="username" type="text" class="formfld" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>"> 
                     </td>
                 </tr>
                 <tr> 
                   <td width="22%" valign="top" class="vncellreq">Password</td>
                   <td width="78%" class="vtable"> 
-                    <input name="password1" type="password" class="formfld" id="password1" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>"> <br>
-                                       <input name="password2" type="password" class="formfld" id="password2" size="20" value="<?php echo ($_GET['act']=='edit' ? "********" : "" ); ?>">
+                    <input name="password" type="password" class="formfld" id="password" size="20" value=""> <br>
+                                       <input name="password2" type="password" class="formfld" id="password2" size="20" value="">
 &nbsp;(confirmation)                                   </td>
                 </tr>
                 <tr> 
                   <td width="22%" valign="top" class="vncell">Full name</td>
                   <td width="78%" class="vtable"> 
-                    <input name="fullname" type="text" class="formfld" id="fullname" size="20" value="<?=htmlspecialchars($user['fullname']);?>">
+                    <input name="fullname" type="text" class="formfld" id="fullname" size="20" value="<?=htmlspecialchars($pconfig['fullname']);?>">
                     <br>
                     User's full name, for your own information only</td>
                 </tr>
                 <tr> 
                   <td width="22%" valign="top" class="vncell">Group Name</td>
                   <td width="78%" class="vtable">
-                                 <select name="group" class="formfld" id="group">
-                      <?php foreach ($config['system']['groups'] as $gname => $group): ?>
-                       
-                      <option value="<?=$gname;?>" <?php if ($gname == $user['group']) echo "selected"; ?>>
-                      <?=htmlspecialchars($gname);?>
+                                 <select name="groupname" class="formfld" id="groupname">
+                      <?php foreach ($config['system']['group'] as $group): ?>
+                      <option value="<?=$group['name'];?>" <?php if ($group['name'] == $pconfig['groupname']) echo "selected"; ?>>
+                      <?=htmlspecialchars($group['name']);?>
                       </option>
                       <?php endforeach; ?>
                     </select>                   
@@ -203,7 +193,9 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
                   <td width="22%" valign="top">&nbsp;</td>
                   <td width="78%"> 
                     <input name="save" type="submit" class="formbtn" value="Save"> 
-                    <input name="old_username" type="hidden" value="<?=$_GET['username'];?>">
+                       <?php if (isset($id) && $a_user[$id]): ?>
+                    <input name="id" type="hidden" value="<?=$id;?>">
+                           <?php endif; ?>
                   </td>
                 </tr>
               </table>
@@ -218,26 +210,21 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
            <td width="20%" class="listhdrr">Group</td>                  
            <td width="10%" class="list"></td>
                </tr>
-<?php
-       if(is_array($config['system']['users'])){
-               foreach($config['system']['users'] as $username => $user){
-?>
+       <?php $i = 0; foreach($a_user as $userent): ?>
                <tr>
-           <td class="listlr">
-              <?=$username; ?>&nbsp;
-           </td>
-           <td class="listr">
-              <?=htmlspecialchars($user['fullname']);?>&nbsp;
-           </td>
-              <td class="listr">
-              <?=$user['group'];?>
-              </td>
-           <td valign="middle" nowrap class="list"> <a href="system_usermanager.php?act=edit&username=<?=$username; ?>"><img src="e.gif" title="edit user" width="17" height="17" border="0"></a>
-              &nbsp;<a href="system_usermanager.php?act=delete&username=<?=$username; ?>" onclick="return confirm('Do you really want to delete this User?')"><img src="x.gif" title="delete user" width="17" height="17" border="0"></a></td>
+                  <td class="listlr">
+                    <?=htmlspecialchars($userent['name']); ?>&nbsp;
+                  </td>
+                  <td class="listr">
+                    <?=htmlspecialchars($userent['fullname']);?>&nbsp;
+                  </td>
+                  <td class="listbg">
+                    <?=htmlspecialchars($userent['groupname']); ?>&nbsp;
+                  </td>
+                  <td valign="middle" nowrap class="list"> <a href="system_usermanager.php?act=edit&id=<?=$i; ?>"><img src="e.gif" title="edit user" width="17" height="17" border="0"></a>
+                     &nbsp;<a href="system_usermanager.php?act=del&id=<?=$i; ?>" onclick="return confirm('Do you really want to delete this User?')"><img src="x.gif" title="delete user" width="17" height="17" border="0"></a></td>
                </tr>
-<?php
-               }
-       } ?>
+       <?php $i++; endforeach; ?>
            <tr> 
                        <td class="list" colspan="3"></td>
                        <td class="list"> <a href="system_usermanager.php?act=new"><img src="plus.gif" title="add user" width="17" height="17" border="0"></a></td>
@@ -255,40 +242,23 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
   </table>
 <?php 
 } else { // end of admin user code, start of normal user code
-       if(isset($_POST['save'])) {
-               //value-checking
-               if(trim($_POST['password1'])!="********" && 
-                  trim($_POST['password1'])!="" && 
-                  trim($_POST['password1'])!=trim($_POST['password2'])){
-                       //passwords are to be changed but don't match
-                       $input_errors[]="passwords don't match";
-               }
-               if((trim($_POST['password1'])=="" || trim($_POST['password1'])=="********") && 
-                  (trim($_POST['password2'])=="" || trim($_POST['password2'])=="********")){
-                       //assume password should be left as is if a password is set already.
-                       if(!empty($config['system']['users'][$_POST['old_username']]['password'])){
-                               $_POST['password1']="********";
-                               $_POST['password2']="********";
-                       } else {
-                               $input_errors[]="password must not be empty";
-                       }
-               } else {
-                       if(trim($_POST['password1'])!=trim($_POST['password2'])){
-                               //passwords are to be changed or set but don't match
-                               $input_errors[]="passwords don't match";
-                       } else {
-                               //check password for invalid characters
-                               if(!preg_match('/^[a-zA-Z0-9_\-\.@\~\(\)\&\*\+§?!\$£°\%;:]*$/',$_POST['username'])){
-                                       $input_errors[] = "password contains illegal characters, only  letters from A-Z and a-z, _, -, .,@,~,(,),&,*,+,§,?,!,$,£,°,%,;,: and numbers are allowed";
-                                       //test pw: AZaz_-.@~()&*+§?!$£°%;:
-                               }
-                       }
-               }
+       if (isset($_POST['save'])) {
+
+           unset($input_errors);
+    
+       /* input validation */
+               $reqdfields = explode(" ", "password");
+               $reqdfieldsn = explode(",", "Password");
+       
+       do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+       
+       if ($_POST['password'] != $_POST['password2'])
+               $input_errors[] = "The passwords do not match.";
+       
                if (!$input_errors) {
                        //all values are okay --> saving changes
-                       if(trim($_POST['password1'])!="********" && trim($_POST['password1'])!=""){
-                               $config['system']['users'][$_SERVER['REMOTE_USER']]['password']=crypt(trim($_POST['password1']));
-                       }
+                       $config['system']['user'][$userindex[$_SERVER['REMOTE_USER']]]['password']=crypt(trim($_POST['password']));
+
                        write_config();
                        $retval = system_password_configure();
                        $savemsg = get_std_save_message($retval);
@@ -298,6 +268,7 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
 
        
 ?>
+<?php include("fbegin.inc"); ?>
 <?php if ($input_errors) print_input_errors($input_errors); ?>
 <?php if ($savemsg) print_info_box($savemsg); ?>
       <form action="system_usermanager.php" method="post" name="iform" id="iform">
@@ -307,7 +278,7 @@ if($_GET['act']=="new" || $_GET['act']=="edit"){
             </tr>
                    <tr> 
                      <td width="22%" valign="top" class="vncell">Password</td>
-                     <td width="78%" class="vtable"> <input name="password1" type="password" class="formfld" id="password1" size="20"> 
+                     <td width="78%" class="vtable"> <input name="password" type="password" class="formfld" id="password" size="20"> 
                        <br> <input name="password2" type="password" class="formfld" id="password2" size="20"> 
                        &nbsp;(confirmation) <br> <span class="vexpl">Select a new password</span></td>
                    </tr>