diff --git a/lam/lib/config.inc b/lam/lib/config.inc index ab5948cf..44a3dfd0 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -525,33 +525,54 @@ class Config { /** * Returns the list of attributes to show in user list * + * @param string $scope account type * @return string the attribute list */ - function get_userlistAttributes() { - return $this->userlistAttributes; + function get_listAttributes($scope) { + switch ($scope) { + case 'user': + return $this->userlistAttributes; + break; + case 'group': + return $this->grouplistAttributes; + break; + case 'host': + return $this->hostlistAttributes; + break; + default: + return ''; + break; + } } /** * Sets the list of attributes to show in user list * * @param string $value new attribute string + * @param string $scope account type * @return boolean true if $value has correct format */ - function set_userlistAttributes($value) { + function set_listAttributes($value, $scope) { if (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) { - $this->userlistAttributes = $value; + switch ($scope) { + case 'user': + $this->userlistAttributes = $value; + break; + case 'group': + $this->grouplistAttributes = $value; + break; + case 'host': + $this->hostlistAttributes = $value; + break; + default: + return false; + break; + } + return true; + } + else { + return false; } - else return false; - return true; - } - - /** - * Returns the list of attributes to show in group list - * - * @return string the attribute list - */ - function get_grouplistAttributes() { - return $this->grouplistAttributes; } /** @@ -568,30 +589,6 @@ class Config { return true; } - /** - * Returns the list of attributes to show in host list - * - * @return string the attribute list - */ - function get_hostlistAttributes() { - return $this->hostlistAttributes; - } - - /** - * Sets the list of attributes to show in host list - * - * @param string $value new attribute string - * @return boolean true if $value has correct format - */ - function set_hostlistAttributes($value) { - if (! $value && ($this->hostsuffix == "")) $this->hostlistAttributes = ""; - elseif (is_string($value) && eregi("^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$", $value)) { - $this->hostlistAttributes = $value; - } - else return false; - return true; - } - /** * Returns the maximum number of rows in user/group/host lists * diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index b2f0bfac..cdbdad18 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -32,12 +32,11 @@ $Id$ /** * Builds the regular expressions from the filter values. * -* @param array $post HTTP Post values * @param array $attributes list of displayed attributes * @return array filter data array($attribute => array('regex' => $reg, 'original' => $orig)) * $reg is the regular expression to use, $orig the user's unmodified input string */ -function listBuildFilter($post, $attributes) { +function listBuildFilter($attributes) { $filter = array(); for ($i = 0; $i < sizeof($attributes); $i++) { if (isset($_POST["filter" . strtolower($attributes[$i])]) && eregi('^([0-9a-z_\\*\\$])+$', $_POST["filter" . strtolower($attributes[$i])])) { @@ -287,53 +286,49 @@ function listDoPost($scope) { /** * Returns the LDAP attribute names and their description for the user list * +* @param string $scope account type * @return array list of LDAP attributes and descriptions */ -function listGetAttributeUserArray() { - return array ( - "uid" => _("User ID"), - "uidnumber" => _("UID number"), - "gidnumber" => _("GID number"), - "cn" => _("Username"), - "host" => _("Allowed hosts"), - "givenname" => _("First name"), - "sn" => _("Last name"), - "homedirectory" => _("Home directory"), - "loginshell" => _("Login shell"), - "mail" => _("E-Mail"), - "gecos" => _("Description") - ); -} - -/** -* Returns the LDAP attribute names and their description for the group list -* -* @return array list of LDAP attributes and descriptions -*/ -function listGetAttributeGroupArray() { - return array ( - "cn" => _("Group name"), - "gidnumber" => _("GID number"), - "memberuid" => _("Group members"), - "member" => _("Group member DNs"), - "description" => _("Group description") - ); -} - -/** -* Returns the LDAP attribute names and their description for the host list -* -* @return array list of LDAP attributes and descriptions -*/ -function listGetAttributeHostArray() { - return array ( - "uid" => _("Host username"), - "cn" => _("Host name"), - "rid" => _("RID (Windows UID)"), - "description" => _("Host description"), - "uidnumber" => _("UID number"), - "gidnumber" => _("GID number") - ); +function listGetAttributeArray($scope) { + switch ($scope) { + case 'user': + return array ( + "uid" => _("User ID"), + "uidnumber" => _("UID number"), + "gidnumber" => _("GID number"), + "cn" => _("Username"), + "host" => _("Allowed hosts"), + "givenname" => _("First name"), + "sn" => _("Last name"), + "homedirectory" => _("Home directory"), + "loginshell" => _("Login shell"), + "mail" => _("E-Mail"), + "gecos" => _("Description") + ); + break; + case 'group': + return array ( + "cn" => _("Group name"), + "gidnumber" => _("GID number"), + "memberuid" => _("Group members"), + "member" => _("Group member DNs"), + "description" => _("Group description") + ); + break; + case 'host': + return array ( + "uid" => _("Host username"), + "cn" => _("Host name"), + "rid" => _("RID (Windows UID)"), + "description" => _("Host description"), + "uidnumber" => _("UID number"), + "gidnumber" => _("GID number") + ); + break; + default: + return array(); + break; + } } /** @@ -391,4 +386,43 @@ function listPrintJavaScript() { echo "\n"; } +/** +* Returns an hash array containing with all attributes to be shown and their descriptions. +* Format: array(attribute => description) +* +* @param string $scope account type +* @return array attribute list +*/ +function listGetAttributeDescriptionList($scope) { + $ret = array(); + $attr_string = $_SESSION["config"]->get_listAttributes($scope); + $temp_array = explode(";", $attr_string); + $hash_table = listGetAttributeArray($scope); + // generate column attributes and descriptions + for ($i = 0; $i < sizeof($temp_array); $i++) { + // if value is predifined, look up description in hash_table + if (substr($temp_array[$i],0,1) == "#") { + $attr = strtolower(substr($temp_array[$i],1)); + if (isset($hash_table[$attr])) { + $ret[$attr] = $hash_table[$attr]; + } + else { + $ret[$attr] = $attr; + } + } + // if not predefined, the attribute is seperated by a ":" from description + else { + $attr = explode(":", $temp_array[$i]); + if (isset($attr[1])) { + $ret[$attr[0]] = $attr[1]; + } + else { + $ret[$attr[0]] = $attr[0]; + } + } + } + return $ret; +} + + ?> \ No newline at end of file diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 02c37a36..3b5675f3 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -124,9 +124,9 @@ if (isset($_GET["modulesback"])) { $conf->set_Suffix('host', $_SESSION['conf_suffhosts']); $conf->set_Suffix('domain', $_SESSION['conf_suffdomains']); $conf->set_Suffix('tree', $_SESSION['conf_sufftree']); - $conf->set_userlistAttributes($_SESSION['conf_usrlstattr']); - $conf->set_grouplistAttributes($_SESSION['conf_grplstattr']); - $conf->set_hostlistAttributes($_SESSION['conf_hstlstattr']); + $conf->set_listAttributes($_SESSION['conf_usrlstattr'], 'user'); + $conf->set_listAttributes($_SESSION['conf_grplstattr'], 'group'); + $conf->set_listAttributes($_SESSION['conf_hstlstattr'], 'host'); $conf->set_MaxListEntries($_SESSION['conf_maxlistentries']); $conf->set_defaultLanguage($_SESSION['conf_lang']); $conf->set_scriptpath($_SESSION['conf_scriptpath']); @@ -292,19 +292,19 @@ echo ("\n"); // user list attributes echo ("". - ""); + ""); echo ("\n"); $tabindex++; // group list attributes echo ("". - ""); + ""); echo ("\n"); $tabindex++; // host list attributes echo ("". - ""); + ""); echo ("\n"); $tabindex++; diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php index a71d8a13..9740f24f 100644 --- a/lam/templates/config/confsave.php +++ b/lam/templates/config/confsave.php @@ -128,17 +128,17 @@ if (!$conf->set_Suffix("tree", $sufftree)) { echo ("\n


" . _("Back to preferences...") . ""); exit; } -if (!$conf->set_userlistAttributes($usrlstattr)) { +if (!$conf->set_listAttributes($usrlstattr, 'user')) { echo ("" . _("User list attributes are invalid!") . ""); echo ("\n


" . _("Back to preferences...") . ""); exit; } -if (!$conf->set_grouplistAttributes($grplstattr)) { +if (!$conf->set_listAttributes($grplstattr, 'group')) { echo ("" . _("Group list attributes are invalid!") . ""); echo ("\n


" . _("Back to preferences...") . ""); exit; } -if (!$conf->set_hostlistAttributes($hstlstattr)) { +if (!$conf->set_listAttributes($hstlstattr, 'host')) { echo ("" . _("Host list attributes are invalid!") . ""); echo ("\n


" . _("Back to preferences...") . ""); exit; diff --git a/lam/templates/lists/listgroups.php b/lam/templates/lists/listgroups.php index 5c3c37d0..3d430632 100644 --- a/lam/templates/lists/listgroups.php +++ b/lam/templates/lists/listgroups.php @@ -67,11 +67,9 @@ echo "\n"; listPrintJavaScript(); // generate attribute-description table -$attr_array = array(); // list of LDAP attributes to show -$desc_array = array(); // list of descriptions for the attributes -$attr_string = $_SESSION["config"]->get_grouplistAttributes(); -$temp_array = explode(";", $attr_string); -$hash_table = listGetAttributeGroupArray(); +$temp_array = listGetAttributeDescriptionList($scope); +$attr_array = array_keys($temp_array); // list of LDAP attributes to show +$desc_array = array_values($temp_array); // list of descriptions for the attributes // get current page if (isset($_GET["page"])) $page = $_GET["page"]; @@ -83,24 +81,6 @@ if ($_SESSION["config"]->get_MaxListEntries() <= 0) else $max_page_entries = $_SESSION["config"]->get_MaxListEntries(); -// generate column attributes and descriptions -for ($i = 0; $i < sizeof($temp_array); $i++) { - // if value is predifined, look up description in hash_table - if (substr($temp_array[$i],0,1) == "#") { - $attr = strtolower(substr($temp_array[$i],1)); - $attr_array[$i] = $attr; - if ($hash_table[$attr]) $desc_array[] = strtoupper($hash_table[$attr]); - else $desc_array[] = strtoupper($attr); - } - // if not predefined, the attribute is seperated by a ":" from description - else { - $attr = explode(":", $temp_array[$i]); - $attr_array[$i] = $attr[0]; - if ($attr[1]) $desc_array[$i] = strtoupper($attr[1]); - else $desc_array[$i] = strtoupper($attr[0]); - } -} - // get sorting column if (isset($_GET["sort"])) $sort = $_GET["sort"]; else $sort = strtolower($attr_array[0]); @@ -138,13 +118,12 @@ if ($refresh) { } } -$filter = listBuildFilter($_POST, $attr_array); +$filter = listBuildFilter($attr_array); $info = listFilterAccounts($info, $filter); if (sizeof($info) == 0) StatusMessage("WARN", "", _("No groups found!")); // sort rows by sort column ($sort) if ($info) { $info = listSort($sort, $attr_array, $info); - $_SESSION[$scope . 'info'] = $info; } // build filter URL diff --git a/lam/templates/lists/listhosts.php b/lam/templates/lists/listhosts.php index b333f636..132319a3 100644 --- a/lam/templates/lists/listhosts.php +++ b/lam/templates/lists/listhosts.php @@ -67,11 +67,9 @@ echo "\n"; listPrintJavaScript(); // generate attribute-description table -$attr_array = array(); // list of LDAP attributes to show -$desc_array = array(); // list of descriptions for the attributes -$attr_string = $_SESSION["config"]->get_hostlistAttributes(); -$temp_array = explode(";", $attr_string); -$hash_table = listGetAttributeHostArray(); +$temp_array = listGetAttributeDescriptionList($scope); +$attr_array = array_keys($temp_array); // list of LDAP attributes to show +$desc_array = array_values($temp_array); // list of descriptions for the attributes // get current page if (isset($_GET["page"])) $page = $_GET["page"]; @@ -83,24 +81,6 @@ if ($_SESSION["config"]->get_MaxListEntries() <= 0) else $max_page_entries = $_SESSION["config"]->get_MaxListEntries(); -// generate column attributes and descriptions -for ($i = 0; $i < sizeof($temp_array); $i++) { - // if value is predifined, look up description in hash_table - if (substr($temp_array[$i],0,1) == "#") { - $attr = strtolower(substr($temp_array[$i],1)); - $attr_array[$i] = $attr; - if ($hash_table[$attr]) $desc_array[] = strtoupper($hash_table[$attr]); - else $desc_array[] = strtoupper($attr); - } - // if not predefined, the attribute is seperated by a ":" from description - else { - $attr = explode(":", $temp_array[$i]); - $attr_array[$i] = $attr[0]; - if ($attr[1]) $desc_array[$i] = strtoupper($attr[1]); - else $desc_array[$i] = strtoupper($attr[0]); - } -} - // get sorting column if (isset($_GET["sort"])) $sort = $_GET["sort"]; else $sort = strtolower($attr_array[0]); @@ -138,13 +118,12 @@ if ($refresh) { } } -$filter = listBuildFilter($_POST, $attr_array); +$filter = listBuildFilter($attr_array); $info = listFilterAccounts($info, $filter); if (sizeof($info) == 0) StatusMessage("WARN", "", _("No hosts found!")); // sort rows by sort column ($sort) if ($info) { $info = listSort($sort, $attr_array, $info); - $_SESSION[$scope . 'info'] = $info; } // build filter URL diff --git a/lam/templates/lists/listusers.php b/lam/templates/lists/listusers.php index 0e5676f2..59341560 100644 --- a/lam/templates/lists/listusers.php +++ b/lam/templates/lists/listusers.php @@ -61,7 +61,7 @@ if (isset($_GET['norefresh'])) $refresh = false; if (isset($_POST['refresh'])) $refresh = true; // check if primary group should be translated -if (isset($_POST['trans_primary'])) $trans_primary = "on"; +if (isset($_POST['trans_primary']) && ($_POST['trans_primary'] == 'on')) $trans_primary = "on"; else $trans_primary = "off"; if (isset($_SESSION['trans_primary_hash'])) $trans_primary_hash = $_SESSION['trans_primary_hash']; else $trans_primary_hash = array(); @@ -107,29 +107,9 @@ if ($_SESSION["config"]->get_MaxListEntries() <= 0) { else $max_page_entries = $_SESSION["config"]->get_MaxListEntries(); // generate attribute-description table -$attr_array = array(); // list of LDAP attributes to show -$desc_array = array(); // list of descriptions for the attributes -$attr_string = $_SESSION["config"]->get_userlistAttributes(); -$temp_array = explode(";", $attr_string); -$hash_table = listGetAttributeUserArray(); - -// generate column attributes and descriptions -for ($i = 0; $i < sizeof($temp_array); $i++) { - // if value is predifined, look up description in hash_table - if (substr($temp_array[$i],0,1) == "#") { - $attr = strtolower(substr($temp_array[$i],1)); - $attr_array[$i] = $attr; - if ($hash_table[$attr]) $desc_array[] = strtoupper($hash_table[$attr]); - else $desc_array[] = strtoupper($attr); - } - // if not predefined, the attribute is seperated by a ":" from description - else { - $attr = explode(":", $temp_array[$i]); - $attr_array[$i] = $attr[0]; - if ($attr[1]) $desc_array[$i] = strtoupper($attr[1]); - else $desc_array[$i] = strtoupper($attr[0]); - } -} +$temp_array = listGetAttributeDescriptionList($scope); +$attr_array = array_keys($temp_array); // list of LDAP attributes to show +$desc_array = array_values($temp_array); // list of descriptions for the attributes if (isset($_GET["sort"])) $sort = $_GET["sort"]; else $sort = strtolower($attr_array[0]); @@ -167,13 +147,12 @@ if ($refresh) { } } -$filter = listBuildFilter($_POST, $attr_array); +$filter = listBuildFilter($attr_array); $info = listFilterAccounts($info, $filter); if (sizeof($info) == 0) StatusMessage("WARN", "", _("No users found!")); // sort rows by sort column ($sort) if ($info) { $info = listSort($sort, $attr_array, $info); - $_SESSION[$scope . 'info'] = $info; } // build filter URL @@ -219,7 +198,6 @@ if (sizeof($info) != 0) { // resort if needed if ($sort == "gidnumber") { $info = listSort($sort, $attr_array, $info); - $_SESSION[$scope . 'info'] = $info; } } // print user list diff --git a/lam/tests/conf-test.php b/lam/tests/conf-test.php index 29997a01..b3ddea78 100644 --- a/lam/tests/conf-test.php +++ b/lam/tests/conf-test.php @@ -47,9 +47,9 @@ $Suff_users = $conf->get_Suffix('user'); $Suff_groups = $conf->get_Suffix('group'); $Suff_hosts = $conf->get_Suffix('host'); $Suff_domains = $conf->get_Suffix('domain'); -$userlistAttributes = $conf->get_userlistAttributes(); -$grouplistAttributes = $conf->get_grouplistAttributes(); -$hostlistAttributes = $conf->get_hostlistAttributes(); +$userlistAttributes = $conf->get_listAttributes('user'); +$grouplistAttributes = $conf->get_listAttributes('group'); +$hostlistAttributes = $conf->get_listAttributes('host'); $maxlistentries = $conf->get_maxlistentries(); $defaultlanguage = $conf->get_defaultlanguage(); $scriptpath = $conf->get_scriptPath(); @@ -66,9 +66,9 @@ $conf->set_Suffix('user', "ou=test,o=test,c=de"); $conf->set_Suffix('group', "ou=testgrp,o=test,c=de"); $conf->set_Suffix('host', "ou=testhst,o=test,c=de"); $conf->set_Suffix('domain', "ou=testdom,o=test,c=de"); -$conf->set_userlistAttributes("#uid;#cn"); -$conf->set_grouplistAttributes("#gidNumber;#cn;#memberUID"); -$conf->set_hostlistAttributes("#cn;#uid;#description"); +$conf->set_listAttributes("#uid;#cn", 'user'); +$conf->set_listAttributes("#gidNumber;#cn;#memberUID", 'group'); +$conf->set_listAttributes("#cn;#uid;#description", 'host'); $conf->set_maxlistentries("54"); $conf->set_defaultlanguage("de_AT:iso639_de:Deutsch (Oesterreich)"); $conf->set_scriptPath("/var/www/lam/lib/script"); @@ -87,9 +87,9 @@ if ($conf2->get_Suffix('user') != "ou=test,o=test,c=de") echo ("
get_Suffix('group') != "ou=testgrp,o=test,c=de") echo ("
Saving group suffix failed!
"); if ($conf2->get_Suffix('host') != "ou=testhst,o=test,c=de") echo ("
Saving host suffix failed!
"); if ($conf2->get_Suffix('domain') != "ou=testdom,o=test,c=de") echo ("
Saving domain suffix failed!
"); -if ($conf2->get_userlistAttributes() != "#uid;#cn") echo ("
Saving userlistAttributes failed!
"); -if ($conf2->get_grouplistAttributes() != "#gidNumber;#cn;#memberUID") echo ("
Saving grouplistAttributes failed!
"); -if ($conf2->get_hostlistAttributes() != "#cn;#uid;#description") echo ("
Saving hostlistAttributes failed!
"); +if ($conf2->get_listAttributes('user') != "#uid;#cn") echo ("
Saving userlistAttributes failed!
"); +if ($conf2->get_listAttributes('group') != "#gidNumber;#cn;#memberUID") echo ("
Saving grouplistAttributes failed!
"); +if ($conf2->get_listAttributes('host') != "#cn;#uid;#description") echo ("
Saving hostlistAttributes failed!
"); if ($conf2->get_maxlistentries() != "54") echo ("
Saving maxlistentries failed!
"); if ($conf2->get_defaultlanguage() != "de_AT:iso639_de:Deutsch (Oesterreich)") echo ("
Saving default language failed!
"); if ($conf2->get_scriptPath() != "/var/www/lam/lib/script") echo ("
Saving script path failed!
"); @@ -107,9 +107,9 @@ $conf2->set_Suffix('user', $Suff_users); $conf2->set_Suffix('group', $Suff_groups); $conf2->set_Suffix('host', $Suff_hosts); $conf2->set_Suffix('domain', $Suff_domains); -$conf2->set_userlistAttributes($userlistAttributes); -$conf2->set_grouplistAttributes($grouplistAttributes); -$conf2->set_hostlistAttributes($hostlistAttributes); +$conf2->set_listAttributes($userlistAttributes, 'user'); +$conf2->set_listAttributes($grouplistAttributes, 'group'); +$conf2->set_listAttributes($hostlistAttributes, 'host'); $conf2->set_maxlistentries($maxlistentries); $conf2->set_defaultLanguage($defaultlanguage); $conf2->set_scriptPath($scriptpath);
". _("Attributes in User List") . " *:get_userlistAttributes() . "\">get_listAttributes('user') . "\">" . _("Help") . "
". _("Attributes in Group List") . " *:get_grouplistAttributes() . "\">get_listAttributes('group') . "\">" . _("Help") . "
". _("Attributes in Host List") . " **:get_hostlistAttributes() . "\">get_listAttributes('host') . "\">" . _("Help") . "