Cleaning up LDAP support

This commit is contained in:
jengo 2000-11-17 21:16:49 +00:00
parent 41f184664e
commit 471f42b67a
5 changed files with 71 additions and 65 deletions

View File

@ -22,15 +22,16 @@
$phpgw->template->set_block("header","row","footer");
$phpgw->templateotal = account_total();
$total = account_total();
$phpgw->template->set_var("bg_color",$phpgw_info["theme"]["bg_color"]);
$phpgw->template->set_var("th_bg",$phpgw_info["theme"]["th_bg"]);
$phpgw->template->set_var("left_next_matchs",$phpgw->nextmatchs->left("accounts.php",$start,$phpgw->templateotal));
$phpgw->template->set_var("left_next_matchs",$phpgw->nextmatchs->left("accounts.php",$start,$total));
$phpgw->template->set_var("lang_user_accounts",lang("user accounts"));
$phpgw->template->set_var("right_next_matchs",$phpgw->nextmatchs->right("accounts.php",$start,$phpgw->templateotal));
$phpgw->template->set_var("right_next_matchs",$phpgw->nextmatchs->right("accounts.php",$start,$total));
$phpgw->template->set_var("lang_loginid",$phpgw->nextmatchs->show_sort_order($sort,"account_lid",$order,"accounts.php",lang("LoginID")));
$phpgw->template->set_var("lang_lastname",$phpgw->nextmatchs->show_sort_order($sort,"account_lastname",$order,"accounts.php",lang("last name")));
$phpgw->template->set_var("lang_firstname",$phpgw->nextmatchs->show_sort_order($sort,"account_firstname",$order,"accounts.php",lang("first name")));
@ -63,6 +64,7 @@
if (! $lastname) $lastname = ' ';
if (! $firstname) $firstname = ' ';
$phpgw->template->set_var("row_loginid",$loginid);
$phpgw->template->set_var("row_firstname",$firstname);
$phpgw->template->set_var("row_lastname",$lastname);
$phpgw->template->set_var("row_edit",'<a href="'.$phpgw->link("editaccount.php","account_id="
@ -78,10 +80,10 @@
$phpgw->template->set_var("row_view",'<a href="' . $phpgw->link("viewaccount.php", "account_id="
. $account_id) . '"> ' . lang("View") . ' </a>');
if ($phpgw->templateotal == 1) {
if ($total == 1) {
$phpgw->template->set_var("output","");
}
if ($phpgw->templateotal != ++$i) {
if ($total != ++$i) {
$phpgw->template->parse("output","row",True);
}
}

View File

@ -41,13 +41,17 @@
$sr = ldap_search($ldap,$phpgw_info["server"]["ldap_context"],$filter,array("uid"));
$info = ldap_get_entries($ldap, $sr);
$total = 0;
$total = -1;
for ($i=0;$i<count($info);$i++) {
if (! $phpgw_info["server"]["global_denied_users"][$info[$i]["uid"][0]]) {
$total++;
}
}
if ($total == 1) {
$total = 2;
}
return $total;
}
@ -116,15 +120,15 @@
// This method is only temp. We need to figure out the best way to assign uidnumbers and
// guidnumbers.
//$phpgw->db->query("select (max(account_id)+1) from accounts");
//$phpgw->db->next_record();
$phpgw->db->query("select (max(account_id)+1) from accounts");
$phpgw->db->next_record();
//$account_info["account_id"] = $phpgw->db->f(0);
$account_info["account_id"] = $phpgw->db->f(0);
// Much of this is going to be guess work for now, until we get things planned out.
$entry["uid"] = $account_info["loginid"];
//$entry["uidNumber"] = $account_info["account_id"];
#$entry["gidNumber"] = $account_info["account_id"];
$entry["uidNumber"] = $account_info["account_id"];
$entry["gidNumber"] = $account_info["account_id"];
$entry["userpassword"] = $account_info["passwd"];
$entry["loginShell"] = "/bin/bash";
$entry["homeDirectory"] = "/home/" . $account_info["loginid"];
@ -151,28 +155,8 @@
$entry["objectclass"][3] = "inetOrgperson";
$entry["objectclass"][4] = "person";
$entry["objectclass"][5] = "top";
$i=0;
reset ($account_info["permissions"]);
while (list($key,$value) = each($account_info["permissions"]))
{
$entry["phpgw_account_perms"][$i] = $key;
$i++;
}
// find a free userid, we need that for the dn
$sri = ldap_search($ldap,rawurldecode("$dn"),"objectclass=*");
$allValues = ldap_get_entries($ldap, $sri);
$newUIDNumber = 0;
for($i=0; $i < $allValues["count"]; $i++)
{
if (($allValues[$i]["uidnumber"][0]) > $newUIDNumber) $newUIDNumber = $allValues[$i]["uidnumber"][0];
}
$newUIDNumber++;
$entry["uidNumber"] = $newUIDNumber;
$dn=sprintf("uidnumber=%s, %s", $newUIDNumber, $phpgw_info["server"]["ldap_context"]);
/* $dn=sprintf("cn=%s %s, %s", $givenname, $sn, $BASEDN);*/
$dn=sprintf("uid=%s, %s", $account_info["loginid"], $phpgw_info["server"]["ldap_context"]);
// add the entries
if (ldap_add($ldap, $dn, $entry)) {
@ -184,6 +168,23 @@
@ldap_close($ldap);
add_default_preferences($account_info["account_id"]);
$phpgw->db->lock(array("accounts","preferences"));
while ($permission = each($account_info["permissions"])) {
if ($phpgw_info["apps"][$permission[0]]["enabled"]) {
$phpgw->accounts->add_app($permission[0]);
}
}
$sql = "insert into accounts (account_id,account_lid,account_pwd,account_firstname,"
. "account_lastname,account_permissions,account_groups,account_status,"
. "account_lastpwd_change) values ('" . $account_info["account_id"] . "','"
. $account_info["loginid"] . "','x','". addslashes($account_info["firstname"]) . "','"
. addslashes($account_info["lastname"]) . "','" . $phpgw->accounts->add_app("",True)
. "','" . $account_info["groups"] . "','A',0)";
$phpgw->db->query($sql);
$phpgw->db->unlock();
$sep = $phpgw->common->filesystem_separator();

View File

@ -22,7 +22,7 @@
if ($order) {
$ordermethod = "order by $order $sort";
} else {
$ordermethod = "order by account_lastname,account_firstname,account_lid asc";
$ordermethod = "order by account_lid,account_lastname,account_firstname asc";
}
if (! $sort) {

View File

@ -1,6 +1,6 @@
<!-- BEGIN header -->
<p>
<table border="0" width="65%" align="center">
<table border="0" width="70%" align="center">
<tr bgcolor="{bg_color}">
<td align="left">{left_next_matchs}</td>
<td align="center">{lang_user_accounts}</td>
@ -9,8 +9,9 @@
</table>
<center>
<table border=0 width=65%>
<table border="0" width="70%">
<tr bgcolor="{th_bg}">
<td>{lang_loginid}</td>
<td>{lang_lastname}</td>
<td>{lang_firstname}</td>
<td>{lang_edit}</td>
@ -23,6 +24,7 @@
<!-- BEGIN row -->
<tr bgcolor="{tr_color}">
<td>{row_loginid}</td>
<td>{row_lastname}</td>
<td>{row_firstname}</td>
<td width="5%">{row_edit}</td>
@ -36,9 +38,9 @@
</center>
<form method="POST" action="{actionurl}">
<table border="0" width="65%" align="center">
<table border="0" width="70%" align="center">
<tr>
<td align=left>
<td align="left">
<input type="submit" value="{lang_add}"></form>
</td>
<td align="right">

View File

@ -104,7 +104,8 @@
echo "<option value=\"" . $phpgw->db->f("lang_id") . "\"";
if ($phpgw_info["user"]["preferences"]["common"]["lang"]) {
if ($phpgw->db->f("lang_id") == $phpgw_info["user"]["preferences"]["common"]["lang"]) {
echo " selected"; }
echo " selected";
}
} elseif ($phpgw->db->f("lang_id") == "EN") {
echo " selected";
}