1300 |
richard |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
2 |
<HTML><!-- Written by Rexy, Romero P. & 3abTux -->
|
|
|
3 |
<HEAD>
|
|
|
4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
5 |
<TITLE>Users import</TITLE>
|
2817 |
rexy |
6 |
<link rel="stylesheet" href="/css/acc.css" type="text/css">
|
1300 |
richard |
7 |
</HEAD>
|
|
|
8 |
<body>
|
|
|
9 |
<?php
|
1508 |
richard |
10 |
// Choice of language
|
1300 |
richard |
11 |
$Language = 'en';
|
|
|
12 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
|
|
13 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
14 |
$Language = strtolower(substr(chop($Langue[0]),0,2)); }
|
|
|
15 |
if($Language == 'fr'){
|
1583 |
richard |
16 |
$l_title = "Importer et vider la base des usagers";
|
|
|
17 |
$l_database_state = "état actuel de la base : nombre de groupes =";
|
1300 |
richard |
18 |
$l_number_of_users = "Nombre d'usagers";
|
1583 |
richard |
19 |
$l_text_import = "Importer à partir d'un fichier texte";
|
|
|
20 |
$l_text_import_help = "Ce fichier ne doit contenir que des noms d'usagers écrits les uns sous les autres.";
|
1300 |
richard |
21 |
$l_file = "Fichier";
|
1583 |
richard |
22 |
$l_users_group = "Définissez leur groupe (conseillé)";
|
|
|
23 |
$l_send = "Importer";
|
|
|
24 |
$l_empty = "Vider";
|
1835 |
raphael.pi |
25 |
$l_empty_warn = "Vous êtes sur le point de vider entièrement la base de donnée des utilisateurs... Souhaitez vous continuer?";
|
1300 |
richard |
26 |
$l_imported_files = "Fichiers des identifiants/mot_de_passe importés durant les dernières 24h :";
|
1583 |
richard |
27 |
$l_db_import = "Importer à partir d'une sauvegarde de la base d'usagers";
|
|
|
28 |
$l_db_import_help = "Afin de pouvoir imputer les dernières traces de connexion, une sauvegarde de la base actuelle sera automatiquement réalisée.";
|
|
|
29 |
$l_db_reset = "Vider la base des usagers";
|
|
|
30 |
$l_error_ext_txt = "Erreur! Veuillez sélectionner un fichier avec l'extension '.csv' ou '.txt'";
|
|
|
31 |
$l_error_ext_sql = "Erreur! Veuillez sélectionner un fichier avec l'extension '.sql' ou '.sql.gz'";
|
1300 |
richard |
32 |
$l_group_empty = "La liste des groupes est vide";
|
|
|
33 |
$l_out_title = " --- Accès à Internet via ALCASAR --- ";
|
|
|
34 |
$l_out_login = "Nom de connexion :";
|
|
|
35 |
$l_out_passwd = "Mot de passe :";
|
|
|
36 |
$l_out_mind = "Pensez à changer votre mot de passe (lien sur la page d'authentification)";
|
|
|
37 |
}
|
|
|
38 |
else {
|
1583 |
richard |
39 |
$l_title = "Import and empty the users database";
|
1300 |
richard |
40 |
$l_database_state ="State of the database : number of groups =";
|
|
|
41 |
$l_number_of_users = "Number of users";
|
1583 |
richard |
42 |
$l_text_import = "Import from a text file";
|
1300 |
richard |
43 |
$l_text_import_help = "In this file, you must write only the user login one below the other.";
|
|
|
44 |
$l_file = "File";
|
|
|
45 |
$l_users_group = "Define their group (advisable)";
|
1583 |
richard |
46 |
$l_send = "Import";
|
|
|
47 |
$l_empty = "Empty";
|
1835 |
raphael.pi |
48 |
$l_empty_warn = "You are close to empty the whole user database... Would you like to proceed?";
|
1300 |
richard |
49 |
$l_imported_files = "Logins/passwords file imported during the last 24h :";
|
1583 |
richard |
50 |
$l_db_import = "Import from a saved users database file";
|
1300 |
richard |
51 |
$l_db_import_help = "In order to impute the last connections, the actual users database will be automaticly saved.";
|
1583 |
richard |
52 |
$l_db_reset = "Empty the users database";
|
1300 |
richard |
53 |
$l_error_ext_txt = "Error! Please select a file with '.txt' or '.csv' extension";
|
1583 |
richard |
54 |
$l_error_ext_sql = "Error! Please select a file with '.sql' or '.sql.gz' extension";
|
1300 |
richard |
55 |
$l_group_empty = "The group list is empty";
|
|
|
56 |
$l_out_title = " --- Internet access via ALCASAR --- ";
|
|
|
57 |
$l_out_login = "Login :";
|
|
|
58 |
$l_out_passwd = "Password :";
|
|
|
59 |
$l_out_mind = "Don't forget to change your password (a link is on the authentication window)";
|
|
|
60 |
}
|
2414 |
tom.houday |
61 |
|
|
|
62 |
require('/etc/freeradius-web/config.php');
|
|
|
63 |
|
1300 |
richard |
64 |
function getImportFileList(){
|
|
|
65 |
$importFile = array();
|
|
|
66 |
if ($handle = opendir('/tmp')) {
|
|
|
67 |
while (false !== ($file = readdir($handle))) {
|
|
|
68 |
if ($file != "." && $file != "..") {
|
|
|
69 |
$ext = pathinfo($file ,PATHINFO_EXTENSION);
|
|
|
70 |
$name = substr($file, 0, -(strlen($ext)+1)); //Retirer les lettres de l'extension ET le point
|
|
|
71 |
if ($ext=="pwd"){
|
|
|
72 |
$importFile[] = $name;
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
closedir($handle);
|
|
|
77 |
}
|
|
|
78 |
return $importFile;
|
|
|
79 |
}
|
2414 |
tom.houday |
80 |
|
1300 |
richard |
81 |
function GenPassword($nb_car="8")
|
2414 |
tom.houday |
82 |
{
|
1508 |
richard |
83 |
// Random password
|
1300 |
richard |
84 |
$password = "";
|
|
|
85 |
$chaine = "aAzZeErRtTyYuUIopP152346897mMLkK";
|
|
|
86 |
$chaine .= "jJhHgGfFdDsSqQwWxXcCvVbBnN152346897";
|
2414 |
tom.houday |
87 |
while($nb_car != 0) {
|
1300 |
richard |
88 |
$i = rand(0,71);
|
|
|
89 |
$password .= $chaine[$i];
|
2414 |
tom.houday |
90 |
$nb_car--;
|
1300 |
richard |
91 |
}
|
2414 |
tom.houday |
92 |
return $password;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
function freeradiusweb_removeDisallowedChars($login)
|
|
|
96 |
{
|
2415 |
tom.houday |
97 |
global $config;
|
|
|
98 |
|
2414 |
tom.houday |
99 |
if ($login != '')
|
|
|
100 |
{
|
|
|
101 |
$accent = "âêôûéàèùîáâãäçèéêëìíîïñòóôõöùúûü";
|
|
|
102 |
$login = preg_replace("/[^\w$accent\.\/\@\:\-]/",'',$login);
|
|
|
103 |
}
|
|
|
104 |
if ($login != '' && $config['general_strip_realms'] == 'yes'){
|
|
|
105 |
$realm_del = ($config['general_realm_delimiter'] != '') ? $config['general_realm_delimiter'] : '@';
|
|
|
106 |
$realm_for = ($config['general_realm_format'] != '') ? $config['general_realm_format'] : 'suffix';
|
|
|
107 |
$new = explode($realm_del,$login,2);
|
|
|
108 |
if (count($new) == 2)
|
|
|
109 |
$login = ($realm_for == 'suffix') ? $new[0] : $new[1];
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
return $login;
|
|
|
113 |
}
|
|
|
114 |
|
1300 |
richard |
115 |
?>
|
|
|
116 |
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
|
|
|
117 |
<tr><th><? echo "$l_title"; ?></th></tr>
|
|
|
118 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
119 |
</TABLE>
|
|
|
120 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
|
|
|
121 |
<tr><td valign="middle" align="left">
|
|
|
122 |
<CENTER><H3>
|
|
|
123 |
<?php
|
2415 |
tom.houday |
124 |
echo "$l_database_state ";
|
1300 |
richard |
125 |
|
|
|
126 |
$LIBpath = "../lib/";
|
|
|
127 |
if (is_file($LIBpath."sql/drivers/$config[sql_type]/functions.php"))
|
|
|
128 |
{
|
|
|
129 |
include_once($LIBpath."sql/drivers/$config[sql_type]/functions.php");
|
|
|
130 |
}
|
|
|
131 |
else
|
|
|
132 |
{
|
|
|
133 |
echo "<b>Could not include SQL library</b><br>\n";
|
|
|
134 |
exit();
|
|
|
135 |
}
|
|
|
136 |
include_once($LIBpath.'functions.php');
|
|
|
137 |
if ($config['sql_use_operators'] == 'true')
|
|
|
138 |
{
|
|
|
139 |
include($LIBpath."operators.php");
|
|
|
140 |
$text = ',op';
|
|
|
141 |
$passwd_op = ",':='";
|
|
|
142 |
}
|
|
|
143 |
$link = @da_sql_pconnect($config);
|
|
|
144 |
if (isset ($_POST ['choix'])) { $choix = $_POST ['choix']; }
|
|
|
145 |
else { $choix = ''; }
|
|
|
146 |
if ($choix == "raz")
|
|
|
147 |
{
|
1827 |
raphael.pi |
148 |
exec ("sudo /usr/local/bin/alcasar-logout.sh all");
|
|
|
149 |
exec ("sudo /usr/local/bin/alcasar-mysql.sh --raz");
|
1300 |
richard |
150 |
}
|
1508 |
richard |
151 |
// a file is downloaded
|
1502 |
richard |
152 |
if(isset($_FILES['import-users']) && ($_FILES['import-users']['name'] !=""))
|
1300 |
richard |
153 |
{
|
|
|
154 |
unset($result);
|
|
|
155 |
if (isset ($_POST['groupe'])) $group = $_POST ['groupe'];
|
1583 |
richard |
156 |
list($file_name , $extension) = explode("." , $_FILES['import-users']['name'] , 2);
|
1508 |
richard |
157 |
if ($choix == "csv") // import of a txt file
|
1300 |
richard |
158 |
{
|
1508 |
richard |
159 |
if (($extension != 'csv') && ($extension != 'txt')) $result = $l_error_ext_txt;
|
1300 |
richard |
160 |
else
|
|
|
161 |
{
|
1583 |
richard |
162 |
$destination = '/tmp/import_file.txt';
|
1827 |
raphael.pi |
163 |
exec ("sudo /usr/local/bin/alcasar-mysql.sh --dump");
|
1300 |
richard |
164 |
move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
|
|
|
165 |
$RS_in = file ($destination);
|
|
|
166 |
$da_abort=0;
|
|
|
167 |
if ($link)
|
|
|
168 |
{
|
|
|
169 |
if (is_file($LIBpath."crypt/$config[general_encryption_method].php"))
|
|
|
170 |
{
|
|
|
171 |
include($LIBpath."crypt/$config[general_encryption_method].php");
|
|
|
172 |
$tmpdate = date("Ymd-his");
|
1502 |
richard |
173 |
$file_out = "/tmp/$tmpdate-$file_name.pwd" ;
|
1300 |
richard |
174 |
$RS_out = fopen ("$file_out", "wb");
|
|
|
175 |
foreach ($RS_in as $no => $ligne)
|
|
|
176 |
{
|
|
|
177 |
if (substr($ligne,0,3) == pack('CCC',239,187,191)) # remove UTF8-BOM
|
|
|
178 |
{
|
|
|
179 |
$ligne = substr ($ligne,3);
|
|
|
180 |
}
|
2415 |
tom.houday |
181 |
$tligne = explode(" ",$ligne);
|
1300 |
richard |
182 |
$login = trim ($tligne[0]);
|
|
|
183 |
$password = trim ($tligne[1]);
|
|
|
184 |
if ($login != '')
|
|
|
185 |
{
|
|
|
186 |
if ($password == "")
|
|
|
187 |
{
|
|
|
188 |
$password = GenPassword();
|
2414 |
tom.houday |
189 |
}
|
|
|
190 |
$login = freeradiusweb_removeDisallowedChars($login);
|
1831 |
raphael.pi |
191 |
$login = da_sql_escape_string($link,$login);
|
2415 |
tom.houday |
192 |
$passwd = da_encrypt($password);
|
1831 |
raphael.pi |
193 |
$passwd = da_sql_escape_string($link,$passwd);
|
1508 |
richard |
194 |
// insertion (login + password) dans la table "radcheck" (si l'usager existe --> changement de mot de passe)
|
1300 |
richard |
195 |
$res = @da_sql_query($link,$config,"INSERT INTO $config[sql_check_table] (attribute,value,username $text) VALUES ('$config[sql_password_attribute]','$passwd','$login' $passwd_op);");
|
|
|
196 |
if (!$res || !@da_sql_affected_rows($link,$res,$config))
|
|
|
197 |
{
|
|
|
198 |
echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
199 |
$da_abort=1;
|
|
|
200 |
}
|
|
|
201 |
else
|
|
|
202 |
{
|
1508 |
richard |
203 |
// create the user informations file
|
1300 |
richard |
204 |
fputs($RS_out,"$l_out_title\r\n\r\n");
|
|
|
205 |
fputs($RS_out,"$l_out_login $login | $l_out_passwd $password\r\n\r\n");
|
|
|
206 |
fputs($RS_out,"$l_out_mind\r\n\r\n");
|
|
|
207 |
fputs($RS_out,"--------------------------------------------------------------------------------\r\n\r\n");
|
|
|
208 |
}
|
1508 |
richard |
209 |
// insertion de l'usager dans la table "userinfo"
|
2415 |
tom.houday |
210 |
if ($config['sql_use_user_info_table'] == 'true' && !$da_abort)
|
1300 |
richard |
211 |
{
|
|
|
212 |
$res = @da_sql_query($link,$config, "SELECT username FROM $config[sql_user_info_table] WHERE username = '$login';");
|
|
|
213 |
if ($res)
|
|
|
214 |
{
|
|
|
215 |
if (!@da_sql_num_rows($res,$config))
|
|
|
216 |
{
|
1561 |
richard |
217 |
$res = @da_sql_query($link,$config,"INSERT INTO $config[sql_user_info_table] (username) VALUES ('$login');");
|
1300 |
richard |
218 |
if (!$res || !@da_sql_affected_rows($link,$res,$config))
|
|
|
219 |
echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
|
|
|
220 |
}
|
|
|
221 |
else
|
|
|
222 |
echo "<b>User already exists in user info table.</b><br>\n";
|
|
|
223 |
}
|
|
|
224 |
else
|
|
|
225 |
echo "<b>Could not add user information in user info table: " . da_sql_error($link,$config) . "</b><br>\n";
|
2415 |
tom.houday |
226 |
if ((isset($group)) && (!empty($group)))
|
1300 |
richard |
227 |
{
|
1831 |
raphael.pi |
228 |
$group = da_sql_escape_string($link,$group);
|
1300 |
richard |
229 |
$res = @da_sql_query($link,$config,"SELECT username FROM $config[sql_usergroup_table] WHERE username = '$login' AND groupname = '$group';");
|
|
|
230 |
if ($res)
|
|
|
231 |
{
|
|
|
232 |
if (!@da_sql_num_rows($res,$config))
|
|
|
233 |
{
|
|
|
234 |
$res = @da_sql_query($link,$config,"INSERT INTO $config[sql_usergroup_table] (username,groupname) VALUES ('$login','$group');");
|
|
|
235 |
if (!$res || !@da_sql_affected_rows($link,$res,$config))
|
|
|
236 |
echo "<b>Could not add user to group $group. SQL Error</b><br>\n";
|
|
|
237 |
} # end if
|
|
|
238 |
else
|
|
|
239 |
echo "<b>User already is a member of group $group</b><br>\n";
|
|
|
240 |
} # end if
|
|
|
241 |
else
|
|
|
242 |
echo "<b>Could not add user to group $group: " . da_sql_error($link,$config) . "</b><br>\n";
|
1508 |
richard |
243 |
} // end if ($group)
|
|
|
244 |
} // end if ($config)
|
|
|
245 |
} // end if ($login !='')
|
|
|
246 |
} // end foreach
|
1300 |
richard |
247 |
fclose($RS_out);
|
1508 |
richard |
248 |
} // end if (is file)
|
|
|
249 |
} // end if (link)
|
1583 |
richard |
250 |
unlink ($destination);
|
|
|
251 |
} // end if (extension = (txt or cvs))
|
1300 |
richard |
252 |
}
|
1508 |
richard |
253 |
else if ($choix == "bdd") // database import
|
1300 |
richard |
254 |
{
|
1583 |
richard |
255 |
if (($extension == 'sql') || ($extension == 'sql.gz'))
|
1300 |
richard |
256 |
{
|
1583 |
richard |
257 |
$destination = '/tmp/import_file.'.$extension;
|
1827 |
raphael.pi |
258 |
exec ("sudo /usr/local/bin/alcasar-mysql.sh --dump");
|
1300 |
richard |
259 |
move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
|
1827 |
raphael.pi |
260 |
exec ("sudo /usr/local/bin/alcasar-mysql.sh --import $destination");
|
1583 |
richard |
261 |
//echo "OK : $destination";
|
|
|
262 |
unlink ($destination);
|
1300 |
richard |
263 |
}
|
1583 |
richard |
264 |
else $result = $l_error_ext_sql;
|
1300 |
richard |
265 |
}
|
|
|
266 |
}
|
|
|
267 |
if ($link)
|
|
|
268 |
{
|
|
|
269 |
$res = @da_sql_query($link,$config,"SELECT GroupName FROM radusergroup GROUP BY GroupName");
|
|
|
270 |
if ($res)
|
|
|
271 |
{
|
|
|
272 |
$nb_group = @da_sql_num_rows($res,$config);
|
|
|
273 |
echo $nb_group;
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
echo ", $l_number_of_users = ";
|
|
|
277 |
if ($link)
|
|
|
278 |
{
|
|
|
279 |
$res = @da_sql_query($link,$config,"SELECT UserName FROM userinfo");
|
|
|
280 |
if ($res)
|
|
|
281 |
{
|
|
|
282 |
$nb_user = @da_sql_num_rows($res,$config);
|
|
|
283 |
echo "$nb_user";
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
echo "</td></tr><tr><td>";
|
|
|
287 |
echo "<TABLE width=\"100%\" border=0 cellspacing=0 cellpadding=1>";
|
|
|
288 |
echo "<tr><td valign=\"middle\" align=\"left\" colspan=\"2\">";
|
|
|
289 |
echo "<CENTER><H3>$l_text_import</H3></CENTER></td></tr>";
|
|
|
290 |
echo "<tr><td valign=\"middle\" align=\"left\">";
|
|
|
291 |
echo "$l_text_import_help<br>";
|
|
|
292 |
echo "<tr><td valign=\"middle\" align=\"left\">";
|
|
|
293 |
echo "<br><FORM action='$_SERVER[PHP_SELF]' method=POST ENCTYPE=\"multipart/form-data\">";
|
1583 |
richard |
294 |
echo "$l_file (.txt or .csv) : <input type=\"file\" name=\"import-users\"><br>";
|
1300 |
richard |
295 |
echo "$l_users_group : ";
|
|
|
296 |
require("../lib/defaults.php");
|
|
|
297 |
include_once("../lib/$config[general_lib_type]/group_info.php");
|
|
|
298 |
if (isset($existing_groups)){
|
|
|
299 |
echo "<select name=\"groupe\">";
|
|
|
300 |
echo "<option value=\"\" selected>";
|
|
|
301 |
foreach ($member_groups as $group)
|
|
|
302 |
echo "<option value=\"$group\">$group\n";
|
|
|
303 |
echo " </select>";
|
|
|
304 |
}
|
|
|
305 |
else echo "$l_group_empty";
|
|
|
306 |
echo "<br>";
|
|
|
307 |
echo "<input type='hidden' name='choix' value='csv'>";
|
|
|
308 |
if (($choix == "csv") && isset($result)) echo "<b>".$result."</b><BR>";
|
|
|
309 |
echo "<input type=\"submit\" value=\"$l_send\">";
|
|
|
310 |
echo "</FORM></td>";
|
|
|
311 |
echo "<td>";
|
|
|
312 |
$ImportFileList = getImportFileList();
|
|
|
313 |
if (count($ImportFileList) > 0){
|
|
|
314 |
echo "$l_imported_files";
|
|
|
315 |
echo "<ul>";
|
|
|
316 |
foreach ( $ImportFileList as $ImportFile ) //on parcours le tableau
|
|
|
317 |
{
|
|
|
318 |
echo "<li>".$ImportFile." ( <a href=\"import_file.php?file=$ImportFile\">txt</a> - <a href=\"import_file.php?file=$ImportFile&format=pdf\">pdf</a> )</li>";
|
|
|
319 |
}
|
|
|
320 |
echo "</ul>";
|
|
|
321 |
} else {
|
|
|
322 |
echo "<br>";
|
|
|
323 |
}
|
|
|
324 |
echo "</td></tr></table>";
|
|
|
325 |
echo "<tr><td valign=\"middle\" align=\"left\">";
|
|
|
326 |
echo "<H3><CENTER>$l_db_import</CENTER></H3>";
|
|
|
327 |
echo "$l_db_import_help <br><br>";
|
|
|
328 |
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST ENCTYPE=\"multipart/form-data\">";
|
1583 |
richard |
329 |
echo "$l_file (.sql or .sql.gz) : <input type=\"file\" name=\"import-users\"><br>";
|
1300 |
richard |
330 |
echo "<input type='hidden' name='choix' value='bdd'>";
|
|
|
331 |
if (($choix == "bdd") && isset($result)) echo "<b>".$result."</b><BR>";
|
|
|
332 |
echo "<input type=\"submit\" value=\"$l_send\">";
|
|
|
333 |
echo "</FORM>";
|
|
|
334 |
echo "</td></tr>";
|
|
|
335 |
echo "<tr><td valign=\"middle\" align=\"left\">";
|
|
|
336 |
echo "<H3><CENTER>$l_db_reset</CENTER></H3>";
|
|
|
337 |
echo "$l_db_import_help<br><br>";
|
1835 |
raphael.pi |
338 |
echo "<FORM onsubmit=\"return confirm('$l_empty_warn');\" action='$_SERVER[PHP_SELF]' method=POST>";
|
1300 |
richard |
339 |
echo "<input type='hidden' name='choix' value='raz'>";
|
1583 |
richard |
340 |
echo "<input type=\"submit\" value=\"$l_empty\">";
|
1300 |
richard |
341 |
echo "</FORM>";
|
|
|
342 |
echo "</TD></TR></TABLE>";
|
|
|
343 |
?>
|
|
|
344 |
</BODY>
|
|
|
345 |
</HTML>
|