refactoring

This commit is contained in:
Roland Gruber 2018-12-23 11:11:23 +01:00
parent 2a10013f36
commit 077556a6a9
4 changed files with 44 additions and 39 deletions

View File

@ -57,9 +57,10 @@ include_once("html.inc");
$modulesINC_dirname = substr(__FILE__, 0, strlen(__FILE__) - 12) . "/modules";
$modulesINC_dir = dir($modulesINC_dirname);
// get module names.
while ($entry = $modulesINC_dir->read())
if ((substr($entry, strlen($entry) - 4, 4) == '.inc') && is_file($modulesINC_dirname . '/'.$entry)) {
include_once($modulesINC_dirname . '/'.$entry);
while ($entry = $modulesINC_dir->read()) {
if ((substr($entry, strlen($entry) - 4, 4) == '.inc') && is_file($modulesINC_dirname . '/'.$entry)) {
include_once($modulesINC_dirname . '/'.$entry);
}
}
/**

View File

@ -1183,15 +1183,15 @@ class posixAccount extends baseModule implements passwordService {
$errors[] = $error;
}
}
if ($this->get_scope()=='user') {
if (($this->get_scope() == 'user') && !get_preg($this->attributes['uid'][0], 'username')) {
// Check if Username contains only valid characters
if (!get_preg($this->attributes['uid'][0], 'username'))
$errors[] = $this->messages['uid'][2];
}
if ($this->get_scope()=='host') {
if ($this->get_scope() == 'host') {
// Check if Hostname contains only valid characters
if (!get_preg($this->attributes['uid'][0], 'hostname'))
$errors[] = $this->messages['uid'][4];
if (!get_preg($this->attributes['uid'][0], 'hostname')) {
$errors[] = $this->messages['uid'][4];
}
if (!isset($this->attributes[$homedirAttrName][0])) {
$this->attributes[$homedirAttrName][0] = '/dev/null';
}

View File

@ -924,8 +924,9 @@ class posixGroup extends baseModule implements passwordService {
$errors[] = $this->messages['cn'][0];
}
// Check if Groupname contains only valid characters
if ( !get_preg($this->attributes['cn'][0],'groupname'))
$errors[] = $this->messages['cn'][2];
if (!get_preg($this->attributes['cn'][0],'groupname')) {
$errors[] = $this->messages['cn'][2];
}
// Create automatic useraccount with number if original user already exists
// Reset name to original name if new name is in use
// Set username back to original name if new group name is in use
@ -933,34 +934,36 @@ class posixGroup extends baseModule implements passwordService {
$this->attributes['cn'][0] = $this->orig['cn'][0];
}
// Change gid to a new gid until a free gid is found
else while ($this->groupNameExists($this->attributes['cn'][0])) {
// get last character of group name
$lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-1, 1);
// Last character is no number
if ( !preg_match('/^([0-9])+$/', $lastchar))
/* Last character is no number. Therefore we only have to
* add "2" to it.
*/
$this->attributes['cn'][0] = $this->attributes['cn'][0] . '2';
else {
/* Last character is a number -> we have to increase the number until we've
* found a groupname with trailing number which is not in use.
*
* $i will show us were we have to split groupname so we get a part
* with the groupname and a part with the trailing number
else {
while ($this->groupNameExists($this->attributes['cn'][0])) {
// get last character of group name
$lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-1, 1);
// Last character is no number
if ( !preg_match('/^([0-9])+$/', $lastchar))
/* Last character is no number. Therefore we only have to
* add "2" to it.
*/
$i=strlen($this->attributes['cn'][0])-1;
$mark = false;
// Set $i to the last character which is a number in $account_new->general_username
while (!$mark) {
if (preg_match('/^([0-9])+$/',substr($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0])-$i))) $i--;
else $mark=true;
$this->attributes['cn'][0] = $this->attributes['cn'][0] . '2';
else {
/* Last character is a number -> we have to increase the number until we've
* found a groupname with trailing number which is not in use.
*
* $i will show us were we have to split groupname so we get a part
* with the groupname and a part with the trailing number
*/
$i=strlen($this->attributes['cn'][0])-1;
$mark = false;
// Set $i to the last character which is a number in $account_new->general_username
while (!$mark) {
if (preg_match('/^([0-9])+$/',substr($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0])-$i))) $i--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($this->attributes['cn'][0], 0, $i+1);
$lastchars = substr($this->attributes['cn'][0], $i+1, strlen($this->attributes['cn'][0])-$i);
// Put username together
$this->attributes['cn'][0] = $firstchars . (intval($lastchars)+1);
}
// increase last number with one
$firstchars = substr($this->attributes['cn'][0], 0, $i+1);
$lastchars = substr($this->attributes['cn'][0], $i+1, strlen($this->attributes['cn'][0])-$i);
// Put username together
$this->attributes['cn'][0] = $firstchars . (intval($lastchars)+1);
}
}
// Show warning if lam has changed group name

View File

@ -42,9 +42,10 @@ include_once("selfService.inc");
$typesINC_dirname = substr(__FILE__, 0, strlen(__FILE__) - 10) . "/types";
$typesINC_dir = dir($typesINC_dirname);
// get module names.
while ($entry = $typesINC_dir->read())
if ((substr($entry, strlen($entry) - 4, 4) == '.inc') && is_file($typesINC_dirname . '/'.$entry)) {
include_once($typesINC_dirname . '/'.$entry);
while ($entry = $typesINC_dir->read()) {
if ((substr($entry, strlen($entry) - 4, 4) == '.inc') && is_file($typesINC_dirname . '/'.$entry)) {
include_once($typesINC_dirname . '/'.$entry);
}
}