Subversion Repositories ALCASAR

Rev

Rev 1502 | Rev 1561 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1502 Rev 1508
Line 5... Line 5...
5
<TITLE>Users import</TITLE>
5
<TITLE>Users import</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
7
</HEAD>
8
<body>
8
<body>
9
<?php
9
<?php
10
# Choice of language
10
// Choice of language
11
$Language = 'en';
11
$Language = 'en';
12
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
12
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
13
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
13
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
14
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
14
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
15
if($Language == 'fr'){
15
if($Language == 'fr'){
Line 72... Line 72...
72
	}
72
	}
73
	return $importFile;
73
	return $importFile;
74
}
74
}
75
function GenPassword($nb_car="8")
75
function GenPassword($nb_car="8")
76
	{
76
	{
77
 /* generation aléatoire du mot de passe */
77
// Random password
78
	$password = "";
78
	$password = "";
79
	$chaine  = "aAzZeErRtTyYuUIopP152346897mMLkK";
79
	$chaine  = "aAzZeErRtTyYuUIopP152346897mMLkK";
80
	$chaine .= "jJhHgGfFdDsSqQwWxXcCvVbBnN152346897";
80
	$chaine .= "jJhHgGfFdDsSqQwWxXcCvVbBnN152346897";
81
	while($nb_car != 0)
81
	while($nb_car != 0)
82
		{
82
		{
Line 120... Line 120...
120
	else { $choix = ''; }
120
	else { $choix = ''; }
121
if ($choix == "raz")
121
if ($choix == "raz")
122
	{
122
	{
123
	exec ("sudo /usr/local/sbin/alcasar-mysql.sh --raz");
123
	exec ("sudo /usr/local/sbin/alcasar-mysql.sh --raz");
124
	}
124
	}
125
# un fichier est importé
125
// a file is downloaded
126
if(isset($_FILES['import-users']) && ($_FILES['import-users']['name'] !=""))
126
if(isset($_FILES['import-users']) && ($_FILES['import-users']['name'] !=""))
127
	{
127
	{
128
	unset($result);
128
	unset($result);
129
	if (isset ($_POST['service'])) $service = $_POST['service'];
129
	if (isset ($_POST['service'])) $service = $_POST['service'];
130
	if (isset ($_POST['groupe'])) $group = $_POST ['groupe'];
130
	if (isset ($_POST['groupe'])) $group = $_POST ['groupe'];
131
	$destination = '/tmp/import_file.txt';
131
	$destination = '/tmp/import_file.txt';
132
	list($file_name , $extension) = explode("." , $_FILES['import-users']['name']); 
132
	list($file_name , $extension) = explode("." , $_FILES['import-users']['name']); 
133
	$extension = strstr($_FILES['import-users']['name'], '.');
133
	echo "choix = ".$choix.", service = ".$service.", groupe = ".$group.", file_name = ".$file_name.", extension = ".$extension;
134
	if ($choix == "csv")
134
	if ($choix == "csv") // import of a txt file
135
//import d'un fichier txt
-
 
136
		{
135
		{
137
		if (($extension != '.csv') && ($extension != '.txt')) $result = $l_error_ext_txt;
136
		if (($extension != 'csv') && ($extension != 'txt')) $result = $l_error_ext_txt;
138
		else 
137
		else 
139
			{
138
			{
140
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --dump");
139
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --dump");
141
			move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
140
			move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
142
			$RS_in   = file ($destination);
141
			$RS_in   = file ($destination);
Line 165... Line 164...
165
								$password = GenPassword();
164
								$password = GenPassword();
166
								}	
165
								}	
167
							$login = da_sql_escape_string($login);
166
							$login = da_sql_escape_string($login);
168
							$passwd = da_sql_escape_string($passwd);
167
							$passwd = da_sql_escape_string($passwd);
169
							$passwd = da_encrypt($password);
168
							$passwd = da_encrypt($password);
170
/* insertion (login + password) dans la table "radcheck" (si l'usager existe --> changement de mot de passe) */
169
// insertion (login + password) dans la table "radcheck" (si l'usager existe --> changement de mot de passe)
171
							$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);");
170
							$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);");
172
							if (!$res || !@da_sql_affected_rows($link,$res,$config))
171
							if (!$res || !@da_sql_affected_rows($link,$res,$config))
173
								{
172
								{
174
								echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
173
								echo "<b>Unable to add user $login: " . da_sql_error($link,$config) . "</b><br>\n";
175
								$da_abort=1;
174
								$da_abort=1;
176
								}
175
								}
177
							else
176
							else
178
								{
177
								{
179
/* create the user informations file */
178
// create the user informations file
180
								fputs($RS_out,"$l_out_title\r\n\r\n");
179
								fputs($RS_out,"$l_out_title\r\n\r\n");
181
								if ($service != "" ) { fputs($RS_out,"Service          : $service\r\n\r\n");}
180
								if ($service != "" ) { fputs($RS_out,"Service          : $service\r\n\r\n");}
182
								fputs($RS_out,"$l_out_login $login   |   $l_out_passwd $password\r\n\r\n");
181
								fputs($RS_out,"$l_out_login $login   |   $l_out_passwd $password\r\n\r\n");
183
								fputs($RS_out,"$l_out_mind\r\n\r\n");
182
								fputs($RS_out,"$l_out_mind\r\n\r\n");
184
								fputs($RS_out,"--------------------------------------------------------------------------------\r\n\r\n");
183
								fputs($RS_out,"--------------------------------------------------------------------------------\r\n\r\n");
185
								}	
184
								}	
186
/* insertion de l'usager dans la table "userinfo" */
185
// insertion de l'usager dans la table "userinfo"
187
							if ($config[sql_use_user_info_table] == 'true' && !$da_abort)
186
							if ($config[sql_use_user_info_table] == 'true' && !$da_abort)
188
								{
187
								{
189
							$res = @da_sql_query($link,$config, "SELECT username FROM $config[sql_user_info_table] WHERE username = '$login';");
188
							$res = @da_sql_query($link,$config, "SELECT username FROM $config[sql_user_info_table] WHERE username = '$login';");
190
							if ($res)
189
							if ($res)
191
								{
190
								{
Line 215... Line 214...
215
										else
214
										else
216
											echo "<b>User already is a member of group $group</b><br>\n";
215
											echo "<b>User already is a member of group $group</b><br>\n";
217
										} # end if
216
										} # end if
218
									else
217
									else
219
										echo "<b>Could not add user to group $group: " . da_sql_error($link,$config) . "</b><br>\n";
218
										echo "<b>Could not add user to group $group: " . da_sql_error($link,$config) . "</b><br>\n";
220
									} # end if ($group)
219
									} // end if ($group)
221
						 		} # end if ($config)		
220
						 		} // end if ($config)		
222
							} # end if ($login !='')
221
							} // end if ($login !='')
223
						} # end foreach
222
						} // end foreach
224
					fclose($RS_out);
223
					fclose($RS_out);
225
					} # end if (is file)
224
					} // end if (is file)
226
				} # end if (link)
225
				} // end if (link)
227
			}
226
			}
228
		}
227
		}
229
	else if ($choix == "bdd")
228
	else if ($choix == "bdd") // database import
230
//import d'une Bdd
-
 
231
		{
229
		{
232
		if ($extension != '.sql') $result = $l_error_ext_sql;
230
		if ($extension != 'sql') $result = $l_error_ext_sql;
233
		else 
231
		else 
234
			{
232
			{
235
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --dump");
233
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --dump");
236
			move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
234
			move_uploaded_file($_FILES['import-users']['tmp_name'], $destination);
237
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --import $destination");
235
			exec ("sudo /usr/local/sbin/alcasar-mysql.sh --import $destination");
-
 
236
			echo "OK : $destination";
238
			}
237
			}
239
		}
238
		}
240
	}
239
	}
241
if ($link)
240
if ($link)
242
	{
241
	{