Added function autoexpand user/group/hostnames
This commit is contained in:
parent
65d9eda1cc
commit
98b4e65f3a
|
@ -153,7 +153,7 @@ $helpArray = array (
|
|||
"400" => array ("ext" => "FALSE", "Headline" => _("Username"),
|
||||
"Text" => _("Username of the user which should be created. Valid characters are: a-z,0-9, .-_. Lam doesn't allow a number as first
|
||||
character because it's impossible to create a homedirectory starting with a number. Lam doesn't allow capital letters A-Z because it
|
||||
can cause several problems.")),
|
||||
can cause several problems. If username is allready used username will expanded with a number. The next free number will be used.")),
|
||||
"401" => array ("ext" => "FALSE", "Headline" => _("UID Number"),
|
||||
"Text" => _("If empty UID Number will be generated automaticly. Valid values are between ").$_SESSION['config']->get_minUID()._(" and ").$_SESSION['config']->get_maxUID()."."),
|
||||
"402" => array ("ext" => "FALSE", "Headline" => _("Additional Groupmembership"),
|
||||
|
@ -169,7 +169,7 @@ $helpArray = array (
|
|||
"407" => array ("ext" => "FALSE", "Headline" => _("Groupname"),
|
||||
"Text" => _("Groupname of the group which should be created. Valid characters are: a-z,0-9, .-_. Lam doesn't allow a number as first
|
||||
character because it's impossible to create a homedirectory starting with a number. Lam doesn't allow capital letters A-Z because it
|
||||
can cause several problems.")),
|
||||
can cause several problems. If groupname is allready used username will expanded with a number. The next free number will be used.")),
|
||||
"408" => array ("ext" => "FALSE", "Headline" => _("GID Number"),
|
||||
"Text" => _("If empty GID Number will be generated automaticly. Valid values are between ").$_SESSION['config']->get_minGID()._(" and ").$_SESSION['config']->get_maxGID()."."),
|
||||
"409" => array ("ext" => "FALSE", "Headline" => _("Gecos"),
|
||||
|
@ -177,7 +177,7 @@ $helpArray = array (
|
|||
"410" => array ("ext" => "FALSE", "Headline" => _("Hostname"),
|
||||
"Text" => _("Groupname of the group which should be created. Valid characters are: a-z,0-9, .-_$. Lam doesn't allow a number as first
|
||||
character because it's impossible to create a homedirectory starting with a number. Lam doesn't allow capital letters A-Z because it
|
||||
can cause several problems. Hostnames are always ending with $. If last character isn't $ it will be added.")),
|
||||
can cause several problems. Hostnames are always ending with $. If last character isn't $ it will be added. If hostname is allready used username will expanded with a number. The next free number will be used.")),
|
||||
"411" => array ("ext" => "FALSE", "Headline" => _("UID Number"),
|
||||
"Text" => _("If empty UID Number will be generated automaticly. Valid values are between ").$_SESSION['config']->get_minMachine()._(" and ").$_SESSION['config']->get_maxMachine()."."),
|
||||
"412" => array ("ext" => "FALSE", "Headline" => _("Primary Group"),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>LDAP Account Manager</title>
|
||||
<meta http-equiv="refresh" content="0; URL=templates/login.php">';
|
||||
</head>
|
||||
<body>
|
||||
<meta http-equiv="refresh" content="0; URL=templates/login.php">';
|
||||
</body>
|
||||
</html>
|
|
@ -177,13 +177,55 @@ function checkglobal($values, $type, $values_old=false) { // This functions chec
|
|||
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username))
|
||||
return _('Username contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !');
|
||||
// Check if user already exists
|
||||
$return->general_username = $values->general_username;
|
||||
// Create automatic useraccount with number if original user allready exists
|
||||
while ($temp = ldapexists($return, $type, $values_old)) {
|
||||
// get last character of username
|
||||
$lastchar = substr($return->general_username, strlen($return->general_username)-1, 1);
|
||||
// Last character is no number
|
||||
if ( !ereg('^([0-9])+$', $lastchar))
|
||||
$return->general_username = $return->general_username . '2';
|
||||
else {
|
||||
$i=strlen($return->general_username)-1;
|
||||
$mark = false;
|
||||
while (!$mark) {
|
||||
if (ereg('^([0-9])+$',substr($return->general_username, $i, strlen($return->general_username)-$i))) $i--;
|
||||
else $mark=true;
|
||||
}
|
||||
// increase last number with one
|
||||
$firstchars = substr($return->general_username, 0, $i+1);
|
||||
$lastchars = substr($return->general_username, $i+1, strlen($return->general_username)-$i);
|
||||
$return->general_username = $firstchars . (intval($lastchars)+1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'group' :
|
||||
// Check if Groupname contents only valid characters
|
||||
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username))
|
||||
return _('Groupname contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !');
|
||||
// Check if group already exists
|
||||
if ($values->general_gecos=='') $return->general_gecos = $values->general_username ;
|
||||
// Check if user already exists
|
||||
$return->general_username = $values->general_username;
|
||||
// Create automatic groupaccount with number if original user allready exists
|
||||
while ($temp = ldapexists($return, $type, $values_old)) {
|
||||
// get last character of username
|
||||
$lastchar = substr($return->general_username, strlen($return->general_username)-1, 1);
|
||||
// Last character is no number
|
||||
if ( !ereg('^([0-9])+$', $lastchar))
|
||||
$return->general_username = $return->general_username . '2';
|
||||
else {
|
||||
$i=strlen($return->general_username)-1;
|
||||
$mark = false;
|
||||
while (!$mark) {
|
||||
if (ereg('^([0-9])+$',substr($return->general_username, $i, strlen($return->general_username)-$i))) $i--;
|
||||
else $mark=true;
|
||||
}
|
||||
// increase last number with one
|
||||
$firstchars = substr($return->general_username, 0, $i+1);
|
||||
$lastchars = substr($return->general_username, $i+1, strlen($return->general_username)-$i);
|
||||
$return->general_username = $firstchars . (intval($lastchars)+1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'host' :
|
||||
if ( substr($values->general_username, strlen($values->general_username)-1, strlen($values->general_username)) != '$' )
|
||||
|
@ -194,10 +236,31 @@ function checkglobal($values, $type, $values_old=false) { // This functions chec
|
|||
// Check if Hostname already exists
|
||||
$return->general_homedir = '/dev/null';
|
||||
$return->general_shell = '/bin/false';
|
||||
// Check if user already exists
|
||||
$return->general_username = $values->general_username;
|
||||
if ($values->general_gecos=='') $return->general_gecos = $values->general_username;
|
||||
// Create automatic groupaccount with number if original user allready exists
|
||||
while ($temp = ldapexists($return, $type, $values_old)) {
|
||||
// get last character of username
|
||||
$lastchar = substr($return->general_username, strlen($return->general_username)-2, 1);
|
||||
// Last character is no number
|
||||
if ( !ereg('^([0-9])+$', $lastchar))
|
||||
$return->general_username = $return->general_username . '2';
|
||||
else {
|
||||
$i=strlen($return->general_username)-3;
|
||||
$mark = false;
|
||||
while (!$mark) {
|
||||
if (ereg('^([0-9])+$',substr($return->general_username, $i, strlen($return->general_username)-1))) $i--;
|
||||
else $mark=true;
|
||||
}
|
||||
// increase last number with one
|
||||
$firstchars = substr($return->general_username, 0, $i+1);
|
||||
$lastchars = substr($return->general_username, $i+1, strlen($return->general_username)-$i);
|
||||
$return->general_username = $firstchars . (intval($lastchars)+1). '$';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($temp = ldapexists($values, $type, $values_old)) return $temp;
|
||||
// Check if UID is valid. If none value was entered, the next useable value will be inserted
|
||||
$return->general_uidNumber = checkid($values, $type, $values_old);
|
||||
if (is_string($return->general_uidNumber)) return $return->general_uidNumber;
|
||||
|
|
Loading…
Reference in New Issue