Subversion Repositories ALCASAR

Rev

Rev 2097 | Rev 2134 | 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 2108 2017-01-06 08:50:25Z richard $
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{
1030 stephane 37
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
847 richard 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
 
1026 richard 47
//On récupère le nom de connexion de la session active. on attend que chilli ait mis à jour ses tables
48
sleep (1);
49
exec ("sudo /usr/sbin/chilli_query list | grep 'pass' | grep -Ew '($remote_ip)'" , $tab);
1878 raphael.pi 50
if(isset($tab[0]))
725 stephane 51
$user = explode (" ", $tab[0]);
52
 
53
#### Affichage des 3 dernières connexions de $user[5]
54
function secondsToDuration($seconds = null){
55
	if ($seconds == null) return "";
56
 
57
	$temp = $seconds % 3600;
58
	$time[0] = ( $seconds - $temp ) / 3600 ;	// hours
732 richard 59
	$time[2] = $temp % 60 ;				// seconds
725 stephane 60
	$time[1] = ( $temp - $time[2] ) / 60;		// minutes
61
 
732 richard 62
	return $time[0]." h ".$time[1]." m ".$time[2]." s";
725 stephane 63
}
64
 
65
 
66
 
528 stephane 67
# Choice of language
68
//reste quelques traductions à faire
69
$Language = 'en';
70
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
71
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
72
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
73
if($Language == 'es'){
734 richard 74
	$l_login1			= "El éxito de la autenticación";
528 stephane 75
	$l_logout			= "Conexión de cierre";
2066 richard 76
	$l_logout_question		= "¿Seguro que desea desconectar?";
955 richard 77
	$l_loggedout			= "Su sesión se cierra";
528 stephane 78
	$l_wait				= "Por favor, espere un momento ...";
2066 richard 79
	$l_state_label			= "Estado";
80
	$l_session_id_label		= "Sesión ID";
81
	$l_max_session_time_label	= "Tiempo máximo de sesión";
82
	$l_max_idle_time_label		= "Tiempo de inactividad autorizado";
2064 richard 83
	$l_start_time_label		= "Start Time";	// to translate
528 stephane 84
	$l_session_time_label		= "Tiempo de conexión";
2064 richard 85
	$l_idle_time_label		= "Idle Time";	// to translate
86
	$l_downloaded_label		= "Downloaded";	// to translate
87
	$l_uploaded_label		= "Uploaded";	// to translate
88
	$l_original_url_label		= "Original URL";	// to translate
89
	$l_not_available		= "Not available";	// to translate
90
	$l_error			= "error";		// to translate
91
	$l_welcome			= "Welcome";	// to translate
92
	$l_conn_history			= "Your last $nb_connection_history connections";	// to translate
93
	$l_connected 			= "logged"; // to translate
94
	$l_a_connection			= "You have"; // to translate
95
	$l_a_connection_time		= "active connections on the network"; // to translate
528 stephane 96
}
2086 richard 97
else if ($Language == 'zh'){
2066 richard 98
	$l_login1			= "验证通过";
99
	$l_logout			= "关闭连接";
100
	$l_logout_question		= "您确定需要断开连接吗?";
101
	$l_loggedout			= "您已登出";
102
	$l_wait				= "请等待 ...";
103
	$l_state_label			= "连接状态";
104
	$l_session_id_label		= "连接ID";
105
	$l_max_session_time_label	= "最大连接时间";
106
	$l_max_idle_time_label		= "最大闲置时间";
107
	$l_start_time_label		= "起始连接时间";
108
	$l_session_time_label		= "连接时间";
109
	$l_idle_time_label		= "闲置时间";
110
	$l_downloaded_label		= "数据下载";
111
	$l_uploaded_label		= "数据上传";
112
	$l_original_url_label		= "初始网址";
113
	$l_not_available		= "不可用";
114
	$l_error			= "出错";
115
	$l_welcome			= "欢迎";
116
	$l_conn_history			= "您最近的$nb_connection_history次连接";
117
	$l_connected 			= "已登录";  
118
	$l_a_connection			= "您已经有";
119
	$l_a_connection_time		= "在线时间";
120
}
2086 richard 121
else if ($Language == 'ar'){
122
	$l_login1			= "نجاح المصادقة";
123
	$l_logout			= "إغلاق الدورة";
124
	$l_logout_question		= "هل تريد فعلاً قطع الاتصال؟";
125
	$l_loggedout			= "دورتكَ مُغلَقة";
126
	$l_wait				= "...إنتظر بعض اللحظات";
127
	$l_state_label			= "وَضْع";
128
	$l_session_id_label		= "معرف الدورة";
129
	$l_max_session_time_label	= "الوقت المسموح للإتصال";
130
	$l_max_idle_time_label		= "الحد الأقصى لعدم التنشيط";
131
	$l_start_time_label		= "بداية الإتصال";
132
	$l_session_time_label		= "مدة الإتصال";
133
	$l_idle_time_label		= "انعدام التنشيط";
134
	$l_downloaded_label		= "تم تحميل المعطيات";
135
	$l_uploaded_label		= "تم إرسال المعطيات";
136
	$l_original_url_label		= "تم طلب URL";
137
	$l_not_available		= "غير متوفّر";
138
	$l_na				= "N/D";
139
	$l_error			= "خطأ";
140
	$l_welcome			= "مرحباً بك";
141
	$l_conn_history			= "($nb_connection_history) سِجِل اتصالاتك الاخيرة";
142
	$l_connected 			= "دورة ناشطة";  
143
	$l_a_connection			= "لديك";
144
	$l_a_connection_time		= "اتصالات ناشطة على الشبكة";
145
}
912 richard 146
else if ($Language == 'pt'){
147
	$l_login1			= "Autenticação bem sucedida.";
148
	$l_logout			= "Fechando a conexão";
955 richard 149
	$l_logout_question		= "Tem certeza de que deseja desconectar agora?";
971 richard 150
	$l_loggedout			= "Sua conexão será fechada";
912 richard 151
	$l_wait				= "Por favor, aguarde um momento ...";
971 richard 152
	$l_state_label			= "Estado da conexão";
955 richard 153
	$l_session_id_label		= "Sessão ID";
971 richard 154
	$l_max_session_time_label	= "Restante em horas da conexão";
155
	$l_max_idle_time_label		= "Restante máximo liberado por dia";
156
	$l_start_time_label		= "Dia, mês, ano e hora da conexão";
955 richard 157
	$l_session_time_label		= "Duração da conexão";
158
	$l_idle_time_label		= "Tempo de Espera";
971 richard 159
	$l_downloaded_label		= "Recebidos";
160
	$l_uploaded_label		= "Enviados";
912 richard 161
	$l_original_url_label		= "URL Original";
955 richard 162
	$l_not_available		= "Não disponível";
163
	$l_error			= "Erro";
971 richard 164
	$l_welcome			= "Bem-vindo(a)";
165
	$l_conn_history			= "Suas últimos conexões : $nb_connection_history";
955 richard 166
	$l_connected 			= "Conectado"; 
971 richard 167
	$l_a_connection			= "Conexão ativa já detectada para essa LAN";
912 richard 168
	$l_a_connection_time		= "Tempo (s)";
169
}
2086 richard 170
else if ($Language == 'de'){
734 richard 171
	$l_login1			= "Erfolgreiche Authentifizierung";
528 stephane 172
	$l_logout			= "Beenden der Verbindung";
2074 richard 173
	$l_logout_question		= "Möchten Sie die Verbindung jetzt wirklich trennen?";
2064 richard 174
	$l_loggedout			= "Ihre Sitzung ist geschlossen";
528 stephane 175
	$l_wait				= "Bitte warten Sie einen Moment ...";
2064 richard 176
	$l_state_label			= "State";		// to translate
177
	$l_session_id_label		= "Session ID";	// to translate
178
	$l_max_session_time_label	= "Max Session Time";	// to translate
179
	$l_max_idle_time_label		= "Max Idle Time";		// to translate
180
	$l_start_time_label		= "Start Time";	// to translate
528 stephane 181
	$l_session_time_label		= "Online-zeit";
2064 richard 182
	$l_idle_time_label		= "Idle Time";	// to translate
183
	$l_downloaded_label		= "Downloaded";	// to translate
184
	$l_uploaded_label		= "Uploaded";	// to translate
185
	$l_original_url_label		= "Original URL";	// to translate
186
	$l_not_available		= "Not available";	// to translate
187
	$l_error			= "error";		// to translate
188
	$l_welcome			= "Welcome"; 	// to translate
189
	$l_conn_history			= "Your last $nb_connection_history connections";	// to translate
190
	$l_connected 			= "logged"; // to translate 
191
	$l_a_connection			= "You have"; // to translate
192
	$l_a_connection_time		= "active connections on the network"; // to translate
528 stephane 193
}
2086 richard 194
else if ($Language == 'nl'){
734 richard 195
	$l_login1			= "Succesvolle authenticatie";
528 stephane 196
	$l_logout			= "Slotkoers verbinding";
2073 richard 197
	$l_logout_question		= "Bent u zeker dat u wilt nu los te koppelen?";
2064 richard 198
	$l_loggedout			= "Uw sessie is gesloten";
528 stephane 199
	$l_wait				= "Wacht een moment ...";
2064 richard 200
	$l_state_label			= "State";		// to translate
201
	$l_session_id_label		= "Session ID";	// to translate
202
	$l_max_session_time_label	= "Max Session Time";	// to translate
203
	$l_max_idle_time_label		= "Max Idle Time";		// to translate
204
	$l_start_time_label		= "Start Time";	// to translate
528 stephane 205
	$l_session_time_label		= "Online tijd";
2064 richard 206
	$l_idle_time_label		= "Idle Time";	// to translate
207
	$l_downloaded_label		= "Downloaded";	// to translate
208
	$l_uploaded_label		= "Uploaded";	// to translate
209
	$l_original_url_label		= "Original URL";	// to translate
210
	$l_not_available		= "Not available";	// to translate
211
	$l_error			= "error";		// to translate
212
	$l_welcome			= "Welcome";	// to translate
213
	$l_conn_history			= "Your last $nb_connection_history connections";	// to translate
214
	$l_connected 			= "logged"; // to translate 
215
	$l_a_connection			= "You have"; // to translate
216
	$l_a_connection_time		= "active connections on the network"; // to translate
528 stephane 217
}
2086 richard 218
else if ($Language == 'fr'){
2064 richard 219
	$l_login1			= "Authentification réussie";
528 stephane 220
	$l_logout			= "Fermeture de la session";
2066 richard 221
	$l_logout_question		= "Êtes vous sûr de vouloir vous déconnecter?";
2064 richard 222
	$l_loggedout			= "Votre session est fermée";
528 stephane 223
	$l_wait				= "Patientez un instant ....";
2066 richard 224
	$l_state_label			= "État";
2064 richard 225
	$l_session_id_label		= "Session ID";
226
	$l_max_session_time_label	= "Temps de connexion autorisé";
2066 richard 227
	$l_max_idle_time_label		= "Temps d'inactivité autorisé";
2064 richard 228
	$l_start_time_label		= "Début de connexion";
229
	$l_session_time_label		= "Durée de connexion";
230
	$l_idle_time_label		= "Inactivité";
231
	$l_downloaded_label		= "Données téléchargées";
232
	$l_uploaded_label		= "Données envoyées";
233
	$l_original_url_label		= "URL demandée";
234
	$l_not_available		= "Non disponible";
235
	$l_error			= "erreur";
236
	$l_welcome			= "Bienvenue";
237
	$l_conn_history			= "Vos $nb_connection_history dernières connexions";
737 franck 238
	$l_connected 			= "session active";  
1708 richard 239
	$l_a_connection			= "Vous avez";
240
	$l_a_connection_time		= "connexions actives sur le réseau";
528 stephane 241
}
242
else {
243
	$l_login1			= "Successful authentication.";
244
	$l_logout			= "Closing connection";
2064 richard 245
	$l_logout_question		= "Are you sure you want to disconnect now?";
246
	$l_loggedout			= "Your session is closed";
528 stephane 247
	$l_wait				= "Please wait a moment ...";
2064 richard 248
	$l_state_label			= "State";
249
	$l_session_id_label		= "Session ID";
528 stephane 250
	$l_max_session_time_label	= "Max Session Time";
251
	$l_max_idle_time_label		= "Max Idle Time";
2064 richard 252
	$l_start_time_label		= "Start Time";
528 stephane 253
	$l_session_time_label		= "Session Time";
2064 richard 254
	$l_idle_time_label		= "Idle Time";
255
	$l_downloaded_label		= "Downloaded";
256
	$l_uploaded_label		= "Uploaded";
528 stephane 257
	$l_original_url_label		= "Original URL";
2064 richard 258
	$l_not_available		= "Not available";
259
	$l_error			= "error";
260
	$l_welcome			= "Welcome";
261
	$l_conn_history			= "Your last $nb_connection_history connections";
734 richard 262
	$l_connected 			= "logged"; 
2064 richard 263
	$l_a_connection			= "You have";
264
	$l_a_connection_time		= "active connections on the network";
528 stephane 265
}
734 richard 266
 
267
// si on a pas d'accès à la bdd, la page s'affiche quand même correctement
268
if (isset($user[5])){
269
	if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
270
		include_once("/etc/freeradius-web/config.php");
271
		include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
272
 
273
		$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
274
		$link = @da_sql_pconnect($config); // on affiche pas les erreurs
275
 
276
		if ($link){
277
			$res = @da_sql_query($link,$config,$sql); // on affiche pas les erreurs
278
 
279
			if ($res){
1026 richard 280
				$a_connection = ""; $a_connected=0; $connection_history.= "<ul>";
734 richard 281
				while(($row = @da_sql_fetch_array($res,$config))){
282
					$connected = "";
872 richard 283
					$start_conn = date_create($row['acctstarttime']);
737 franck 284
					$connection_history.="<li>".date_format($start_conn, 'd M Y - H:i:s')." - (";
872 richard 285
					if ($row['acctstoptime'] == "") {
737 franck 286
						$connected = $l_connected;
1026 richard 287
						$a_connected = $a_connected +1;
737 franck 288
					}else{
872 richard 289
						$connected = secondsToDuration($row['acctsessiontime']);
737 franck 290
					}
291
					$connection_history.= "$connected)</li>";
734 richard 292
				}
293
				$connection_history.="</ul>";
737 franck 294
				if ($a_connected > 1){
1026 richard 295
					$a_connection = $l_a_connection." ".$a_connected." ".$l_a_connection_time; }
737 franck 296
			}
297
		}
2013 raphael.pi 298
 
299
		//store in a file user @IP who can join this page.
2108 richard 300
		$filename='/var/tmp/havp/current_users.txt';
2013 raphael.pi 301
		//change me avoid duplicate user @IP
302
		$change_me = 1;
303
		//check if filename exists
304
		if(file_exists($filename)){
305
			$fichier = fopen($filename, "r");
306
			$content = file($filename);
307
 
308
			//if file is empty, we put user @IP in it.
309
			if(empty($content))
310
			{
311
				file_put_contents($filename, $_SERVER['REMOTE_ADDR']);
312
			}
313
			else
314
			{
315
				//if we found duplicate IP, it will not write user @IP in filename (set change_me = 0)
316
				foreach($content as $line){
317
				        $line = preg_replace('/\s+/', '', $line);
318
				        if($line == $_SERVER['REMOTE_ADDR'])
319
				        {
320
				                $change_me = 0;
321
				        }
322
 
323
				}
324
 
325
				//if user @IP does not exist, we will write it in filename
326
				if($change_me)
327
				{
328
				        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
329
				}
330
			}
331
 
332
		}
333
		else
334
		{
335
			//we create filename and we put user @IP in it.
336
			file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
337
		}
338
 
339
 
734 richard 340
	}
341
}
528 stephane 342
?>
343
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
344
<html lang="fr">
345
<!-- written by steweb57 -->
734 richard 346
	<head>
347
		<title>Alcasar - <?php echo $organisme; ?></title>
348
		<meta http-equiv="Cache-control" content="no-cache">
349
		<meta http-equiv="Pragma" content="no-cache">
350
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
351
		<script type="text/javascript" src="./js/ChilliLibrary.js"></script>
352
		<script type="text/javascript" src="./js/statusControler.js"></script>
353
		<link type="text/css" href="./css/status.css" rel="stylesheet">
354
	</head>
355
	<body>
356
		<div id="Chilli">
357
		<div id="locationName"></div>
358
		<div id="chilliPage">
359
		<div id="loggedOutPage" class="c1">
360
			<table id="disconnectTable">
361
				<tr>
362
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
363
					<td><p class="text_auth"><?php echo $l_loggedout; ?></p></td>
364
				</tr>
365
			</table>
366
		</div>
367
		<div id="statusPage" class="c1">
368
			<table border="0" id="statusTable">
369
				<tr>
737 franck 370
					<td colspan="2">
371
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
372
							<tr>
373
								<td valign="top" rowspan="4">
374
									<img height="150" src="./images/logo-alcasar.png" alt="logo">
375
								</td>
376
								<td class="text_auth_welcom">
377
									<?php echo $l_login1; ?>
378
								</td>
379
							</tr>
380
							<tr>
381
								<td class="text_auth">
382
									<?php echo $l_welcome; ?>
383
									<br><span id="userName"></span>
384
								</td>
385
							</tr>
386
							<tr>
387
								<td class="alert">
1878 raphael.pi 388
									<?php if(isset($a_connection))echo $a_connection; ?>
737 franck 389
								</td>
390
							</tr>
391
							<tr>
392
								<td colspan="2" align="center" class="link_logout">
393
									<a href="#" onclick="return logoutWithConfirmation('<?php echo $l_logout_question;?>');" class="lien_deco"><?php echo $l_logout; ?></a>
394
								</td>
395
							</tr>
396
						</table>
734 richard 397
					</td>
398
				</tr>
528 stephane 399
<!--tr id="connectRow">
400
<td id="statusMessageLabel" class="chilliLabel"><strong><?php echo $l_state_label; ?></strong></td>
401
<td id="statusMessage" class="chilliValue">Connected</td>
402
</tr-->
403
<!--tr id="sessionIdRow">
404
<td id="sessionIdLabel" class="chilliLabel"><strong><?php echo $l_session_id_label; ?></strong></td>
405
<td id="sessionId" class="chilliValue"><?php echo $l_not_available; ?></td>
406
</tr-->
734 richard 407
				<tr id="sessionTimeoutRow">
408
					<td id="sessionTimeoutLabel" class="chilliLabel"><?php echo $l_max_session_time_label; ?></td>
409
					<td id="sessionTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
410
				</tr>
411
				<tr id="idleTimeoutRow">
412
					<td id="idleTimeoutLabel" class="chilliLabel"><?php echo $l_max_idle_time_label; ?></td>
413
					<td id="idleTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
414
				</tr>
415
				<tr id="startTimeRow">
416
					<td id="startTimeLabel" class="chilliLabel"><?php echo $l_start_time_label; ?></td>
417
					<td id="startTime" class="chilliValue"><?php echo $l_not_available; ?></td>
418
				</tr>
419
				<tr id="sessionTimeRow">
420
					<td id="sessionTimeLabel" class="chilliLabel"><?php echo $l_session_time_label; ?></td>
421
					<td id="sessionTime" class="chilliValue"><?php echo $l_not_available; ?></td>
422
				</tr>
423
				<tr id="idleTimeRow">
424
					<td id="idleTimeLabel" class="chilliLabel"><?php echo $l_idle_time_label; ?></td>
425
					<td id="idleTime" class="chilliValue"><?php echo $l_not_available; ?></td>
426
				</tr>
427
				<tr id="inputOctetsRow">
428
					<td id="inputOctetsLabel" class="chilliLabel"><?php echo $l_downloaded_label; ?></td>
2073 richard 429
					<td id="inputOctets" class="chilliValue"><?php echo $l_not_available; ?></td>
734 richard 430
				</tr>
431
				<tr id="outputOctetsRow">
432
					<td id="outputOctetsLabel" class="chilliLabel"><?php echo $l_uploaded_label; ?></td>
2073 richard 433
					<td id="outputOctets" class="chilliValue"><?php echo $l_not_available; ?></td>
734 richard 434
				</tr>
725 stephane 435
<!--tr id="originalURLRow">
734 richard 436
<td id="originalURLLabel" class="chilliLabel"><?php echo $l_original_url_label; ?></td>
2073 richard 437
<td id="originalURL" class="chilliValue"><?php echo $l_not_available; ?></td>
725 stephane 438
</tr-->
734 richard 439
				<tr>
440
					<td colspan=2 id="conHistoryLabel" class="chilliLabel"><?php echo $l_conn_history; ?></td>
441
				</tr>
442
				<tr id="conHistoryRow">
443
					<td colspan=2 id="conHistory" class="chilliValue"><?php echo $connection_history; ?></td>
444
				</tr>
445
			</table>
446
		</div>
447
		<div id="waitPage">
448
			<table id="waitTable">
449
				<tr>
450
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
451
					<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>
452
				</tr>
453
			</table>
454
		</div>
455
		<div id="errorPage">
456
			<table id="errorTable">
457
				<tr>
458
					<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
459
					<td><span id="errorMessage"><?php echo $l_error; ?></span></td>
460
				</tr>
461
			</table>
462
		</div>
463
		</div>
528 stephane 464
<!--div id="debugPage" style="display:inline;">
465
<textarea id="debugarea" rows="20" cols="60">
466
</textarea>
734 richard 467
</div-->
468
		</div>
469
	</body>
2008 raphael.pi 470
 
2097 raphael.pi 471
 
528 stephane 472
</html>