more general list functions in config.inc,

put attribute-description code in lists.inc
This commit is contained in:
Roland Gruber 2005-04-14 17:42:15 +00:00
parent ab44ea6afc
commit fb89aaa120
8 changed files with 151 additions and 184 deletions

View File

@ -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() {
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)) {
switch ($scope) {
case 'user':
$this->userlistAttributes = $value;
break;
case 'group':
$this->grouplistAttributes = $value;
break;
case 'host':
$this->hostlistAttributes = $value;
break;
default:
return false;
break;
}
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;
else {
return false;
}
}
/**
@ -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
*

View File

@ -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,9 +286,12 @@ 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() {
function listGetAttributeArray($scope) {
switch ($scope) {
case 'user':
return array (
"uid" => _("User ID"),
"uidnumber" => _("UID number"),
@ -303,14 +305,8 @@ function listGetAttributeUserArray() {
"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() {
break;
case 'group':
return array (
"cn" => _("Group name"),
"gidnumber" => _("GID number"),
@ -318,14 +314,8 @@ function listGetAttributeGroupArray() {
"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() {
break;
case 'host':
return array (
"uid" => _("Host username"),
"cn" => _("Host name"),
@ -334,6 +324,11 @@ function listGetAttributeHostArray() {
"uidnumber" => _("UID number"),
"gidnumber" => _("GID number")
);
break;
default:
return array();
break;
}
}
/**
@ -391,4 +386,43 @@ function listPrintJavaScript() {
echo "</script>\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;
}
?>

View File

@ -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 ("<table border=0>\n");
// user list attributes
echo ("<tr><td align=\"right\"><b>".
_("Attributes in User List") . " *:</b></td>".
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"usrlstattr\" value=\"" . $conf->get_userlistAttributes() . "\"></td>");
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"usrlstattr\" value=\"" . $conf->get_listAttributes('user') . "\"></td>");
echo ("<td><a href=\"../help.php?HelpNumber=206\" target=\"lamhelp\">" . _("Help") . "</a></td></tr>\n");
$tabindex++;
// group list attributes
echo ("<tr><td align=\"right\"><b>".
_("Attributes in Group List") . " *:</b></td>".
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"grplstattr\" value=\"" . $conf->get_grouplistAttributes() . "\"></td>");
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"grplstattr\" value=\"" . $conf->get_listAttributes('group') . "\"></td>");
echo ("<td><a href=\"../help.php?HelpNumber=206\" target=\"lamhelp\">" . _("Help") . "</a></td></tr>\n");
$tabindex++;
// host list attributes
echo ("<tr><td align=\"right\"><b>".
_("Attributes in Host List") . " **:</b></td>".
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"hstlstattr\" value=\"" . $conf->get_hostlistAttributes() . "\"></td>");
"<td><input tabindex=\"$tabindex\" size=50 type=\"text\" name=\"hstlstattr\" value=\"" . $conf->get_listAttributes('host') . "\"></td>");
echo ("<td><a href=\"../help.php?HelpNumber=206\" target=\"lamhelp\">" . _("Help") . "</a></td></tr>\n");
$tabindex++;

View File

@ -128,17 +128,17 @@ if (!$conf->set_Suffix("tree", $sufftree)) {
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_userlistAttributes($usrlstattr)) {
if (!$conf->set_listAttributes($usrlstattr, 'user')) {
echo ("<font color=\"red\"><b>" . _("User list attributes are invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_grouplistAttributes($grplstattr)) {
if (!$conf->set_listAttributes($grplstattr, 'group')) {
echo ("<font color=\"red\"><b>" . _("Group list attributes are invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;
}
if (!$conf->set_hostlistAttributes($hstlstattr)) {
if (!$conf->set_listAttributes($hstlstattr, 'host')) {
echo ("<font color=\"red\"><b>" . _("Host list attributes are invalid!") . "</b></font>");
echo ("\n<br><br><br><a href=\"javascript:history.back()\">" . _("Back to preferences...") . "</a>");
exit;

View File

@ -67,11 +67,9 @@ echo "</head><body>\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

View File

@ -67,11 +67,9 @@ echo "</head><body>\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

View File

@ -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

View File

@ -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 ("<br><font color=
if ($conf2->get_Suffix('group') != "ou=testgrp,o=test,c=de") echo ("<br><font color=\"#FF0000\">Saving group suffix failed!</font><br>");
if ($conf2->get_Suffix('host') != "ou=testhst,o=test,c=de") echo ("<br><font color=\"#FF0000\">Saving host suffix failed!</font><br>");
if ($conf2->get_Suffix('domain') != "ou=testdom,o=test,c=de") echo ("<br><font color=\"#FF0000\">Saving domain suffix failed!</font><br>");
if ($conf2->get_userlistAttributes() != "#uid;#cn") echo ("<br><font color=\"#FF0000\">Saving userlistAttributes failed!</font><br>");
if ($conf2->get_grouplistAttributes() != "#gidNumber;#cn;#memberUID") echo ("<br><font color=\"#FF0000\">Saving grouplistAttributes failed!</font><br>");
if ($conf2->get_hostlistAttributes() != "#cn;#uid;#description") echo ("<br><font color=\"#FF0000\">Saving hostlistAttributes failed!</font><br>");
if ($conf2->get_listAttributes('user') != "#uid;#cn") echo ("<br><font color=\"#FF0000\">Saving userlistAttributes failed!</font><br>");
if ($conf2->get_listAttributes('group') != "#gidNumber;#cn;#memberUID") echo ("<br><font color=\"#FF0000\">Saving grouplistAttributes failed!</font><br>");
if ($conf2->get_listAttributes('host') != "#cn;#uid;#description") echo ("<br><font color=\"#FF0000\">Saving hostlistAttributes failed!</font><br>");
if ($conf2->get_maxlistentries() != "54") echo ("<br><font color=\"#FF0000\">Saving maxlistentries failed!</font><br>");
if ($conf2->get_defaultlanguage() != "de_AT:iso639_de:Deutsch (Oesterreich)") echo ("<br><font color=\"#FF0000\">Saving default language failed!</font><br>");
if ($conf2->get_scriptPath() != "/var/www/lam/lib/script") echo ("<br><font color=\"#FF0000\">Saving script path failed!</font><br>");
@ -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);