From 98b4e65f3a5c7cc21c597a5e2d5d6bddebf05c6c Mon Sep 17 00:00:00 2001 From: katagia Date: Mon, 9 Jun 2003 14:17:23 +0000 Subject: [PATCH] Added function autoexpand user/group/hostnames --- lam/help/help.inc | 6 ++-- lam/index.html | 2 +- lam/lib/account.inc | 67 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/lam/help/help.inc b/lam/help/help.inc index 64c1a2d0..eff152bb 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -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"), diff --git a/lam/index.html b/lam/index.html index 6c0ec572..12a79d8d 100644 --- a/lam/index.html +++ b/lam/index.html @@ -1,8 +1,8 @@ LDAP Account Manager +'; -'; \ No newline at end of file diff --git a/lam/lib/account.inc b/lam/lib/account.inc index d91faaa3..b38206be 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -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;