Added function autoexpand user/group/hostnames

This commit is contained in:
katagia 2003-06-09 14:17:23 +00:00
parent 65d9eda1cc
commit 98b4e65f3a
3 changed files with 69 additions and 6 deletions

View File

@ -153,7 +153,7 @@ $helpArray = array (
"400" => array ("ext" => "FALSE", "Headline" => _("Username"), "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 "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 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"), "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()."."), "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"), "402" => array ("ext" => "FALSE", "Headline" => _("Additional Groupmembership"),
@ -169,7 +169,7 @@ $helpArray = array (
"407" => array ("ext" => "FALSE", "Headline" => _("Groupname"), "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 "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 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"), "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()."."), "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"), "409" => array ("ext" => "FALSE", "Headline" => _("Gecos"),
@ -177,7 +177,7 @@ $helpArray = array (
"410" => array ("ext" => "FALSE", "Headline" => _("Hostname"), "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 "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 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"), "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()."."), "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"), "412" => array ("ext" => "FALSE", "Headline" => _("Primary Group"),

View File

@ -1,8 +1,8 @@
<html> <html>
<head> <head>
<title>LDAP Account Manager</title> <title>LDAP Account Manager</title>
<meta http-equiv="refresh" content="0; URL=templates/login.php">';
</head> </head>
<body> <body>
<meta http-equiv="refresh" content="0; URL=templates/login.php">';
</body> </body>
</html> </html>

View File

@ -177,13 +177,55 @@ function checkglobal($values, $type, $values_old=false) { // This functions chec
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username)) if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username))
return _('Username contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !'); return _('Username contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !');
// Check if user already exists // 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; break;
case 'group' : case 'group' :
// Check if Groupname contents only valid characters // Check if Groupname contents only valid characters
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username)) if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username))
return _('Groupname contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !'); 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 ; 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; break;
case 'host' : case 'host' :
if ( substr($values->general_username, strlen($values->general_username)-1, strlen($values->general_username)) != '$' ) 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 // Check if Hostname already exists
$return->general_homedir = '/dev/null'; $return->general_homedir = '/dev/null';
$return->general_shell = '/bin/false'; $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; 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; 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 // 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); $return->general_uidNumber = checkid($values, $type, $values_old);
if (is_string($return->general_uidNumber)) return $return->general_uidNumber; if (is_string($return->general_uidNumber)) return $return->general_uidNumber;