Subversion Repositories ALCASAR

Rev

Rev 1286 | Rev 1295 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
452 richard 1
<?php
958 franck 2
# $Id: index.php 1287 2014-01-08 23:01:20Z richard $
1249 richard 3
#
1287 richard 4
# index.php for ALCASAR captive portal
1249 richard 5
# by REXY
6
# UI & css style by stephane ERARD
7
# The contents of this file may be used under the terms of the GNU
8
# General Public License Version 2, provided that the above copyright
9
# notice and this permission notice is included in all copies or
10
# substantial portions of the software.
11
/****************************************************************
12
*			GLOBAL FILE PATHS			*
13
*****************************************************************/
14
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
15
 
16
/****************************************************************
17
*			FILE reading test			*
18
*****************************************************************/
19
$conf_files=array(CONF_FILE);
20
foreach ($conf_files as $file){
21
	if (!file_exists($file)){
22
		exit("File ".$file." unknown");
23
	}
24
	if (!is_readable($file)){
25
		exit("You don't have read rights on the file ".$file);
26
	}
27
}
28
/****************************************************************
29
*			Read CONF_FILE				*
30
*****************************************************************/
31
$ouvre=fopen(CONF_FILE,"r");
32
if ($ouvre){
33
	while (!feof ($ouvre))
34
	{
35
		$tampon = fgets($ouvre, 4096);
36
		if (strpos($tampon,"=")!==false){
37
			$tmp = explode("=",$tampon);
38
			$conf[$tmp[0]] = $tmp[1];
39
		}
40
	}
41
}else{
42
	exit("Error opening the file ".CONF_FILE);
43
}
44
fclose($ouvre);
45
$hostname = alcasar.$conf["DOMAIN"];
784 richard 46
$network_pb = False;
1249 richard 47
$cert_add = "http://$hostname/certs";
360 richard 48
$direct_access = False;
832 richard 49
$diagnostic = "can't contact the default router";
363 richard 50
$remote_ip = ($_SERVER['REMOTE_ADDR']);
51
$tab = array();$user = array();
566 stephane 52
$connection_history =  "";
53
$nb_connection_history = 3;
54
 
522 richard 55
# on discrimine les accès directs sur Alcasar par rapport aux redirections (blacklist ou pannes rso)
783 richard 56
if (($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_ADDR']) || preg_match ("/^alcasar/", $_SERVER['HTTP_HOST']) || preg_match ("/^$hostname/", $_SERVER['HTTP_HOST']))
522 richard 57
	{
58
	$direct_access=True;
59
	exec ("sudo /usr/sbin/chilli_query list|grep $remote_ip" , $tab);
60
	$user = explode (" ", $tab[0]);
61
	}
566 stephane 62
#### Affichage des 3 dernières connexions de $user[5]
63
function secondsToDuration($seconds = null){
64
	if ($seconds == null) return "";
509 richard 65
 
566 stephane 66
	$temp = $seconds % 3600;
67
	$time[0] = ( $seconds - $temp ) / 3600 ;	// hours
732 richard 68
	$time[2] = $temp % 60 ;				// seconds
566 stephane 69
	$time[1] = ( $temp - $time[2] ) / 60;		// minutes
70
 
732 richard 71
	return $time[0]." h ".$time[1]." m ".$time[2]." s";
566 stephane 72
}
509 richard 73
 
566 stephane 74
$l_connected = "connected"; // a traduire (choix de la langue ci-dessous mais nécessitant de $connection_history)
75
// si on a pas d'accès à la bdd, la page s'affiche quand même correctement
783 richard 76
if ((isset ($user[4])) && ($user[4] != "0")){
566 stephane 77
	if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
78
		include_once("/etc/freeradius-web/config.php");
79
		include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
80
 
81
		$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
82
		$link = @da_sql_pconnect($config); // on affiche pas les erreurs
83
 
84
		if ($link){
85
			$res = @da_sql_query($link,$config,$sql); // on affiche pas les erreurs
86
 
87
			if ($res){
88
				$connection_history.= "<ul>";
89
				while(($row = @da_sql_fetch_array($res,$config))){
90
					$connected = "";
91
					if ($row[acctstoptime] == "") $connected = " ($l_connected)";
92
					$connection_history.="<li title='$row[username] $row[acctstarttime] $row[acctstoptime] (".secondsToDuration($row[acctsessiontime]).")'>$row[acctstarttime] (".secondsToDuration($row[acctsessiontime]).") $connected</li>";
93
				}
94
				$connection_history.="</ul>";
95
			}
96
		}
97
	}
98
}
509 richard 99
####
100
 
360 richard 101
# Choice of language
102
$Language = 'en';
103
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
104
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
105
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
106
if($Language == 'fr'){
107
  $l_access_denied = "ACC&Egrave;S REFUS&Eacute;";
399 franck 108
  $l_access_welcome = "Bienvenue sur ALCASAR";
360 richard 109
  $l_access_unavailable = "ACC&Egrave;S INDISPONIBLE";
110
  $l_required_domain = "Site WEB demand&eacute;";
536 franck 111
  $l_explain_acc_access = "Le centre de gestion permet d'administrer le portail. Vous devez poss&eacute;der un compte d'administration ou de gestion pour y acc&eacute;der.";
360 richard 112
  $l_explain_access_deny = "Vous tentez d'acc&eacute;der &agrave; une ressource dont le contenu est r&eacute;put&eacute; contenir des informations inappropri&eacute;es.";
113
  $l_explain_net_pb = "Votre portail d&eacute;tecte que l'acc&egrave;s &agrave; Internet est indisponible.";
114
  $l_contact_access_deny = "Contactez le responsable de la s&eacute;curit&eacute; (OSSI/RSSI) si vous pensez que ce filtrage est abusif.";
509 richard 115
  $l_contact_net_pb = "Contactez votre responsable informatique ou votre prestataire Internet pour plus d'information.";
399 franck 116
  $l_welcome = "Page principale de votre portail captif";
566 stephane 117
  $l_acc_access = "<a href=\"https://$hostname/acc\">Acc&egrave;s au centre de gestion</a>";
118
  $l_install_certif = "<a href=\"$cert_add/certificat_alcasar_ca.crt\">Installer le certificat racine</a>";
119
  $l_install_certif_more = "<a href=\"$cert_add/certificat_alcasar_ca.crt\">Installation du certificat de l'autorit&eacute; racine d'ALCASAR</a>";
536 franck 120
  $l_certif_explain = "Permet l'&eacute;change de donn&eacute;es s&eacute;curis&eacute;es entre votre station de consultation et le portail captif ALCASAR.<BR>Si ce certificat n'est pas enregistr&eacute; sur votre station de consultation, il est possible que des alertes de s&eacute;curit&eacute;s soient &eacute;mises par votre navigateur.<br><br>";
688 richard 121
  $l_certif_explain_help = "<a href=\"alcasar-certificat.pdf\" target=\"_blank\">Aide complémentaire</a>";
1124 crox53 122
  $l_category = "catégorie :";
832 richard 123
if ((isset ($user[4])) && ($user[4] == "0")) {
509 richard 124
	  $l_logout_explain = "Aucune session de consultation Internet n'est actuellement ouverte sur votre syst&egrave;me.";
566 stephane 125
	  $l_logout = "<a href=\"http://www.google.fr\">Ouvrir une session Internet</a>";}
369 richard 126
  else {
832 richard 127
	  if ($user[5] != $user[0]) // authentication exception or not
128
	  {
129
	  	$l_logout_explain = "Ferme la session de l'usager actuellement connect&eacute;. <br><br>Utilisateur connect&eacute; : <a href=\"http://$hostname:3990/logoff\" title=\"Deconnecter l'utilisateur $user[5]\"><b>$user[5]</b></a><br><br>$nb_connection_history derni&egrave;res connexions :$connection_history";
130
		$l_logout = "<a href=\"http://$hostname:3990/logoff\">Se d&eacute;connecter d'internet</a>";
131
	  }
132
	  else
133
	  {
134
		  $l_logout_explain = "Votre système ($user[5]) est en exception d'authentication.<br><br>$nb_connection_history last connections :$connection_history";
135
		  $l_logout = "Information des connexions";
136
	  }
137
	}
566 stephane 138
  $l_password_change = "<a href=\"https://$hostname/pass\">Changer votre mot de passe</a>";
536 franck 139
  $l_password_change_explain = "Vous redirige sur la page de changement du mot de passe de votre compte d'acc&egrave;s &agrave; internet.<br><br>Vous devez avoir un compte internet valide.";
360 richard 140
  $l_back_page = "<a href=\"javascript:history.back()\">Page pr&eacute;c&eacute;dente</a>";
141
}
912 richard 142
else if($Language == 'pt'){
143
  $l_access_denied = "Acesso negado";
144
  $l_access_welcome = "Bem-vindo ao Alcasar";
145
  $l_access_unavailable = "ACESSO INDISPONÍVEL";
146
  $l_required_domain = "Site WEB Obrigatório";
955 richard 147
  $l_explain_acc_access = "Este é o centro de controle do portal para acessar você deve ter uma conta administrativa valida.";
912 richard 148
  $l_explain_access_deny = "Você tenta se conectar a um recurso cujo conteúdo é considerado inadequado no conteúdo de informações.";
955 richard 149
  $l_explain_net_pb = "O sistema detectou que o acesso é de risco, não será permitido o acesso";
912 richard 150
  $l_contact_access_deny = "Entre em contato com o administrador do sistema de segurança se acha que essa filtragem é abusiva.";
151
  $l_contact_net_pb = "Entre em contato com a empresa fornecedora de Internet para mais informações";
955 richard 152
  $l_welcome = "Página do portal";
153
  $l_acc_access = "<a href=\"https://$hostname/acc\">ALCASAR Controle Center</a>";
912 richard 154
  $l_install_certif = "<a href=\"$cert_add/certificat_alcasar_ca.crt\">Instalar Certificado Alcasar AC</a>";
155
  $l_install_certif_more = "<a href=\"$cert_add/certificat_alcasar_ca.cert\">Instalar Certificado Alcasar AC</a>";
156
  $l_certif_explain = "O certificado Permiti a troca de dados seguro entre seu computador e o portal Alcasar.<BR>Se este certificado não estiver incorporado no seu computador, alguns alertas de segurança deverá aparecer no navegador.<br><br>";
955 richard 157
  $l_certif_explain_help = "<a href=\"alcasar-certificat.pdf\" target=\"_blank\">Essa foi uma ajuda complementar</a>";
1124 crox53 158
  $l_category = "categoria :";
912 richard 159
if ((isset ($user[4])) && ($user[4] == "0")) {
955 richard 160
	  $l_logout_explain = "Não há conexão de Internet aberta em seu computador, deseja conectar?";
922 richard 161
	  $l_logout = "<a href=\"http://www.google.pt\">Abrir uma conexão de Internet</a>";}
912 richard 162
  else {
163
	  if ($user[5] != $user[0]) // authentication exception or not
164
	  {
955 richard 165
		  $l_logout_explain = "Se desejar, feche a conexão do usuário atual conectado.<br> Usuário conectado : <a href=\"http://$hostname:3990/logoff\" title=\"Disconnect user $user[5]\"><b>$user[5]</b></a><br><br>$nb_connection_history last connections :$connection_history";
922 richard 166
		  $l_logout = "<a href=\"http://$hostname:3990/logoff\">Sair da Internet</a>";
912 richard 167
	  }
168
	  else
169
	  {
955 richard 170
		  $l_logout_explain = "O sistema ($user[5]) detctou exesso de autenticação.<br><br>$nb_connection_history logins últimos :$connection_history";
922 richard 171
		  $l_logout = "Informações de conexões";
912 richard 172
	  }
173
  	}
922 richard 174
  $l_password_change = "<a href=\"https://$hostname/pass\">Mudar sua senha</a>";
955 richard 175
  $l_password_change_explain = "Você será redirecionado à página de alteração de senha.<br><br> e deverá ter uma conta de usuário valido para efetuar a troca e acessar à Internet.";
922 richard 176
  $l_back_page = "<a href=\"javascript:history.back()\">Página anterior</a>";
912 richard 177
}
360 richard 178
else {
179
  $l_access_denied = "ACCESS DENIED";
369 richard 180
  $l_access_welcome = "Welcome on ALCASAR";
360 richard 181
  $l_access_unavailable = "ACCESS UNAVAILABLE";
182
  $l_required_domain = "Required WEB site";
369 richard 183
  $l_explain_acc_access = "This center control the portal. You must have an administrative account.";
801 richard 184
  $l_explain_access_deny = "You try to connect to a resource whose content is deemed to contain inappropriate information.";
360 richard 185
  $l_explain_net_pb = "Your portal has just detected that the Internet access is down";
186
  $l_contact_access_deny = "Contact your security system manager if you think this filtering is abusive.";
187
  $l_contact_net_pb = "Contact your network responsive or your Internet provider for more information";
369 richard 188
  $l_welcome = "Your captive portal main page";
566 stephane 189
  $l_acc_access = "<a href=\"https://$hostname/acc\">ALCASAR Control Center</a>";
611 franck 190
  $l_install_certif = "<a href=\"$cert_add/certificat_alcasar_ca.crt\">Install ALCASAR AC Certificate</a>";
566 stephane 191
  $l_install_certif_more = "<a href=\"$cert_add/certificat_alcasar_ca.cert\">Install ALCASAR AC Certificate</a>";
688 richard 192
  $l_certif_explain = "Allow secure data exchange between your computer and ALCASAR portal.<BR>If this certificate isn't incorporated in your computer, some security alerts should appear in your browser.<br><br>";
193
  $l_certif_explain_help = "<a href=\"alcasar-certificat.pdf\" target=\"_blank\">Complementary help</a>";
1124 crox53 194
  $l_category = "category :";
783 richard 195
if ((isset ($user[4])) && ($user[4] == "0")) {
369 richard 196
	  $l_logout_explain = "No Internet consultation session is actualy open on your system";
912 richard 197
	  $l_logout = "<a href=\"http://www.google.com\">Open an Internet session</a>";}
369 richard 198
  else {
832 richard 199
	  if ($user[5] != $user[0]) // authentication exception or not
200
	  {
922 richard 201
		  $l_logout_explain = "Close the session of the user currently connected.<br> User logged-on : <a href=\"http://$hostname:3990/logoff\" title=\"Disconnect user $user[5]\"><b>$user[5]</b></a><br><br>$nb_connection_history last connections :$connection_history";
783 richard 202
		  $l_logout = "<a href=\"http://$hostname:3990/logoff\">Logoff from internet</a>";
832 richard 203
	  }
204
	  else
205
	  {
922 richard 206
		  $l_logout_explain = "Your system ($user[5]) is in exception of authentication.<br><br>$nb_connection_history Last logins :$connection_history";
832 richard 207
		  $l_logout = "Connections information";
208
	  }
783 richard 209
  	}
566 stephane 210
  $l_password_change = "<a href=\"https://$hostname/pass\">Change your password</a>";
799 richard 211
  $l_password_change_explain = "Redirect you on password change page.<br><br> You should already have an Internet access account.";
360 richard 212
  $l_back_page = "<a href=\"javascript:history.back()\">Previous page</a>";
213
}
369 richard 214
$l_title = ($direct_access ? $l_access_welcome : ($network_pb ? $l_access_unavailable : $l_access_denied));
360 richard 215
$l_explain = ($direct_access ? $l_explain_acc_access : ($network_pb ? $l_explain_net_pb : $l_explain_access_deny));
509 richard 216
 
217
# Attribution des icones / images
218
$img_rep = "images/";
219
$img_organisme = "organisme.png";
220
$img_access = "globe_acces_70.png";
221
$img_connect = "globe_70.png";
222
$img_warning = "globe_warning_70.png";
223
$img_pwd = "cle_ombre.png";
224
$img_certificate = "certificat.png";
225
$img_acc = "logo-alcasar_70.png";
226
$img_false = "interdit.png";
227
$img_internet = $img_connect;
228
 
783 richard 229
if ((isset ($user[4])) && ($user[4] == "0")) {
509 richard 230
	if (! $network_pb) {
231
		$img_internet = $img_access;
232
		}
233
		else {
234
		$img_internet = $img_warning;
235
	}
236
}
237
else {
238
	$img_internet = $img_connect;
239
}
240
 
452 richard 241
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
360 richard 242
?>
566 stephane 243
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
244
	<html>
245
	<head>
246
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
247
	<title>ALCASAR - <?php echo $l_title; ?></title>
248
	<meta http-equiv="Cache-control" content="no-cache">
249
	<meta http-equiv="Pragma" content="no-cache">
250
	<link rel="stylesheet" type="text/css" href="css/style_intercept.css">
251
	<script type="text/javascript">
509 richard 252
		function valoriserDiv5(param){
253
			document.getElementById("box_info").innerHTML = param.innerHTML;
254
		}
255
	</script>
360 richard 256
</head>
566 stephane 257
<body onload="valoriserDiv5(text_conn);">
509 richard 258
<?php
360 richard 259
if ($direct_access){
260
	echo "
566 stephane 261
		<div id=\"cadre_titre\" class=\"titre_controle\">
262
			<p id=\"acces_controle\" class=\"titre_controle\">$l_title</p>";
509 richard 263
	if ($network_pb) {
566 stephane 264
		echo "	<span>$l_explain_net_pb</span>";
509 richard 265
		}
360 richard 266
	}
509 richard 267
	else {
268
		echo"
566 stephane 269
			<div id=\"cadre_titre\" class=\"titre_refus\">
270
				<p id=\"acces_controle\" class=\"titre_refus\">$l_title</p>";
363 richard 271
	}
360 richard 272
?>
566 stephane 273
			<div id="boite_logo">
274
				<img src="images/organisme.png">
275
			</div>
276
		</div>
277
		<div id="contenu_acces">
278
			<div id="box_url">
1124 crox53 279
<?php 
280
if (! $direct_access){
281
	$pattern = preg_replace('/www./','',$_SERVER['HTTP_HOST']);
1286 richard 282
	$domain_bl = exec("grep -Re ^$pattern /etc/dansguardian/lists/blacklists/*/domains|cut -d'/' -f6");
283
	echo "$l_required_domain : $_SERVER[HTTP_HOST]<BR>$l_category $domain_bl";
1124 crox53 284
}
285
?>
566 stephane 286
			</div>
1124 crox53 287
 
509 richard 288
<?php
289
if ($direct_access){
566 stephane 290
	echo "	<div id=\"box_bienvenue\">
360 richard 291
				$l_welcome
566 stephane 292
			</div>
293
			<div class=\"box_menu\" id=\"box_conn\" onmouseover=\"valoriserDiv5(text_conn);\">
294
				<span>$l_logout</span>
295
				<img src=\"$img_rep$img_internet\">
296
			</div>
297
			<div class=\"box_menu\" id=\"box_certif\" onmouseover=\"valoriserDiv5(text_certif);\">
298
				<span>$l_install_certif</span>
299
				<img src=\"$img_rep$img_certificate\">
300
			</div>
301
			<div class=\"box_menu\" id=\"box_mdp\" onmouseover=\"valoriserDiv5(text_mdp);\">
302
				<img src=\"$img_rep$img_pwd\">
303
				<span>$l_password_change</span>
304
			</div>		
305
			<div class=\"box_menu\" id=\"box_acc\" onmouseover=\"valoriserDiv5(text_acc);\">
306
				<span>$l_acc_access</span>
307
				<img src=\"$img_rep$img_acc\">
308
			</div>
309
			<div class=\"div-cache\" id=\"text_conn\">
310
				<h2>$l_logout</h2>
311
				<p>$l_logout_explain</p>
312
				<img src=\"$img_rep$img_internet\">
313
			</div>
314
			<div class=\"div-cache\" id=\"text_certif\">
315
				<h2>$l_install_certif_more</h2>
316
				<p>$l_certif_explain $l_certif_explain_help</p>
317
				<img src=\"$img_rep$img_certificate\">				
318
			</div>
319
			<div class=\"div-cache\" id=\"text_mdp\">
320
				<h2>$l_password_change</h2>
321
				<p>$l_password_change_explain</p>
322
				<img src=\"$img_rep$img_pwd\">
323
			</div>
324
			<div class=\"div-cache\" id=\"text_acc\">
325
				<h2>$l_acc_access</h2>
326
				<p>$l_explain</p>
327
				<img src=\"$img_rep$img_acc\">
328
			</div>
329
			<div id=\"box_info\">
330
			</div>";
509 richard 331
	}
332
	else {
333
		echo "
566 stephane 334
			<div id=\"box_refuse\">
509 richard 335
				<img src=\"$img_rep$img_false\">
566 stephane 336
				<p>$l_explain</p>
337
			</div>
338
			<div id=\"liens_redir\">
339
				<p>$l_back_page</p>
340
			</div>";
509 richard 341
		}
342
	if (($network_pb)&&(! $direct_access)) {
566 stephane 343
	echo "	<span>Diagnostic : $diagnostic</span>";
509 richard 344
	}
363 richard 345
?>
566 stephane 346
		</div>
347
	</body>
360 richard 348
</html>