get ldap userlevel and user id from ldap now, configure the ldap groups levels in the config file; please note if you assigned rights to certain users they might have vanished as the userid is now the uidnumber from ldap

git-svn-id: http://www.observium.org/svn/observer/trunk@2539 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-09-21 22:04:05 +00:00
parent cc5ad3b7d5
commit 838617100c
2 changed files with 51 additions and 7 deletions
+46 -7
View File
@@ -1,10 +1,11 @@
<?php <?php
$ds = @ldap_connect($config['auth_ldap_server'],$config['auth_ldap_port']);
function authenticate($username,$password) function authenticate($username,$password)
{ {
global $config; global $config, $ds;
$ds=@ldap_connect($config['auth_ldap_server'],$config['auth_ldap_port']);
if ($ds) if ($ds)
{ {
if ($config['auth_ldap_version']) if ($config['auth_ldap_version'])
@@ -61,19 +62,57 @@ function adduser($username, $password, $level, $email = "", $realname = "")
function user_exists($username) function user_exists($username)
{ {
return 0; # FIXME to be implemented global $config, $ds;
$filter = "(" . $config['auth_ldap_prefix'] . $username . ")";
$search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter);
$entries = ldap_get_entries($ds, $search);
if ($entries['count'])
{
return 1;
}
return 0;
} }
function get_userlevel($username) function get_userlevel($username)
{ {
# FIXME should come from LDAP global $config, $ds;
return dbFetchCell("SELECT `level` FROM `users` WHERE `username` = ?", array($username));
$userlevel = 0;
# Find all defined groups $username is in
$filter = "(&(|(cn=" . join(")(cn=", array_keys($config['auth_ldap_groups'])) . "))(memberUid=" . $username . "))";
$search = ldap_search($ds, $config['auth_ldap_groupbase'], $filter);
$entries = ldap_get_entries($ds, $search);
# Loop the list and find the highest level
foreach ($entries as $entry)
{
$groupname = $entry['cn'][0];
if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel)
{
$userlevel = $config['auth_ldap_groups'][$groupname]['level'];
}
}
return $userlevel;
} }
function get_userid($username) function get_userid($username)
{ {
# FIXME should come from LDAP global $config, $ds;
return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username` = ?", array($username));
$filter = "(" . $config['auth_ldap_prefix'] . $username . ")";
$search = ldap_search($ds, trim($config['auth_ldap_suffix'],','), $filter);
$entries = ldap_get_entries($ds, $search);
if ($entries['count'])
{
return $entries[0]['uidnumber'][0];
}
return -1;
} }
function deluser($username) function deluser($username)
+5
View File
@@ -310,6 +310,11 @@ $config['auth_ldap_prefix'] = "uid=";
$config['auth_ldap_suffix'] = ",ou=People,dc=example,dc=com"; $config['auth_ldap_suffix'] = ",ou=People,dc=example,dc=com";
$config['auth_ldap_group'] = "cn=observium,ou=groups,dc=example,dc=com"; $config['auth_ldap_group'] = "cn=observium,ou=groups,dc=example,dc=com";
$config['auth_ldap_groupbase'] = "ou=group,dc=luciad,dc=com";
$config['auth_ldap_groups']['admin']['level'] = 10;
$config['auth_ldap_groups']['pfy']['level'] = 7;
$config['auth_ldap_groups']['support']['level'] = 1;
### Hardcoded ASN descriptions ### Hardcoded ASN descriptions
$config['astext'][65333] = "Cymru Bogon Feed"; $config['astext'][65333] = "Cymru Bogon Feed";