Add min/max account_id to admin config.inc.php, and ldap accounts is using it

This commit is contained in:
Miles Lott 2001-03-29 07:26:28 +00:00
parent cd3c45db5f
commit fef9d740a9
2 changed files with 36 additions and 13 deletions

View File

@ -33,6 +33,16 @@
</tr>
<?php $selected = array(); ?>
<tr bgcolor="e6e6e6">
<td>Minimum account id (e.g. 500 or 100, etc.):</td>
<td><input name="newsettings[account_min_id]" value="<?php echo $current_config["account_min_id"]; ?>"></td>
</tr>
<tr bgcolor="e6e6e6">
<td>Maximum account id (e.g. 65535 or 1000000):</td>
<td><input name="newsettings[account_max_id]" value="<?php echo $current_config["account_max_id"]; ?>"></td>
</tr>
<?php $selected = array(); ?>
<tr bgcolor="e6e6e6">
<td>If using LDAP, do you want to store homedirectory and loginshell attributes for new accounts?:</td>
<td><input type="checkbox" name="newsettings[ldap_extra_attributes]" value="True"<?php echo ($current_config["ldap_extra_attributes"]?" checked":""); ?>></td>

View File

@ -301,25 +301,38 @@
{
global $phpgw_info, $phpgw;
if (!$account_id) {
mt_srand((double)microtime()*1000000);
$account_id = mt_rand (100, 65535);
}
// auto_increment/serial in the db won't necessarily work for ldap, nor would
// randomization. Need to check for lastid in ldap, then create newid for sql and ldap
$ds = $phpgw->common->ldapConnect();
if (!$account_id) {
if ($phpgw_info["server"]["account_min_id"]) { $min = $phpgw_info["server"]["account_min_id"]; }
if ($phpgw_info["server"]["account_max_id"]) { $max = $phpgw_info["server"]["account_max_id"]; }
$nextid = $phpgw->common->last_id("accounts_ldap",$min,$max);
// Loop until we find a free id
$free = 0;
while (!$free) {
$ldap_fields = "";
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=".$nextid);
$ldap_test = ldap_get_entries($ds, $sri);
if ($ldap_test[0]['dn'][0]) {
$nextid = $phpgw->common->next_id("accounts_ldap",$min,$max);
} else {
$free = True;
}
}
if ($phpgw_info["server"]["account_max_id"] && ($nextid > $phpgw_info["server"]["account_max_id"])) {
return False;
}
$account_id = $nextid;
//echo $account_id;exit;
}
/* if (!$account_id) {
$this->db->query("insert into phpgw_accounts (account_lid, account_type, account_pwd, "
. "account_firstname, account_lastname, account_status) values ('" . $account_lid
. "','" . $account_type . "','" . md5($account_pwd) . "', '" . $account_firstname
. "','" . $account_lastname . "','" . $account_status . "')",__LINE__,__FILE__);
} else { */
$this->db->query("insert into phpgw_accounts (account_id, account_lid, account_type, account_pwd, "
. "account_firstname, account_lastname, account_status) values ('" . $account_id . "','" . $account_lid
. "','" . $account_type . "','" . md5($account_pwd) . "', '" . $account_firstname
. "','" . $account_lastname . "','" . $account_status . "')",__LINE__,__FILE__);
$ds = $phpgw->common->ldapConnect();
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uid=".$account_lid);
$allValues = ldap_get_entries($ds, $sri);