From 081a46fe3bc2393778c4e270cd8388230d39b38c Mon Sep 17 00:00:00 2001 From: plumbeo Date: Mon, 26 Dec 2016 15:47:47 +0100 Subject: Captive portal: add popup with session details to the active sessions list in the status page --- src/usr/local/www/status_captiveportal.php | 70 +++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'src/usr/local/www/status_captiveportal.php') diff --git a/src/usr/local/www/status_captiveportal.php b/src/usr/local/www/status_captiveportal.php index 9e2e177..b4c702d 100644 --- a/src/usr/local/www/status_captiveportal.php +++ b/src/usr/local/www/status_captiveportal.php @@ -36,6 +36,56 @@ require_once("filter.inc"); require_once("shaper.inc"); require_once("captiveportal.inc"); +function print_details($cpent) { + global $config, $cpzone, $cpzoneid; + + printf("", convert_seconds_to_dhms($session_time)); + + /* print the time left before session timeout or session terminate time or the closer of the two if both are set */ + if (!empty($cpent[7]) && !empty($cpent[9])) { + $session_time_left = min($cpent[0] + $cpent[7] - time(),$cpent[9] - time()); + printf(gettext("Session time left: %s") . "
", convert_seconds_to_dhms($session_time_left)); + } elseif (!empty($cpent[7]) && empty($cpent[9])) { + $session_time_left = $cpent[0] + $cpent[7] - time(); + printf(gettext("Session time left: %s") . "
", convert_seconds_to_dhms($session_time_left)); + } elseif (empty($cpent[7]) && !empty($cpent[9])) { + $session_time_left = $cpent[9] - time(); + printf(gettext("Session time left: %s") . "
", convert_seconds_to_dhms($session_time_left)); + } + + /* print idle time and time left before disconnection if idle timeout is set */ + if ($_GET['showact']) { + $last_act = captiveportal_get_last_activity($cpent[2], $cpent[3]); + + /* if the user never sent traffic, set last activity time to the login time */ + $last_act = $last_act ? $last_act : $cpent[0]; + + $idle_time = time() - $last_act; + printf(gettext("Idle time: %s") . "
", convert_seconds_to_dhms($idle_time)); + + if (!empty($cpent[8])) { + $idle_time_left = $last_act + $cpent[8] - time(); + printf(gettext("Idle time left: %s") . "
", convert_seconds_to_dhms($idle_time_left)); + } + } + + /* print bytes sent and received, invert the values if reverse accounting is enabled */ + $volume = getVolume($cpent[2], $cpent[3]); + $reverse = isset($config['captiveportal'][$cpzone]['reverseacct']) ? true : false; + if ($reverse) { + printf(gettext("Bytes sent: %s") . "
" . gettext("Bytes received: %s") . "\" data-html=\"true\">", format_bytes($volume['output_bytes']), format_bytes($volume['input_bytes'])); + } else { + printf(gettext("Bytes sent: %s") . "
" . gettext("Bytes received: %s") . "\" data-html=\"true\">", format_bytes($volume['input_bytes']), format_bytes($volume['output_bytes'])); + } + + /* print username */ + printf("%s
", htmlspecialchars($cpent[4])); +} + $cpzone = $_GET['zone']; if (isset($_POST['zone'])) { $cpzone = $_POST['zone']; @@ -66,12 +116,11 @@ if ($_GET['act'] == "del" && !empty($cpzone) && isset($cpzoneid) && isset($_GET[ exit; } -if (!empty($cpzone)) { - $cpdb = captiveportal_read_db(); -} $pgtitle = array(gettext("Status"), gettext("Captive Portal")); if (!empty($cpzone)) { + $cpdb = captiveportal_read_db(); + $pgtitle[] = htmlspecialchars($a_cp[$cpzone]['zone']); if (isset($config['voucher'][$cpzone]['enable'])) { @@ -151,7 +200,7 @@ if (!empty($cpzone)): ?> foreach ($cpdb as $cpent): ?> - + @@ -165,21 +214,22 @@ if (!empty($cpzone)): ?> print "
" . htmlspecialchars($mac_man[$mac_hi]) . ""; } } -?>   +?> - + + $last_act = captiveportal_get_last_activity($cpent[2], $cpent[3]); + /* if the user never sent traffic, set last activity time to the login time */ + $last_act = $last_act ? $last_act : $cpent[0]; +?>