Line 1... |
Line 1... |
1 |
<?php
|
1 |
<?php
|
2 |
# $Id: index.php 1986 2016-07-12 16:42:55Z raphael.pion $
|
2 |
# $Id: index.php 1987 2016-07-12 22:24:04Z richard $
|
3 |
#
|
3 |
#
|
4 |
# index.php for ALCASAR captive portal
|
4 |
# index.php for ALCASAR
|
5 |
# by REXY
|
5 |
# by REXY
|
6 |
# UI & css style by stephane ERARD
|
6 |
# UI & css style by stephane ERARD
|
7 |
# The contents of this file may be used under the terms of the GNU
|
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
|
8 |
# General Public License Version 2, provided that the above copyright
|
9 |
# notice and this permission notice is included in all copies or
|
9 |
# notice and this permission notice is included in all copies or
|
Line 52... |
Line 52... |
52 |
$remote_ip = preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
|
52 |
$remote_ip = preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
|
53 |
$tab = array();$user = array();
|
53 |
$tab = array();$user = array();
|
54 |
$connection_history = "";
|
54 |
$connection_history = "";
|
55 |
$nb_connection_history = 3;
|
55 |
$nb_connection_history = 3;
|
56 |
|
56 |
|
57 |
# Obtenir l'état de connexion de l'utilisateur. 1 si connecté sinon 0.
|
57 |
# Retrieve the user info behind the remote ip
|
58 |
exec ("sudo /usr/sbin/chilli_query list|grep $remote_ip" , $tab);
|
58 |
exec ("sudo /usr/sbin/chilli_query list|grep $remote_ip" , $tab);
|
59 |
$user = explode (" ", $tab[0]);
|
59 |
$user = explode (" ", $tab[0]);
|
60 |
|
60 |
|
61 |
#then we clean his cache to redirect him properly
|
61 |
# cleaning the cache
|
62 |
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
|
62 |
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
|
63 |
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
63 |
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
64 |
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
64 |
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
65 |
header("Cache-Control: post-check=0, pre-check=0", false);
|
65 |
header("Cache-Control: post-check=0, pre-check=0", false);
|
66 |
header("Pragma: no-cache");
|
66 |
header("Pragma: no-cache");
|
67 |
|
67 |
|
68 |
|
68 |
|
69 |
# on discrimine les accès directs sur Alcasar par rapport aux redirections (blacklist ou pannes rso)
|
69 |
# Test if it'a direct connexion to ALCASAR
|
70 |
if (isset($_SERVER['HTTP_HOST']) && (($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_ADDR']) || preg_match ("/^alcasar$/", $_SERVER['HTTP_HOST']) || preg_match ("/^$hostname$/", $_SERVER['HTTP_HOST']) || preg_match ("/^$organisme$/", $_SERVER['HTTP_HOST'])))
|
70 |
if (isset($_SERVER['HTTP_HOST']) && (($_SERVER['HTTP_HOST'] == $_SERVER['SERVER_ADDR']) || preg_match ("/^alcasar$/", $_SERVER['HTTP_HOST']) || preg_match ("/^$hostname$/", $_SERVER['HTTP_HOST']) || preg_match ("/^$organisme$/", $_SERVER['HTTP_HOST'])))
|
71 |
{
|
71 |
{
|
72 |
$direct_access=True;
|
72 |
$direct_access=True;
|
73 |
}
|
73 |
}
|
74 |
#### Affichage des 3 dernières connexions de $user[5]
|
74 |
# Function to adapt time connexion in seconds to H,M,S
|
75 |
function secondsToDuration($seconds = null){
|
75 |
function secondsToDuration($seconds = null){
|
76 |
if ($seconds == null) return "";
|
76 |
if ($seconds == null) return "";
|
77 |
|
77 |
|
78 |
$temp = $seconds % 3600;
|
78 |
$temp = $seconds % 3600;
|
79 |
$time[0] = ( $seconds - $temp ) / 3600 ; // hours
|
79 |
$time[0] = ( $seconds - $temp ) / 3600 ; // hours
|
Line 81... |
Line 81... |
81 |
$time[1] = ( $temp - $time[2] ) / 60; // minutes
|
81 |
$time[1] = ( $temp - $time[2] ) / 60; // minutes
|
82 |
|
82 |
|
83 |
return $time[0]." h ".$time[1]." m ".$time[2]." s";
|
83 |
return $time[0]." h ".$time[1]." m ".$time[2]." s";
|
84 |
}
|
84 |
}
|
85 |
|
85 |
|
86 |
$l_connected = "connected"; // a traduire (choix de la langue ci-dessous mais nécessitant de $connection_history)
|
- |
|
87 |
// si on a pas d'accès à la bdd, la page s'affiche quand même correctement
|
86 |
# If the user is connected : retrieve the 3 last connexions
|
88 |
if ((isset ($user[4])) && ($user[4] != "0")){
|
87 |
if ((isset ($user[4])) && ($user[4] != "0")){
|
89 |
if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
|
88 |
if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
|
90 |
include_once("/etc/freeradius-web/config.php");
|
89 |
include_once("/etc/freeradius-web/config.php");
|
91 |
include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
|
90 |
include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
|
92 |
|
- |
|
93 |
$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
|
91 |
$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
|
94 |
$link = @da_sql_pconnect($config); // on affiche pas les erreurs
|
92 |
$link = @da_sql_pconnect($config); // on affiche pas les erreurs
|
95 |
|
- |
|
96 |
if ($link){
|
93 |
if ($link){
|
97 |
$res = @da_sql_query($link,$config,$sql); // on affiche pas les erreurs
|
94 |
$res = @da_sql_query($link,$config,$sql); // on affiche pas les erreurs
|
98 |
|
95 |
|
99 |
if ($res){
|
96 |
if ($res){
|
100 |
$connection_history.= "<ul>";
|
97 |
$connection_history.= "<ul>";
|
101 |
while(($row = @da_sql_fetch_array($res,$config))){
|
98 |
while(($row = @da_sql_fetch_array($res,$config))){
|
102 |
$connected = "";
|
99 |
$connected = "";
|
103 |
if ($row['acctstoptime'] == "") $connected = " ($l_connected)";
|
100 |
if ($row['acctstoptime'] == "") $connected = " (active)";
|
104 |
$connection_history.="<li title='$row[username] $row[acctstarttime] $row[acctstoptime] (".secondsToDuration($row['acctsessiontime']).")'>$row[acctstarttime] (".secondsToDuration($row['acctsessiontime']).") $connected</li>";
|
101 |
$connection_history.="<li title='$row[username] $row[acctstarttime] $row[acctstoptime] (".secondsToDuration($row['acctsessiontime']).")'>$row[acctstarttime] (".secondsToDuration($row['acctsessiontime']).") $connected</li>";
|
105 |
}
|
102 |
}
|
106 |
$connection_history.="</ul>";
|
103 |
$connection_history.="</ul>";
|
107 |
}
|
104 |
}
|
108 |
}
|
105 |
}
|
109 |
}
|
106 |
}
|
110 |
}
|
107 |
}
|
111 |
else
|
108 |
else
|
112 |
{
|
109 |
{
|
113 |
# cas où l'utilisateur non-loggué décide de joindre une page HTTP/S => redirection http://URL
|
110 |
# the user isn't connected and he isn't in the ipset "not_auth_yet" yet
|
114 |
exec("sudo /usr/sbin/ipset list not_auth_yet | grep $remote_ip | wc -l 2>&1", $ipset_not_auth_yet);
|
111 |
exec("sudo /usr/sbin/ipset list not_auth_yet | grep $remote_ip | wc -l 2>&1", $ipset_not_auth_yet);
|
115 |
# ALCASAR => redirection index.php
|
- |
|
116 |
# on place l'IP de l'utilisateur dans un ipset not_auth_yet pour ne pas boucler sur index.php et atteindre la page souhaité qui sera traité par coova-chilli
|
- |
|
117 |
if(!$direct_access && $ipset_not_auth_yet[0] == '0')
|
112 |
if(!$direct_access && $ipset_not_auth_yet[0] == '0')
|
118 |
{
|
113 |
{
|
119 |
exec("sudo /usr/sbin/ipset add not_auth_yet $remote_ip");
|
114 |
exec("sudo /usr/sbin/ipset add not_auth_yet $remote_ip"); # Add in the ipset "not_auth_yet" to not loop when redirected
|
120 |
#On force l'utilisateur a refaire une requete DNS sur la même URL intercepté. (comme un CTRL+F5)
|
- |
|
121 |
echo "<script>window.location.reload(true)</script>";
|
115 |
echo "<script>window.location.assign='http://$_SERVER[HTTP_HOST]'</script>";
|
122 |
echo "<script>window.location.href='http://$_SERVER[HTTP_HOST]'</script>";
|
116 |
echo "<script>window.location.reload(true)</script>"; # the user web browser need to perform a new DNS request when redirected (as in a "<CTRL>+F5")
|
123 |
header("Location: http://$_SERVER[HTTP_HOST]");
|
117 |
//header("Location: http://$_SERVER[HTTP_HOST]");
|
124 |
exit;
|
118 |
exit;
|
125 |
}
|
119 |
}
|
126 |
|
- |
|
127 |
}
|
120 |
}
|
128 |
####
|
- |
|
129 |
|
121 |
|
130 |
# Choice of language
|
122 |
# Choice of language
|
131 |
$Language = 'en';
|
123 |
$Language = 'en';
|
132 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
124 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
133 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
125 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
Line 259... |
Line 251... |
259 |
$l_back_page = "<a href=\"javascript:history.back()\">Previous page</a>";
|
251 |
$l_back_page = "<a href=\"javascript:history.back()\">Previous page</a>";
|
260 |
$l_service_sms = "SMS service enable";
|
252 |
$l_service_sms = "SMS service enable";
|
261 |
$l_service_sms_n = "SMS service disable";
|
253 |
$l_service_sms_n = "SMS service disable";
|
262 |
$l_acc_sms = "Auto registration by SMS";
|
254 |
$l_acc_sms = "Auto registration by SMS";
|
263 |
}
|
255 |
}
|
- |
|
256 |
|
264 |
$l_title = ($direct_access ? $l_access_welcome : ($network_pb ? $l_access_unavailable : $l_access_denied));
|
257 |
$l_title = ($direct_access ? $l_access_welcome : ($network_pb ? $l_access_unavailable : $l_access_denied));
|
265 |
$l_explain = ($direct_access ? $l_explain_acc_access : ($network_pb ? $l_explain_net_pb : $l_explain_access_deny));
|
258 |
$l_explain = ($direct_access ? $l_explain_acc_access : ($network_pb ? $l_explain_net_pb : $l_explain_access_deny));
|
266 |
|
259 |
|
267 |
# Attribution des icones / images
|
260 |
# set the icons
|
268 |
$img_rep = "images/";
|
261 |
$img_rep = "images/";
|
269 |
$img_organisme = "organisme.png";
|
262 |
$img_organisme = "organisme.png";
|
270 |
$img_access = "globe_acces_70.png";
|
263 |
$img_access = "globe_acces_70.png";
|
271 |
$img_connect = "globe_70.png";
|
264 |
$img_connect = "globe_70.png";
|
272 |
$img_warning = "globe_warning_70.png";
|
265 |
$img_warning = "globe_warning_70.png";
|
Line 326... |
Line 319... |
326 |
</div>
|
319 |
</div>
|
327 |
</div>
|
320 |
</div>
|
328 |
<div id="contenu_acces">
|
321 |
<div id="contenu_acces">
|
329 |
<div id="box_url">
|
322 |
<div id="box_url">
|
330 |
<?php
|
323 |
<?php
|
331 |
//search here in the blacklist categories (if ((! $direct_access) && (! $network_pb)){}
|
324 |
# search here in the blacklist categories if we want to display it (if ((! $direct_access) && (! $network_pb)){}
|
332 |
?>
|
325 |
?>
|
333 |
</div>
|
326 |
</div>
|
334 |
<?php
|
327 |
<?php
|
335 |
# CHECK IF the SMS service is enable
|
328 |
# Check if the SMS service is enable
|
336 |
$service_SMS_status="false";
|
329 |
$service_SMS_status="false";
|
337 |
if ($service_SMS_status == "true") {
|
330 |
if ($service_SMS_status == "true") {
|
338 |
$sms_div='
|
331 |
$sms_div='
|
339 |
<div class="box_menu" id="box_acc" onmouseover="valoriserDiv5(text_acc);">
|
332 |
<div class="box_menu" id="box_acc" onmouseover="valoriserDiv5(text_acc);">
|
340 |
<span>'.$l_sms_access.'</span>
|
333 |
<span>'.$l_sms_access.'</span>
|