diff --git a/admin/common.inc.php b/admin/common.inc.php index 341f89d..dee764f 100644 --- a/admin/common.inc.php +++ b/admin/common.inc.php @@ -169,5 +169,7 @@ function cmp_by_usernames(&$user1, &$user2) { $namemapdata = file_get_contents($davconfig['namemap.file']); $namemap = json_decode($namemapdata, true); -uasort($namemap, "cmp_by_usernames"); -?> \ No newline at end of file +if (is_array($namemap)) { + uasort($namemap, "cmp_by_usernames"); +} +?> diff --git a/admin/scripts/users.js b/admin/scripts/users.js index 18e5d5c..f5e69db 100644 --- a/admin/scripts/users.js +++ b/admin/scripts/users.js @@ -102,7 +102,7 @@ function displayusereditor(title, userid, username, firstname, lastname, groups) return false; } } - if (!this.groups.value.match(/^([0-9a-zA-z]+[,\s]*)+$/)) { + if (!this.groups.value.match(/^[0-9a-zA-z]+(\s*,\s*[0-9a-zA-z]+)*$/)) { alert(intl.translate("The groups field has to be a comma separated list of group names which must consist of letters or digits!")); this.groups.focus(); return false; diff --git a/admin/users.php b/admin/users.php index 6bdbf25..af8f3bb 100644 --- a/admin/users.php +++ b/admin/users.php @@ -123,7 +123,7 @@ function validateUserData(&$userdata, $forinsert) { if (empty($userdata['lastname'])) { $userdata['lastname'] = null; } - if (!preg_match('/^([0-9a-zA-z]+[,\s]*)+$/', $userdata['groups'])) { + if (!preg_match('/^[0-9a-zA-z]+(\s*,\s*[0-9a-zA-z]+)*$/', $userdata['groups'])) { array_push($errormsgs, _('Groups must be a list of group names separated by commas. Group names must consist of letters and digits.')); } return $errormsgs; @@ -209,7 +209,12 @@ function updateGroups(&$userdata) { fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); $written[$group] = true; } else { - fwrite($fh, $groupline); + if (in_array($userdata['username'], $users)) { + array_splice($users, array_search($userdata['username'], $users),1); + } + if (count($users) > 0 ) { + fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); + } } } foreach ($written as $group => $done) { @@ -286,8 +291,8 @@ function removeDigest($username) { $digests = file($GLOBALS['davconfig']['digest.file']); $fh = fopen($GLOBALS['davconfig']['digest.file'], 'w'); foreach ($digests as $digest) { - list($username, $realm, $data) = explode(":", $digest); - if (!($username == $userdata['username'] + list($user, $realm, $data) = explode(":", $digest); + if (!($user == $username && $realm == $GLOBALS['davconfig']['dav.realm'])) { fwrite($fh, $digest); } @@ -311,9 +316,11 @@ function removeFromGroups($username) { $users[$key] = trim($user); } if (in_array($username, $users)) { - $users = array_splice($users, array_search($username, $users)); + array_splice($users, array_search($username, $users),1); + } + if (count($users) > 0 ) { + fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); } - fprintf($fh, "%s: %s\n", $group, implode(" ", $users)); } fclose($fh); }