1 |
<? /* |
<?php /* |
2 |
LuDAP : Lightweight Users Directory Administration Protocol |
LuDAP : Lightweight Users Directory Administration Protocol |
3 |
$Id$ |
$Header$ |
4 |
------------------------------------------------------------------------ |
------------------------------------------------------------------------ |
5 |
copyright (C) 2003 mose . mose@ludap.org |
copyright (C) 2003 mose . mose@ludap.org |
|
copyright (C) 2001, 2002 mose, makina corpus - mose@makina-corpus.org |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
18 |
the Free Software Foundation, Inc., |
the Free Software Foundation, Inc., |
19 |
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
------------------------------------------------------------------------ |
------------------------------------------------------------------------ |
|
file: inc/auth.php |
|
|
description: manages auth, login form and sessions |
|
|
used in: index.php |
|
21 |
*/ |
*/ |
22 |
|
|
23 |
|
require('setup.smarty.php'); |
24 |
|
|
25 |
|
include LUDAP_DIR.'ludap.lib.php'; |
26 |
|
$L = new ludap($C,LUDAPCONF); |
27 |
|
$L->conn() or die("Impossible to connect"); |
28 |
|
|
29 |
|
if (get_magic_quotes_gpc()) { |
30 |
|
foreach($_REQUEST as $k=>$v) { |
31 |
|
if (!is_array($_REQUEST[$k])) $_REQUEST[$k] = stripslashes($v); |
32 |
|
} |
33 |
|
} |
34 |
|
|
35 |
session_start(); |
session_start(); |
36 |
|
|
37 |
$logged_in = (isset($_SESSION['me'])) ? $_SESSION['me'] : false; |
$authgroup = (defined('AUTHGROUP')) ? AUTHGROUP : false; |
38 |
|
|
39 |
|
$me = (isset($_SESSION['me']) and !isset($_GET['logout'])) ? $_SESSION['me'] : false; |
40 |
|
$admin = (isset($_SESSION['admin']) and !isset($_GET['logout'])) ? $_SESSION['admin'] : false; |
41 |
$login = (isset($_POST['login'])) ? $_POST['login'] : false; |
$login = (isset($_POST['login'])) ? $_POST['login'] : false; |
42 |
$passd = (isset($_POST['passd'])) ? $_POST['passd'] : false; |
$passd = (isset($_POST['passd'])) ? $_POST['passd'] : false; |
43 |
$logout = (isset($_GET['logout'])) ? true : false; |
$id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : false; |
44 |
|
$output = false; |
45 |
|
$outgood = false; |
46 |
|
$msg = false; |
47 |
|
$ladmin = false; |
48 |
|
|
49 |
$auth = FALSE; |
|
50 |
$output = FALSE; |
if (isset($login) and isset($passd)) { |
51 |
$admin = FALSE; |
$L->auth($me, $authgroup, $login, $passd); |
52 |
$showform = TRUE; |
$output = $L->message; |
53 |
|
$S->assign('output', $L->message); |
|
function authlog($type,$path="logs") { |
|
|
global $S; |
|
|
$S->assign('type',$type); |
|
|
$log = $S->fetch('logline.tpl'); |
|
|
$fp = @fopen("$path/.auth.log", "a+"); |
|
|
if ($fp) { |
|
|
while (!flock($fp,2) and ($i < 30)) { sleep(2); $i++; } |
|
|
@fputs($fp,"$log\n"); |
|
|
flock($fp,3); |
|
|
@fclose($fp); |
|
|
} |
|
54 |
} |
} |
55 |
|
|
56 |
if (!$logged_in or $logout) { |
$S->assign('admin',$admin); |
57 |
if ($logout) { |
if (isset($_SESSION['me'])) { |
58 |
authlog("Logout - ".$_SESSION['me'],$logdir); |
$S->assign('me',$_SESSION['me']); |
59 |
session_destroy(); |
} |
60 |
$output = "Votre session a été detruite."; |
$S->assign('schema_user', $L->schema_user); |
61 |
} elseif ($login && $passd) { |
$S->assign('attributes_user', $L->attributes_user); |
62 |
$cf = $conf['ludap']; |
$S->assign('baseattr', $L->conf['baseattr']); |
63 |
$conn = ldap_connect($cf['host']) or die("Hôte LDAP innaccessible !<hr>GULP!"); |
$S->assign('basedn', $L->conf['basedn']); |
64 |
$binddn = $cf['baseattr']."=".utf8_encode($login).", ".$cf['basedn']; |
$S->assign('host', $L->conf['host']); |
65 |
if (@ldap_bind($conn,$binddn,$passd)) { |
$S->assign('id',$id); |
66 |
$i = ldap_search($conn,$cf['basedn'],$cf['baseattr']."=$login",array('cn','dn')); |
$S->assign('useframe', $useframe); |
67 |
$ii = ldap_first_entry($conn,$i); |
|
68 |
$ccn = @ldap_get_values($conn,$ii,'cn'); |
$S->assign('mquery',$mquery); |
|
$dcn = @ldap_get_dn($conn,$ii); |
|
|
$w = $cf['membattr']; |
|
|
$ix = ldap_search($conn,$cf['groupdn'],$cf['groupattr']."=$dcn",array("$w")); |
|
|
$iix = ldap_get_entries($conn,$ix); |
|
|
for ($x=0; $x<$iix["count"]; $x++) { |
|
|
$gps[] = $iix["$x"]["$w"][0]; |
|
|
} |
|
|
$cn = $ccn[0]; |
|
|
$auth = TRUE; |
|
|
$me = $login; |
|
|
$pass = $passd; |
|
|
session_register('me','cn','pass','gps'); |
|
|
authlog("Login - $login",$logdir); |
|
|
} else { |
|
|
$auth = FALSE; |
|
|
$output = "Mot de passe invalide pour $login !"; |
|
|
authlog("BadPasswd - $login",$logdir); |
|
|
} |
|
|
@ldap_unbind($conn); |
|
|
@ldap_close($conn); |
|
|
} |
|
|
} else { |
|
|
$auth = TRUE; |
|
|
$me = $logged_in; |
|
|
} |
|
|
|
|
|
if ((!$conf['global']['open'] and !$auth) or $identify) { |
|
|
$S->assign('showform',$showform); |
|
|
$S->assign('output',$output); |
|
|
|
|
|
$S->display('login.tpl'); |
|
|
echo "<pre>";print_r(get_defined_vars());echo "</pre>"; |
|
|
/* |
|
|
*/ |
|
|
exit; |
|
|
} |
|
69 |
?> |
?> |