22 |
copyright (C) 2001, 2002 mose, makina corpus - mose@makina-corpus.org |
copyright (C) 2001, 2002 mose, makina corpus - mose@makina-corpus.org |
23 |
*/ |
*/ |
24 |
|
|
25 |
/** |
/** LuDAP manages conf files and in/out ldap functions |
26 |
* LuDAP lib |
* |
27 |
|
* That class deals with LDAP in a simplified way, using |
28 |
|
* config files with smarty lib to get some default values |
29 |
* |
* |
30 |
* \package ludap |
* \class ludap |
31 |
|
* \file ludap.lib.php |
32 |
* \link http://ludap.org |
* \link http://ludap.org |
33 |
* \version 0.5 |
* \version 0.5 |
34 |
* \copyright (C) 2003 mose <mose@mose.com> |
* \copyright (C) 2003 mose |
35 |
* \author mose <mose@mose.com> |
* \date 2000-2003 |
36 |
* \access public |
* \author mose@mose.com |
37 |
*/ |
*/ |
38 |
|
|
39 |
class ludap { |
class ludap { |
40 |
|
|
41 |
|
/** version of ludap source code |
42 |
|
*/ |
43 |
var $ver = '0.5'; |
var $ver = '0.5'; |
44 |
|
|
45 |
|
/** ressource identifier for the ldap connection |
46 |
|
*/ |
47 |
var $conn = ''; |
var $conn = ''; |
48 |
|
|
49 |
|
/** what is the last thing the instance has to say ? |
50 |
|
*/ |
51 |
var $message = ''; |
var $message = ''; |
52 |
|
|
53 |
|
/** is the instance authenticated ? |
54 |
|
*/ |
55 |
var $auth = false; |
var $auth = false; |
56 |
|
|
57 |
|
/** is the instance created under admin status ? |
58 |
|
*/ |
59 |
var $admin = false; |
var $admin = false; |
60 |
|
|
61 |
|
/** where does ludap class stores his conf array ? |
62 |
|
* |
63 |
|
*/ |
64 |
var $conf = array(); |
var $conf = array(); |
65 |
|
|
66 |
var $logfile = ".ludap.log"; |
var $logfile = ".ludap.log"; |
75 |
|
|
76 |
var $schema_mail = array(); |
var $schema_mail = array(); |
77 |
|
|
78 |
|
/** constructor of LuDAP instance |
79 |
|
* \param C instance of the config class |
80 |
|
* \param conf_file file path relative to smarty::config_dir |
81 |
|
*/ |
82 |
function ludap($C, $conf_file) { |
function ludap($C, $conf_file) { |
83 |
$this->conf = $C->get($conf_file); |
$this->conf = $C->get($conf_file); |
84 |
|
|
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
|
/** method to check if php has ldap enabled or not |
107 |
|
* \param void nothing is required to be provided there |
108 |
|
* \return void nothing, it just die() if ldap module not found |
109 |
|
* \since v0.5 |
110 |
|
* \todo write a better return (boolean) |
111 |
|
*/ |
112 |
function check_ldap_ability() { |
function check_ldap_ability() { |
113 |
if (!function_exists("ldap_connect")) { |
if (!function_exists("ldap_connect")) { |
114 |
if (!extension_loaded('ldap')) { |
if (!extension_loaded('ldap')) { |
124 |
} |
} |
125 |
} |
} |
126 |
|
|
127 |
|
/** for writing in defined ludap::logfile |
128 |
|
* \param type short message indicating what to log. freeformed. |
129 |
|
* \return void nothing, the line is just added to the ludap::logfile |
130 |
|
*/ |
131 |
function rawlog($type) { |
function rawlog($type) { |
132 |
global $S; |
global $S; |
133 |
$file = $this->logfile; |
$file = $this->logfile; |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
|
/** prepares and returns error message |
146 |
|
* \todo check if not obsolete |
147 |
|
*/ |
148 |
function showerror() { |
function showerror() { |
149 |
global $S; |
global $S; |
150 |
$S->assign('errno',ldap_errno($this->conn)); |
$S->assign('errno',ldap_errno($this->conn)); |
153 |
return $S->fetch('errorline.tpl'); |
return $S->fetch('errorline.tpl'); |
154 |
} |
} |
155 |
|
|
156 |
|
/** establish a connection to the LDAP server |
157 |
|
*/ |
158 |
function conn() { |
function conn() { |
159 |
$this->check_ldap_ability(); |
$this->check_ldap_ability(); |
160 |
$conn = @ldap_connect($this->conf['host']); |
$conn = @ldap_connect($this->conf['host']); |
166 |
} |
} |
167 |
} |
} |
168 |
|
|
169 |
|
/** erases the current session $_SESSION['me'] |
170 |
|
*/ |
171 |
function logout() { |
function logout() { |
172 |
if (isset($_SESSION['me'])) { |
if (isset($_SESSION['me'])) { |
173 |
$this->rawlog("Logout - ".@$_SESSION['me']); |
$this->rawlog("Logout - ".@$_SESSION['me']); |
177 |
} |
} |
178 |
} |
} |
179 |
|
|
180 |
|
/** establish a connection to the LDAP server |
181 |
|
*/ |
182 |
function auth($me, $login=false , $pass=false) { |
function auth($me, $login=false , $pass=false) { |
183 |
if (!$me) { |
if (!$me) { |
184 |
$this->logout(); |
$this->logout(); |
214 |
} |
} |
215 |
} |
} |
216 |
|
|
217 |
function domenu($list,$it) { |
/** gets a list of users |
218 |
foreach ($list as $k=>$l) { |
* \todo de-globalize $sort and $rsort to put them in arguments |
219 |
if ($it == $k) { |
*/ |
|
$back.= "<option value='$k' selected>$l\n"; |
|
|
} else { |
|
|
$back.= "<option value='$k'>$l\n"; |
|
|
} |
|
|
} |
|
|
return "$back"; |
|
|
} |
|
|
|
|
220 |
function get_users_list($heads,$search='',$limit=0,$start=0,$end=0) { |
function get_users_list($heads,$search='',$limit=0,$start=0,$end=0) { |
221 |
global $sort, $rsort; |
global $sort, $rsort; |
222 |
$inf = array(); |
$inf = array(); |
223 |
$sr = ldap_search($this->conn, $this->conf['basedn'], $search, $heads); |
if (!$search) $search = "*"; |
224 |
|
$sr = ldap_search($this->conn, $this->conf['basedn'], "(".$this->conf['membattr']."=".$search.")", $heads); |
225 |
$info = ldap_get_entries($this->conn,$sr); |
$info = ldap_get_entries($this->conn,$sr); |
226 |
for ($n = 0; $n < $info['count']; $n++) { |
for ($n = 0; $n < $info['count']; $n++) { |
227 |
foreach ($heads as $lt) { |
foreach ($heads as $lt) { |
244 |
return $inf; |
return $inf; |
245 |
} |
} |
246 |
|
|
247 |
|
/** gets all info about one group |
248 |
|
*/ |
249 |
function get_gid($id, $attrs) { |
function get_gid($id, $attrs) { |
250 |
if (is_array($attrs)) { |
if (is_array($attrs)) { |
251 |
$i = ldap_search($this->conn,$this->conf['groupdn'],"(".$this->conf['membattr']."=".utf8_encode($id).")", $attrs); |
$i = ldap_search($this->conn,$this->conf['groupdn'],"(".$this->conf['membattr']."=".utf8_encode($id).")", $attrs); |
289 |
return $fres; |
return $fres; |
290 |
} |
} |
291 |
|
|
292 |
|
/** gets all info about one user |
293 |
|
*/ |
294 |
function get_id($id,$attrs='') { |
function get_id($id,$attrs='') { |
295 |
global $conn; |
global $conn; |
296 |
$fres = array(); |
$fres = array(); |
330 |
return $fres; |
return $fres; |
331 |
} |
} |
332 |
|
|
333 |
// ROU 20030303 récupère la liste des adresses mails |
/** gets mails. obsolete function |
334 |
|
* \todo fix this with new code |
335 |
|
*/ |
336 |
function get_mails($id='') { |
function get_mails($id='') { |
337 |
global $conn, $conf; |
global $conn, $conf; |
338 |
// inhibit for now |
// inhibit for now |
352 |
} |
} |
353 |
return $f_mails; |
return $f_mails; |
354 |
} |
} |
|
// ROU 20030303 |
|
355 |
|
|
356 |
|
/** gets a list of groups for one user |
357 |
|
*/ |
358 |
function get_groups($id='') { |
function get_groups($id='') { |
359 |
if ($id) { |
if ($id) { |
360 |
$limit = "(".$this->conf['groupattr'].'= '.$this->conf['baseattr']."=".$id.", ".$this->conf['basedn'].")"; |
$limit = "(".$this->conf['groupattr'].'= '.$this->conf['baseattr']."=".$id.", ".$this->conf['basedn'].")"; |
374 |
} |
} |
375 |
} |
} |
376 |
|
|
377 |
|
/** delete one group |
378 |
|
* \todo write that function ! |
379 |
|
*/ |
380 |
function del_groups($id) { |
function del_groups($id) { |
381 |
|
|
382 |
} |
} |
383 |
|
|
384 |
|
/** gets all info about one group |
385 |
|
* \todo add some error management |
386 |
|
*/ |
387 |
function del_user($id) { |
function del_user($id) { |
388 |
return ldap_delete($this->conn, $this->conf['baseattr']."=".utf8_encode($id).", ".$this->conf['basedn']); |
return ldap_delete($this->conn, $this->conf['baseattr']."=".utf8_encode($id).", ".$this->conf['basedn']); |
389 |
} |
} |
390 |
|
|
391 |
|
/** used formerly to return the default home dir for a user |
392 |
|
* \todo adapt to new code |
393 |
|
*/ |
394 |
function defaultdir($id) { |
function defaultdir($id) { |
395 |
return "/home/$id"; |
return "/home/$id"; |
396 |
} |
} |
397 |
|
|
398 |
|
/** used to setup a tryout for incremental value in ldap |
399 |
|
* not used anymore |
400 |
|
*/ |
401 |
function increment($attr) { |
function increment($attr) { |
402 |
global $conn, $conf; |
global $conn, $conf; |
403 |
$i = ldap_search($conn,$this->conf['basedn'],$this->conf['baseattr']."=*",array($attr)); |
$i = ldap_search($conn,$this->conf['basedn'],$this->conf['baseattr']."=*",array($attr)); |
449 |
} |
} |
450 |
} |
} |
451 |
|
|
452 |
|
/** gets all info about one group |
453 |
|
* \bug requires php-domxml module. that should be checked first |
454 |
|
*/ |
455 |
function xml2array($branch,$n='',$k='') { |
function xml2array($branch,$n='',$k='') { |
456 |
global $xobj; |
global $xobj; |
457 |
$branch = $branch->first_child(); |
$branch = $branch->first_child(); |
477 |
break; |
break; |
478 |
} |
} |
479 |
if ($branch->has_child_nodes()) { |
if ($branch->has_child_nodes()) { |
480 |
$result = $this->xml2array($branch,$n,$k); |
array_merge($xobj, $this->xml2array($branch,$n,$k)); |
|
array_merge($xobj, $result); |
|
481 |
} |
} |
482 |
} |
} |
483 |
$branch = $branch->next_sibling(); |
$branch = $branch->next_sibling(); |