1
GuillauG
Help AutoLogin to Xoops
  • 2003/10/22 4:36

  • GuillauG

  • Just popping in

  • Posts: 4

  • Since: 2003/10/17


Hi,
I want the user coming on my Intranet be auto login in XOOPS if their user exist on a LDAP server.

I already make a PHP who get the username via a JavaScript and then return the value to the PHP via a $_Post and this PHP verify if the user exist in LDAP. Now i want to modify Login section on XOOPS so the user will be autologged with his windows session.

How can i do that?

thanks!

2
Society
Re: Help AutoLogin to Xoops
  • 2003/10/22 6:18

  • Society

  • Not too shy to talk

  • Posts: 178

  • Since: 2002/1/10


same for me :) i tried some wired things
but i get it not to work :)

Autologin is not the problem the problem is ldap

3
Anonymous
Re: Help AutoLogin to Xoops
  • 2003/10/22 10:26

  • Anonymous

  • Posts: 0

  • Since: 0


To check the User or get the User from LDAP you have to get the Information from the LDAP Server like this:

function getUser($userName, $includeGroups=false)
    {
        global 
$xoopsConfig;
        
$this->error = null;
        
$userObj = null;
        
$entryDN = $xoopsConfig['ldapusercont'];
        
$filter = "(cn=".$userName.")";
        
$justthese = array("uidnumber", "cn", "gecos", "webidsynchid");
        if(
$includeGroups)
        {
            
$justthese[] = "groupmembership";
        }

        
$info = $this->findLDAPObject($entryDN, $justthese, $filter);
        if(!
$info)
        {
            
$this->error = "User $userName not found";
            unset(
$justthese);
            return 
null;
        }

        
$userObj = new xoopsLDAPUser;
        
$userObj->dn = $info[0]["dn"];
        
$userObj->cn = $info[0]["cn"][0];
        
$userObj->extid = $info[0]["webidsynchid"][0];

        if(isset(
$info[0]["uidnumber"][0]))
        {
            
$userObj->uid = $info[0]["uidnumber"][0];
            
$userObj->gecos = $info[0]["gecos"][0];
        }

        if (
$info[0]["groupmembership"]["count"] > 0)
        {
            
$userObj->groups = array();
            for(
$i = 0; $i < $info[0]["groupmembership"]["count"]; $i++)
            {
                
$userObj->groups[] = $info[0]["groupmembership"][$i];
            }
        }

        unset(
$info);
        return 
$userObj;
    }

This is just a example there must be more inside, so it would be an own Class for connecting to the LDAP Server:

function connect()
    {
        global 
$xoopsConfig;
        
$this->error = null;
        
$server = ($xoopsConfig['ldapcleartext'] == 1) ? "ldap" : "ldaps";
        
$server .= "://" . $xoopsConfig['ldapserver'];
        
$this->conn = ldap_connect($server, $xoopsConfig['ldapserverport']);
        if(!
$this->conn)
        {
            
$this->conn = null;
            
$this->error = "Failed connection to " . $server;
            return 
false;
        }
        return 
true;
    }

Get an LDAP object associated with a given DN

function findLDAPObject($dn, $attributes=null, $filter=null)
    {
        
$this->error = null;

        if(!
$filter)
        {
            
$filter = "(objectclass=*)";
        }

        
$sr = ldap_search($this->conn, $dn, $filter, $attributes);
        if(!
$sr)
        {
            return 
$this->returnLDAPFailure("Search for Object: $dn");
        }

        if(
ldap_count_entries($this->conn, $sr) < 1)
        {
            
$this->error = "No entries found for $dn";
            return 
false;
        }

        
$info = ldap_get_entries($this->conn, $sr);
        return 
$info;
    }

function returnLDAPFailure($prefString)
    {
        
$this->error = $prefString . " LDAP Error: " .
            
ldap_err2str(ldap_errno($this->conn));
        return 
false;
    }

// Private
// Authenticate a user specified by a given DN
// using a given password.
function doBind($userDN, $password)
    {
        global 
$xoopsConfig;
        
$this->bound = false;
        
$this->error = null;
        if(!
$this->conn)
        {
            if(!
$this->connect())
            {
                return 
false;
            }
        }
        
ldap_bind($this->conn, $userDN, $password);
        if(
ldap_errno($this->conn) != 0)
        {
            
$userDN .= " LDAP Server: " . $xoopsConfig['ldapserver'];
            return 
$this->returnLDAPFailure("Bind DN: " . $userDN);
        }

        
$this->bound = true;
        return 
true;
    }

// Do authentication for the admin
function bindAdmin()
    {
        global 
$xoopsConfig;
        return 
$this->doBind($xoopsConfig['ldapadmin'], $xoopsConfig['ldapadminpass']);
    }

So happy Xoopsing

Greetz Predator