318 |
richard |
1 |
<?php
|
|
|
2 |
/* written by steweb57 */
|
775 |
stephane |
3 |
require_once("lib/alcasar/freeradius/siteconfig.php");
|
|
|
4 |
require_once("lib/alcasar/freeradius/ldapconfig.php");
|
1677 |
richard |
5 |
/************************************************************************
|
|
|
6 |
* CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION *
|
|
|
7 |
*************************************************************************/
|
318 |
richard |
8 |
|
|
|
9 |
define ("ALCASAR_RADIUS_SITE", "/etc/raddb/sites-available/alcasar");
|
|
|
10 |
define ("ALCASAR_RADIUS_MODULE_LDAP", "/etc/raddb/modules/ldap");
|
615 |
richard |
11 |
define ("ALCASAR_CONF_FILE", "/usr/local/etc/alcasar.conf");
|
318 |
richard |
12 |
|
1677 |
richard |
13 |
/****************************************************************
|
|
|
14 |
* FONCTION ERREUR *
|
|
|
15 |
*****************************************************************/
|
318 |
richard |
16 |
|
|
|
17 |
function erreur($er){
|
|
|
18 |
header('Location:ldap.php?erreur=$er');
|
|
|
19 |
exit();
|
|
|
20 |
}
|
|
|
21 |
|
1677 |
richard |
22 |
/****************************************************************
|
|
|
23 |
* VARIABLES DE FORMULAIRE *
|
|
|
24 |
*****************************************************************/
|
318 |
richard |
25 |
|
|
|
26 |
//Récupération des variables de formulaire
|
|
|
27 |
if (isset($_POST['auth_enable'])) $auth_enable = $_POST['auth_enable']; else erreur('Erreur de variable auth_enable');
|
|
|
28 |
if ($auth_enable == "1"){ //test $auth_enable
|
|
|
29 |
if (isset($_POST['ldap_server'])) $ldap_server = $_POST['ldap_server']; else erreur('Erreur de variable ldap_server');
|
|
|
30 |
if (isset($_POST['ldap_base_dn'])) $ldap_base_dn = $_POST['ldap_base_dn']; else erreur('Erreur de variable ldap_base_dn');
|
|
|
31 |
if (isset($_POST['ldap_filter'])) $ldap_filter = $_POST['ldap_filter']; else erreur('Erreur de variable ldap_filter');
|
|
|
32 |
if (isset($_POST['ldap_base_filter'])) $ldap_base_filter = $_POST['ldap_base_filter']; else erreur('Erreur de variable ldap_base_filter');
|
|
|
33 |
if (isset($_POST['ldap_user'])) $ldap_user = $_POST['ldap_user']; else erreur('Erreur de variable ldap_user');
|
775 |
stephane |
34 |
if (isset($_POST['ldap_password'])) $ldap_password = $_POST['ldap_password']; else erreur('Erreur de variable ldap_password');
|
318 |
richard |
35 |
} //test $auth_enable
|
|
|
36 |
|
1677 |
richard |
37 |
/****************************************************************
|
|
|
38 |
* TEST DES FICHIERS DE CONFIGURATION *
|
|
|
39 |
*****************************************************************/
|
318 |
richard |
40 |
|
|
|
41 |
//Test de présence et des droits en modification des fichiers de configuration.
|
1160 |
stephane |
42 |
/* texte à internationaliser : pas urgent : débugage uniquement */
|
318 |
richard |
43 |
if (!file_exists(ALCASAR_RADIUS_SITE)){
|
|
|
44 |
exit("Fichier de configuration du virtual-host 'alcasar' de freeradius non présent");
|
|
|
45 |
}
|
|
|
46 |
if (!file_exists(ALCASAR_RADIUS_MODULE_LDAP)){
|
|
|
47 |
exit("Fichier de configuration du module ldap pour freeradius non présent");
|
|
|
48 |
}
|
|
|
49 |
if (!is_writable(ALCASAR_RADIUS_SITE)){
|
|
|
50 |
exit("Vous n'avez pas les droits d'écriture sur le fichier /etc/raddb/sites-available/alcasar");
|
|
|
51 |
}
|
|
|
52 |
if (!is_writable(ALCASAR_RADIUS_MODULE_LDAP)){
|
|
|
53 |
exit("Vous n'avez pas les droits d'écriture sur le fichier /etc/raddb/modules/ldap");
|
|
|
54 |
}
|
|
|
55 |
|
1677 |
richard |
56 |
/****************************************************************
|
|
|
57 |
* Fichier ALCASAR_RADIUS_SITE *
|
|
|
58 |
*****************************************************************/
|
775 |
stephane |
59 |
$site = new siteConfig();
|
|
|
60 |
$site->load(ALCASAR_RADIUS_SITE);
|
|
|
61 |
if ($auth_enable == "1"){ //test $auth_enable
|
777 |
stephane |
62 |
/*
|
|
|
63 |
ON ACTIVE LE LDAP
|
|
|
64 |
*/
|
|
|
65 |
/*
|
|
|
66 |
Configure autorize section with:
|
|
|
67 |
ldap {
|
|
|
68 |
fail=1
|
|
|
69 |
}
|
|
|
70 |
*/
|
|
|
71 |
if ($site->authorize->ldap === false){ // always test before update
|
776 |
stephane |
72 |
$site->authorize->addSection('ldap');
|
|
|
73 |
$site->authorize->ldap->addPair('fail','1');
|
|
|
74 |
}else{
|
777 |
stephane |
75 |
if ($site->authorize->ldap->fail === false){ // always test before update
|
776 |
stephane |
76 |
$site->authorize->ldap->addPair('fail','1');
|
|
|
77 |
}
|
|
|
78 |
}
|
777 |
stephane |
79 |
/*
|
|
|
80 |
Configure authenticate section with
|
|
|
81 |
Auth-Type LDAP {
|
|
|
82 |
ldap
|
|
|
83 |
}
|
|
|
84 |
*/
|
|
|
85 |
if ($site->authenticate->getSectionInstance('Auth-Type','LDAP')===false){ // always test before update
|
776 |
stephane |
86 |
$site->authenticate->addSection('Auth-Type', 'LDAP');
|
|
|
87 |
$site->authenticate->getSectionInstance('Auth-Type','LDAP')->addSection('ldap');
|
|
|
88 |
}
|
775 |
stephane |
89 |
} else {
|
777 |
stephane |
90 |
/*
|
|
|
91 |
ON DESACTIVE LE LDAP
|
|
|
92 |
*/
|
|
|
93 |
if ($site->authorize->ldap !== false){ // always test before update
|
|
|
94 |
$site->authorize->deleteSection("ldap");
|
|
|
95 |
}
|
|
|
96 |
if ($site->authenticate->getSectionInstance('Auth-Type','LDAP')!==false){ // always test before update
|
|
|
97 |
$site->authenticate->deleteSection('Auth-Type','LDAP');
|
|
|
98 |
}
|
775 |
stephane |
99 |
}
|
318 |
richard |
100 |
//Sauvegarde du /etc/raddb/sites-available/alcasar
|
775 |
stephane |
101 |
$site->save(ALCASAR_RADIUS_SITE);
|
318 |
richard |
102 |
|
1677 |
richard |
103 |
/****************************************************************
|
|
|
104 |
* Fichier ALCASAR_RADIUS_MODULE_LDAP *
|
|
|
105 |
*****************************************************************/
|
318 |
richard |
106 |
//on ne modifie ALCASAR_RADIUS_MODULE_LDAP uniquement si l'authentification ldap est active
|
|
|
107 |
if ($auth_enable == "1"){ //test $auth_enable
|
775 |
stephane |
108 |
// chargement de la configuration courante
|
|
|
109 |
$ldap = new ldapConfig();
|
|
|
110 |
$ldap->load(ALCASAR_RADIUS_MODULE_LDAP);
|
|
|
111 |
// mise à jours des données
|
779 |
stephane |
112 |
//$ldap->server = $ldap_server;
|
|
|
113 |
$ldap->host = $ldap_server;
|
780 |
stephane |
114 |
$ldap->identity = $ldap_user;
|
775 |
stephane |
115 |
$ldap->password = $ldap_password;
|
780 |
stephane |
116 |
$ldap->basedn = $ldap_base_dn;
|
779 |
stephane |
117 |
//$ldap->filter = $ldap_filter;
|
|
|
118 |
$ldap->uid = $ldap_filter;
|
775 |
stephane |
119 |
$ldap->base_filter = $ldap_base_filter;
|
|
|
120 |
//sauvegarde du fichier /etc/raddb/modules/ldap
|
|
|
121 |
$ldap->save(ALCASAR_RADIUS_MODULE_LDAP);
|
318 |
richard |
122 |
} //test $auth_enable
|
|
|
123 |
|
1677 |
richard |
124 |
/********************************************************
|
|
|
125 |
* Redémarage des service *
|
|
|
126 |
*********************************************************/
|
318 |
richard |
127 |
|
615 |
richard |
128 |
if ($auth_enable == "1"){
|
1677 |
richard |
129 |
file_put_contents(ALCASAR_CONF_FILE, str_replace('LDAP=off', 'LDAP=on', file_get_contents(ALCASAR_CONF_FILE)));
|
1822 |
raphael.pi |
130 |
exec("sudo sed -i \"s/^LDAP_IP=.*/LDAP_IP=$ldap_server/g\" ALCASAR_CONF_FILE");}
|
615 |
richard |
131 |
else {
|
1677 |
richard |
132 |
file_put_contents(ALCASAR_CONF_FILE, str_replace('LDAP=on', 'LDAP=off', file_get_contents(ALCASAR_CONF_FILE)));
|
1822 |
raphael.pi |
133 |
exec("sudo sed -i \"s/^LDAP_IP=.*/LDAP_IP=0.0.0.0/g\" ALCASAR_CONF_FILE");}
|
615 |
richard |
134 |
exec ("sudo /usr/local/bin/alcasar-iptables.sh");
|
1578 |
richard |
135 |
exec ("sudo /usr/bin/systemctl restart radiusd");
|
318 |
richard |
136 |
|
1677 |
richard |
137 |
/****************************************************************
|
|
|
138 |
* Redirection vers la page de configuration LDAP *
|
|
|
139 |
*****************************************************************/
|
318 |
richard |
140 |
|
|
|
141 |
header('Location:ldap.php?update=ok');
|
|
|
142 |
exit();
|
615 |
richard |
143 |
?>
|