Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2239 → Rev 2240

/web/status.php
1,73 → 1,75
<?php
# $Id$
#
# status.php for Alcasar captive portal
# status.php for ALCASAR captive portal
# by steweb57 & Rexy
#
/****************************************************************
* GLOBAL FILE PATHS *
*****************************************************************/
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
 
/****************************************************************
* FILE TEST *
* FILE reading test *
*****************************************************************/
//Test de présence et des droits en lecture des fichiers de configuration.
if (!file_exists(CONF_FILE)){
exit("Fichier de configuration ".CONF_FILE." non présent");
$conf_files = array(CONF_FILE);
foreach ($conf_files as $file) {
if (!file_exists($file)) {
exit("Fichier $file non présent");
}
if (!is_readable($file)) {
exit("Vous n'avez pas les droits de lecture sur le fichier $file");
}
}
if (!is_readable(CONF_FILE)){
exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
}
 
/****************************************************************
* Read CONF_FILE *
*****************************************************************/
$ouvre=fopen(CONF_FILE,"r");
if ($ouvre){
while (!feof ($ouvre))
{
$tampon = fgets($ouvre, 4096);
if (strpos($tampon,"=")!==false){
$tmp = explode("=",$tampon);
$conf[$tmp[0]] = $tmp[1];
}
$file_conf = fopen(CONF_FILE, 'r');
if (!$file_conf) {
exit('Error opening the file '.CONF_FILE);
}
while (!feof($file_conf)) {
$buffer = fgets($file_conf, 4096);
if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
$tmp = explode('=', $buffer);
$conf[$tmp[0]] = trim($tmp[1]);
}
}else{
exit("Erreur d'ouverture du fichier ".CONF_FILE);
}
fclose($ouvre);
fclose($file_conf);
 
$organisme = $conf["ORGANISM"];
$remote_ip = preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
$connection_history = "";
$organisme = $conf['ORGANISM'];
$remote_ip = preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$cn = '';
$connection_history = '';
$nb_connection_history = 3;
 
// Wait for chilli (uptade its tables)
sleep (1);
// Wait for chilli (update its tables)
sleep(1); // TODO: wait after login only?
// Retrieve user info in tab $user[]
exec ("sudo /usr/sbin/chilli_query list | grep 'pass' | grep -Ew '($remote_ip)'" , $tab);
if(isset($tab[0]))
$user = explode (" ", $tab[0]);
exec("sudo /usr/sbin/chilli_query list | grep 'pass' | grep -Ew '($remote_ip)'" , $tab);
if (isset($tab[0])) {
$user = explode(' ', $tab[0]);
}
 
#### Time conversion
function secondsToDuration($seconds = null){
if ($seconds == null) return "";
// Time conversion
function secondsToDuration($seconds = null) {
if ($seconds === null) return '';
$temp = $seconds % 3600;
$time[0] = ( $seconds - $temp ) / 3600 ; // hours
$time[2] = $temp % 60 ; // seconds
$time[1] = ( $temp - $time[2] ) / 60; // minutes
return $time[0]." h ".$time[1]." m ".$time[2]." s";
$time[2] = $temp % 60 ; // seconds
$time[1] = ($temp - $time[2]) / 60; // minutes
$time[0] = ($seconds - $temp) / 3600 ; // hours
return $time[0].' h '.$time[1].' m '.$time[2].' s';
}
 
# Choice of language
//reste quelques traductions à faire
// TODO: reste quelques traductions à faire
$Language = 'en';
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$Language = strtolower(substr(chop($Langue[0]),0,2));
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$Langue = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$Language = strtolower(substr(chop($Langue[0]), 0, 2));
}
if($Language == 'es'){
if ($Language === 'es') { // Spanish
$l_login1 = "El éxito de la autenticación";
$l_logout = "Conexión de cierre";
$l_logout_question = "¿Seguro que desea desconectar?";
91,8 → 93,7
$l_a_connection = "You have"; // to translate
$l_a_connection_time = "active connections on the network"; // to translate
$l_close_warning = "Advertencia: se desconectará si cierra esta ventana";
}
else if ($Language == 'zh'){
} else if ($Language === 'zh') { // Chinese
$l_login1 = "验证通过";
$l_logout = "关闭连接";
$l_logout_question = "您确定需要断开连接吗?";
116,8 → 117,7
$l_a_connection = "您已经有";
$l_a_connection_time = "在线时间";
$l_close_warning = "警告: 您将会断开连接如果您在关闭此窗口";
}
else if ($Language == 'ar'){
} else if ($Language === 'ar') { // Arabic
$l_login1 = "نجاح المصادقة";
$l_logout = "إغلاق الدورة";
$l_logout_question = "هل تريد فعلاً قطع الاتصال؟";
142,8 → 142,7
$l_a_connection = "لديك";
$l_a_connection_time = "اتصالات ناشطة على الشبكة";
$l_close_warning = "تحذير: سيتم قطع الاتصال إذا قمت بإغلاق هذه النافذة";
}
else if ($Language == 'pt'){
} else if ($Language === 'pt') { // Portuguese
$l_login1 = "Autenticação bem sucedida.";
$l_logout = "Fechando a conexão";
$l_logout_question = "Tem certeza de que deseja desconectar agora?";
167,8 → 166,7
$l_a_connection = "Conexão ativa já detectada para essa LAN";
$l_a_connection_time = "Tempo (s)";
$l_close_warning = "Aviso: você será desconectado se fechar esta janela";
}
else if ($Language == 'de'){
} else if ($Language === 'de') { // German
$l_login1 = "Erfolgreiche Authentifizierung";
$l_logout = "Beenden der Verbindung";
$l_logout_question = "Möchten Sie die Verbindung jetzt wirklich trennen?";
192,8 → 190,7
$l_a_connection = "You have"; // to translate
$l_a_connection_time = "active connections on the network"; // to translate
$l_close_warning = "Warnung: Sie werden getrennt, wenn Sie dieses Fenster schließen";
}
else if ($Language == 'nl'){
} else if ($Language === 'nl') { // Dutch
$l_login1 = "Succesvolle authenticatie";
$l_logout = "Slotkoers verbinding";
$l_logout_question = "Bent u zeker dat u wilt nu los te koppelen?";
217,8 → 214,7
$l_a_connection = "You have"; // to translate
$l_a_connection_time = "active connections on the network"; // to translate
$l_close_warning = "Waarschuwing: u zal worden afgebroken als u dit venster sluiten";
}
else if ($Language == 'fr'){
} else if ($Language === 'fr') { // French
$l_login1 = "Authentification réussie";
$l_logout = "Fermeture de la session";
$l_logout_question = "Êtes vous sûr de vouloir vous déconnecter?";
242,8 → 238,7
$l_a_connection = "Vous avez";
$l_a_connection_time = "connexions actives sur le réseau";
$l_close_warning = "Attention : vous serez déconnecté si vous fermez cette fenêtre";
}
else {
} else { // English
$l_login1 = "Successful authentication.";
$l_logout = "Closing connection";
$l_logout_question = "Are you sure you want to disconnect now?";
269,206 → 264,204
$l_close_warning = "Warning: you will be disconnected if you close this window";
}
 
if (isset($user[5])){
// Retrieve the last connections
if ((is_file("./acc/manager/lib/sql/drivers/mysql/functions.php"))&&(is_file("/etc/freeradius-web/config.php"))){
include_once("/etc/freeradius-web/config.php");
include_once("./acc/manager/lib/sql/drivers/mysql/functions.php");
$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0 , $nb_connection_history";
if (isset($user[5])) {
if ((is_file('acc/manager/lib/sql/drivers/mysql/functions.php')) && (is_file('/etc/freeradius-web/config.php'))) {
require_once('/etc/freeradius-web/config.php');
require_once('acc/manager/lib/sql/drivers/mysql/functions.php');
$link = @da_sql_pconnect($config);
if ($link){
$res = @da_sql_query($link,$config,$sql);
if ($res){
$a_connection = ""; $a_connected=0; $connection_history.= "<ul>";
while(($row = @da_sql_fetch_array($res,$config))){
$connected = "";
if ($link) {
// Retrieve the last connections
$sql = "SELECT UserName, AcctStartTime, AcctStopTime, acctsessiontime FROM radacct WHERE UserName='$user[5]' ORDER BY AcctStartTime DESC LIMIT 0, $nb_connection_history";
$res = @da_sql_query($link, $config, $sql);
if ($res) {
$a_connection = '';
$a_connected = 0;
$connection_history = '<ul>';
while (($row = @da_sql_fetch_array($res,$config))) {
$start_conn = date_create($row['acctstarttime']);
$connection_history.="<li>".date_format($start_conn, 'd M Y - H:i:s')." - (";
if ($row['acctstoptime'] == "") {
if (empty($row['acctstoptime'])) {
$connected = $l_connected;
$a_connected = $a_connected +1;
}else{
$a_connected++;
} else {
$connected = secondsToDuration($row['acctsessiontime']);
}
$connection_history.= "$connected)</li>";
$connection_history .= '<li>'.date_format($start_conn, 'd M Y - H:i:s')." - ($connected)</li>";
}
$connection_history.="</ul>";
if ($a_connected > 1){
$a_connection = $l_a_connection." ".$a_connected." ".$l_a_connection_time; }
$connection_history .= '</ul>';
if ($a_connected > 1) {
$a_connection = $l_a_connection.' '.$a_connected.' '.$l_a_connection_time;
}
}
}
// Retrieve first name & last name
$sql = "SELECT Name FROM userinfo WHERE UserName='$user[5]'";
$link = @da_sql_pconnect($config);
if ($link){
$res = @da_sql_query($link,$config,$sql);
if ($res){
 
// Retrieve first name & last name
$sql = "SELECT Name FROM userinfo WHERE UserName='$user[5]'";
$res = @da_sql_query($link, $config, $sql);
if ($res) {
$row = @da_sql_fetch_array($res,$config);
$cn = ($row['name'] != '') ? $row['name'] : $user[5];
$cn = (!empty($row['name'])) ? $row['name'] : $user[5];
}
}
//store the user @IP in a file (to test if he is still active).
$filename='/var/tmp/havp/current_users.txt';
$change_me = 1; //avoid duplicate user @IP
if(file_exists($filename)){
$fichier = fopen($filename, "r");
 
// Store the user @IP in a file (to test if he is still active).
$filename = '/var/tmp/havp/current_users.txt';
if (file_exists($filename)) {
$current_users_file = fopen($filename, 'r');
$content = file($filename);
if (empty($content))
{
fclose($current_users_file);
if (empty($content)) {
file_put_contents($filename, $_SERVER['REMOTE_ADDR']);
}
else
{
} else {
$change_me = 1; // avoid duplicate user @IP
// if we found duplicate IP, we will not write user @IP (just set change_me = 0)
foreach($content as $line){
foreach ($content as $line) {
$line = preg_replace('/\s+/', '', $line);
if($line == $_SERVER['REMOTE_ADDR'])
{
if ($line === $_SERVER['REMOTE_ADDR']) {
$change_me = 0;
}
}
// if user @IP does not exist, we write it
if($change_me)
{
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
if ($change_me) {
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL, FILE_APPEND);
}
}
}
else
{
//we create filename and we write user @IP.
} else {
// we create filename and we write user @IP.
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
}
}
 
// Cleaning the cache
header('Expires: Tue, 01 Jan 2000 00:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE html>
<html>
<!-- written by steweb57 & Rexy -->
<head>
<title>Alcasar - <?php echo $organisme; ?></title>
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="./js/ChilliLibrary.js"></script>
<script type="text/javascript" src="./js/statusControler.js"></script>
<link type="text/css" href="./css/status.css" rel="stylesheet">
<meta charset="UTF-8">
<title>ALCASAR - <?= $organisme ?></title>
<link type="text/css" href="css/status.css" rel="stylesheet">
<script src="js/ChilliLibrary.js"></script>
<script src="js/statusControler.js"></script>
</head>
<body>
<div id="Chilli">
<div id="locationName"></div>
<div id="chilliPage">
<div id="loggedOutPage" class="c1">
<table id="disconnectTable">
<tr>
<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
<td><p class="text_auth"><?php echo $l_loggedout; ?></p></td>
</tr>
</table>
<div id="locationName"></div>
<div id="chilliPage">
<div id="loggedOutPage" class="c1">
<table id="disconnectTable">
<tr>
<td><img height="150" src="images/logo-alcasar.png" alt="logo"></td>
<td><p class="text_auth"><?= $l_loggedout ?></p></td>
</tr>
</table>
</div>
<div id="statusPage" class="c1">
<table border="0" id="statusTable">
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" rowspan="4">
<img height="150" src="images/logo-alcasar.png" alt="logo">
</td>
<td class="text_auth_welcom">
<?= $l_login1 ?>
</td>
</tr>
<tr>
<td class="text_auth">
<?= $l_welcome ?><br><?= $cn ?>
</td>
</tr>
<tr>
<td class="alert">
<?= ((isset($a_connection)) ? $a_connection : '') ?>
</td>
</tr>
<tr>
<td colspan="2" align="center" class="link_logout">
<a href="#" onclick="return logoutWithConfirmation('<?= $l_logout_question ?>');" class="lien_deco"><?= $l_logout ?></a>
</td>
</tr>
</table>
</td>
</tr>
<!--
<tr id="connectRow">
<td id="statusMessageLabel" class="chilliLabel"><strong><?= $l_state_label ?></strong></td>
<td id="statusMessage" class="chilliValue">Connected</td>
</tr>
<tr id="sessionIdRow">
<td id="sessionIdLabel" class="chilliLabel"><strong><?= $l_session_id_label ?></strong></td>
<td id="sessionId" class="chilliValue"><?= $l_not_available ?></td>
</tr>
-->
<tr id="sessionTimeoutRow">
<td id="sessionTimeoutLabel" class="chilliLabel"><?= $l_max_session_time_label ?></td>
<td id="sessionTimeout" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="idleTimeoutRow">
<td id="idleTimeoutLabel" class="chilliLabel"><?= $l_max_idle_time_label ?></td>
<td id="idleTimeout" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="startTimeRow">
<td id="startTimeLabel" class="chilliLabel"><?= $l_start_time_label ?></td>
<td id="startTime" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="sessionTimeRow">
<td id="sessionTimeLabel" class="chilliLabel"><?= $l_session_time_label ?></td>
<td id="sessionTime" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="idleTimeRow">
<td id="idleTimeLabel" class="chilliLabel"><?= $l_idle_time_label ?></td>
<td id="idleTime" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="inputOctetsRow">
<td id="inputOctetsLabel" class="chilliLabel"><?= $l_downloaded_label ?></td>
<td id="inputOctets" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<tr id="outputOctetsRow">
<td id="outputOctetsLabel" class="chilliLabel"><?= $l_uploaded_label ?></td>
<td id="outputOctets" class="chilliValue"><?= $l_not_available ?></td>
</tr>
<!--
<tr id="originalURLRow">
<td id="originalURLLabel" class="chilliLabel"><?= $l_original_url_label ?></td>
<td id="originalURL" class="chilliValue"><?= $l_not_available ?></td>
</tr>
-->
<tr>
<td colspan="2" id="conHistoryLabel" class="chilliLabel"><?= $l_conn_history ?></td>
</tr>
<tr id="conHistoryRow">
<td colspan="2" id="conHistory" class="chilliValue"><?= $connection_history ?></td>
</tr>
<tr>
<td colspan="2" id="close-warning">(<?= $l_close_warning ?>)</td>
</tr>
</table>
</div>
<div id="waitPage">
<table id="waitTable">
<tr>
<td><img height="150" src="images/logo-alcasar.png" alt="logo"></td>
<td><p class="text_auth"><img src="images/wait.gif" width="16" height="16" class="wait" alt="<?= $l_wait ?>"><?= $l_wait ?></p></td>
</tr>
</table>
</div>
<div id="errorPage">
<table id="errorTable">
<tr>
<td><img height="150" src="images/logo-alcasar.png" alt="logo"></td>
<td><span id="errorMessage"><?= $l_error ?></span></td>
</tr>
</table>
</div>
</div>
</div>
<div id="statusPage" class="c1">
<table border="0" id="statusTable">
<tr>
<td colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" rowspan="4">
<img height="150" src="./images/logo-alcasar.png" alt="logo">
</td>
<td class="text_auth_welcom">
<?php echo $l_login1; ?>
</td>
</tr>
<tr>
<td class="text_auth">
<?php echo "$l_welcome <br> $cn";?>
</td>
</tr>
<tr>
<td class="alert">
<?php if(isset($a_connection))echo $a_connection; ?>
</td>
</tr>
<tr>
<td colspan="2" align="center" class="link_logout">
<a href="#" onclick="return logoutWithConfirmation('<?php echo $l_logout_question;?>');" class="lien_deco"><?php echo $l_logout; ?></a>
</td>
</tr>
</table>
</td>
</tr>
<!--tr id="connectRow">
<td id="statusMessageLabel" class="chilliLabel"><strong><?php echo $l_state_label; ?></strong></td>
<td id="statusMessage" class="chilliValue">Connected</td>
</tr-->
<!--tr id="sessionIdRow">
<td id="sessionIdLabel" class="chilliLabel"><strong><?php echo $l_session_id_label; ?></strong></td>
<td id="sessionId" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr-->
<tr id="sessionTimeoutRow">
<td id="sessionTimeoutLabel" class="chilliLabel"><?php echo $l_max_session_time_label; ?></td>
<td id="sessionTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="idleTimeoutRow">
<td id="idleTimeoutLabel" class="chilliLabel"><?php echo $l_max_idle_time_label; ?></td>
<td id="idleTimeout" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="startTimeRow">
<td id="startTimeLabel" class="chilliLabel"><?php echo $l_start_time_label; ?></td>
<td id="startTime" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="sessionTimeRow">
<td id="sessionTimeLabel" class="chilliLabel"><?php echo $l_session_time_label; ?></td>
<td id="sessionTime" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="idleTimeRow">
<td id="idleTimeLabel" class="chilliLabel"><?php echo $l_idle_time_label; ?></td>
<td id="idleTime" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="inputOctetsRow">
<td id="inputOctetsLabel" class="chilliLabel"><?php echo $l_downloaded_label; ?></td>
<td id="inputOctets" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<tr id="outputOctetsRow">
<td id="outputOctetsLabel" class="chilliLabel"><?php echo $l_uploaded_label; ?></td>
<td id="outputOctets" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr>
<!--tr id="originalURLRow">
<td id="originalURLLabel" class="chilliLabel"><?php echo $l_original_url_label; ?></td>
<td id="originalURL" class="chilliValue"><?php echo $l_not_available; ?></td>
</tr-->
<tr>
<td colspan=2 id="conHistoryLabel" class="chilliLabel"><?php echo $l_conn_history; ?></td>
</tr>
<tr id="conHistoryRow">
<td colspan=2 id="conHistory" class="chilliValue"><?php echo $connection_history; ?></td>
</tr>
<tr>
<td colspan=2 id="close-warning">(<?php echo $l_close_warning; ?>)</td>
</tr>
</table>
</div>
<div id="waitPage">
<table id="waitTable">
<tr>
<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
<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>
</tr>
</table>
</div>
<div id="errorPage">
<table id="errorTable">
<tr>
<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
<td><span id="errorMessage"><?php echo $l_error; ?></span></td>
</tr>
</table>
</div>
</div>
<!--div id="debugPage" style="display:inline;">
<textarea id="debugarea" rows="20" cols="60">
</textarea>
</div-->
</div>
</body>
</html>