From 8c6b75e5a52a48a2f8c1fcd54f143ec19780000d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Jul 2004 15:15:30 +0000 Subject: [PATCH] moved min/maxGID to module settings --- lam/help/help.inc | 3 +- lam/lib/baseModule.inc | 4 +++ lam/lib/config.inc | 53 ++---------------------------- lam/lib/modules/posixGroup.inc | 41 +++++++++++++++++++++-- lam/session-vars.txt | 2 -- lam/templates/config/conflogin.php | 2 -- lam/templates/config/confmain.php | 14 -------- lam/templates/config/confsave.php | 14 -------- lam/tests/conf-test.php | 12 ++----- 9 files changed, 48 insertions(+), 97 deletions(-) diff --git a/lam/help/help.inc b/lam/help/help.inc index e0472877..cca557da 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -153,8 +153,7 @@ $helpArray = array ( "407" => array ("ext" => "FALSE", "Headline" => _("Groupname"), "Text" => _("Group name of the group which should be created. Valid characters are: a-z,0-9, .-_. Lam does not allow a number as first character because groupadd also does not allow it. Lam does not allow capital letters A-Z because it can cause several problems. If groupname is already used groupname will be 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 %s and %s."), - "variables" => array($_SESSION['config']->get_minGID(), $_SESSION['config']->get_maxGID())), + "Text" => _("If empty GID number will be generated automaticly depending on your configuration settings.")), "409" => array ("ext" => "FALSE", "Headline" => _("Gecos"), "Text" => _("Group description. If left empty group name will be used.")), "410" => array ("ext" => "FALSE", "Headline" => _("Host name"), diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 69185713..18839a26 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -45,6 +45,9 @@ class baseModule { /** the account type of this module (user, group, host) */ var $scope; + /** configuration settings of all modules */ + var $moduleSettings; + /** * Creates a new base module class * @@ -53,6 +56,7 @@ class baseModule { function baseModule($scope) { $this->scope = $scope; $this->meta = $this->get_metaData(); + if (isset($_SESSION['config'])) $this->moduleSettings = $_SESSION['config']->get_moduleSettings(); } /** diff --git a/lam/lib/config.inc b/lam/lib/config.inc index c65bd87e..2dbf2b91 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -123,10 +123,6 @@ class Config { var $MinUID; /** Maximum UID number for users */ var $MaxUID; - /** Minimum GID number for groups */ - var $MinGID; - /** Maximum GID number for groups */ - var $MaxGID; /** Minimum UID number for Samba hosts */ var $MinMachine; /** Maximum UID number for Samba hosts */ @@ -183,7 +179,7 @@ class Config { /** List of all settings in config file */ var $settings = array("ServerURL", "Passwd", "Admins", "usersuffix", "groupsuffix", "hostsuffix", - "domainsuffix", "MinUID", "MaxUID", "MinGID", "MaxGID", "MinMachine", "MaxMachine", + "domainsuffix", "MinUID", "MaxUID", "MinMachine", "MaxMachine", "userlistAttributes", "grouplistAttributes", "hostlistAttributes", "maxlistentries", "defaultLanguage", "scriptPath", "scriptServer", "cachetimeout", "pwdhash", "usermodules", "groupmodules", "hostmodules", "modules"); @@ -269,6 +265,7 @@ class Config { $option = substr($line, $keylen + 2, strlen($line) - $keylen - 2); $pos = strpos($option, ":"); $name = substr($option, 0, $pos); + if (!isset($this->moduleSettings[$name])) continue; $file_array[$i] = "modules: " . $name . ": " . implode("+::+", $this->moduleSettings[$name]) . "\n"; $mod_saved[] = $name; // mark keyword as saved } @@ -297,8 +294,6 @@ class Config { "# e.g. ou=domains,dc=yourdomain,dc=org\n" . "domainsuffix: " . $this->domainsuffix . "\n"); if (!in_array("MinUID", $saved)) array_push($file_array, "\n\n# minimum UID number\n" . "minUID: " . $this->MinUID . "\n"); if (!in_array("MaxUID", $saved)) array_push($file_array, "\n\n# maximum UID number\n" . "maxUID: " . $this->MaxUID . "\n"); - if (!in_array("MinGID", $saved)) array_push($file_array, "\n\n# minimum GID number\n" . "minGID: " . $this->MinGID . "\n"); - if (!in_array("MaxGID", $saved)) array_push($file_array, "\n\n# maximum GID number\n" . "maxGID: " . $this->MaxGID . "\n"); if (!in_array("MinMachine", $saved)) array_push($file_array, "\n\n# minimum UID number for Samba hosts\n" . "minMachine: " . $this->MinMachine . "\n"); if (!in_array("MaxMachine", $saved)) array_push($file_array, "\n\n# maximum UID number for Samba hosts\n" . "maxMachine: " . $this->MaxMachine . "\n"); if (!in_array("userlistAttributes", $saved)) array_push($file_array, "\n\n# list of attributes to show in user list\n# entries can either be predefined values (e.g. '#cn' or '#uid')" . @@ -347,8 +342,6 @@ class Config { echo "" . _("DomainSuffix") . ": " . $this->domainsuffix . "
\n"; echo "" . _("Minimum UID number") . ": " . $this->MinUID . "
\n"; echo "" . _("Maximum UID number") . ": " . $this->MaxUID . "
\n"; - echo "" . _("Minimum GID number") . ": " . $this->MinGID . "
\n"; - echo "" . _("Maximum GID number") . ": " . $this->MaxGID . "
\n"; echo "" . _("Minimum Machine number") . ": " . $this->MinMachine . "
\n"; echo "" . _("Maximum Machine number") . ": " . $this->MaxMachine . "
\n"; echo "" . _("Attributes in User List") . ": " . $this->userlistAttributes . "
\n"; @@ -590,48 +583,6 @@ class Config { return true; } - /** - * Returns the minimum GID to use when creating new groups - * - * @return the minimum GID number - */ - function get_minGID() { - return $this->MinGID; - } - - /** - * Sets the minimum GID to use when creating new groups - * - * @param $value new minimum GID number - * @return true if $value has correct format - */ - function set_minGID($value) { - if (is_numeric($value)) $this->MinGID = $value; - else return false; - return true; - } - - /** - * Returns the maximum GID to use when creating new groups - * - * @return the maximum GID number - */ - function get_maxGID() { - return $this->MaxGID; - } - - /** - * Sets the maximum GID to use when creating new groups - * - * @param $value new maximum GID number - * @return true if $value has correct format - */ - function set_maxGID($value) { - if (is_numeric($value)) $this->MaxGID = $value; - else return false; - return true; - } - /** * Returns the minimum UID to use when creating new Samba hosts * diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index c3f9edb9..2b36cf25 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -54,6 +54,18 @@ $Id$ */ class posixGroup extends baseModule { + /** + * Creates a new posixGroup object. + */ + function posixGroup($scope) { + // error messages for input checks + $this->messages['minGID'] = array('ERROR', _('Minimum GID number'), _('Minimum GID number is invalid or empty!')); + $this->messages['maxGID'] = array('ERROR', _('Maximum GID number'), _('Maximum GID number is invalid or empty!')); + $this->messages['cmpGID'] = array('ERROR', _('Maximum GID number'), _('Maximum GID number must be greater than minimum GID number!')); + // call parent constructor + parent::baseModule($scope); + } + /** * Returns meta data that is interpreted by parent class * @@ -73,6 +85,31 @@ class posixGroup extends baseModule { $return["alias"] = _('Unix'); // module dependencies $return['dependencies'] = array('depends' => array(), 'conflicts' => array('inetOrgPerson', 'account', 'sambaDomain')); + // configuration options + $return['config_options']['group'] = array( + array( + 0 => array('kind' => 'text', 'text' => '' . _('Minimum GID number') . " *: "), + 1 => array('kind' => 'input', 'name' => 'posixGroup_minGID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), + 2 => array('kind' => 'text', 'value' => ' '), + 3 => array('kind' => 'text', 'text' => '' . _('Maximum GID number') . " *: "), + 4 => array('kind' => 'input', 'name' => 'posixGroup_maxGID', 'type' => 'text', 'size' => '10', 'maxlength' => '255'), + 5 => array('kind' => 'help', 'value' => 'TODO')) + ); + // configuration descriptions + $return['config_descriptions'] = array( + 'legend' => _("GID ranges for Unix groups"), + 'descriptions' => array( + 'posixGroup_minGID' => "Minimum GID number for Unix groups", + 'posixGroup_maxGID' => "Maximum GID number for Unix groups", + ) + ); + // configuration checks + $return['config_checks']['group']['posixGroup_minGID'] = array('type' => 'regex', 'regex' => '^[0-9]+$', + 'required' => true, 'required_message' => $this->messages['minGID'], 'error_message' => $this->messages['minGID']); + $return['config_checks']['group']['posixGroup_maxGID'] = array('type' => 'regex', 'regex' => '^[0-9]+$', + 'required' => true, 'required_message' => $this->messages['maxGID'], 'error_message' => $this->messages['maxGID']); + $return['config_checks']['group']['cmpGID'] = array('type' => 'int_greater', 'cmp_name1' => 'posixGroup_maxGID', + 'cmp_name2' => 'posixGroup_minGID', 'error_message' => $this->messages['cmpGID']); return $return; } @@ -357,8 +394,8 @@ class posixGroup extends baseModule { // Check if UID is valid. If none value was entered, the next useable value will be inserted // load min and may uidNumber - $minID = intval($_SESSION[$_SESSION[$this->base]->config]->get_minGID()); - $maxID = intval($_SESSION[$_SESSION[$this->base]->config]->get_maxGID()); + $minID = intval($this->moduleSettings['posixGroup_minGID'][0]); + $maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]); $dn_gids = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('gidNumber', 'posixGroup', '*'); // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) foreach ($dn_gids as $gid) $gids[] = $gid[0]; diff --git a/lam/session-vars.txt b/lam/session-vars.txt index bbaad0e1..83afa43e 100644 --- a/lam/session-vars.txt +++ b/lam/session-vars.txt @@ -68,8 +68,6 @@ convsave, confmain, conflogin: - conf_suffdomains: Eingabe von confmain - conf_minUID: Eingabe von confmain - conf_maxUID: Eingabe von confmain -- conf_minGID: Eingabe von confmain -- conf_maxGID: Eingabe von confmain - conf_minMach: Eingabe von confmain - conf_maxMach: Eingabe von confmain - conf_usrlstattr: Eingabe von confmain diff --git a/lam/templates/config/conflogin.php b/lam/templates/config/conflogin.php index 469a80d1..0fb58a22 100644 --- a/lam/templates/config/conflogin.php +++ b/lam/templates/config/conflogin.php @@ -52,8 +52,6 @@ unset($_SESSION['conf_suffgroups']); unset($_SESSION['conf_suffhosts']); unset($_SESSION['conf_minUID']); unset($_SESSION['conf_maxUID']); -unset($_SESSION['conf_minGID']); -unset($_SESSION['conf_maxGID']); unset($_SESSION['conf_minMach']); unset($_SESSION['conf_maxMach']); unset($_SESSION['conf_usrlstattr']); diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 24416f57..001f47c9 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -59,8 +59,6 @@ if ($_POST['back'] || $_POST['submitconf'] || $_POST['editmodules']){ $_SESSION['conf_suffdomains'] = $_POST['suffdomains']; $_SESSION['conf_minUID'] = $_POST['minUID']; $_SESSION['conf_maxUID'] = $_POST['maxUID']; - $_SESSION['conf_minGID'] = $_POST['minGID']; - $_SESSION['conf_maxGID'] = $_POST['maxGID']; $_SESSION['conf_minMach'] = $_POST['minMach']; $_SESSION['conf_maxMach'] = $_POST['maxMach']; $_SESSION['conf_usrlstattr'] = $_POST['usrlstattr']; @@ -131,8 +129,6 @@ if ($_GET["modulesback"] == "true") { $conf->set_DomainSuffix($_SESSION['conf_suffdomains']); $conf->set_minUID($_SESSION['conf_minUID']); $conf->set_maxUID($_SESSION['conf_maxUID']); - $conf->set_minGID($_SESSION['conf_minGID']); - $conf->set_maxGID($_SESSION['conf_maxGID']); $conf->set_minMachine($_SESSION['conf_minMach']); $conf->set_maxMachine($_SESSION['conf_maxMach']); $conf->set_userlistAttributes($_SESSION['conf_usrlstattr']); @@ -314,16 +310,6 @@ echo ("" . _("Maximum UID number") . " *: ". "get_maxUID() . "\">\n"); // UID text echo ("" . _("Help") . "\n"); -// minGID -echo ("". - _("Minimum GID number") . " *: ". - "get_minGID() . "\">\n"); -echo "   \n"; -// maxGID -echo ("" . _("Maximum GID number")." *: ". - "get_maxGID() . "\">\n"); -// GID text -echo ("" . _("Help") . "\n"); // minMach echo ("". _("Minimum Machine number") . " **: ". diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php index b547debe..5387bc83 100644 --- a/lam/templates/config/confsave.php +++ b/lam/templates/config/confsave.php @@ -54,8 +54,6 @@ $suffhosts = $_SESSION['conf_suffhosts']; $suffdomains = $_SESSION['conf_suffdomains']; $minUID = $_SESSION['conf_minUID']; $maxUID = $_SESSION['conf_maxUID']; -$minGID = $_SESSION['conf_minGID']; -$maxGID = $_SESSION['conf_maxGID']; $minMach = $_SESSION['conf_minMach']; $maxMach = $_SESSION['conf_maxMach']; $usrlstattr = $_SESSION['conf_usrlstattr']; @@ -131,16 +129,6 @@ if (!$conf->set_maxUID($maxUID)) { echo ("\n


" . _("Back to preferences...") . ""); exit; } -if (!$conf->set_minGID($minGID)) { - echo ("" . _("Minimum GID number is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} -if (!$conf->set_maxGID($maxGID)) { - echo ("" . _("Maximum GID number is invalid!") . ""); - echo ("\n


" . _("Back to preferences...") . ""); - exit; -} if (!$conf->set_minMachine($minMach)) { echo ("" . _("Minimum Machine number is invalid!") . ""); echo ("\n


" . _("Back to preferences...") . ""); @@ -297,8 +285,6 @@ unset($_SESSION['conf_suffhosts']); unset($_SESSION['conf_suffdomains']); unset($_SESSION['conf_minUID']); unset($_SESSION['conf_maxUID']); -unset($_SESSION['conf_minGID']); -unset($_SESSION['conf_maxGID']); unset($_SESSION['conf_minMach']); unset($_SESSION['conf_maxMach']); unset($_SESSION['conf_usrlstattr']); diff --git a/lam/tests/conf-test.php b/lam/tests/conf-test.php index 49cab02f..cec40b2c 100644 --- a/lam/tests/conf-test.php +++ b/lam/tests/conf-test.php @@ -41,8 +41,6 @@ $Suff_hosts = $conf->get_HostSuffix(); $Suff_domains = $conf->get_DomainSuffix(); $MinUID = $conf->get_minUID(); $MaxUID = $conf->get_maxUID(); -$MinGID = $conf->get_minGID(); -$MaxGID = $conf->get_maxGID(); $MinMachine = $conf->get_minMachine(); $MaxMachine = $conf->get_maxMachine(); $userlistAttributes = $conf->get_userlistAttributes(); @@ -67,8 +65,6 @@ $conf->set_HostSuffix("ou=testhst,o=test,c=de"); $conf->set_DomainSuffix("ou=testdom,o=test,c=de"); $conf->set_minUID("25"); $conf->set_maxUID("254"); -$conf->set_minGID("253"); -$conf->set_maxGID("1234"); $conf->set_minMachine("3"); $conf->set_maxMachine("47"); $conf->set_userlistAttributes("#uid;#cn"); @@ -79,7 +75,7 @@ $conf->set_defaultlanguage("de_AT:iso639_de:Deutsch (Oesterreich)"); $conf->set_scriptPath("/var/www/lam/lib/script"); $conf->set_scriptServer("127.0.0.1"); $conf->set_pwdhash("SMD5"); -$conf->set_moduleSettings(array("test1" => 11, "test2" => "abc", 'test3' => 3)); +$conf->set_moduleSettings(array("test1" => array(11), "test2" => array("abc"), 'test3' => array(3))); $conf->save(); echo ("done
"); // at last all preferences are read from lam.conf and compared @@ -95,8 +91,6 @@ if ($conf2->get_HostSuffix() != "ou=testhst,o=test,c=de") echo ("
get_DomainSuffix() != "ou=testdom,o=test,c=de") echo ("
Saving domain suffix failed!
"); if ($conf2->get_minUID() != "25") echo ("
Saving minUID failed!
"); if ($conf2->get_maxUID() != "254") echo ("
Saving maxUID failed!
"); -if ($conf2->get_minGID() != "253") echo ("
Saving minGID failed!
"); -if ($conf2->get_maxGID() != "1234") echo ("
Saving maxGID failed!
"); if ($conf2->get_minMachine() != "3") echo ("
Saving maxMachine failed!
"); if ($conf2->get_maxMachine() != "47") echo ("
Saving minMachine failed!
"); if ($conf2->get_userlistAttributes() != "#uid;#cn") echo ("
Saving userlistAttributes failed!
"); @@ -108,7 +102,7 @@ if ($conf2->get_scriptPath() != "/var/www/lam/lib/script") echo ("
get_scriptServer() != "127.0.0.1") echo ("
Saving script server failed!
"); if ($conf2->get_pwdhash() != "SMD5") echo ("
Saving pwdhash failed!
"); $msettings = $conf2->get_moduleSettings(); -if (($msettings['test1'] != 11) || ($msettings['test2'] != 'abc') || ($msettings['test3'] != '3')) echo ("
Saving module settings failed!
"); +if (($msettings['test1'][0] != 11) || ($msettings['test2'][0] != 'abc') || ($msettings['test3'][0] != '3')) echo ("
Saving module settings failed!
"); echo ("done
"); // restore old values echo ("Restoring old preferences..."); @@ -122,8 +116,6 @@ $conf2->set_HostSuffix($Suff_hosts); $conf2->set_DomainSuffix($Suff_domains); $conf2->set_minUID($MinUID); $conf2->set_maxUID($MaxUID); -$conf2->set_minGID($MinGID); -$conf2->set_maxGID($MaxGID); $conf2->set_minMachine($MinMachine); $conf2->set_maxMachine($MaxMachine); $conf2->set_userlistAttributes($userlistAttributes);