Subversion Repositories ALCASAR

Rev

Rev 955 | Rev 971 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
528 stephane 1
<?php
958 franck 2
# $Id: status.php 958 2012-07-19 09:01:30Z franck $
528 stephane 3
#
4
# status.php for Alcasar captive portal
847 richard 5
# by steweb57 & Rexy
528 stephane 6
# 
847 richard 7
/****************************************************************
8
*			GLOBAL FILE PATHS			*
9
*****************************************************************/
10
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
11
 
12
/****************************************************************
13
*				FILE TEST			*
14
*****************************************************************/
15
//Test de présence et des droits en lecture des fichiers de configuration.
16
if (!file_exists(CONF_FILE)){
17
	exit("Fichier de configuration ".CONF_FILE." non présent");
18
}
19
if (!is_readable(CONF_FILE)){
20
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
21
}
22
 
23
/****************************************************************
24
*			Read CONF_FILE				*
25
*****************************************************************/
26
$ouvre=fopen(CONF_FILE,"r");
27
if ($ouvre){
28
	while (!feof ($ouvre))
29
	{
30
		$tampon = fgets($ouvre, 4096);
31
		if (strpos($tampon,"=")!==false){
32
			$tmp = explode("=",$tampon);
33
			$conf[$tmp[0]] = $tmp[1];
34
		}
35
	}
36
}else{
37
	exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
38
}
39
fclose($ouvre);
40
 
41
$organisme = $conf["ORGANISM"];
42
 
725 stephane 43
$remote_ip = ($_SERVER['REMOTE_ADDR']);
44
$connection_history =  "";
45
$nb_connection_history = 3;
528 stephane 46
 
725 stephane 47
//On récupère le nom de connexion de la session active. //on a l'info en ajax, mais trop tard -> A MODIFIER
48
exec ("sudo /usr/sbin/chilli_query list|grep $remote_ip" , $tab);
49
$user = explode (" ", $tab[0]);
50
 
51
#### Affichage des 3 dernières connexions de $user[5]
52
function secondsToDuration($seconds = null){
53
	if ($seconds == null) return "";
54
 
55
	$temp = $seconds % 3600;
56
	$time[0] = ( $seconds - $temp ) / 3600 ;	// hours
732 richard 57
	$time[2] = $temp % 60 ;				// seconds
725 stephane 58
	$time[1] = ( $temp - $time[2] ) / 60;		// minutes
59
 
732 richard 60
	return $time[0]." h ".$time[1]." m ".$time[2]." s";
725 stephane 61
}
62
 
63
 
64
 
528 stephane 65
# Choice of language
66
//reste quelques traductions à faire
67
$Language = 'en';
68
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
69
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
70
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
71
if($Language == 'es'){
734 richard 72
	$l_login1			= "El éxito de la autenticación";
528 stephane 73
	$l_logout			= "Conexión de cierre";
955 richard 74
	$l_logout_question		= "Are you sure you want to disconnect now?";	//à traduire
75
	$l_loggedout			= "Su sesión se cierra";
528 stephane 76
	$l_wait				= "Por favor, espere un momento ...";
955 richard 77
	$l_state_label			= "State";		//à traduire
78
	$l_session_id_label		= "Session ID";	//à traduire
528 stephane 79
	$l_max_session_time_label	= "Max Session Time";	//à traduire
80
	$l_max_idle_time_label		= "Max Idle Time";		//à traduire
955 richard 81
	$l_start_time_label		= "Start Time";	//à traduire
528 stephane 82
	$l_session_time_label		= "Tiempo de conexión";
955 richard 83
	$l_idle_time_label		= "Idle Time";	//à traduire
84
	$l_downloaded_label		= "Downloaded";	//à traduire
85
	$l_uploaded_label		= "Uploaded";	//à traduire
528 stephane 86
	$l_original_url_label		= "Original URL";	//à traduire
955 richard 87
	$l_not_available		= "Not available";	//à traduire
88
	$l_na				= "N/A";		//à traduire
89
	$l_error			= "error";		//à traduire
90
	$l_welcome			= "Welcome";	//à traduire
91
	$l_conn_history			= "Your last $nb_connection_history connections";	//à traduire
737 franck 92
	$l_connected 			= "logged"; //à traduire
93
	$l_a_connection			= "Active connection detected on LAN"; //à traduire
94
	$l_a_connection_time		= "time(s)"; //à traduire
528 stephane 95
}
912 richard 96
else if ($Language == 'pt'){
97
	$l_login1			= "Autenticação bem sucedida.";
98
	$l_logout			= "Fechando a conexão";
955 richard 99
	$l_logout_question		= "Tem certeza de que deseja desconectar agora?";
100
	$l_loggedout			= "Sua conexão foi fechada";
912 richard 101
	$l_wait				= "Por favor, aguarde um momento ...";
955 richard 102
	$l_state_label			= "Estado";
103
	$l_session_id_label		= "Sessão ID";
104
	$l_max_session_time_label	= "Restante de horas mensais da conexão";
105
	$l_max_idle_time_label		= "Hora máxima liberada por dia";
106
	$l_start_time_label		= "Hora, dia, mês e ano da conexão";
107
	$l_session_time_label		= "Duração da conexão";
108
	$l_idle_time_label		= "Tempo de Espera";
109
	$l_downloaded_label		= "Bits Recebidos";
110
	$l_uploaded_label		= "Bits Enviados";
912 richard 111
	$l_original_url_label		= "URL Original";
955 richard 112
	$l_not_available		= "Não disponível";
113
	$l_na				= "N/A";
114
	$l_error			= "Erro";
115
	$l_welcome			= "Bem vindo";
116
	$l_conn_history			= "Suas últimos $nb_connection_history conexões";
117
	$l_connected 			= "Conectado"; 
912 richard 118
	$l_a_connection			= "Conexão ativa detectada na LAN";
119
	$l_a_connection_time		= "Tempo (s)";
120
}
528 stephane 121
else if($Language == 'de'){
734 richard 122
	$l_login1			= "Erfolgreiche Authentifizierung";
528 stephane 123
	$l_logout			= "Beenden der Verbindung";
124
	$l_logout_question	= "Are you sure you want to disconnect now?";	//à traduire
125
	$l_loggedout		= "Ihre Sitzung ist geschlossen";
126
	$l_wait				= "Bitte warten Sie einen Moment ...";
127
	$l_state_label				= "State";		//à traduire
128
	$l_session_id_label			= "Session ID";	//à traduire
129
	$l_max_session_time_label	= "Max Session Time";	//à traduire
130
	$l_max_idle_time_label		= "Max Idle Time";		//à traduire
131
	$l_start_time_label			= "Start Time";	//à traduire
132
	$l_session_time_label		= "Online-zeit";
133
	$l_idle_time_label			= "Idle Time";	//à traduire
134
	$l_downloaded_label			= "Downloaded";	//à traduire
135
	$l_uploaded_label			= "Uploaded";	//à traduire
136
	$l_original_url_label		= "Original URL";	//à traduire
137
	$l_not_available			= "Not available";	//à traduire
138
	$l_na						= "N/A";		//à traduire
139
	$l_error					= "error";		//à traduire
140
	$l_welcome					= "Welcome"; 	//à traduire
734 richard 141
	$l_conn_history				= "Your last $nb_connection_history connections";	//à traduire
142
	$l_connected 			= "logged"; //à traduire 
737 franck 143
	$l_a_connection			= "Active connection detected on LAN"; //à traduire
144
	$l_a_connection_time		= "time(s)"; //à traduire
528 stephane 145
}
146
else if($Language == 'nl'){
734 richard 147
	$l_login1			= "Succesvolle authenticatie";
528 stephane 148
	$l_logout			= "Slotkoers verbinding";
149
	$l_logout_question	= "Are you sure you want to disconnect now?";	//à traduire
150
	$l_loggedout		= "Uw sessie is gesloten";
151
	$l_wait				= "Wacht een moment ...";
152
	$l_state_label				= "State";		//à traduire
153
	$l_session_id_label			= "Session ID";	//à traduire
154
	$l_max_session_time_label	= "Max Session Time";	//à traduire
155
	$l_max_idle_time_label		= "Max Idle Time";		//à traduire
156
	$l_start_time_label			= "Start Time";	//à traduire
157
	$l_session_time_label		= "Online tijd";
158
	$l_idle_time_label			= "Idle Time";	//à traduire
159
	$l_downloaded_label			= "Downloaded";	//à traduire
160
	$l_uploaded_label			= "Uploaded";	//à traduire
161
	$l_original_url_label		= "Original URL";	//à traduire
162
	$l_not_available			= "Not available";	//à traduire
163
	$l_na						= "N/A";		//à traduire
164
	$l_error					= "error";		//à traduire
165
	$l_welcome					= "Welcome";	//à traduire
734 richard 166
	$l_conn_history				= "Your last $nb_connection_history connections";	//à traduire
167
	$l_connected 			= "logged"; //à traduire 
737 franck 168
	$l_a_connection			= "Active connection detected on LAN"; //à traduire
169
	$l_a_connection_time		= "time(s)"; //à traduire
528 stephane 170
}
171
else if($Language == 'fr'){
734 richard 172
	$l_login1			= "Authentification r&eacute;ussie";
528 stephane 173
	$l_logout			= "Fermeture de la session";
536 franck 174
	$l_logout_question	= "Etes vous sûr de vouloir vous déconnecter?";
528 stephane 175
	$l_loggedout		= "Votre session est fermée";
176
	$l_wait				= "Patientez un instant ....";
177
	$l_state_label				= "Etat";
178
	$l_session_id_label			= "Session ID";
179
	$l_max_session_time_label	= "Temps de connexion autoris&eacute";
180
	$l_max_idle_time_label		= "Inactivit&eacute; max. autoris&eacute;e";
181
	$l_start_time_label			= "D&eacute;but de connexion";
182
	$l_session_time_label		= "Dur&eacute;e de connexion";
183
	$l_idle_time_label			= "Inactivit&eacute;";
184
	$l_downloaded_label			= "Donn&eacute;es t&eacute;l&eacute;charg&eacute;es";
185
	$l_uploaded_label			= "Donn&eacute;es envoy&eacute;es";
536 franck 186
	$l_original_url_label		= "URL demand&eacute;e";
528 stephane 187
	$l_not_available			= "Non disponible";
188
	$l_na						= "N/D";	//à traduire
189
	$l_error					= "erreur";
190
	$l_welcome					= "Bienvenue";
734 richard 191
	$l_conn_history				= "Vos $nb_connection_history derni&egrave;res connexions";
737 franck 192
	$l_connected 			= "session active";  
193
	$l_a_connection			= "Vous &ecirc;tes d&eacute;j&agrave; connect&eacute; sur le r&eacute;seau";
194
	$l_a_connection_time		= "fois";
528 stephane 195
}
196
else {
197
	$l_login1			= "Successful authentication.";
198
	$l_logout			= "Closing connection";
199
	$l_logout_question	= "Are you sure you want to disconnect now?";
200
	$l_loggedout		= "Your session is closed";
201
	$l_wait				= "Please wait a moment ...";
202
	$l_state_label				= "State";
203
	$l_session_id_label			= "Session ID";
204
	$l_max_session_time_label	= "Max Session Time";
205
	$l_max_idle_time_label		= "Max Idle Time";
206
	$l_start_time_label			= "Start Time";
207
	$l_session_time_label		= "Session Time";
208
	$l_idle_time_label			= "Idle Time";
209
	$l_downloaded_label			= "Downloaded";
210
	$l_uploaded_label			= "Uploaded";
211
	$l_original_url_label		= "Original URL";
212
	$l_not_available			= "Not available";
213
	$l_na						= "N/A";
214
	$l_error					= "error";
215
	$l_welcome					= "Welcome";
734 richard 216
	$l_conn_history				= "Your last $nb_connection_history connections";
217
	$l_connected 			= "logged"; 
737 franck 218
	$l_a_connection			= "Active connection detected on LAN";
219
	$l_a_connection_time		= "time(s)";
528 stephane 220
}
734 richard 221
 
222
// si on a pas d'accès à la bdd, la page s'affiche quand même correctement
223
if (isset($user[5])){
224
	if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
225
		include_once("/etc/freeradius-web/config.php");
226
		include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
227
 
228
		$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
229
		$link = @da_sql_pconnect($config); // on affiche pas les erreurs
230
 
231
		if ($link){
232
			$res = @da_sql_query($link,$config,$sql); // on affiche pas les erreurs
233
 
234
			if ($res){
235
				$connection_history.= "<ul>";
236
				while(($row = @da_sql_fetch_array($res,$config))){
237
					$connected = "";
872 richard 238
					$start_conn = date_create($row['acctstarttime']);
737 franck 239
					$connection_history.="<li>".date_format($start_conn, 'd M Y - H:i:s')." - (";
872 richard 240
					if ($row['acctstoptime'] == "") {
737 franck 241
						$connected = $l_connected;
242
					}else{
872 richard 243
						$connected = secondsToDuration($row['acctsessiontime']);
737 franck 244
					}
245
					$connection_history.= "$connected)</li>";
246
//					$connection_history.="<li>".date_format($start_conn, 'd M Y - H:i:s')." - (".secondsToDuration($row[acctsessiontime]).") $connected</li>";
734 richard 247
				}
248
				$connection_history.="</ul>";
249
			}
250
		}
737 franck 251
		$sql_2 = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' AND AcctStopTime IS NULL ORDER BY AcctStartTime DESC";
252
		$link_2 = @da_sql_pconnect($config); // on affiche pas les erreurs
253
 
254
		if ($link_2){
255
			$res_2 = @da_sql_query($link_2,$config,$sql_2); // on affiche pas les erreurs
256
			$a_connection = "";
257
			if ($res_2){
258
				while(($row_2 = @da_sql_fetch_array($res_2,$config))){
259
					$a_connected = 1;
872 richard 260
					if ($row_2['acctstoptime'] == "") $a_connected = $a_connected + 1;
737 franck 261
				}
262
				if ($a_connected > 1){
263
					$a_connection = $l_a_connection." ".$a_connected." ".$l_a_connection_time;
264
				}
265
			}
266
		}
734 richard 267
	}
268
}
528 stephane 269
?>
270
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
271
<html lang="fr">
272
<!-- written by steweb57 -->
734 richard 273
	<head>
274
		<title>Alcasar - <?php echo $organisme; ?></title>
275
		<meta http-equiv="Cache-control" content="no-cache">
276
		<meta http-equiv="Pragma" content="no-cache">
277
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
278
		<script type="text/javascript" src="./js/ChilliLibrary.js"></script>
279
		<script type="text/javascript" src="./js/statusControler.js"></script>
280
		<link type="text/css" href="./css/status.css" rel="stylesheet">
281
	</head>
282
	<body>
283
		<div id="Chilli">
284
		<div id="locationName"></div>
285
		<div id="chilliPage">
286
		<div id="loggedOutPage" class="c1">
287
			<table id="disconnectTable">
288
				<tr>
289
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
290
					<td><p class="text_auth"><?php echo $l_loggedout; ?></p></td>
291
				</tr>
292
			</table>
293
		</div>
294
		<div id="statusPage" class="c1">
295
			<table border="0" id="statusTable">
296
				<tr>
737 franck 297
					<td colspan="2">
298
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
299
							<tr>
300
								<td valign="top" rowspan="4">
301
									<img height="150" src="./images/logo-alcasar.png" alt="logo">
302
								</td>
303
								<td class="text_auth_welcom">
304
									<?php echo $l_login1; ?>
305
								</td>
306
							</tr>
307
							<tr>
308
								<td class="text_auth">
309
									<?php echo $l_welcome; ?>
310
									<br><span id="userName"></span>
311
								</td>
312
							</tr>
313
							<tr>
314
								<td class="alert">
315
									<?php echo $a_connection; ?>
316
								</td>
317
							</tr>
318
							<tr>
319
								<td colspan="2" align="center" class="link_logout">
320
									<a href="#" onclick="return logoutWithConfirmation('<?php echo $l_logout_question;?>');" class="lien_deco"><?php echo $l_logout; ?></a>
321
								</td>
322
							</tr>
323
						</table>
734 richard 324
					</td>
325
				</tr>
528 stephane 326
<!--tr id="connectRow">
327
<td id="statusMessageLabel" class="chilliLabel"><strong><?php echo $l_state_label; ?></strong></td>
328
<td id="statusMessage" class="chilliValue">Connected</td>
329
</tr-->
330
<!--tr id="sessionIdRow">
331
<td id="sessionIdLabel" class="chilliLabel"><strong><?php echo $l_session_id_label; ?></strong></td>
332
<td id="sessionId" class="chilliValue"><?php echo $l_not_available; ?></td>
333
</tr-->
734 richard 334
				<tr id="sessionTimeoutRow">
335
					<td id="sessionTimeoutLabel" class="chilliLabel"><?php echo $l_max_session_time_label; ?></td>
336
					<td id="sessionTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
337
				</tr>
338
				<tr id="idleTimeoutRow">
339
					<td id="idleTimeoutLabel" class="chilliLabel"><?php echo $l_max_idle_time_label; ?></td>
340
					<td id="idleTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
341
				</tr>
342
				<tr id="startTimeRow">
343
					<td id="startTimeLabel" class="chilliLabel"><?php echo $l_start_time_label; ?></td>
344
					<td id="startTime" class="chilliValue"><?php echo $l_not_available; ?></td>
345
				</tr>
346
				<tr id="sessionTimeRow">
347
					<td id="sessionTimeLabel" class="chilliLabel"><?php echo $l_session_time_label; ?></td>
348
					<td id="sessionTime" class="chilliValue"><?php echo $l_not_available; ?></td>
349
				</tr>
350
				<tr id="idleTimeRow">
351
					<td id="idleTimeLabel" class="chilliLabel"><?php echo $l_idle_time_label; ?></td>
352
					<td id="idleTime" class="chilliValue"><?php echo $l_not_available; ?></td>
353
				</tr>
354
				<tr id="inputOctetsRow">
355
					<td id="inputOctetsLabel" class="chilliLabel"><?php echo $l_downloaded_label; ?></td>
356
					<td id="inputOctets" class="chilliValue"><?php echo $l_na; ?></td>
357
				</tr>
358
				<tr id="outputOctetsRow">
359
					<td id="outputOctetsLabel" class="chilliLabel"><?php echo $l_uploaded_label; ?></td>
360
					<td id="outputOctets" class="chilliValue"><?php echo $l_na; ?></td>
361
				</tr>
725 stephane 362
<!--tr id="originalURLRow">
734 richard 363
<td id="originalURLLabel" class="chilliLabel"><?php echo $l_original_url_label; ?></td>
528 stephane 364
<td id="originalURL" class="chilliValue"><?php echo $l_na; ?></td>
725 stephane 365
</tr-->
734 richard 366
				<tr>
367
					<td colspan=2 id="conHistoryLabel" class="chilliLabel"><?php echo $l_conn_history; ?></td>
368
				</tr>
369
				<tr id="conHistoryRow">
370
					<td colspan=2 id="conHistory" class="chilliValue"><?php echo $connection_history; ?></td>
371
				</tr>
372
			</table>
373
		</div>
374
		<div id="waitPage">
375
			<table id="waitTable">
376
				<tr>
377
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
378
					<td><p class="text_auth"><img src="./images/wait.gif" width="16" height="16" class="wait" alt="<?php echo $l_wait; ?>"><?php echo $l_wait; ?></p></td>
379
				</tr>
380
			</table>
381
		</div>
382
		<div id="errorPage">
383
			<table id="errorTable">
384
				<tr>
385
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
386
					<td><span id="errorMessage"><?php echo $l_error; ?></span></td>
387
				</tr>
388
			</table>
389
		</div>
390
		</div>
528 stephane 391
<!--div id="debugPage" style="display:inline;">
392
<textarea id="debugarea" rows="20" cols="60">
393
</textarea>
734 richard 394
</div-->
395
		</div>
396
	</body>
528 stephane 397
</html>