From f643f10ee07befd3e6d950fccfafebe17204fa1b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 9 May 2003 16:22:46 +0000 Subject: [PATCH] added default language --- lam/config/lam.conf_sample | 3 + lam/lib/config.inc | 57 +++++-- lam/templates/config/conflogin.php | 7 +- lam/templates/config/confmain.php | 265 ++++++++++++++++++++++++----- lam/templates/config/confsave.php | 64 ++++--- lam/tests/conf-test.php | 4 + 6 files changed, 319 insertions(+), 81 deletions(-) diff --git a/lam/config/lam.conf_sample b/lam/config/lam.conf_sample index 50964209..86e7bad2 100644 --- a/lam/config/lam.conf_sample +++ b/lam/config/lam.conf_sample @@ -61,3 +61,6 @@ hostlistAttributes: #cn;#rid;#description;gidNumber:GID # maximum number of rows to show in user/group/host lists maxlistentries: 30 + +# default language (a line from language.conf) +defaultLanguage: de_DE:iso639_de:Deutsch (Deutschland) diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 81fa9318..42145e25 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -24,7 +24,7 @@ $Id$ */ -// sets language settings for i18n +// sets language settings for automatic translation function setlanguage() { if ($_SESSION['language']) { $language = explode(":", $_SESSION['language']); @@ -77,6 +77,9 @@ class Config { // maximum number of rows shown in user/group/host list var $maxlistentries; + // default language + var $defaultLanguage; + // constructor, loads preferences from ../config/lam.conf function Config() { $this->reload(); @@ -157,6 +160,10 @@ class Config { $this->maxlistentries = chop(substr($line, 16, strlen($line)-16)); continue; } + if (substr($line, 0, 17) == "defaultLanguage: ") { + $this->defaultLanguage = chop(substr($line, 17, strlen($line)-17)); + continue; + } } fclose($file); } @@ -179,7 +186,7 @@ class Config { // 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 = $maxlstent = False; + $save_usrlstatrr = $save_grplstatrr = $save_hstlstatrr = $save_maxlstent = $save_deflang = False; $file = fopen($conffile, "r"); $file_array = array(); while (!feof($file)) { @@ -269,6 +276,11 @@ class Config { $save_maxlstent = True; continue; } + if (substr($file_array[$i], 0, 17) == "defaultLanguage: ") { + $file_array[$i] = "defaultLanguage: " . $this->defaultLanguage . "\n"; + $save_deflang = True; + continue; + } } // check if we have to add new entries (e.g. if user upgraded LAM and has an old lam.conf) 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); @@ -295,6 +307,7 @@ class Config { 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); 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); + if (!$save_deflang == True) array_push($file_array, "\n\n# default language (a line from language.conf)\n" . "defaultLanguage: " . $this->defaultLanguage); $file = fopen($conffile, "w"); if ($file) { for ($i = 0; $i < sizeof($file_array); $i++) fputs($file, $file_array[$i]); @@ -323,11 +336,12 @@ class Config { echo _("userlistAttributes: ") . $this->userlistAttributes . "
"; echo _("grouplistAttributes: ") . $this->grouplistAttributes . "
"; echo _("hostlistAttributes: ") . $this->hostlistAttributes . "
"; - echo _("maxlistentries: ") . $this->maxlistentries; + echo _("maxlistentries: ") . $this->maxlistentries . "
"; + echo _("defaultLanguage: ") . $this->defaultLanguage; } // functions to read/write preferences - + // returns the server address as string function get_ServerURL() { return $this->ServerURL; @@ -338,12 +352,12 @@ class Config { if (is_string($value)) $this->ServerURL = $value; else echo _("Config->set_ServerURL failed!"); } - + // 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 @@ -516,26 +530,37 @@ class Config { else echo _("Config->set_hostlistAttributes failed!"); } - /** - * - * - * + /** + * + * + * * @return maxlistentries */ function get_MaxListEntries() { return $this->maxlistentries; } - - /** + + /** * @brief sets the maximum of entries to display on one page of the lists - * + * * @param value maximum count of entries on one page - * - * @return + * + * @return */ function set_MaxListEntries ($value) { if (is_numeric($value)) $this->maxlistentries = $value; - else echo _("Config->set_MaxListEntries failed!"); + else echo _("Config->set_MaxListEntries failed!" . $value); + } + + // returns the default language string + function get_defaultLanguage() { + return $this->defaultLanguage; + } + + // sets the default language string + function set_defaultLanguage($value) { + if (is_string($value)) $this->defaultLanguage = $value; + else echo _("Config->set_defaultLanguage failed!"); } diff --git a/lam/templates/config/conflogin.php b/lam/templates/config/conflogin.php index 791dbee5..0d88879b 100644 --- a/lam/templates/config/conflogin.php +++ b/lam/templates/config/conflogin.php @@ -9,7 +9,7 @@ $Id$ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -37,7 +37,10 @@ session_start(); -




+

+ +

+


diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 2dd9a413..ca845a6a 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -9,25 +9,62 @@ $Id$ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - - + + + */ // start session session_save_path("../../sess"); session_start(); +// check if button was pressed and if we have to save the setting or go back to login +if ($_POST['back'] || $_POST['submitconf']){ + // save settings + if ($_POST['submitconf']){ + // save HTTP-POST variables in session + // get data if register_globals is off + if ($_POST['passwd']) $passwd = $_POST['passwd']; + if ($_POST['passwd1']) $passwd1 = $_POST['passwd1']; + if ($_POST['passwd2']) $passwd2 = $_POST['passwd2']; + if ($_POST['serverurl']) $serverurl = $_POST['serverurl']; + if ($_POST['admins']) $admins = $_POST['admins']; + if ($_POST['suffusers']) $suffusers = $_POST['suffusers']; + if ($_POST['suffgroups']) $suffgroups = $_POST['suffgroups']; + if ($_POST['suffhosts']) $suffhosts = $_POST['suffhosts']; + if ($_POST['minUID']) $minUID = $_POST['minUID']; + if ($_POST['maxUID']) $maxUID = $_POST['maxUID']; + if ($_POST['minGID']) $minGID = $_POST['minGID']; + if ($_POST['maxGID']) $maxGID = $_POST['maxGID']; + if ($_POST['minMach']) $minMach = $_POST['minMach']; + if ($_POST['maxMach']) $maxMach = $_POST['maxMach']; + if ($_POST['usrlstattr']) $usrlstattr = $_POST['usrlstattr']; + if ($_POST['grplstattr']) $grplstattr = $_POST['grplstattr']; + if ($_POST['hstlstattr']) $hstlstattr = $_POST['hstlstattr']; + if ($_POST['maxlistentries']) $maxlistentries = $_POST['maxlistentries']; + if ($_POST['language']) $language = $_POST['language']; + session_register('passwd', 'passwd1', 'passwd2', 'serverurl', 'admins', 'suffusers', + 'suffgroups', 'suffhosts', 'minUID', 'maxUID', 'minGID', 'maxGID', 'minMach', + 'maxMach', 'usrlstattr', 'grplstattr', 'hstlstattr', 'maxlistentries', 'language'); + echo(""); + } + // back to login + else if ($_POST['back']){ + echo(""); + } + exit; +} + // get password if register_globals is off if ($_POST['passwd']) $passwd = $_POST['passwd']; @@ -53,72 +90,214 @@ echo ("" . _("LDAP Account Manager Configuration") . "\n"); echo "\n"; echo ("\n"); echo ("\n"); -echo ("

\"LDAP




\n"); -echo ("\n"); +echo ("

". + "\"LDAP




\n"); + +// display formular +echo ("\n"); echo ("
" . _("Server settings") . ""); echo (""); -echo ("\n"); -echo ("\n"); +// serverURL +echo ("". + "\n"); +echo ("\n"); + +// new line echo (""); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); + +// user suffix +echo ("". + "\n"); +echo ("\n"); +// group suffix +echo ("". + "\n"); +echo ("\n"); +// host suffix +echo ("". + "\n"); +echo ("\n"); + echo ("

" . _("Server Address") . ":

get_ServerURL() . "\">

" . _("Server Address of LDAP server (e.g. ldap://localhost:389 or ldaps://localhost:636)") . "

" . _("Server Address") . ":

". + "get_ServerURL() . "\">". + "

". + _("Server Address of LDAP server (e.g. ldap://localhost:389 or ldaps://localhost:636)"). + "

 

" . _("UserSuffix") . ":

get_UserSuffix() . "\">

" . _("This is the suffix from where to search for users.
(e.g. ou=People,dc=yourcompany,dc=com)") . "

" . _("GroupSuffix") . ":

get_GroupSuffix() . "\">

" . _("This is the suffix from where to search for groups.
(e.g. ou=group,dc=yourcompany,dc=com)") . "

" . _("HostSuffix") . ":

get_HostSuffix() . "\">

" . _("This is the suffix from where to search for Samba hosts.
(e.g. ou=machines,dc=yourcompany,dc=com)") . "

". + _("UserSuffix") . ":

get_UserSuffix() . "\">

". + _("This is the suffix from where to search for users.
(e.g. ou=People,dc=yourcompany,dc=com)"). + "

". + _("GroupSuffix") . ":

get_GroupSuffix() . "\">

". + _("This is the suffix from where to search for groups.
(e.g. ou=group,dc=yourcompany,dc=com)"). + "

". + _("HostSuffix") . ":

get_HostSuffix() . "\">

". + _("This is the suffix from where to search for Samba hosts.
(e.g. ou=machines,dc=yourcompany,dc=com)"). + "

"); echo ("
"); -echo ("
"); +echo ("
"); echo ("
" . _("Ranges") . ""); echo (""); -echo (""); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); + +// minUID +echo ("". + "\n"); +// UID text +echo ("\n"); +// minGID +echo ("". + "\n"); +// GID text +echo ("\n"); +// minMach +echo ("". + "\n"); +// Machine text +echo ("\n"); + echo ("
 
" . _("Minimum UID number") . ": get_minUID() . "\">\n"); -echo ("  " . _("Maximum UID number") . ": get_maxUID() . "\">

" . _("These are the minimum and maximum numbers to use for user IDs") . "

" . _("Minimum GID number") . ": get_minGID() . "\">\n"); -echo ("  " . _("Maximum GID number") . ": get_maxGID() . "\">

" . _("These are the minimum and maximum numbers to use for group IDs") . "

" . _("Minimum Machine number") . ": get_minMachine() . "\">\n"); -echo ("  " . _("Maximum Machine number") . ": get_maxMachine() . "\">

" . _("These are the minimum and maximum numbers to use for Samba hosts.
Do not use the same range as for user IDs.") . "

". + _("Minimum UID number") . ": get_minUID() . "\">\n"); +// maxUID +echo ("  " . _("Maximum UID number") . ": ". + "get_maxUID() . "\">

". + _("These are the minimum and maximum numbers to use for user IDs"). + "

". + _("Minimum GID number") . ": get_minGID() . "\">\n"); +// maxGID +echo ("  " . _("Maximum GID number").": ". + "get_maxGID() . "\">

". + _("These are the minimum and maximum numbers to use for group IDs"). + "

". + _("Minimum Machine number") . ": get_minMachine() . "\">\n"); +// maxMach +echo ("  " . _("Maximum Machine number") . ": ". + "get_maxMachine() . "\">

". + _("These are the minimum and maximum numbers to use for Samba hosts.
Do not use the same range as for user IDs.") . "

"); echo ("
"); -echo ("
"); +echo ("
"); echo ("
" . _("LDAP List settings") . ""); echo (""); -echo (""); -echo (""); -echo (""); -echo (""); -echo (""); + +// user list attributes +echo ("". + ""); +// list attributes description +echo (""); +// user list attributes +echo ("". + ""); +// user list attributes +echo ("". + ""); +// two new lines echo (""); echo (""); -echo ("\n"); -echo ("\n"); -echo ("\n"); -echo ("\n"); +// admin list +echo ("". + "\n"); +// admin list description +echo ("\n"); +// maximum list entries +echo ("". + "\n"); +// maximum list entries description +echo ("\n"); + echo ("
 

" . _("Attributes in User List:") . "

get_userlistAttributes() . "\">

" . _("This is the list of attributes to show in the lists. The entries can either be predefined values (e.g. '#cn' or '#gidNumber') or individual ones (e.g. 'cn:Group Name'). The entries are seperated by semicolons.") - . "

" . _("Attributes in Group List:") . "

get_grouplistAttributes() . "\">

" . _("Attributes in Host List:") . "

get_hostlistAttributes() . "\">

". + _("Attributes in User List:") . "

get_userlistAttributes() . "\">

". + _("This is the list of attributes to show in the lists. The entries can either be predefined values". + " (e.g. '#cn' or '#gidNumber') or individual ones (e.g. 'cn:Group Name'). The entries are seperated by semicolons."). + "

". + _("Attributes in Group List:") . "

get_grouplistAttributes() . "\">

". + _("Attributes in Host List:") . "

get_hostlistAttributes() . "\">
 
 

" . _("List of valid users") . ":

get_Adminstring() . "\">

" . _("Usernames must be seperated by semicolons
(e.g. cn=admin,dc=yourcompany,dc=com;uid=root,ou=people,dc=yourcompany,dc=com)") . "

" . _("Maximum displayed entries") . ":

get_MaxListEntries() . "\">

" . _("This is the maximum count of entries which are displayed on one page of the user/host/group lists.") . "

". + _("List of valid users") . ":

get_Adminstring() . "\">

". + _("Usernames must be seperated by semicolons")."
". + _("(e.g. cn=admin,dc=yourcompany,dc=com;uid=root,ou=people,dc=yourcompany,dc=com)"). + "

". + _("Maximum displayed entries") . ":

". + _("This is the maximum count of entries which are displayed on one page of the user/host/group lists."). + "

"); echo ("
"); -echo ("
"); +echo ("
"); + +echo ("
" . _("Language settings") . ""); +echo (""); + +// language +echo (""); + +echo ("
"); +// read available languages +$languagefile = "../../config/language.conf"; +if(is_file($languagefile)) +{ + $file = fopen($languagefile, "r"); + $i = 0; + while(!feof($file)) + { + $line = fgets($file, 1024); + if($line == "\n" || $line[0] == "#") continue; // ignore comment and empty lines + $languages[$i] = $line; + $i++; + } + fclose($file); +// generate language list +echo (""); +} +else +{ + echo _("Unable to load available languages. For further instructions please contact the Admin of this site."); +} + + +echo ("
\n"); +echo ("
"); +echo ("
"); echo ("
" . _("Security settings") . ""); echo (""); -echo (""); -echo ("\n"); +// new password +echo ("". + ""); +// reenter password +echo ("". + "\n"); echo ("
" . _("New Password") . ":
" . _("Reenter Password") . ":
". + _("New Password") . ":
". + _("Reenter Password") . ":
\n"); echo ("
"); -echo ("
"); +echo ("
"); + +// buttons echo (""); -echo ("\n"); + +echo ("\n"); + echo ("
     ");
-echo ("
".
+	"".
+	"".
+	"
\n"); +// password for configuration echo ("
\n"); + echo ("
\n"); echo ("\n"); echo ("\n"); diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php index dc9b4086..5494e113 100644 --- a/lam/templates/config/confsave.php +++ b/lam/templates/config/confsave.php @@ -32,24 +32,25 @@ include_once ('../../lib/config.inc'); $conf = new Config(); // get data if register_globals is off -if ($_POST['passwd']) $passwd = $_POST['passwd']; -if ($_POST['passwd1']) $passwd1 = $_POST['passwd1']; -if ($_POST['passwd2']) $passwd2 = $_POST['passwd2']; -if ($_POST['serverurl']) $serverurl = $_POST['serverurl']; -if ($_POST['admins']) $admins = $_POST['admins']; -if ($_POST['suffusers']) $suffusers = $_POST['suffusers']; -if ($_POST['suffgroups']) $suffgroups = $_POST['suffgroups']; -if ($_POST['suffhosts']) $suffhosts = $_POST['suffhosts']; -if ($_POST['minUID']) $minUID = $_POST['minUID']; -if ($_POST['maxUID']) $maxUID = $_POST['maxUID']; -if ($_POST['minGID']) $minGID = $_POST['minGID']; -if ($_POST['maxGID']) $maxGID = $_POST['maxGID']; -if ($_POST['minMach']) $minMach = $_POST['minMach']; -if ($_POST['maxMach']) $maxMach = $_POST['maxMach']; -if ($_POST['usrlstattr']) $usrlstattr = $_POST['usrlstattr']; -if ($_POST['grplstattr']) $grplstattr = $_POST['grplstattr']; -if ($_POST['hstlstattr']) $hstlstattr = $_POST['hstlstattr']; -if ($_POST['maxlistentries']) $maxlistentries = $_POST['maxlistentries']; +if ($_SESSION['passwd']) $passwd = $_SESSION['passwd']; +if ($_SESSION['passwd1']) $passwd1 = $_SESSION['passwd1']; +if ($_SESSION['passwd2']) $passwd2 = $_SESSION['passwd2']; +if ($_SESSION['serverurl']) $serverurl = $_SESSION['serverurl']; +if ($_SESSION['admins']) $admins = $_SESSION['admins']; +if ($_SESSION['suffusers']) $suffusers = $_SESSION['suffusers']; +if ($_SESSION['suffgroups']) $suffgroups = $_SESSION['suffgroups']; +if ($_SESSION['suffhosts']) $suffhosts = $_SESSION['suffhosts']; +if ($_SESSION['minUID']) $minUID = $_SESSION['minUID']; +if ($_SESSION['maxUID']) $maxUID = $_SESSION['maxUID']; +if ($_SESSION['minGID']) $minGID = $_SESSION['minGID']; +if ($_SESSION['maxGID']) $maxGID = $_SESSION['maxGID']; +if ($_SESSION['minMach']) $minMach = $_SESSION['minMach']; +if ($_SESSION['maxMach']) $maxMach = $_SESSION['maxMach']; +if ($_SESSION['usrlstattr']) $usrlstattr = $_SESSION['usrlstattr']; +if ($_SESSION['grplstattr']) $grplstattr = $_SESSION['grplstattr']; +if ($_SESSION['hstlstattr']) $hstlstattr = $_SESSION['hstlstattr']; +if ($_SESSION['maxlistentries']) $maxlistentries = $_SESSION['maxlistentries']; +if ($_SESSION['language']) $language = $_SESSION['language']; // check if password is correct // if not: load login page @@ -58,7 +59,8 @@ if ($passwd != $conf->get_Passwd()) { exit; } -echo ("




"); +echo ("

". + "




"); // check new preferences if (chop($serverurl) == "") { @@ -153,6 +155,9 @@ $conf->set_userlistAttributes($usrlstattr); $conf->set_grouplistAttributes($grplstattr); $conf->set_hostlistAttributes($hstlstattr); $conf->set_MaxListEntries($maxlistentries); +$conf->set_defaultLanguage($language); + + // check if password was changed if ($pass1 != $pass2) { @@ -169,5 +174,24 @@ $conf->save(); echo ("" . _("The following settings were saved:") . "

"); $conf->printconf(); echo ("




" . _("Back to Login") . ""); - +// remove settings from session +unset($_SESSION['passwd']); +unset($_SESSION['passwd1']); +unset($_SESSION['passwd2']); +unset($_SESSION['serverurl']); +unset($_SESSION['admins']); +unset($_SESSION['suffusers']); +unset($_SESSION['suffgroups']); +unset($_SESSION['suffhosts']); +unset($_SESSION['minUID']); +unset($_SESSION['maxUID']); +unset($_SESSION['minGID']); +unset($_SESSION['maxGID']); +unset($_SESSION['minMach']); +unset($_SESSION['maxMach']); +unset($_SESSION['usrlstattr']); +unset($_SESSION['grplstattr']); +unset($_SESSION['hstlstattr']); +unset($_SESSION['maxlistentries']); +unset($_SESSION['language']); ?> diff --git a/lam/tests/conf-test.php b/lam/tests/conf-test.php index 23f9d20e..3239637d 100644 --- a/lam/tests/conf-test.php +++ b/lam/tests/conf-test.php @@ -47,6 +47,7 @@ $userlistAttributes = $conf->get_userlistAttributes(); $grouplistAttributes = $conf->get_grouplistAttributes(); $hostlistAttributes = $conf->get_hostlistAttributes(); $maxlistentries = $conf->get_maxlistentries(); +$defaultlanguage = $conf->get_defaultlanguage(); echo ("done
"); // next we modify them and save lam.conf echo ("Changing preferences..."); @@ -67,6 +68,7 @@ $conf->set_userlistAttributes("#uid;#cn"); $conf->set_grouplistAttributes("#gidNumber;#cn;#memberUID"); $conf->set_hostlistAttributes("#cn;#uid;#description"); $conf->set_maxlistentries("54"); +$conf->set_defaultlanguage("de_AT:iso639_de:Deutsch (Oesterreich)"); $conf->save(); echo ("done
"); // at last all preferences are read from lam.conf and compared @@ -91,6 +93,7 @@ if ($conf->get_userlistAttributes() != "#uid;#cn") echo ("
get_grouplistAttributes() != "#gidNumber;#cn;#memberUID") echo ("
Saving grouplistAttributes failed!
"); if ($conf->get_hostlistAttributes() != "#cn;#uid;#description") echo ("
Saving hostlistAttributes failed!
"); if ($conf->get_maxlistentries() != "54") echo ("
Saving maxlistentries failed!
"); +if ($conf->get_defaultlanguage() != "de_AT:iso639_de:Deutsch (Oesterreich)") echo ("
Saving default language failed!
"); echo ("done
"); // restore old values echo ("Restoring old preferences..."); @@ -111,6 +114,7 @@ $conf->set_userlistAttributes($userlistAttributes); $conf->set_grouplistAttributes($grouplistAttributes); $conf->set_hostlistAttributes($hostlistAttributes); $conf->set_maxlistentries($maxlistentries); +$conf->set_defaultLanguage($defaultlanguage); $conf->save(); echo ("done
"); // finished