318 |
richard |
1 |
<?php
|
775 |
stephane |
2 |
require_once("lib/alcasar/freeradius/siteconfig.php");
|
|
|
3 |
require_once("lib/alcasar/freeradius/ldapconfig.php");
|
|
|
4 |
|
318 |
richard |
5 |
/* written by steweb57 */
|
|
|
6 |
/****************************************************************
|
|
|
7 |
* CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION *
|
|
|
8 |
*****************************************************************/
|
|
|
9 |
|
|
|
10 |
define ("ALCASAR_RADIUS_SITE", "/etc/raddb/sites-available/alcasar");
|
|
|
11 |
define ("ALCASAR_RADIUS_MODULE_LDAP", "/etc/raddb/modules/ldap");
|
|
|
12 |
|
|
|
13 |
/********************************************************
|
|
|
14 |
* TEST DES FICHIERS DE CONFIGURATION *
|
|
|
15 |
*********************************************************/
|
|
|
16 |
|
|
|
17 |
//Test de présence et des droits en lecture des fichiers de configuration.
|
|
|
18 |
if (!file_exists(ALCASAR_RADIUS_SITE)){
|
|
|
19 |
exit("Fichier ".ALCASAR_RADIUS_SITE." non présent");
|
|
|
20 |
}
|
|
|
21 |
if (!file_exists(ALCASAR_RADIUS_MODULE_LDAP)){
|
|
|
22 |
exit("Fichier ".ALCASAR_RADIUS_MODULE_LDAP." non présent");
|
|
|
23 |
}
|
|
|
24 |
if (!is_readable(ALCASAR_RADIUS_SITE)){
|
|
|
25 |
exit("Vous n'avez pas les droits d'écriture sur le fichier ".ALCASAR_RADIUS_SITE);
|
|
|
26 |
}
|
|
|
27 |
if (!is_readable(ALCASAR_RADIUS_MODULE_LDAP)){
|
|
|
28 |
exit("Vous n'avez pas les droits d'écriture sur le fichier ".ALCASAR_RADIUS_MODULE_LDAP);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
/********************************************************
|
|
|
32 |
* VARIABLES DE FORMULAIRE *
|
|
|
33 |
*********************************************************/
|
|
|
34 |
|
|
|
35 |
if (isset($_GET['erreur'])&&(!($_GET['erreur']==""))) $erreur = $_GET['erreur']; else $erreur = false;//valeur de $erreur non controlée car ne sert qu'un afficher un msg.
|
|
|
36 |
if (isset($_GET['update'])&&($_GET['update']=="ok")) $update = true; else $update = false;
|
|
|
37 |
|
|
|
38 |
$message = "";
|
|
|
39 |
if ((bool)$erreur){
|
344 |
richard |
40 |
$message = "<div align=\"center\"><br>";
|
|
|
41 |
$message.="<strong><font color=\"red\">".$erreur."</font></strong><br>";
|
|
|
42 |
$message.="<br></div>";
|
318 |
richard |
43 |
}else{
|
|
|
44 |
if ($update){
|
344 |
richard |
45 |
$message = "<div align=\"center\"><br>";
|
688 |
richard |
46 |
$message.="<strong><font color=\"green\">Mise à jour des paramètres ldap réalisé avec succès</font><br></strong>";
|
344 |
richard |
47 |
$message.="<br></div>";
|
318 |
richard |
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/****************************************************************
|
|
|
52 |
* VARIABLES RESULTATS *
|
|
|
53 |
*****************************************************************/
|
|
|
54 |
//Création des variables nécessaires
|
|
|
55 |
//variables ldap
|
775 |
stephane |
56 |
$ldap_on = "";
|
318 |
richard |
57 |
$ldap_server = ""; //IP ou nom DNS du seveur LDAP (ou AD)
|
|
|
58 |
//par défaut : server = "ldap.your.domain"
|
|
|
59 |
$ldap_identity = ""; //nom d'utilisateur qui intérroge le ldap (vide = anonyme)
|
|
|
60 |
//par défaut : # identity = "cn=admin,o=My Org,c=UA"
|
|
|
61 |
$ldap_password = ""; //mot de passe de l'utilisateur intérrogeant le ldap
|
|
|
62 |
//par défaut : # password = mypass
|
|
|
63 |
$ldap_basedn = ""; //DN de base ou l'on recherchera les utilisateurs
|
|
|
64 |
//par défaut : basedn = "o=My Org,c=UA"
|
|
|
65 |
$ldap_filter = ""; //permet entre autre de déterminer l'attribut utilisé pour la recherche d'un utilisateur dans LDAP
|
|
|
66 |
//attribut uid pour un ldap standard, samaccountname pour AD
|
|
|
67 |
//par défaut : filter = "(uid=%{Stripped-User-Name:-%{User-Name}})"
|
|
|
68 |
$ldap_base_filter = ""; //
|
|
|
69 |
//par défaut : # base_filter = "(objectclass=radiusprofile)"
|
|
|
70 |
|
|
|
71 |
/********************************************************
|
775 |
stephane |
72 |
* Fichier ALCASAR_RADIUS_SITE *
|
318 |
richard |
73 |
*********************************************************/
|
775 |
stephane |
74 |
$site = new siteConfig();
|
|
|
75 |
$site->load(ALCASAR_RADIUS_SITE);
|
|
|
76 |
$ldap_on = $site->authorize->ldap;
|
776 |
stephane |
77 |
|
775 |
stephane |
78 |
/********************************************************
|
|
|
79 |
* Fichier ALCASAR_RADIUS_MODULE_LDAP *
|
|
|
80 |
*********************************************************/
|
318 |
richard |
81 |
//Lecture du fichier /etc/raddb/modules/ldap
|
775 |
stephane |
82 |
$ldap = new ldapConfig();
|
|
|
83 |
$ldap->load(ALCASAR_RADIUS_MODULE_LDAP);
|
779 |
stephane |
84 |
$ldap_server = $ldap->host; // others options only in alcasar 3.x ($ldap->server)
|
775 |
stephane |
85 |
$ldap_identity = $ldap->identity;
|
|
|
86 |
$ldap_password = $ldap->password;
|
|
|
87 |
$ldap_basedn = $ldap->basedn;
|
779 |
stephane |
88 |
$ldap_filter = $ldap->uid;// others options only in alcasar 3.x ($ldap->filter)
|
775 |
stephane |
89 |
$ldap_base_filter = $ldap->base_filter;
|
318 |
richard |
90 |
|
|
|
91 |
|
|
|
92 |
# Choice of language
|
|
|
93 |
$Language = 'en';
|
|
|
94 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
|
|
95 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
96 |
$Language = strtolower(substr(chop($Langue[0]),0,2)); }
|
|
|
97 |
if($Language == 'fr'){
|
675 |
richard |
98 |
$l_ldap_title = "Authentification externe : LDAP";
|
|
|
99 |
$l_ldap_legend = "Authentification LDAP";
|
318 |
richard |
100 |
$l_ldap_auth_enable_label = "Activer l'authentification LDAP:";
|
675 |
richard |
101 |
$l_ldap_YES = "OUI";
|
|
|
102 |
$l_ldap_NO = "NON";
|
318 |
richard |
103 |
$l_ldap_server_label = "Nom du serveur LDAP:";
|
675 |
richard |
104 |
$l_ldap_server_text = "Nom ou IP du serveur LDAP éventuel.";
|
318 |
richard |
105 |
$l_ldap_base_dn_label = "DN de la base LDAP:";
|
|
|
106 |
$l_ldap_base_dn_text = "DN est le 'Distinguished Name', il situe les informations utilisateurs, exemple: 'o=Mon entreprise, c=FR'.";
|
|
|
107 |
$l_ldap_filter_label = "Identifiant LDAP:";
|
675 |
richard |
108 |
$l_ldap_filter_text = "Clé utilisée pour la recherche d'un identifiant de connexion, exemple: 'uid', 'sn', etc. Pour un AD mettre 'sAMAccountName'.";
|
318 |
richard |
109 |
$l_ldap_base_filter_label = "Filtre de l'utilisateur LDAP:";
|
|
|
110 |
$l_ldap_base_filter_text = "Sur option, vous pouvez en plus limiter les objets recherchés avec des filtres additionnels. Par exemple 'objectClass=posixGroup' aurait comme conséquence l'utilisation de '(&(uid=username)(objectClass=posixGroup))'";
|
675 |
richard |
111 |
$l_ldap_user_label = "Utilisateur LDAP:";
|
|
|
112 |
$l_ldap_user_text = "Laissez vide pour utiliser un accès invité. Si renseigné, ALCASAR se connectera au serveur LDAP en tant qu'un utilisateur spécifié, exemple: 'uid=Utilisateur,ou=MonUnité,o=MaCompagnie,c=FR'. Requis pour les serveurs possédant un Active Directory.";
|
318 |
richard |
113 |
$l_ldap_password_label = "Mot de passe LDAP:";
|
|
|
114 |
$l_ldap_password_text = "Laissez vide pour un accès invité. Sinon, indiquez le mot de passe de connexion. Requis pour les serveurs possédant un Active Directory.";
|
675 |
richard |
115 |
$l_ldap_submit = "Enregistrer";
|
|
|
116 |
$l_ldap_reset = "Annuler";
|
|
|
117 |
$l_ldap_test_network_failed = "Pas de connectivité réseau avec le serveur LDAP.";
|
658 |
stephane |
118 |
$l_ldap_test_connection_failed = "Impossible de se connecter au serveur LDAP.";
|
675 |
richard |
119 |
$l_ldap_test_bind_ok = "Connexion LDAP réussie...";
|
|
|
120 |
$l_ldap_test_bind_failed = "Echec d'authentification sur le serveur LDAP...Vérifiez votre configuration ldap...";
|
318 |
richard |
121 |
} else {
|
675 |
richard |
122 |
$l_ldap_title = "External authentication : LDAP";
|
|
|
123 |
$l_ldap_legend = "LDAP authentication";
|
318 |
richard |
124 |
$l_ldap_auth_enable_label = "Use LDAP authentication :";
|
675 |
richard |
125 |
$l_ldap_YES = "YES";
|
|
|
126 |
$l_ldap_NO = "NO";
|
318 |
richard |
127 |
$l_ldap_server_label = "LDAP server name:";
|
675 |
richard |
128 |
$l_ldap_server_text = "This is the hostname or IP address of the LDAP server.";
|
318 |
richard |
129 |
$l_ldap_base_dn_label = "LDAP base dn:";
|
|
|
130 |
$l_ldap_base_dn_text = "This is the 'Distinguished Name', locating the user information, e.g. 'o=My Company,c=US'.";
|
|
|
131 |
$l_ldap_filter_label = "LDAP uid:";
|
675 |
richard |
132 |
$l_ldap_filter_text = "This is the key under which to search for a given login identity, e.g. 'uid', 'sn', etc.. For AD use 'sAMAccountName'.";
|
318 |
richard |
133 |
$l_ldap_base_filter_label = "LDAP user filter:";
|
|
|
134 |
$l_ldap_base_filter_text = "Optionally you can further limit the searched objects with additional filters. For example 'objectClass=posixGroup' would result in the use of '(&(uid=username)(objectClass=posixGroup))'";
|
675 |
richard |
135 |
$l_ldap_user_label = "LDAP user dn:";
|
|
|
136 |
$l_ldap_user_text = "Leave blank to use anonymous binding. If filled, ALCASAR uses the specified distinguished name on login attempts to find the correct user, e.g. 'uid=Username,ou=MyUnit,o=MyCompany,c=US'. Required for Active Directory Servers.";
|
318 |
richard |
137 |
$l_ldap_password_label = "LDAP password:";
|
|
|
138 |
$l_ldap_password_text = "Leave blank to use anonymous binding. Else fill in the password for the above user. Required for Active Directory Servers.";
|
675 |
richard |
139 |
$l_ldap_submit = "Save";
|
|
|
140 |
$l_ldap_reset = "Reset";
|
|
|
141 |
$l_ldap_test_network_failed = "LDAP server is not reachable.";
|
658 |
stephane |
142 |
$l_ldap_test_connection_failed = "LDAP connexion failed...";
|
675 |
richard |
143 |
$l_ldap_test_bind_ok = "LDAP connexion success...";
|
|
|
144 |
$l_ldap_test_bind_failed = "LDAP authentication failed...Check your ldap setup...";
|
318 |
richard |
145 |
}
|
620 |
stephane |
146 |
|
|
|
147 |
function ldap_test($f_ldap_server, $f_ldap_identity, $f_ldap_password, $f_ldap_port = "389"){
|
|
|
148 |
// Test du serveur
|
|
|
149 |
if (!$sock = @fsockopen($f_ldap_server, $f_ldap_port, $num, $error, 2)) {
|
658 |
stephane |
150 |
// no network connection
|
620 |
stephane |
151 |
return -1;
|
|
|
152 |
} else {
|
|
|
153 |
fclose($sock);
|
|
|
154 |
// Connexion au serveur LDAP
|
|
|
155 |
$ldapconn = ldap_connect($f_ldap_server, $f_ldap_port);
|
|
|
156 |
ldap_set_option($ldapconn, LDAP_OPT_TIMELIMIT, 2);
|
|
|
157 |
if ($ldapconn) {
|
|
|
158 |
$ldapbind = ldap_bind($ldapconn, $f_ldap_identity, $f_ldap_password);
|
|
|
159 |
if ($ldapbind) {
|
658 |
stephane |
160 |
// LDAP Bind success
|
|
|
161 |
ldap_unbind($ldapconn);
|
|
|
162 |
return 1;
|
620 |
stephane |
163 |
} else {
|
658 |
stephane |
164 |
// LDAP Bind failed
|
|
|
165 |
return 0;
|
620 |
stephane |
166 |
}
|
|
|
167 |
} else {
|
658 |
stephane |
168 |
// LDAP connection failed
|
|
|
169 |
return -2;
|
620 |
stephane |
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
|
318 |
richard |
174 |
/********************************
|
|
|
175 |
* TO DO *
|
|
|
176 |
*********************************/
|
|
|
177 |
//internationnalisation à mettre en haut du fichier pour internationnaliser les erreurs de script!
|
|
|
178 |
?>
|
|
|
179 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
180 |
<html><!-- written by steweb57 -->
|
|
|
181 |
<head>
|
344 |
richard |
182 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
318 |
richard |
183 |
<title><?php echo $l_ldap_title; ?></title>
|
|
|
184 |
<link rel="stylesheet" href="/css/style.css" type="text/css">
|
344 |
richard |
185 |
<link rel="stylesheet" href="/css/ldap.css" type="text/css">
|
318 |
richard |
186 |
<script language="javascript">
|
|
|
187 |
function testLdapActif(){
|
|
|
188 |
//List des ID des éléments à désactiver
|
|
|
189 |
var listToDisables = new Array("ldap_server","ldap_dn","ldap_filter","ldap_base_filter","ldap_user","ldap_password");
|
|
|
190 |
|
|
|
191 |
if (document.getElementById("auth_enable").value == "1"){
|
|
|
192 |
for (var i=0;i<listToDisables.length;i++){
|
|
|
193 |
document.getElementById(listToDisables[i]).style.backgroundColor ="#ffffff";
|
|
|
194 |
document.getElementById(listToDisables[i]).disabled = false;
|
|
|
195 |
}
|
|
|
196 |
} else {
|
|
|
197 |
for (var i=0;i<listToDisables.length;i++){
|
|
|
198 |
document.getElementById(listToDisables[i]).style.backgroundColor ="#c0c0c0";
|
|
|
199 |
document.getElementById(listToDisables[i]).disabled = true;
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
</script>
|
|
|
204 |
</head>
|
|
|
205 |
<body onLoad="testLdapActif();">
|
|
|
206 |
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
|
207 |
<tr><th><?php echo $l_ldap_legend; ?></th></tr>
|
|
|
208 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width=1 height=2></td></tr>
|
|
|
209 |
</table>
|
|
|
210 |
<table width="100%" border=1 cellspacing=0 cellpadding=1>
|
|
|
211 |
<tr><td valign="middle" align="left">
|
|
|
212 |
<form name="config_ldap" method="post" action="update_ldap.php">
|
|
|
213 |
<fieldset>
|
620 |
stephane |
214 |
<legend>
|
|
|
215 |
<?php
|
658 |
stephane |
216 |
echo $message;
|
|
|
217 |
$pos = strpos($ldap_server, "//");
|
|
|
218 |
if ($pos!==false){
|
|
|
219 |
$new_ldap_server = explode("//",$ldap_server); //pour discriminer le host et le protocole dans la notation "ldap://192.168.182.10" ou "ldaps://monldap.monentreperise.com"
|
|
|
220 |
} else {
|
659 |
richard |
221 |
$new_ldap_server = $ldap_server;
|
658 |
stephane |
222 |
}
|
775 |
stephane |
223 |
if (($ldap_on == "ldap") && (function_exists('ldap_connect'))){
|
620 |
stephane |
224 |
echo "<div align='center'><br>";
|
658 |
stephane |
225 |
switch(ldap_test($new_ldap_server, $ldap_identity, $ldap_password)){
|
|
|
226 |
case -2:
|
|
|
227 |
echo "<font color='red'>".$l_ldap_test_connection_failed."</font>";
|
|
|
228 |
break;
|
620 |
stephane |
229 |
case -1:
|
658 |
stephane |
230 |
echo "<font color='red'>".$l_ldap_test_network_failed."</font>";
|
620 |
stephane |
231 |
break;
|
|
|
232 |
case 0:
|
658 |
stephane |
233 |
echo "<font color='red'>".$l_ldap_test_bind_failed."</font>";
|
620 |
stephane |
234 |
break;
|
|
|
235 |
case 1:
|
658 |
stephane |
236 |
echo "<font color='green'>".$l_ldap_test_bind_ok."</font>";
|
620 |
stephane |
237 |
break;
|
|
|
238 |
default:
|
|
|
239 |
echo "LDAP error";
|
|
|
240 |
}
|
|
|
241 |
echo "<br><br></div>";
|
|
|
242 |
}
|
|
|
243 |
?>
|
|
|
244 |
</legend>
|
318 |
richard |
245 |
<dl>
|
|
|
246 |
<dt>
|
|
|
247 |
<label for="auth_enable"><?php echo $l_ldap_auth_enable_label; ?></label>
|
|
|
248 |
</dt>
|
|
|
249 |
<dd>
|
|
|
250 |
<select id="auth_enable" name="auth_enable" onchange="testLdapActif();">
|
776 |
stephane |
251 |
<?php if ($ldap_on == "ldap") {
|
318 |
richard |
252 |
echo "<option value=\"1\" selected=\"selected\">$l_ldap_YES</option>";
|
|
|
253 |
echo "<option value=\"0\">$l_ldap_NO</option>";
|
|
|
254 |
}else{
|
|
|
255 |
echo "<option value=\"1\">$l_ldap_YES</option>";
|
|
|
256 |
echo "<option value=\"0\" selected=\"selected\">$l_ldap_NO</option>";
|
|
|
257 |
}?>
|
|
|
258 |
</select>
|
|
|
259 |
</dd>
|
|
|
260 |
</dl>
|
|
|
261 |
<dl>
|
|
|
262 |
<dt>
|
|
|
263 |
<label for="ldap_server"><?php echo $l_ldap_server_label; ?></label>
|
344 |
richard |
264 |
<br>
|
318 |
richard |
265 |
<?php echo $l_ldap_server_text; ?></dt>
|
|
|
266 |
<dd>
|
344 |
richard |
267 |
<input id="ldap_server" size="40" name="ldap_server" value="<?php echo htmlspecialchars($ldap_server); ?>">
|
318 |
richard |
268 |
</dd>
|
|
|
269 |
</dl>
|
|
|
270 |
<dl>
|
|
|
271 |
<dt>
|
|
|
272 |
<label for="ldap_dn"><?php echo $l_ldap_base_dn_label; ?></label>
|
344 |
richard |
273 |
<br>
|
318 |
richard |
274 |
<?php echo $l_ldap_base_dn_text; ?></dt>
|
|
|
275 |
<dd>
|
344 |
richard |
276 |
<input id="ldap_dn" size="40" name="ldap_base_dn" value="<?php echo htmlspecialchars($ldap_basedn); ?>">
|
318 |
richard |
277 |
</dd>
|
|
|
278 |
</dl>
|
|
|
279 |
<dl>
|
|
|
280 |
<dt>
|
|
|
281 |
<label for="ldap_filter"><?php echo $l_ldap_filter_label; ?></label>
|
344 |
richard |
282 |
<br>
|
318 |
richard |
283 |
<?php echo $l_ldap_filter_text; ?></dt>
|
|
|
284 |
<dd>
|
344 |
richard |
285 |
<input id="ldap_filter" size="40" name="ldap_filter" value="<?php echo htmlspecialchars($ldap_filter); ?>">
|
318 |
richard |
286 |
</dd>
|
|
|
287 |
</dl>
|
|
|
288 |
<dl>
|
|
|
289 |
<dt>
|
|
|
290 |
<label for="ldap_base_filter"><?php echo $l_ldap_base_filter_label; ?></label>
|
344 |
richard |
291 |
<br>
|
318 |
richard |
292 |
<?php echo $l_ldap_base_filter_text; ?></dt>
|
|
|
293 |
<dd>
|
344 |
richard |
294 |
<input id="ldap_base_filter" size="40" name="ldap_base_filter" value="<?php echo htmlspecialchars($ldap_base_filter); ?>">
|
318 |
richard |
295 |
</dd>
|
|
|
296 |
</dl>
|
|
|
297 |
<dl>
|
|
|
298 |
<dt>
|
|
|
299 |
<label for="ldap_user"><?php echo $l_ldap_user_label; ?></label>
|
344 |
richard |
300 |
<br>
|
318 |
richard |
301 |
<?php echo $l_ldap_user_text; ?></dt>
|
|
|
302 |
<dd>
|
344 |
richard |
303 |
<input id="ldap_user" size="40" name="ldap_user" value="<?php echo htmlspecialchars($ldap_identity); ?>">
|
318 |
richard |
304 |
</dd>
|
|
|
305 |
</dl>
|
|
|
306 |
<dl>
|
|
|
307 |
<dt>
|
|
|
308 |
<label for="ldap_password"><?php echo $l_ldap_password_label; ?></label>
|
344 |
richard |
309 |
<br>
|
318 |
richard |
310 |
<?php echo $l_ldap_password_text; ?></dt>
|
|
|
311 |
<dd>
|
344 |
richard |
312 |
<input id="ldap_password" type="password" size="40" name="ldap_password" value="<?php echo htmlspecialchars($ldap_password);?>">
|
318 |
richard |
313 |
</dd>
|
|
|
314 |
</dl>
|
|
|
315 |
<p>
|
344 |
richard |
316 |
<input id="submit" type="submit" value="<?php echo $l_ldap_submit; ?>" name="submit">
|
318 |
richard |
317 |
|
344 |
richard |
318 |
<input id="reset" type="reset" value="<?php echo $l_ldap_reset; ?>" name="reset">
|
318 |
richard |
319 |
</p>
|
|
|
320 |
|
|
|
321 |
</fieldset>
|
|
|
322 |
</form>
|
344 |
richard |
323 |
<br>
|
318 |
richard |
324 |
</td></tr>
|
|
|
325 |
</table>
|
|
|
326 |
</body>
|
|
|
327 |
</html>
|