Ldap på sme server
HejInden jeg starter vil jeg lige sige at jeg ikke lige viste hvor jeg skulle smide mit spørgsmål, så nu blev det her.
Jeg har en SME server(e-smith) kørende med php-nuke side, jeg har fundet et lille module til min nuke side, så den Ldap istedet for nuke databasen, mit problem er jeg ikke kan få dem til at arbejde sammen,
Jeg har sat det op som beskrevet i den read me der fulgte med, men et eller andet har jeg gjordt forket, for når jeg prøver at logge på min side kommer den og siger den ikke kan connect til localhost, jeg ved ikke hvad jeg har gjordt forkert, nogen der kan hjælpe??
Her er den fil hvor man skulle konfigure forbindelsen til Ldap:
<?php
/***************************************************************************
* synch-ldap.php
* -------------------
* begin : March 11, 2004
* copyright : (C) 2003,2004 William Wong
* email : bwong at voicenet.com
*
* $Id: synch-ldap.php,v 1.01 2003/03/11 $
* $Id: synch-ldap.php,v 1.00 2003/04/10 $
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
if(!defined("SYNCH_LAYER"))
{
define("SYNCH_LAYER","ldap");
// global parameters
$UM_scripts_dir = "/opt/usermanager/scripts";
$UM_enable_samba = true;
$UM_enable_posix = true;
class synch_db
{
var $ldap_server;
var $ldap_bind_dn;
var $ldap_password;
var $ldap_map;
var $ldap_key; // LDAP key field normally maps to 'uid'
var $ldap_objectclass;
var $popserver;
var $exec;
var $logger;
var $ds;
//
// Constructor
//
function synch_db()
{
// LDAP server configuration parameters
$this->ldap_server = "localhost"; // change if necessary
$this->ldap_bind_dn = "cn=admin,dc=mit_domæne,dc=com"; // change
$this->ldap_password = ""; // change
$this->ldap_base = "ou=people,dc=mit_domæne,dc=com"; // change
// LDAP key fields
$this->ldap_key = "uid"; // maps to username
// LDAP objectClas attribute values
$this->ldap_objectclass[] = "top"; // do not change
$this->ldap_objectclass[] = "person"; // do not change
$this->ldap_objectclass[] = "nukeAccount"; // do not change
// Field mapping table: $ldap_map['sql_field'] = "ldap_field";
$this->ldap_map['username'] = $this->ldap_key ; // do not change
$this->ldap_map['user_password'] = "nukepassword"; // do not change
$this->ldap_map['name'] = "sn";
$this->ldap_map['name'] = "gecos";
$this->ldap_map['user_occ'] = "description";
$this->ldap_map['user_email'] = "mail" ; // only if objectclass includes qmailuser or inetorgperson
$this->$popserver='localhost';
// System configuration
$this->exec = "/usr/bin/sudo"; // remember to make changes to /etc/sudoers file
$this->logger = "/usr/bin/logger -t nuke-ldap"; // use "" to turn off logging
return true ;
}
//
// Utility methods
//
function exec($cmd)
{
passthru(escapeshellcmd($this->exec." ".$cmd),$return);
return $return;
}
function log($text) {
if ($this->logger!="") {
$this->exec($this->logger." $text");
}
return true;
}
// called when password is changed via add() and update()
function set_new_password($uname,$passwd) {
global $UM_scripts_dir, $UM_enable_samba, $UM_enable_posix;
// add additional database changes here ...
$this->ldap_connect();
$lresult=$this->ldap_search("(".$this->ldap_key."=$uname)");
foreach ( $lresult[0]['objectclass'] as $id => $class ) {
switch (strtolower($class)) {
case 'sambaaccount':
if ($UM_enable_samba) {
$this->exec("$UM_scripts_dir/UM_smbpasswd.sh $uname $passwd");
}
break;
case 'posixaccount':
if ($UM_enable_posix) {
$salt=""; //generate a salt using characters [A-Z][a-z][0-9]./
$chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for ($i=0;$i<16;$i++) {
$salt.=$chars[mt_rand(0,strlen($chars))];
}
$entry['userPassword']="{CRYPT}".crypt($passwd,substr($salt,0,2));
$lresult = $this->ldap_mod_replace($this->ldap_key."=$uname,".$this->ldap_base, $entry);
}
break;
}
}
$this->ldap_close();
}
// check if account handles more than just nuke attributes
function is_extended_nuke_account ($uname) {
global $UM_enable_samba, $UM_enable_posix;
$this->ldap_connect();
$lresult=$this->ldap_search("(".$this->ldap_key."=$uname)");
$this->ldap_close();
foreach ( $lresult[0]['objectclass'] as $id => $class ) {
switch (strtolower($class)) {
case 'posixaccount':
if ($UM_enable_posix) {
return true;
}
break;
case 'sambaaccount':
if ($UM_enable_samba) {
return true;
}
break;
}
}
return false ;
}
//
// SQL methods
//
function sql_query($query) {
global $db;
return $db->sql_query($query);
}
function sql_numrows($sr) {
global $db;
return $db->sql_numrows($sr);
}
function sql_fetchrow($sr) {
global $db;
return $db->sql_fetchrow($sr);
}
function get_sql_to_ldap_entries($uname) {
global $user_prefix;
$sresult=$this->sql_query("select * from {$user_prefix}_users where username='$uname'");
$sresult=$this->sql_fetchrow($sresult);
foreach ( $this->ldap_map as $sql => $ldap ) {
$entry[$ldap]=$sresult[$sql];
}
return $entry;
}
//
// LDAP methods
//
function ldap_connect() {
$this->ds=ldap_connect($this->ldap_server) or die("Cannot connect to ".$this->ldap_server);
ldap_set_option($this->ds,LDAP_OPT_PROTOCOL_VERSION,3); //1.01
if ( ldap_bind($this->ds,$this->ldap_bind_dn,$this->ldap_password)) {
return true ;
}
ldap_close($this->ds);
die("Cannot bind to ".$this->ldap_bind_dn);
}
function ldap_search($query) {
// $this->log("ldap_search ".$this->ldap_base." ".$query);
$result = ldap_search($this->ds,$this->ldap_base,$query);
if (!$result) {
return false;
}
return ldap_get_entries($this->ds,$result);
}
function ldap_add($dn,$att) {
return ldap_add($this->ds,$dn,$att);
}
function ldap_delete($dn) {
return ldap_delete($this->ds,$dn);
}
function ldap_mod_replace($dn,$att) {
return ldap_mod_replace($this->ds,$dn,$att);
}
function ldap_close() {
return ldap_close($this->ds);
}
//
// Base methods
//
// add ldap entry, call after new user added to user database
function add($uname,$passwd)
{
$this->log("add $uname");
// note: add code here to change password for other fields if necessary
$entry = $this->get_sql_to_ldap_entries($uname);
$entry["objectClass"] = $this->ldap_objectclass ;
$this->ldap_connect();
$lresult = $this->ldap_add($this->ldap_key."=$uname,".$this->ldap_base, $entry);
$this->ldap_close();
$this->set_new_password($uname,$passwd);
return $lresult;
}
// delete entry from ldap, call when user deleted from user database
function delete($uname)
{
// remove the following conditional if deleting a nuke user should always delete the ldap entry
if (is_extended_nuke_account ($uname)) {
return false ; // do not delete ldap entry if not just a nuke user
}
$this->log("delete $uname");
$this->ldap_connect();
$lresult = $this->ldap_delete($this->ldap_key."=$uname,".$this->ldap_base);
$this->ldap_close();
return $lresult;
}
// copy ldap to sql, call before using user database
function load($uname)
{
global $user_prefix;
// $this->log("load $uname");
$this->ldap_connect();
$lresult=$this->ldap_search("(".$this->ldap_key."=$uname)");
$this->ldap_close();
if ($lresult) {
$sqlresult = $this->sql_query("select username, user_id from ".$user_prefix."_users where username='$uname'");
$spasswd = $lresult['nukemailpassword'];
$popserver=$this->popserver;
$mail = $lresult['mail'];
if ( 1 == $this->sql_numrows($sqlresult)) {
$v = "";
$c = "";
foreach ( $this->ldap_map as $sql => $ldap ) {
$v .= $c.$sql."= '".$lresult[0][$ldap][0]."'";
$c = ",";
}
$result = $this->sql_query("update $user_prefix"."_users set ".$v." where username='$uname'");
$this->sql_query("Update ".$user_prefix."_popsettings SET passwd='$spasswd'"
." WHERE uid='".$sqlresult['user_id']."' AND uname='$uname' AND popserver='$popserver'");
} else {
$n="";
$v="";
foreach ( $this->ldap_map as $sql => $ldap ) {
$n .= ",".$sql;
$v .= ",'".$lresult[0][$ldap][0]."'";
}
$result = $this->sql_query("insert into $user_prefix"."_users (user_id$n) values(NULL$v)");
$this->sql_query("Insert into ".$user_prefix."_popsettings (account,uid,popserver,uname,passwd,port,numshow,deletefromserver) "
."values ('$uname','".$sqlresult['user_id']."','$popserver','$uname','$spasswd',110,10,'Y')");
}
return $result;
} else {
return false;
}
}
// update ldap from sql, call after user database updated
function update($uname,$passwd="")
{
$this->log("update $uname");
if ($passwd!="") {
$this->set_new_password($uname,$passwd);
}
// note: add code here to change password for other fields if necessary
$this->ldap_connect();
$lresult = $this->ldap_mod_replace($this->ldap_key."=$uname,".$this->ldap_base, $this->get_sql_to_ldap_entries($uname));
$this->ldap_close();
return $lresult;
}
} // class synch_db
} // if define
?>
modulet kan hentes her: http://www.users.voicenet.com/~bwong/nukeldap/
Håber der er nogen der kan hjælpe mig
