read()){ $ext = substr($entry, strlen($entry)-5, 5); $name = substr($entry, 0, strlen($entry)-5); if ($ext == ".conf") { $ret[$pos] = $name; $pos ++; } } sort($ret); return $ret; } // print meta refresh // $page is the target page function metaRefresh($page) { echo $_SESSION['header']; echo "\n"; echo "
\n"; echo "\n"; echo "" . _("Click here if you are not directed to the next page.") . "\n"; echo "
\n"; echo "\n"; echo "\n"; } /* // class Config */ // manages .conf files class Config { // server address (e.g. ldap://127.0.0.1:389) var $ServerURL; // array of strings: users with admin rights var $Admins; // string: password to edit preferences var $Passwd; // single line with the names of all admin users var $Adminstring; // suffix for users var $Suff_users; // suffix for groups var $Suff_groups; // suffix for Samba hosts var $Suff_hosts; // suffix for domains (Samba 3) var $Suff_domains; // minimum/maximum numbers for UID, GID and UID of Samba Hosts var $MinUID; var $MaxUID; var $MinGID; var $MaxGID; var $MinMachine; var $MaxMachine; // attributes that are shown in the user/group/host tables var $userlistAttributes; var $grouplistAttributes; var $hostlistAttributes; // maximum number of rows shown in user/group/host list var $maxlistentries; // default language var $defaultLanguage; // Path to external script and server where it is executed // optional settings, may not be defined var $scriptPath; var $scriptServer; // if "yes" use the new LDAP schema for Samba 3.x var $samba3; // LDAP cache timeout var $cache_timeout; // name of configuration file var $file; // constructor, loads preferences from config file function Config($file=0) { if (!is_string($file)) { $profiles = getConfigProfiles(); $file = $profiles[0]; } $this->file = $file; $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; } 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() { $conffile = substr(__FILE__, 0, strlen(__FILE__) - 15) . "/config/" . $this->file . ".conf"; if (is_file($conffile) == True) { // booleans to check if value was already saved $save_serverURL = $save_passwd = $save_admins = $save_suffusr = $save_suffgrp = $save_suffhst = $save_minUID = $save_maxUID = $save_minGID = $save_maxGID = $save_minMach = $save_maxMach = $save_usrlstatrr = $save_grplstatrr = $save_hstlstatrr = $save_maxlstent = $save_deflang = $save_scriptPath = $save_scriptServer = $save_samba3 = $save_suffdom = $save_cachetime = False; $file = fopen($conffile, "r"); $file_array = array(); // read config file while (!feof($file)) { array_push($file_array, fgets($file, 1024)); } fclose($file); // generate new configuration file for ($i = 0; $i < sizeof($file_array); $i++) { if (($file_array[$i] == "\n")||($file_array[$i][0] == "#")) continue; // ignore comments // search for keywords if (strtolower(substr($file_array[$i], 0, 11)) == "serverurl: ") { $file_array[$i] = "serverURL: " . $this->ServerURL . "\n"; $save_serverURL = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "passwd: ") { $file_array[$i] = "passwd: " . $this->Passwd . "\n"; $save_passwd = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "admins: ") { $file_array[$i] = "admins: " . $this->Adminstring . "\n"; $save_admins = True; continue; } if (strtolower(substr($file_array[$i], 0, 12)) == "usersuffix: ") { $file_array[$i] = "usersuffix: " . $this->Suff_users . "\n"; $save_suffusr = True; continue; } if (strtolower(substr($file_array[$i], 0, 13)) == "groupsuffix: ") { $file_array[$i] = "groupsuffix: " . $this->Suff_groups . "\n"; $save_suffgrp = True; continue; } if (strtolower(substr($file_array[$i], 0, 12)) == "hostsuffix: ") { $file_array[$i] = "hostsuffix: " . $this->Suff_hosts . "\n"; $save_suffhst = True; continue; } if (strtolower(substr($file_array[$i], 0, 14)) == "domainsuffix: ") { $file_array[$i] = "domainsuffix: " . $this->Suff_domains . "\n"; $save_suffdom = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "minuid: ") { $file_array[$i] = "minUID: " . $this->MinUID . "\n"; $save_minUID = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "maxuid: ") { $file_array[$i] = "maxUID: " . $this->MaxUID . "\n"; $save_maxUID = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "mingid: ") { $file_array[$i] = "minGID: " . $this->MinGID . "\n"; $save_minGID = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "maxgid: ") { $file_array[$i] = "maxGID: " . $this->MaxGID . "\n"; $save_maxGID = True; continue; } if (strtolower(substr($file_array[$i], 0, 12)) == "minmachine: ") { $file_array[$i] = "minMachine: " . $this->MinMachine . "\n"; $save_minMach = True; continue; } if (strtolower(substr($file_array[$i], 0, 12)) == "maxmachine: ") { $file_array[$i] = "maxMachine: " . $this->MaxMachine . "\n"; $save_maxMach = True; continue; } if (strtolower(substr($file_array[$i], 0, 20)) == "userlistattributes: ") { $file_array[$i] = "userlistAttributes: " . $this->userlistAttributes . "\n"; $save_usrlstattr = True; continue; } if (strtolower(substr($file_array[$i], 0, 21)) == "grouplistattributes: ") { $file_array[$i] = "grouplistAttributes: " . $this->grouplistAttributes . "\n"; $save_grplstattr = True; continue; } if (strtolower(substr($file_array[$i], 0, 20)) == "hostlistattributes: ") { $file_array[$i] = "hostlistAttributes: " . $this->hostlistAttributes . "\n"; $save_hstlstattr = True; continue; } if (strtolower(substr($file_array[$i], 0, 16)) == "maxlistentries: ") { $file_array[$i] = "maxlistentries: " . $this->maxlistentries . "\n"; $save_maxlstent = True; continue; } if (strtolower(substr($file_array[$i], 0, 17)) == "defaultlanguage: ") { $file_array[$i] = "defaultLanguage: " . $this->defaultLanguage . "\n"; $save_deflang = True; continue; } if (strtolower(substr($file_array[$i], 0, 12)) == "scriptpath: ") { $file_array[$i] = "scriptPath: " . $this->scriptPath . "\n"; $save_scriptPath = True; continue; } if (strtolower(substr($file_array[$i], 0, 14)) == "scriptserver: ") { $file_array[$i] = "scriptServer: " . $this->scriptServer . "\n"; $save_scriptServer = True; continue; } if (strtolower(substr($file_array[$i], 0, 8)) == "samba3: ") { $file_array[$i] = "samba3: " . $this->samba3 . "\n"; $save_samba3 = True; continue; } if (strtolower(substr($file_array[$i], 0, 14)) == "cachetimeout: ") { $file_array[$i] = "cacheTimeout: " . $this->cache_timeout . "\n"; $save_cachetime = True; continue; } } // check if we have to add new entries (e.g. if user upgraded LAM and has an old config file) if (!$save_serverURL == True) array_push($file_array, "\n\n# server address (e.g. ldap://localhost:389 or ldaps://localhost:636)\n" . "serverURL: " . $this->ServerURL . "\n"); if (!$save_passwd == True) array_push($file_array, "\n\n# password to change these preferences via webfrontend\n" . "passwd: " . $this->Passwd . "\n"); if (!$save_admins == True) array_push($file_array, "\n\n# list of users who are allowed to use LDAP Account Manager\n" . "# names have to be seperated by semicolons\n" . "# e.g. admins: cn=admin,dc=yourdomain,dc=org;cn=root,dc=yourdomain,dc=org\n" . "admins: " . $this->Adminstring . "\n"); if (!$save_suffusr == True) array_push($file_array, "\n\n# suffix of users\n" . "# e.g. ou=People,dc=yourdomain,dc=org\n" . "usersuffix: " . $this->Suff_users . "\n"); if (!$save_suffgrp == True) array_push($file_array, "\n\n# suffix of groups\n" . "# e.g. ou=Groups,dc=yourdomain,dc=org\n" . "groupsuffix: " . $this->Suff_groups . "\n"); if (!$save_suffhst == True) array_push($file_array, "\n\n# suffix of Samba hosts\n" . "# e.g. ou=machines,dc=yourdomain,dc=org\n" . "hostsuffix: " . $this->Suff_hosts . "\n"); if (!$save_suffdom == True) array_push($file_array, "\n\n# suffix of Samba 3 domains\n" . "# e.g. ou=domains,dc=yourdomain,dc=org\n" . "domainsuffix: " . $this->Suff_domains . "\n"); if (!$save_minUID == True) array_push($file_array, "\n\n# minimum UID number\n" . "minUID: " . $this->MinUID . "\n"); if (!$save_maxUID == True) array_push($file_array, "\n\n# maximum UID number\n" . "maxUID: " . $this->MaxUID . "\n"); if (!$save_minGID == True) array_push($file_array, "\n\n# minimum GID number\n" . "minGID: " . $this->MinGID . "\n"); if (!$save_maxGID == True) array_push($file_array, "\n\n# maximum GID number\n" . "maxGID: " . $this->MaxGID . "\n"); if (!$save_minMach == True) array_push($file_array, "\n\n# minimum UID number for Samba hosts\n" . "minMachine: " . $this->MinMachine . "\n"); if (!$save_maxMach == True) array_push($file_array, "\n\n# maximum UID number for Samba hosts\n" . "maxMachine: " . $this->MaxMachine . "\n"); if (!$save_usrlstattr == True) 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')" . "\n# or individual ones (e.g. 'uid:User ID' or 'host:Host Name')\n# values have to be seperated by semicolons\n" . "userlistAttributes: " . $this->userlistAttributes . "\n"); if (!$save_grplstattr == True) array_push($file_array, "\n\n# list of attributes to show in group list\n# entries can either be predefined values (e.g. '#cn' or '#gidNumber')" . "\n# or individual ones (e.g. 'cn:Group Name')\n# values have to be seperated by semicolons\n" . "grouplistAttributes: " . $this->grouplistAttributes . "\n"); if (!$save_hstlstattr == True) array_push($file_array, "\n\n# list of attributes to show in host list\n# entries can either be predefined values (e.g. '#cn' or '#uid')" . "\n# or individual ones (e.g. 'cn:Host Name')\n# values have to be seperated by semicolons\n" . "hostlistAttributes: " . $this->hostlistAttributes . "\n"); if (!$save_maxlstent == True) array_push($file_array, "\n\n# maximum number of rows to show in user/group/host lists\n" . "maxlistentries: " . $this->maxlistentries . "\n"); if (!$save_deflang == True) array_push($file_array, "\n\n# default language (a line from config/language)\n" . "defaultLanguage: " . $this->defaultLanguage . "\n"); if (!$save_scriptPath == True) array_push($file_array, "\n\n# Path to external Script\n" . "scriptPath: " . $this->scriptPath . "\n"); if (!$save_scriptServer == True) array_push($file_array, "\n\n# Server of external Script\n" . "scriptServer: " . $this->scriptServer . "\n"); if (!$save_samba3 == True) array_push($file_array, "\n\n# Set to \"yes\" only if you use the new Samba 3.x schema.\n" . "samba3: " . $this->samba3 . "\n"); if (!$save_cachetime == True) array_push($file_array, "\n\n# Number of minutes LAM caches LDAP searches.\n" . "cacheTimeout: " . $this->cache_timeout . "\n"); $file = fopen($conffile, "w"); if ($file) { for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]); fclose($file); } else { StatusMessage("ERROR", "", _("Cannot open config file!") . " (" . $conffile . ")"); exit; } } } // prints current preferences function printconf() { echo "" . _("Server address") . ": " . $this->ServerURL . "