From c334ffbaacfda513d2ab8a73df3d6a34a6ae664d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 15 Sep 2003 16:24:44 +0000 Subject: [PATCH] added is_samba3() function --- lam/lib/config.inc | 239 ++++++++++++------------- lam/lib/ldap.inc | 2 +- lam/lib/profiles.inc | 4 +- lam/templates/config/confmain.php | 2 +- lam/templates/groupmembers.php | 4 +- lam/templates/lists/listhosts.php | 2 +- lam/templates/lists/listusers.php | 2 +- lam/templates/main.php | 4 +- lam/templates/main_header.php | 6 +- lam/templates/ou_edit.php | 2 +- lam/templates/profedit/profilehost.php | 2 +- lam/templates/profedit/profileuser.php | 2 +- 12 files changed, 133 insertions(+), 138 deletions(-) diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 105b8d75..2edaed53 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -148,112 +148,117 @@ class Config { $this->reload(); } - // reloads preferences from config file - function reload() { - $conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf"; - if (is_file($conffile) == True) { - $file = fopen($conffile, "r"); - while (!feof($file)) { - $line = fgets($file, 1024); - if (($line == "\n")||($line[0] == "#")) continue; // ignore comments - // search keywords - if (strtolower(substr($line, 0, 11)) == "serverurl: ") { - $this->ServerURL = chop(substr($line, 11, strlen($line)-11)); - continue; + // reloads preferences from config file + function reload() { + // list of all settings in config file + $settings = array("ServerURL", "Passwd", "Admins", "usersuffix", "groupsuffix", "hostsuffix", + "domainsuffix", "minuid", "maxuid", "mingid", "maxgid", "minmachine", "maxmachine", + "userlistattributes", "grouplistattributes", "hostlistattributes", "maxlistentries", + "defaultlanguage", "scriptpath", "scriptServer", "samba3", "cachetimeout"); + $conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf"; + if (is_file($conffile) == True) { + $file = fopen($conffile, "r"); + while (!feof($file)) { + $line = fgets($file, 1024); + if (($line == "\n")||($line[0] == "#")) continue; // ignore comments + // search keywords + if (strtolower(substr($line, 0, 11)) == "serverurl: ") { + $this->ServerURL = chop(substr($line, 11, strlen($line)-11)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "passwd: ") { + $this->Passwd = chop(substr($line, 8, strlen($line)-8)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "admins: ") { + $adminstr = chop(substr($line, 8, strlen($line)-8)); + $this->Adminstring = $adminstr; + $this->Admins = explode(";", $adminstr); + continue; + } + if (strtolower(substr($line, 0, 12)) == "usersuffix: ") { + $this->Suff_users = chop(substr($line, 12, strlen($line)-12)); + continue; + } + if (strtolower(substr($line, 0, 13)) == "groupsuffix: ") { + $this->Suff_groups = chop(substr($line, 13, strlen($line)-13)); + continue; + } + if (strtolower(substr($line, 0, 12)) == "hostsuffix: ") { + $this->Suff_hosts = chop(substr($line, 12, strlen($line)-12)); + continue; + } + if (strtolower(substr($line, 0, 14)) == "domainsuffix: ") { + $this->Suff_domains = chop(substr($line, 14, strlen($line)-14)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "minuid: ") { + $this->MinUID = chop(substr($line, 8, strlen($line)-8)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "maxuid: ") { + $this->MaxUID = chop(substr($line, 8, strlen($line)-8)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "mingid: ") { + $this->MinGID = chop(substr($line, 8, strlen($line)-8)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "maxgid: ") { + $this->MaxGID = chop(substr($line, 8, strlen($line)-8)); + continue; + } + if (strtolower(substr($line, 0, 12)) == "minmachine: ") { + $this->MinMachine = chop(substr($line, 12, strlen($line)-12)); + continue; + } + if (strtolower(substr($line, 0, 12)) == "maxmachine: ") { + $this->MaxMachine = chop(substr($line, 12, strlen($line)-12)); + continue; + } + if (strtolower(substr($line, 0, 20)) == "userlistattributes: ") { + $this->userlistAttributes = chop(substr($line, 20, strlen($line)-20)); + continue; + } + if (strtolower(substr($line, 0, 21)) == "grouplistattributes: ") { + $this->grouplistAttributes = chop(substr($line, 21, strlen($line)-21)); + continue; + } + if (strtolower(substr($line, 0, 20)) == "hostlistattributes: ") { + $this->hostlistAttributes = chop(substr($line, 20, strlen($line)-20)); + continue; + } + if (strtolower(substr($line, 0, 16)) == "maxlistentries: ") { + $this->maxlistentries = chop(substr($line, 16, strlen($line)-16)); + continue; + } + if (strtolower(substr($line, 0, 17)) == "defaultlanguage: ") { + $this->defaultLanguage = chop(substr($line, 17, strlen($line)-17)); + continue; + } + if (strtolower(substr($line, 0, 12)) == "scriptpath: ") { + $this->scriptPath = chop(substr($line, 12, strlen($line)-12)); + continue; + } + if (strtolower(substr($line, 0, 14)) == "scriptserver: ") { + $this->scriptServer = chop(substr($line, 14, strlen($line)-14)); + continue; + } + if (strtolower(substr($line, 0, 8)) == "samba3: ") { + $this->samba3 = strtolower(chop(substr($line, 8, strlen($line)-8))); + continue; + } + if (strtolower(substr($line, 0, 14)) == "cachetimeout: ") { + $this->cache_timeout = chop(substr($line, 14, strlen($line)-14)); + continue; + } + } + fclose($file); + } + else { + StatusMessage("ERROR", "", _("Unable to load configuration!") . " (" . $conffile . ")"); + } } - if (strtolower(substr($line, 0, 8)) == "passwd: ") { - $this->Passwd = chop(substr($line, 8, strlen($line)-8)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "admins: ") { - $adminstr = chop(substr($line, 8, strlen($line)-8)); - $this->Adminstring = $adminstr; - $this->Admins = explode(";", $adminstr); - continue; - } - if (strtolower(substr($line, 0, 12)) == "usersuffix: ") { - $this->Suff_users = chop(substr($line, 12, strlen($line)-12)); - continue; - } - if (strtolower(substr($line, 0, 13)) == "groupsuffix: ") { - $this->Suff_groups = chop(substr($line, 13, strlen($line)-13)); - continue; - } - if (strtolower(substr($line, 0, 12)) == "hostsuffix: ") { - $this->Suff_hosts = chop(substr($line, 12, strlen($line)-12)); - continue; - } - if (strtolower(substr($line, 0, 14)) == "domainsuffix: ") { - $this->Suff_domains = chop(substr($line, 14, strlen($line)-14)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "minuid: ") { - $this->MinUID = chop(substr($line, 8, strlen($line)-8)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "maxuid: ") { - $this->MaxUID = chop(substr($line, 8, strlen($line)-8)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "mingid: ") { - $this->MinGID = chop(substr($line, 8, strlen($line)-8)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "maxgid: ") { - $this->MaxGID = chop(substr($line, 8, strlen($line)-8)); - continue; - } - if (strtolower(substr($line, 0, 12)) == "minmachine: ") { - $this->MinMachine = chop(substr($line, 12, strlen($line)-12)); - continue; - } - if (strtolower(substr($line, 0, 12)) == "maxmachine: ") { - $this->MaxMachine = chop(substr($line, 12, strlen($line)-12)); - continue; - } - if (strtolower(substr($line, 0, 20)) == "userlistattributes: ") { - $this->userlistAttributes = chop(substr($line, 20, strlen($line)-20)); - continue; - } - if (strtolower(substr($line, 0, 21)) == "grouplistattributes: ") { - $this->grouplistAttributes = chop(substr($line, 21, strlen($line)-21)); - continue; - } - if (strtolower(substr($line, 0, 20)) == "hostlistattributes: ") { - $this->hostlistAttributes = chop(substr($line, 20, strlen($line)-20)); - continue; - } - if (strtolower(substr($line, 0, 16)) == "maxlistentries: ") { - $this->maxlistentries = chop(substr($line, 16, strlen($line)-16)); - continue; - } - if (strtolower(substr($line, 0, 17)) == "defaultlanguage: ") { - $this->defaultLanguage = chop(substr($line, 17, strlen($line)-17)); - continue; - } - if (strtolower(substr($line, 0, 12)) == "scriptpath: ") { - $this->scriptPath = chop(substr($line, 12, strlen($line)-12)); - continue; - } - if (strtolower(substr($line, 0, 14)) == "scriptserver: ") { - $this->scriptServer = chop(substr($line, 14, strlen($line)-14)); - continue; - } - if (strtolower(substr($line, 0, 8)) == "samba3: ") { - $this->samba3 = strtolower(chop(substr($line, 8, strlen($line)-8))); - continue; - } - if (strtolower(substr($line, 0, 14)) == "cachetimeout: ") { - $this->cache_timeout = chop(substr($line, 14, strlen($line)-14)); - continue; - } - } - fclose($file); - } - else { - StatusMessage("ERROR", "", _("Unable to load configuration!") . " (" . $conffile . ")"); - } - } // saves preferences to config file function save() { @@ -471,23 +476,7 @@ class Config { // returns an array of string with all admin names function get_Admins() { - return $this->Admins; - } - - // needs an array of string containing all admin users - function set_Admins($value) { - if (is_array($value)) { // check if $value is array of strings - $b = true; - for($i = 0; $i < sizeof($value); $i++){ - if (is_string($value[$i]) == false) { - $b = false; - break; - } - } - if ($b) $this->Admins = $value; - } - else return false; - return true; + return explode(";", $this->Adminstring); } // returns all admin users seperated by semicolons @@ -746,6 +735,12 @@ class Config { return $this->samba3; } + // returns true if Samba 3, else false + function is_samba3() { + if ($this->samba3 == "yes") return true; + else return false; + } + // set Samba version: "yes" means 3.x schema, "no" means 2.2.x schema function set_samba3($value) { if (is_string($value) && eregi("^(yes|no)$", $value)) { diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc index d7852832..742a8bdf 100644 --- a/lam/lib/ldap.inc +++ b/lam/lib/ldap.inc @@ -123,7 +123,7 @@ class Ldap{ // searches LDAP for a specific user name // and returns its DN entry function search_username($name) { - if ($this->conf->get_samba3() == "yes") { + if ($this->conf->is_samba3()) { // users have the attribute "posixAccount" or "sambaSamAccount" and uid $name $filter = "(&(objectClass=sambaSamAccount) (uid=$name))"; } diff --git a/lam/lib/profiles.inc b/lam/lib/profiles.inc index fe83da83..0fb1b655 100644 --- a/lam/lib/profiles.inc +++ b/lam/lib/profiles.inc @@ -173,7 +173,7 @@ function loadUserProfile($profile) { continue; } if (substr($line, 0, 12) == "smb_domain: ") { - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { $dn = chop(substr($line, 12, strlen($line)-12)); // load domain object $dom = new samba3domain(); @@ -234,7 +234,7 @@ function loadHostProfile($profile) { continue; } if (substr($line, 0, 12) == "smb_domain: ") { - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { $dn = chop(substr($line, 12, strlen($line)-12)); // load domain object $dom = new samba3domain(); diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index d40f5a80..aad6fd59 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -168,7 +168,7 @@ echo (""); // Samba version echo (""); +if ($conf->is_samba3()) echo (""); else echo (""); echo ("\n"); diff --git a/lam/templates/groupmembers.php b/lam/templates/groupmembers.php index d44f24f4..81e32a00 100644 --- a/lam/templates/groupmembers.php +++ b/lam/templates/groupmembers.php @@ -171,7 +171,7 @@ if ($sr) { echo "get_samba3() == "yes") echo "get_samba3() == "yes") echo "\n"; + if ($_SESSION['config']->is_samba3()) echo "\n"; else echo "\n"; ?> @@ -72,7 +72,7 @@ echo $_SESSION['header']; get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php index b951c56c..71055a27 100644 --- a/lam/templates/ou_edit.php +++ b/lam/templates/ou_edit.php @@ -438,7 +438,7 @@ function display_main() { echo ("
\n"); // domain OUs - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { echo ("
" . _("Domains") . "\n"); echo ("
". _("Samba 3.x schema") . ": " . _("Help") . "
\n"; // search available users $DN = $_SESSION['config']->get_UserSuffix(); - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { $filter = "(&(objectClass=posixAccount)(objectClass=sambaSamAccount))"; } else $filter = "(&(objectClass=posixAccount)(objectClass=sambaAccount))"; @@ -218,4 +218,4 @@ echo ""; echo ""; -?> \ No newline at end of file +?> diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index 33051827..733a4da1 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -112,7 +112,7 @@ for ($k = 0; $k < sizeof($desc_array); $k++) { if (! $_GET['norefresh']) { // configure search filter - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { // Samba hosts have the attribute "sambaSamAccount" and end with "$" $filter = "(&(objectClass=sambaSamAccount) (uid=*$)"; } diff --git a/lam/templates/lists/listusers.php b/lam/templates/lists/listusers.php index 4e06e0c3..774aadcb 100644 --- a/lam/templates/lists/listusers.php +++ b/lam/templates/lists/listusers.php @@ -163,7 +163,7 @@ for ($k = 0; $k < sizeof($desc_array); $k++) { // configure search filter // Users have the attribute "*" - if ($_SESSION['config']->get_samba3() == "yes") { + if ($_SESSION['config']->is_samba3()) { // Samba users have the attribute "sambaSamAccount" and end with "$" $filter = "(&(objectClass=sambaSamAccount) (!(uid=*$))"; } diff --git a/lam/templates/main.php b/lam/templates/main.php index 35e8a569..c4add78f 100644 --- a/lam/templates/main.php +++ b/lam/templates/main.php @@ -52,7 +52,7 @@ if ($conf->Suff_map && ($conf->Suff_map != "")) { if (!$res) $new_suffs[] = $conf->Suff_map; } -if ($_SESSION['config']->get_samba3() == "yes") { +if ($_SESSION['config']->is_samba3()) { $doms = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix()); } @@ -67,7 +67,7 @@ echo (" 0) echo ("\n"); -elseif (($_SESSION['config']->get_samba3() == "yes") && (sizeof($doms) < 1)) { +elseif (($_SESSION['config']->is_samba3()) && (sizeof($doms) < 1)) { $_SESSION['domain_message'] = _("No domains found, please create one."); echo ("\n"); } diff --git a/lam/templates/main_header.php b/lam/templates/main_header.php index 2c110b0d..c6916ff0 100644 --- a/lam/templates/main_header.php +++ b/lam/templates/main_header.php @@ -47,7 +47,7 @@ echo $_SESSION['header']; \n"; + if ($_SESSION['config']->is_samba3()) echo "\n"; else echo "\n"; ?> LDAP Account Manager @@ -64,7 +64,7 @@ echo $_SESSION['header'];
   
' . _("Domains") . '' . _("Users") . '' . _("Groups") . '
\n"); // new OU diff --git a/lam/templates/profedit/profilehost.php b/lam/templates/profedit/profilehost.php index 57cc94dc..e20a7a41 100644 --- a/lam/templates/profedit/profilehost.php +++ b/lam/templates/profedit/profilehost.php @@ -80,7 +80,7 @@ echo ("\n"); // domain echo ("\n"); echo ("\n"); -if ($_SESSION['config']->get_samba3() == "yes") { +if ($_SESSION['config']->is_samba3()) { echo "\n"); // domain echo ("\n"); echo ("\n"); -if ($_SESSION['config']->get_samba3() == "yes") { +if ($_SESSION['config']->is_samba3()) { echo "
   
" . _("Domain") . ":
   
" . _("Domain") . ":