From 2777cb880aa738d0efcc6d4c0b1d6483cdcede6a Mon Sep 17 00:00:00 2001 From: Filippo Date: Wed, 3 Jul 2024 14:27:21 +0200 Subject: [PATCH] Improved accounting features and minor fixes (#539) * Update README.md Clarification on which database should be used as backend * Updated accounting features --- README.md | 2 +- app/common/includes/layout.php | 16 +- app/common/includes/validation.php | 60 +++-- app/common/includes/version.php | 6 +- app/operators/acct-active.php | 86 +++--- app/operators/acct-all.php | 149 +++++++---- app/operators/acct-custom-query.php | 252 ++++++++++++------ app/operators/acct-custom.php | 23 +- app/operators/acct-date.php | 159 ++++++----- app/operators/acct-hotspot-accounting.php | 124 ++++++--- app/operators/acct-ipaddress.php | 131 ++++++--- app/operators/acct-nasipaddress.php | 129 ++++++--- app/operators/acct-username.php | 129 +++++---- .../include/management/functions.php | 11 + .../include/management/pages_common.php | 86 +++--- .../include/management/pages_numbering.php | 23 +- .../include/menu/sidebar/acct/custom.php | 8 +- app/operators/lang/en.php | 22 +- app/operators/mng-del.php | 84 +++--- app/operators/mng-rad-attributes-search.php | 6 +- 20 files changed, 940 insertions(+), 566 deletions(-) diff --git a/README.md b/README.md index 82434c502..8f64ceb50 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **daloRADIUS** is an advanced RADIUS web management application for managing hotspots and general-purpose ISP deployments. It features user management, graphical reporting, accounting, a billing engine, and integrates with [OpenStreetMap](https://www.openstreetmap.org/copyright) for geolocation. The system is based on [FreeRADIUS](https://freeradius.org/) with which it shares access to the backend database. -**daloRADIUS** is written using the [PHP programming language](https://www.php.net/) and uses a [database abstraction layer](https://en.wikipedia.org/wiki/Database_abstraction_layer) (DAL) for database access. Although DAL allows the use of different [database management systems](https://en.wikipedia.org/wiki/Database#Database_management_system) (DBMSs) (e.g. MariaDB, MySQL, PostgreSQL, SQLite, MsSQL, etc.), daloRADIUS has been mainly tested on the [MariaDB](https://mariadb.org/) DBMS. +**daloRADIUS** is written using the [PHP programming language](https://www.php.net/) and uses a [database abstraction layer](https://en.wikipedia.org/wiki/Database_abstraction_layer) (DAL) for database access. Although DAL allows the use of different [database management systems](https://en.wikipedia.org/wiki/Database#Database_management_system) (DBMSs) (e.g., MariaDB, MySQL, PostgreSQL, SQLite, MsSQL, etc.), **it is important to note that daloRADIUS has been fully tested only on the [MariaDB](https://mariadb.org/) DBMS**. Therefore, **the use of other DBMSs is not recommended**. ## Installation ### quick installation diff --git a/app/common/includes/layout.php b/app/common/includes/layout.php index 6867b2398..0e9ddc975 100644 --- a/app/common/includes/layout.php +++ b/app/common/includes/layout.php @@ -442,10 +442,11 @@ function print_checkbox($descriptor) { // - center => contains the page numbering controls // - end => contains additional controls (CSV export) function print_table_prologue($descriptors) { - echo '
'; + echo '
'; + echo '
'; if (isset($descriptors['start']) && is_array($descriptors['start'])) { - echo '
'; + $start = $descriptors['start']; if (isset($start['common_controls'])) { @@ -455,24 +456,25 @@ function print_table_prologue($descriptors) { if (isset($start['additional_controls']) && is_array($start['additional_controls'])) { print_additional_controls($start['additional_controls']); } - echo '
'; + } + echo '
'; + echo '
'; if (isset($descriptors['center']) && is_array($descriptors['center'])) { $center = $descriptors['center']; if (isset($center['draw']) && $center['draw']) { - echo '
'; print_page_numbering($center['params']); - echo '
'; } } + echo '
'; + echo '
'; if (isset($descriptors['end']) && is_array($descriptors['end'])) { - echo '
'; print_additional_controls($descriptors['end']); - echo '
'; } + echo '
'; echo '
'; } diff --git a/app/common/includes/validation.php b/app/common/includes/validation.php index 3c28f5113..7c0be9d26 100644 --- a/app/common/includes/validation.php +++ b/app/common/includes/validation.php @@ -137,37 +137,41 @@ // accounting custom-query options list $acct_custom_query_options_all = array( - "RadAcctId", - "AcctSessionId", - "AcctUniqueId", - "UserName", - "Realm", - "NASIPAddress", - "NASPortId", - "NASPortType", - "AcctStartTime", - "AcctStopTime", - "AcctSessionTime", - "AcctAuthentic", - "ConnectInfo_start", - "ConnectInfo_stop", - "AcctInputOctets", - "AcctOutputOctets", - "CalledStationId", - "CallingStationId", - "AcctTerminateCause", - "ServiceType", - "FramedProtocol", - "FramedIPAddress", - "AcctStartDelay", - "AcctStopDelay" - ); + "radacctid", + "acctsessionid", + "acctuniqueid", + "username", + "realm", + "nasipaddress", + "nasportid", + "nasporttype", + "acctstarttime", + "acctupdatetime", + "acctstoptime", + "acctinterval", + "acctsessiontime", + "acctauthentic", + "connectinfo_start", + "connectinfo_stop", + "acctinputoctets", + "acctoutputoctets", + "calledstationid", + "callingstationid", + "acctterminatecause", + "servicetype", + "framedprotocol", + "framedipaddress", + "framedipv6address", + "framedipv6prefix", + "framedinterfaceid", + "delegatedipv6prefix", + ); // accounting custom-query options selected by default $acct_custom_query_options_default = array( - "UserName", "Realm", "NASIPAddress", "AcctStartTime", "AcctStopTime", - "AcctSessionTime", "AcctInputOctets", "AcctOutputOctets", "CalledStationId", - "CallingStationId", "AcctTerminateCause", "FramedIPAddress" + "username", "nasipaddress", "acctstarttime", "acctstoptime", + "acctsessiontime", "acctinputoctets", "acctoutputoctets", "calledstationid", + "callingstationid", "acctterminatecause", "framedipaddress" ); // billing history query options list diff --git a/app/common/includes/version.php b/app/common/includes/version.php index 7541616b1..29e08f8e6 100644 --- a/app/common/includes/version.php +++ b/app/common/includes/version.php @@ -17,7 +17,7 @@ * * Description: daloRADIUS Version File * - * Modification Date: Thu Apr 18 17:00:00 CET 2024 + * Modification Date: Wed Jul 03 14:00:00 CET 2024 * ********************************************************************************************************* */ @@ -28,5 +28,5 @@ exit; } -$configValues['DALORADIUS_VERSION'] = '2.1 beta'; -$configValues['DALORADIUS_DATE'] = '18 Apr 2024'; +$configValues['DALORADIUS_VERSION'] = '2.2 beta'; +$configValues['DALORADIUS_DATE'] = '03 Jul 2024'; diff --git a/app/operators/acct-active.php b/app/operators/acct-active.php index d27e6446d..75f8b0511 100644 --- a/app/operators/acct-active.php +++ b/app/operators/acct-active.php @@ -21,15 +21,14 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); // validate this parameter before including menu $username = (array_key_exists('username', $_GET) && isset($_GET['username'])) @@ -89,27 +88,26 @@ print_title_and_help($title, $help); - include('../common/includes/db_open.php'); - include('library/datediff.php'); - include('include/management/pages_common.php'); - + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'datediff.php' ]); + $currdate = date("j M Y"); //orig: used as maethod to get total rows - this is required for the pages_numbering.php page - $sql = sprintf("SELECT DISTINCT(ra.username) AS username, rc.attribute AS attribute, rc.Value AS maxtimeexpiration, + $sql = sprintf("SELECT DISTINCT(ra.username) AS username, rc.attribute AS attribute, rc.value AS maxtimeexpiration, SUM(ra.AcctSessionTime) AS usedtime FROM %s AS ra, %s AS rc - WHERE ra.username=rc.username AND (rc.Attribute = 'Max-All-Session' OR rc.Attribute='Expiration') + WHERE ra.username=rc.username AND rc.attribute IN ('Max-All-Session', 'Expiration') GROUP BY ra.username", $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_RADCHECK']); $res = $dbSocket->query($sql); $numrows = $res->numRows(); if ($numrows > 0) { - /* START - Related to pages_numbering.php */ - // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; @@ -152,36 +150,27 @@ list($username, $attribute, $maxtimeexpiration, $usedtime) = $row; - - $status = "Active"; - - if ($attribute == "Expiration") { - if (datediff('d', $maxtimeexpiration, $currdate, false) > 0) { - $status = "Expired"; - } - } else if ($attribute == "Max-All-Session") { - if ($usedtime >= $maxtimeexpiration) { - $status = "End"; - } - } - - $usedtime = time2str($usedtime); - - $usage = ""; if ($attribute == "Expiration") { - $difference = datediff('d', $maxtimeexpiration, $currdate, false); - if ($difference > 0) { - $usage = " " . " $difference days since expired" . " "; + $datediff = datediff('d', $maxtimeexpiration, $currdate, false); + if ($datediff > 0) { + $status = 'Expired'; + $usage = sprintf('%s day(s) since expiration', $datediff); } else { - $usage = substr($difference, 1) . " days until expiration"; + $status = 'Active'; + $usage = sprintf('%s day(s) until expiration', abs($datediff)); } - } else if ($attribute == "Max-All-Session") { - if ($status == "End") { - $usage = " " . abs($maxtimeexpiration - $usedtime) . " seconds overdue credit" . ""; + } elseif ($attribute == "Max-All-Session") { + $time_left = abs($maxtimeexpiration - $usedtime); + $time_left_str = time2str($time_left, true); + + if ($usedtime >= $maxtimeexpiration) { + $status = 'Ended'; + $usage = sprintf('credit overdue: %s', $time_left_str); } else { - $usage = abs($maxtimeexpiration - $usedtime) . " left on credit"; + $status = 'Active'; + $usage = sprintf('credit left: %s', $time_left_str); } - } + } $ajax_id = "divContainerUserInfo_" . $count; $param = sprintf('username=%s', urlencode($username)); @@ -196,7 +185,7 @@ $tooltip = get_tooltip_list_str($tooltip); - $table_row = array( $tooltip, $attribute, $maxtimeexpiration, $usedtime, $status, $usage ); + $table_row = array( $tooltip, $attribute, $maxtimeexpiration, time2str($usedtime, true), $status, $usage ); // print table row print_table_row($table_row); @@ -211,7 +200,7 @@ 'colspan' => $colspan, 'multiple_pages' => $drawNumberLinks ); - $descriptor = array( 'table_foot' => $table_foot ); + $descriptor = array( 'table_foot' => $table_foot ); print_table_bottom($descriptor); @@ -223,11 +212,8 @@ $failureMsg = "Nothing to display"; } - include_once("include/management/actionMessages.php"); - - include('../common/includes/db_close.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); - include('include/config/logging.php'); - + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> diff --git a/app/operators/acct-all.php b/app/operators/acct-all.php index d4612abc7..9778596af 100644 --- a/app/operators/acct-all.php +++ b/app/operators/acct-all.php @@ -21,15 +21,15 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); // init logging variables $log = "visited page: "; @@ -58,7 +58,7 @@ $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) - ? strtolower($_GET['orderType']) : "asc"; + ? strtolower($_GET['orderType']) : "desc"; // print HTML prologue $extra_js = array( @@ -72,17 +72,16 @@ print_html_prologue($title, $langCode, array(), $extra_js); print_title_and_help($title, $help); - - include('../common/includes/db_open.php'); - include_once('include/management/pages_common.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); // setup php session variables for exporting $_SESSION['reportTable'] = $configValues['CONFIG_DB_TBL_RADACCT']; $_SESSION['reportQuery'] = ""; $_SESSION['reportType'] = "accountingGeneric"; - $sql = sprintf("SELECT COUNT(radacctid) FROM %s", $configValues['CONFIG_DB_TBL_RADACCT']); + $sql = sprintf("SELECT COUNT(`radacctid`) FROM %s", $configValues['CONFIG_DB_TBL_RADACCT']); $res = $dbSocket->query($sql); $logDebugSQL .= "$sql;\n"; @@ -93,18 +92,30 @@ /* START - Related to pages_numbering.php */ // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); + // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; - $sql = sprintf("SELECT ra.RadAcctId, dhs.name AS hotspot, ra.username, ra.FramedIPAddress, ra.AcctStartTime, - ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, - ra.AcctTerminateCause, ra.NASIPAddress - FROM %s AS ra LEFT JOIN %s AS dhs ON ra.calledstationid=dhs.mac", - $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']) - . sprintf(" ORDER BY %s %s LIMIT %s, %s", $orderBy, $orderType, $offset, $rowsPerPage); + $sql = sprintf( + "SELECT ra.RadAcctId, dhs.name AS hotspot, ra.username, ra.FramedIPAddress, ra.AcctStartTime, + ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, + ra.NASIPAddress + FROM %s AS ra + LEFT JOIN %s AS dhs ON ra.calledstationid = dhs.mac + ORDER BY %s %s + LIMIT %d, %d", + $configValues['CONFIG_DB_TBL_RADACCT'], + $configValues['CONFIG_DB_TBL_DALOHOTSPOTS'], + $orderBy, + $orderType, + $offset, + $rowsPerPage + ); $res = $dbSocket->query($sql); $logDebugSQL .= "$sql;\n"; @@ -131,7 +142,7 @@ print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top(['class' => 'table-sm']); // second line of table header printTableHead($cols, $orderBy, $orderType); @@ -152,40 +163,85 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = time2str($acctSessionTime); + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - $ajax_id = "divContainerHotspotInfo_" . $count; - $param = sprintf('hotspot=%s', urlencode($hotspot)); - $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; - $tooltip1 = array( + if (hotspots_exists($dbSocket, $hotspot)) { + $ajax_id = "divContainerHotspotInfo_" . $count; + $param = sprintf('hotspot=%s', urlencode($hotspot)); + $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; + + $tooltip1 = [ 'subject' => $hotspot, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); - + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + + $tooltip1 = get_tooltip_list_str($tooltip1); + } else { + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; + } + + if (!empty($username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $tooltip2 = array( + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); - - $tooltip1 = get_tooltip_list_str($tooltip1); - $tooltip2 = get_tooltip_list_str($tooltip2); + ]; + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADACCT')) { + $tooltip2['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($username), ), + 'label' => t('button','UserAccounting'), ]; + } + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADCHECK')) { + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = "(n/a)"; + } + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } + // define table row - $table_row = array( $radAcctId, $tooltip1, $tooltip2, $framedIPAddress, $acctStartTime, $acctStopTime, - $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -215,11 +271,8 @@ $failureMsg = "Nothing to display"; } - include_once("include/management/actionMessages.php"); - - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> diff --git a/app/operators/acct-custom-query.php b/app/operators/acct-custom-query.php index fabe476f5..03abfa055 100644 --- a/app/operators/acct-custom-query.php +++ b/app/operators/acct-custom-query.php @@ -21,15 +21,15 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); // init logging variables $log = "visited page: "; @@ -42,17 +42,17 @@ $sqlfields = (array_key_exists('sqlfields', $_GET) && !empty($_GET['sqlfields']) && is_array($_GET['sqlfields']) && array_intersect($_GET['sqlfields'], $acct_custom_query_options_all) == $_GET['sqlfields']) ? $_GET['sqlfields'] : $acct_custom_query_options_default; - - $cols = array(); + + $cols = []; foreach ($sqlfields as $sqlfield) { $cols[$sqlfield] = $sqlfield; } $colspan = count($cols); $half_colspan = intval($colspan / 2); - + $orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) && - in_array($_GET['orderBy'], array_keys($acct_custom_query_options_all))) - ? $_GET['orderBy'] : array_keys($acct_custom_query_options_all)[0]; + in_array($_GET['orderBy'], $acct_custom_query_options_all)) + ? $_GET['orderBy'] : $acct_custom_query_options_all[0]; $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) @@ -67,70 +67,65 @@ preg_match(DATE_REGEX, $_GET['enddate'], $m) !== false && checkdate($m[2], $m[3], $m[1])) ? $_GET['enddate'] : ""; - + $valid_operators = array("equals" => "=", "contains" => "LIKE"); - $operator = (array_key_exists('operator', $_GET) && !empty($_GET['operator']) && - in_array($_GET['operator'], array_keys($valid_operators))) - ? $_GET['operator'] : ""; - + $where_operator = (array_key_exists('where_operator', $_GET) && !empty($_GET['where_operator']) && + in_array($_GET['where_operator'], array_keys($valid_operators))) + ? $_GET['where_operator'] : ""; + $where_field = (array_key_exists('where_field', $_GET) && !empty($_GET['where_field']) && in_array($_GET['where_field'], $acct_custom_query_options_all)) ? $_GET['where_field'] : ""; - + $where_value = (array_key_exists('where_value', $_GET) && !empty(str_replace("%", "", trim($_GET['where_value'])))) ? str_replace("%", "", trim($_GET['where_value'])) : ""; $where_value_enc = (!empty($where_value)) ? htmlspecialchars($where_value, ENT_QUOTES, 'UTF-8') : ""; - + //feed the sidebar variables $accounting_custom_startdate = $startdate; $accounting_custom_enddate = $enddate; $accounting_custom_value = $where_value_enc; - // print HTML prologue - $extra_js = array( - "static/js/ajax.js", - "static/js/ajaxGeneric.js" - ); - + $extra_js = [ "static/js/ajax.js", "static/js/ajaxGeneric.js", ]; + $title = t('Intro','acctcustomquery.php'); $help = t('helpPage','acctcustomquery'); - - print_html_prologue($title, $langCode, array(), $extra_js); - + + print_html_prologue($title, $langCode, [], $extra_js); print_title_and_help($title, $help); - - include('../common/includes/db_open.php'); - include('include/management/pages_common.php'); - + + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); + // preparing the custom query - - $sql_WHERE = array(); - $partial_query_string_pieces = array(); - + + $sql_WHERE = []; + $partial_query_string_pieces = []; + foreach ($sqlfields as $sqlfield) { $partial_query_string_pieces[] = sprintf("sqlfields[]=%s", $sqlfield); } - + if (!empty($startdate)) { - $sql_WHERE[] = sprintf("AcctStartTime > '%s'", $dbSocket->escapeSimple($startdate)); + $sql_WHERE[] = sprintf("acctstarttime > '%s'", $dbSocket->escapeSimple($startdate)); $partial_query_string_pieces[] = sprintf("startdate=%s", $startdate); } - - if (!empty($startdate)) { - $sql_WHERE[] = sprintf("AcctStartTime < '%s'", $dbSocket->escapeSimple($enddate)); + + if (!empty($enddate)) { + $sql_WHERE[] = sprintf("acctstarttime < '%s'", $dbSocket->escapeSimple($enddate)); $partial_query_string_pieces[] = sprintf("enddate=%s", $enddate); } - + if (!empty($where_value)) { // get the operator - $op = $valid_operators[$operator]; - + $op = $valid_operators[$where_operator]; + // if the op is LIKE then the SQL syntax uses % for pattern matching // and we sorround the $value with % as a wildcard $where_value = $dbSocket->escapeSimple($where_value); - + if ($op == "LIKE") { $where_value = "%" . $where_value . "%"; } @@ -138,64 +133,64 @@ $sql_WHERE[] = sprintf("%s %s '%s'", $where_field, $op, $where_value); $partial_query_string_pieces[] = sprintf("where_field=%s", $where_field); - $partial_query_string_pieces[] = sprintf("operator=%s", $operator); + $partial_query_string_pieces[] = sprintf("operator=%s", $where_operator); $partial_query_string_pieces[] = sprintf("where_value=%s", $where_value_enc); } // executing the custom query - $sql = sprintf("SELECT %s FROM %s", implode(", ", $sqlfields), $configValues['CONFIG_DB_TBL_RADACCT']); - + $sql = sprintf("SELECT `%s` FROM %s", implode("`, `", $sqlfields), $configValues['CONFIG_DB_TBL_RADACCT']); + if (count($sql_WHERE) > 0) { $sql .= " WHERE " . implode(" AND ", $sql_WHERE); } $res = $dbSocket->query($sql); $logDebugSQL .= "$sql;\n"; - + $numrows = $res->numRows(); - + if ($numrows > 0) { - /* START - Related to pages_numbering.php */ - // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file - + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); + // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; - + $sql .= sprintf(" ORDER BY %s %s LIMIT %s, %s", $orderBy, $orderType, $offset, $rowsPerPage); + $res = $dbSocket->query($sql); $logDebugSQL .= "$sql;\n"; - + $per_page_numrows = $res->numRows(); - + // the partial query is built starting from user input // and for being passed to setupNumbering and setupLinks functions $partial_query_string = (count($partial_query_string_pieces) > 0) ? "&" . implode("&", $partial_query_string_pieces) : ""; + $descriptors = []; - $descriptors = array(); - - $params = array( - 'num_rows' => $numrows, - 'rows_per_page' => $rowsPerPage, - 'page_num' => $pageNum, - 'order_by' => $orderBy, - 'order_type' => $orderType, - ); - $descriptors['center'] = array( 'draw' => $drawNumberLinks, 'params' => $params ); + $params = [ + 'num_rows' => $numrows, + 'rows_per_page' => $rowsPerPage, + 'page_num' => $pageNum, + 'order_by' => $orderBy, + 'order_type' => $orderType, + 'partial_query_string' => $partial_query_string, + ]; + $descriptors['center'] = [ 'draw' => $drawNumberLinks, 'params' => $params ]; print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top(['class' => 'table-sm']); // second line of table header printTableHead($cols, $orderBy, $orderType, $partial_query_string); - + // closes table header, opens table body print_table_middle(); @@ -204,7 +199,97 @@ while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) { printf('', $count); foreach ($sqlfields as $field) { - printf("%s", htmlspecialchars($row[$field], ENT_QUOTES, 'UTF-8')); + + switch (strtolower($field)) { + case 'acctinputoctets': + case 'acctoutputoctets': + $value = toxbyte($row[$field]); + break; + + case 'acctsessiontime': + $value = time2str($row[$field], true); + break; + + case 'acctterminatecause': + $value = ($row[$field] == "0") ? 'Unknown' : htmlspecialchars($row[$field], ENT_QUOTES, 'UTF-8'); + break; + + case 'username': + if (!empty($row[$field])) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($row[$field])); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; + + $value = [ + 'subject' => $row[$field], + 'onclick' => $onclick, + 'ajax_id' => $ajax_id, + 'actions' => [], + ]; + + $value['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($row[$field]), ), + 'label' => t('button','UserAccounting'), ]; + + if (user_exists($dbSocket, $row[$field], 'CONFIG_DB_TBL_RADCHECK')) { + $value['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($row[$field]), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $value = get_tooltip_list_str($value); + } else { + $value = "(n/a)"; + } + break; + + case 'realm': + case 'nasipaddress': + case 'nasporttype': + case 'calledstationid': + case 'callingstationid': + case 'servicetype': + case 'framedipaddress': + case 'framedipv6address': + + if (!empty($row[$field])) { + $filtered_query_string_pieces = []; + + foreach ($partial_query_string_pieces as $query_piece) { + if (!preg_match('/^where_/', $query_piece)) { + $filtered_query_string_pieces[] = $query_piece; + } + } + + $filtered_query_string_pieces[] = sprintf("where_field=%s", $field); + $filtered_query_string_pieces[] = + sprintf("where_value=%s", urlencode(htmlspecialchars($row[$field], ENT_QUOTES, 'UTF-8'))); + + $value = [ + 'subject' => $row[$field], + 'actions' => [] + ]; + + foreach (array_keys($valid_operators) as $valid_operator) { + $query_string_with_operator = $filtered_query_string_pieces; + $query_string_with_operator[] = sprintf("where_operator=%s", $valid_operator); + $query_string = (count($query_string_with_operator) > 0) ? "&" . implode("&", $query_string_with_operator) : ""; + $href = get_link_href($query_string, $pageNum, $orderBy, $orderType); + $value['actions'][] = [ 'href' => $href, 'label' => $valid_operator ]; + } + + $value = get_tooltip_list_str($value); + } else { + $value = (!empty($row[$field])) ? $row[$field] : "(n/a)"; + } + break; + + + default: + $value = htmlspecialchars($row[$field], ENT_QUOTES, 'UTF-8'); + break; + + } + + printf("%s", $value); } echo ''; $count++; @@ -213,15 +298,13 @@ // close tbody, // print tfoot // and close table + form (if any) - $table_foot = array( - 'num_rows' => $numrows, - 'rows_per_page' => $per_page_numrows, - 'colspan' => $colspan, - 'multiple_pages' => $drawNumberLinks - ); - $descriptor = array( 'table_foot' => $table_foot ); - - print_table_bottom($descriptor); + $table_foot = [ + 'num_rows' => $numrows, + 'rows_per_page' => $per_page_numrows, + 'colspan' => $colspan, + 'multiple_pages' => $drawNumberLinks + ]; + print_table_bottom([ 'table_foot' => $table_foot ]); // get and print "links" $links = setupLinks_str($pageNum, $maxPage, $orderBy, $orderType, $partial_query_string); @@ -229,12 +312,9 @@ } else { $failureMsg = "Nothing to display"; - include_once("include/management/actionMessages.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); } - - include('../common/includes/db_close.php'); - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); - -?> diff --git a/app/operators/acct-custom.php b/app/operators/acct-custom.php index 1aefc954b..63eff275f 100644 --- a/app/operators/acct-custom.php +++ b/app/operators/acct-custom.php @@ -21,27 +21,22 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include_once('../common/includes/config_read.php'); - $log = "visited page: "; + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + $log = "visited page: "; // print HTML prologue $title = t('Intro','acctcustom.php'); $help = t('helpPage','acctcustom'); - - print_html_prologue($title, $langCode); - - - + print_html_prologue($title, $langCode); print_title_and_help($title, $help); - - include('include/config/logging.php'); + + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> diff --git a/app/operators/acct-date.php b/app/operators/acct-date.php index be3b6e9ee..e76ef4aa5 100644 --- a/app/operators/acct-date.php +++ b/app/operators/acct-date.php @@ -21,15 +21,15 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); // validate this parameter before including menu $username = (array_key_exists('username', $_GET) && !empty(str_replace("%", "", trim($_GET['username'])))) @@ -47,28 +47,28 @@ ? trim($_GET['enddate']) : ""; $cols = array( - "radacctid" => t('all','ID'), - "hotspot" => t('all','HotSpot'), - "nasipaddress" => t('all','NASIPAddress'), - "username" => t('all','Username'), - "framedipaddress" => t('all','IPAddress'), - "acctstarttime" => t('all','StartTime'), - "acctstoptime" => t('all','StopTime'), - "acctsessiontime" => t('all','TotalTime'), - "acctinputoctets" => t('all','Upload'), - "acctoutputoctets" => t('all','Download'), - "acctterminatecause" => t('all','Termination'), - ); + "radacctid" => t('all','ID'), + "name" => t('all','HotSpot'), + "username" => t('all','Username'), + "framedipaddress" => t('all','IPAddress'), + "acctstarttime" => t('all','StartTime'), + "acctstoptime" => t('all','StopTime'), + "acctsessiontime" => t('all','TotalTime'), + "acctinputoctets" => t('all','Upload'), + "acctoutputoctets" => t('all','Download'), + "acctterminatecause" => t('all','Termination'), + "nasipaddress" => t('all','NASIPAddress'), + ); $colspan = count($cols); $half_colspan = intval($colspan / 2); - $orderBy = (array_key_exists('orderBy', $_GET) && !empty($_GET['orderBy']) && + $orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) && in_array($_GET['orderBy'], array_keys($cols))) ? $_GET['orderBy'] : array_keys($cols)[0]; - $orderType = (array_key_exists('orderType', $_GET) && !empty($_GET['orderType']) && + $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) - ? strtolower($_GET['orderType']) : "asc"; + ? strtolower($_GET['orderType']) : "desc"; // init logging variables $log = "visited page: "; @@ -91,8 +91,8 @@ print_title_and_help($title, $help); // we can only use the $dbSocket after we have included '../common/includes/db_open.php' which initialzes the connection and the $dbSocket object - include('../common/includes/db_open.php'); - include('include/management/pages_common.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); $sql_WHERE = array(); $partial_query_params = array(); @@ -127,18 +127,18 @@ $numrows = $res->fetchrow()[0]; if ($numrows > 0) { - /* START - Related to pages_numbering.php */ - // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; $sql = sprintf("SELECT ra.RadAcctId, dhs.name AS hotspot, ra.username, ra.FramedIPAddress, ra.AcctStartTime, ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, - ra.AcctTerminateCause, ra.NASIPAddress + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, + ra.NASIPAddress FROM %s AS ra LEFT JOIN %s AS dhs ON ra.calledstationid=dhs.mac", $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']); if (count($sql_WHERE) > 0) { @@ -176,7 +176,7 @@ print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top(['class' => 'table-sm']); // second line of table header printTableHead($cols, $orderBy, $orderType, $partial_query_string); @@ -197,50 +197,85 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = intval($acctSessionTime); - if ($acctSessionTime === 0) { - $acctSessionTime = "(n/d)"; - } else { - $acctSessionTime = time2str($acctSessionTime); - } - + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - if (!empty($hotspot)) { + if (hotspots_exists($dbSocket, $hotspot)) { $ajax_id = "divContainerHotspotInfo_" . $count; $param = sprintf('hotspot=%s', urlencode($hotspot)); $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; - $tooltip1 = array( - 'subject' => $hotspot, - 'onclick' => $onclick, - 'ajax_id' => $ajax_id, - 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); - + + $tooltip1 = [ + 'subject' => $hotspot, + 'onclick' => $onclick, + 'ajax_id' => $ajax_id, + 'actions' => array(), + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + $tooltip1 = get_tooltip_list_str($tooltip1); } else { - $tooltip1 = "(n/a)"; + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; } - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $tooltip2 = array( + if (!empty($username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; + + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); + ]; + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADACCT')) { + $tooltip2['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($username), ), + 'label' => t('button','UserAccounting'), ]; + } + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADCHECK')) { + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = "(n/a)"; + } - $tooltip2 = get_tooltip_list_str($tooltip2); + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } // define table row - $table_row = array( $radAcctId, $tooltip1, $nasIPAddress, $tooltip2, $framedIPAddress, $acctStartTime, - $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -287,10 +322,8 @@ $failureMsg = "Please specify a valid username"; } - include_once("include/management/actionMessages.php"); - - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> + diff --git a/app/operators/acct-hotspot-accounting.php b/app/operators/acct-hotspot-accounting.php index 305dac415..d655813ce 100644 --- a/app/operators/acct-hotspot-accounting.php +++ b/app/operators/acct-hotspot-accounting.php @@ -21,14 +21,15 @@ ********************************************************************************************************* */ - include ("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); $hotspot = array(); if (isset($_GET['hotspot']) && !empty($_GET['hotspot'])) { @@ -112,8 +113,8 @@ print_title_and_help($title, $help); - include('../common/includes/db_open.php'); - include('include/management/pages_common.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); $tmp = array(); if (count($hotspot) > 0) { @@ -134,7 +135,8 @@ $sql = sprintf("SELECT ra.RadAcctId, dhs.name AS hotspot, ra.username, ra.FramedIPAddress, ra.AcctStartTime, ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, - ra.AcctTerminateCause, ra.NASIPAddress + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, + ra.NASIPAddress FROM %s AS ra LEFT JOIN %s AS dhs ON ra.calledstationid=dhs.mac", $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']) . $sql_WHERE; @@ -143,14 +145,15 @@ if ($numrows > 0) { /* START - Related to pages_numbering.php */ - + // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file - + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); + // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; - + /* END */ // we execute and log the actual query @@ -192,7 +195,7 @@ print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top([ 'class' => 'table-sm' ]); // second line of table header printTableHead($cols, $orderBy, $orderType, $partial_query_string); @@ -213,40 +216,85 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = time2str($acctSessionTime); + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - $ajax_id = "divContainerHotspotInfo_" . $count; - $param = sprintf('hotspot=%s', urlencode($hotspot)); - $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; - $tooltip1 = array( + if (hotspots_exists($dbSocket, $hotspot)) { + $ajax_id = "divContainerHotspotInfo_" . $count; + $param = sprintf('hotspot=%s', urlencode($hotspot)); + $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; + + $tooltip1 = [ 'subject' => $hotspot, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); - + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + + $tooltip1 = get_tooltip_list_str($tooltip1); + } else { + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; + } - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $tooltip2 = array( + if (!empty($username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; + + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); + ]; + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADACCT')) { + $tooltip2['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($username), ), + 'label' => t('button','UserAccounting'), ]; + } + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADCHECK')) { + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } - $tooltip1 = get_tooltip_list_str($tooltip1); - $tooltip2 = get_tooltip_list_str($tooltip2); + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } // define table row - $table_row = array( $radAcctId, $tooltip1, $tooltip2, $framedIPAddress, $acctStartTime, $acctStopTime, - $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -273,12 +321,10 @@ } else { $failureMsg = "Nothing to display"; - include_once("include/management/actionMessages.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); } - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> diff --git a/app/operators/acct-ipaddress.php b/app/operators/acct-ipaddress.php index 6d83d4b9a..5c6234b1a 100644 --- a/app/operators/acct-ipaddress.php +++ b/app/operators/acct-ipaddress.php @@ -21,15 +21,15 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); // validate this parameter before including menu $ipaddress = (array_key_exists('ipaddress', $_GET) && isset($_GET['ipaddress']) && @@ -59,12 +59,12 @@ // whenever possible we use a whitelist approach $orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) && - in_array($_GET['orderBy'], array_keys($param_cols))) - ? $_GET['orderBy'] : array_keys($param_cols)[0]; + in_array($_GET['orderBy'], array_keys($cols))) + ? $_GET['orderBy'] : array_keys($cols)[0]; $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && - in_array($_GET['orderType'], array( "desc", "asc" ))) - ? $_GET['orderType'] : "asc"; + preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) + ? strtolower($_GET['orderType']) : "desc"; // init logging variables $log = "visited page: "; @@ -88,8 +88,8 @@ // we can only use the $dbSocket after we have included '../common/includes/db_open.php' which initialzes the connection and the $dbSocket object - include('../common/includes/db_open.php'); - include('include/management/pages_common.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); $sql_WHERE = (!empty($ipaddress)) ? sprintf(" WHERE FramedIPAddress LIKE '%%%s%%'", $dbSocket->escapeSimple($ipaddress)) @@ -102,7 +102,7 @@ $sql = "SELECT ra.RadAcctId, dh.name AS hotspot, ra.UserName, ra.FramedIPAddress AS FramedIPAddress, ra.AcctStartTime, ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, - ra.AcctTerminateCause, ra.NASIPAddress + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, ra.NASIPAddress FROM %s AS ra LEFT JOIN %s AS dh ON ra.calledstationid=dh.mac"; $sql = sprintf($sql, $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']) . $sql_WHERE; @@ -113,11 +113,10 @@ $numrows = $res->numRows(); if ($numrows > 0) { - /* START - Related to pages_numbering.php */ - // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; @@ -156,7 +155,7 @@ print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top(['class' => 'table-sm']); // second line of table header printTableHead($cols, $orderBy, $orderType, $partial_query_string); @@ -177,40 +176,85 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = time2str($acctSessionTime); + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - $ajax_id = "divContainerHotspotInfo_" . $count; - $param = sprintf('hotspot=%s', urlencode($hotspot)); - $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; - $tooltip1 = array( + if (hotspots_exists($dbSocket, $hotspot)) { + $ajax_id = "divContainerHotspotInfo_" . $count; + $param = sprintf('hotspot=%s', urlencode($hotspot)); + $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; + + $tooltip1 = [ 'subject' => $hotspot, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); - + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + + $tooltip1 = get_tooltip_list_str($tooltip1); + } else { + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; + } + + if (!empty($username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $tooltip2 = array( + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); - - $tooltip1 = get_tooltip_list_str($tooltip1); - $tooltip2 = get_tooltip_list_str($tooltip2); + ]; + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADACCT')) { + $tooltip2['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($username), ), + 'label' => t('button','UserAccounting'), ]; + } + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADCHECK')) { + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = "(n/a)"; + } + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } + // define table row - $table_row = array( $radAcctId, $tooltip1, $tooltip2, $framedIPAddress, $acctStartTime, $acctStopTime, - $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -237,12 +281,11 @@ } else { $failureMsg = "Nothing to display"; - include_once("include/management/actionMessages.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); } - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> + diff --git a/app/operators/acct-nasipaddress.php b/app/operators/acct-nasipaddress.php index d134d4164..68ccbc4f3 100644 --- a/app/operators/acct-nasipaddress.php +++ b/app/operators/acct-nasipaddress.php @@ -21,15 +21,15 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); // validate this parameter before including menu $onlyactive = (array_key_exists('only-active', $_GET) && isset($_GET['only-active'])); @@ -62,11 +62,11 @@ // whenever possible we use a whitelist approach $orderBy = (array_key_exists('orderBy', $_GET) && isset($_GET['orderBy']) && - in_array($_GET['orderBy'], array_keys($param_cols))) - ? $_GET['orderBy'] : array_keys($param_cols)[0]; + in_array($_GET['orderBy'], array_keys($cols))) + ? $_GET['orderBy'] : array_keys($cols)[0]; $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && - in_array(strtolower($_GET['orderType']), array( "desc", "asc" ))) + preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) ? strtolower($_GET['orderType']) : "desc"; // init logging variables @@ -89,8 +89,8 @@ print_title_and_help($title, $help); // we can only use the $dbSocket after we have included '../common/includes/db_open.php' which initialzes the connection and the $dbSocket object - include('../common/includes/db_open.php'); - include('include/management/pages_common.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); $sql_WHERE = (!empty($nasipaddress)) ? sprintf(" WHERE NASIPAddress LIKE '%%%s%%'", $dbSocket->escapeSimple($nasipaddress)) @@ -102,7 +102,9 @@ $_SESSION['reportType'] = "accountingGeneric"; $sql = "SELECT ra.RadAcctId, dh.name as hotspot, ra.UserName, ra.FramedIPAddress, ra.AcctStartTime, ra.AcctStopTime, - ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, ra.AcctTerminateCause, ra.NASIPAddress + ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, + ra.NASIPAddress FROM %s AS ra LEFT JOIN %s AS dh ON ra.calledstationid=dh.mac"; $sql = sprintf($sql, $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']) . $sql_WHERE; @@ -113,8 +115,9 @@ /* START - Related to pages_numbering.php */ // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; @@ -153,7 +156,7 @@ print_table_prologue($descriptors); // print table top - print_table_top(); + print_table_top(['class' => 'table-sm']); // second line of table header printTableHead($cols, $orderBy, $orderType, $partial_query_string); @@ -174,40 +177,85 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = time2str($acctSessionTime); + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - $ajax_id = "divContainerHotspotInfo_" . $count; - $param = sprintf('hotspot=%s', urlencode($hotspot)); - $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; - $tooltip1 = array( + if (hotspots_exists($dbSocket, $hotspot)) { + $ajax_id = "divContainerHotspotInfo_" . $count; + $param = sprintf('hotspot=%s', urlencode($hotspot)); + $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; + + $tooltip1 = [ 'subject' => $hotspot, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); - + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + + $tooltip1 = get_tooltip_list_str($tooltip1); + } else { + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; + } + + if (!empty($username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; - $tooltip2 = array( + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); - - $tooltip1 = get_tooltip_list_str($tooltip1); - $tooltip2 = get_tooltip_list_str($tooltip2); + ]; + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADACCT')) { + $tooltip2['actions'][] = [ 'href' => sprintf('acct-username.php?username=%s', urlencode($username), ), + 'label' => t('button','UserAccounting'), ]; + } + if (user_exists($dbSocket, $username, 'CONFIG_DB_TBL_RADCHECK')) { + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + } + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } // define table row - $table_row = array( $radAcctId, $tooltip1, $tooltip2, $framedIPAddress, $acctStartTime, $acctStopTime, - $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -234,12 +282,11 @@ } else { $failureMsg = "Nothing to display"; - include_once("include/management/actionMessages.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); } - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); print_footer_and_html_epilogue(); -?> + diff --git a/app/operators/acct-username.php b/app/operators/acct-username.php index bbbdfe015..9688911ee 100644 --- a/app/operators/acct-username.php +++ b/app/operators/acct-username.php @@ -21,16 +21,16 @@ ********************************************************************************************************* */ - include("library/checklogin.php"); + include_once implode(DIRECTORY_SEPARATOR, [ __DIR__, '..', 'common', 'includes', 'config_read.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'checklogin.php' ]); $operator = $_SESSION['operator_user']; - - include('library/check_operator_perm.php'); - include_once('../common/includes/config_read.php'); - - include_once("lang/main.php"); - include("../common/includes/validation.php"); - include("../common/includes/layout.php"); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LIBRARY'], 'check_operator_perm.php' ]); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_LANG'], 'main.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'validation.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'layout.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'functions.php' ]); + // validate this parameter before including menu $username = (array_key_exists('username', $_GET) && !empty(str_replace("%", "", trim($_GET['username'])))) ? str_replace("%", "", trim($_GET['username'])) : ""; @@ -58,7 +58,7 @@ $orderType = (array_key_exists('orderType', $_GET) && isset($_GET['orderType']) && preg_match(ORDER_TYPE_REGEX, $_GET['orderType']) !== false) - ? strtolower($_GET['orderType']) : "asc"; + ? strtolower($_GET['orderType']) : "desc"; // init logging variables $log = "visited page: "; @@ -69,7 +69,6 @@ $logQuery .= "on page: "; $logDebugSQL = ""; - // print HTML prologue $extra_js = array( "static/js/pages_common.js", @@ -88,7 +87,8 @@ $sql_WHERE = ""; $partial_query_string = ""; if (!empty($username)) { - include('../common/includes/db_open.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_common.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_open.php' ]); $sql_WHERE = sprintf(" WHERE username='%s'", $dbSocket->escapeSimple($username)); $partial_query_string = sprintf("&username=%s", urlencode($username_enc)); @@ -98,10 +98,7 @@ $_SESSION['reportQuery'] = $sql_WHERE; $_SESSION['reportType'] = "accountingGeneric"; - - include_once('include/management/pages_common.php'); - - $sql = sprintf("SELECT COUNT(radacctid) FROM %s", $configValues['CONFIG_DB_TBL_RADACCT']) . $sql_WHERE; + $sql = sprintf("SELECT COUNT(`radacctid`) FROM %s", $configValues['CONFIG_DB_TBL_RADACCT']) . $sql_WHERE; $res = $dbSocket->query($sql); $logDebugSQL .= "$sql;\n"; @@ -109,18 +106,18 @@ if ($numrows > 0) { - /* START - Related to pages_numbering.php */ - // when $numrows is set, $maxPage is calculated inside this include file - include('include/management/pages_numbering.php'); // must be included after opendb because it needs to read - // the CONFIG_IFACE_TABLES_LISTING variable from the config file + // must be included after opendb because it needs to read + // the CONFIG_IFACE_TABLES_LISTING variable from the config file + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'pages_numbering.php' ]); // here we decide if page numbers should be shown $drawNumberLinks = strtolower($configValues['CONFIG_IFACE_TABLES_LISTING_NUM']) == "yes" && $maxPage > 1; $sql = sprintf("SELECT ra.RadAcctId, dhs.name AS hotspot, ra.username, ra.FramedIPAddress, ra.AcctStartTime, ra.AcctStopTime, ra.AcctSessionTime, ra.AcctInputOctets, ra.AcctOutputOctets, - ra.AcctTerminateCause, ra.NASIPAddress + CASE WHEN ra.AcctTerminateCause = '0' THEN 'Unknown' ELSE ra.AcctTerminateCause END AS AcctTerminateCause, + ra.NASIPAddress FROM %s AS ra LEFT JOIN %s AS dhs ON ra.calledstationid=dhs.mac", $configValues['CONFIG_DB_TBL_RADACCT'], $configValues['CONFIG_DB_TBL_DALOHOTSPOTS']) . $sql_WHERE @@ -172,44 +169,80 @@ list($radAcctId, $hotspot, $username, $framedIPAddress, $acctStartTime, $acctStopTime, $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress) = $row; - $acctSessionTime = time2str($acctSessionTime); + $acctSessionTime = time2str($acctSessionTime, true); $acctInputOctets = toxbyte($acctInputOctets); $acctOutputOctets = toxbyte($acctOutputOctets); - if (!empty($hotspot)) { - + if (hotspots_exists($dbSocket, $hotspot)) { $ajax_id = "divContainerHotspotInfo_" . $count; $param = sprintf('hotspot=%s', urlencode($hotspot)); - $onclick = sprintf("ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','%s','%s')", $ajax_id, $param); - $tooltip1 = array( - 'subject' => $hotspot, - 'onclick' => $onclick, - 'ajax_id' => $ajax_id, - 'actions' => array(), - ); - $tooltip1['actions'][] = array( 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), 'label' => t('Tooltip','HotspotEdit'), ); - $tooltip1['actions'][] = array( 'href' => 'acct-hotspot-compare.php', 'label' => t('all','Compare'), ); + $onclick = "ajaxGeneric('library/ajax/hotspot_info.php','retHotspotGeneralStat','$ajax_id','$param')"; + + $tooltip1 = [ + 'subject' => $hotspot, + 'onclick' => $onclick, + 'ajax_id' => $ajax_id, + 'actions' => array(), + ]; + $tooltip1['actions'][] = [ 'href' => sprintf('mng-hs-edit.php?name=%s', urlencode($hotspot), ), + 'label' => t('Tooltip','HotspotEdit'), ]; + $tooltip1['actions'][] = [ 'href' => 'acct-hotspot-compare.php', + 'label' => t('all','Compare'), ]; + $tooltip1 = get_tooltip_list_str($tooltip1); } else { - $tooltip1 = "(n/a)"; + $tooltip1 = (!empty($hotspot)) ? $hotspot : "(n/a)"; } - $ajax_id = "divContainerUserInfo_" . $count; - $param = sprintf('username=%s', urlencode($username)); - $onclick = sprintf("ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','%s','%s')", $ajax_id, $param); - $tooltip2 = array( + if (user_exists($dbSocket, $username)) { + $ajax_id = "divContainerUserInfo_" . $count; + $param = sprintf('username=%s', urlencode($username)); + $onclick = "ajaxGeneric('library/ajax/user_info.php','retBandwidthInfo','$ajax_id','$param')"; + + $tooltip2 = [ 'subject' => $username, 'onclick' => $onclick, 'ajax_id' => $ajax_id, 'actions' => array(), - ); - $tooltip2['actions'][] = array( 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), 'label' => t('Tooltip','UserEdit'), ); - - $tooltip2 = get_tooltip_list_str($tooltip2); + ]; + $tooltip2['actions'][] = [ 'href' => sprintf('mng-edit.php?username=%s', urlencode($username), ), + 'label' => t('Tooltip','UserEdit'), ]; + + + $tooltip2 = get_tooltip_list_str($tooltip2); + } else { + $tooltip2 = (!empty($username)) ? $username : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $framedIPAddress, $m) !== false) { + $tooltip3 = [ + 'subject' => $framedIPAddress, + 'actions' => array(), + ]; + $tooltip3['actions'][] = [ 'href' => sprintf('acct-ipaddress.php?ipaddress=%s', urlencode($framedIPAddress), ), + 'label' => t('button','IPAccounting'), ]; + + $tooltip3 = get_tooltip_list_str($tooltip3); + } else { + $tooltip3 = (!empty($framedIPAddress)) ? $framedIPAddress : "(n/a)"; + } + + if (preg_match(LOOSE_IP_REGEX, $nasIPAddress, $m) !== false) { + $tooltip4 = [ + 'subject' => $nasIPAddress, + 'actions' => array(), + ]; + $tooltip4['actions'][] = [ 'href' => sprintf('acct-nasipaddress.php?ipaddress=%s', urlencode($nasIPAddress), ), + 'label' => t('button','NASIPAccounting'), ]; + + $tooltip4 = get_tooltip_list_str($tooltip4); + } else { + $tooltip4 = (!empty($nasIPAddress)) ? $nasIPAddress : "(n/a)"; + } // define table row - $table_row = array( $radAcctId, $tooltip1, $tooltip2, $framedIPAddress, $acctStartTime, $acctStopTime, - $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $nasIPAddress); + $table_row = array( $radAcctId, $tooltip1, $tooltip2, $tooltip3, $acctStartTime, $acctStopTime, + $acctSessionTime, $acctInputOctets, $acctOutputOctets, $acctTerminateCause, $tooltip4); // print table row print_table_row($table_row); @@ -240,7 +273,7 @@ } echo '
'; - include_once('include/management/userReports.php'); + include_once implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'userReports.php' ]); userPlanInformation($username, 1); userSubscriptionAnalysis($username, 1); // userSubscriptionAnalysis with argument set to 1 for drawing the table userConnectionStatus($username, 1); // userConnectionStatus (same as above) @@ -250,11 +283,9 @@ $failureMsg = "Please specify a valid username"; } - include_once("include/management/actionMessages.php"); - - include('../common/includes/db_close.php'); - - include('include/config/logging.php'); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_MANAGEMENT'], 'actionMessages.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['COMMON_INCLUDES'], 'db_close.php' ]); + include implode(DIRECTORY_SEPARATOR, [ $configValues['OPERATORS_INCLUDE_CONFIG'], 'logging.php' ]); $inline_extra_js = "window.onload = function() { setupAccordion() };"; diff --git a/app/operators/include/management/functions.php b/app/operators/include/management/functions.php index ace2bb841..794f6a9a7 100644 --- a/app/operators/include/management/functions.php +++ b/app/operators/include/management/functions.php @@ -109,6 +109,17 @@ function insert_single_attribute($dbSocket, $subject, $attribute, $op, $value, $ return false; } +function hotspots_exists($dbSocket, $hotspot_name) { + global $configValues, $logDebugSQL; + $sql = sprintf("SELECT COUNT(DISTINCT(`id`)) FROM %s WHERE `name` = '%s'", + $configValues['CONFIG_DB_TBL_DALOHOTSPOTS'], $dbSocket->escapeSimple($hotspot_name)); + $res = $dbSocket->query($sql); + $logDebugSQL .= "$sql;\n"; + + return $res->fetchrow()[0] > 0; +} + + // give an open $dbSocket and a $username, // returns true if the provided username is found // in the radcheck table, if $table_index is not provided diff --git a/app/operators/include/management/pages_common.php b/app/operators/include/management/pages_common.php index e5027c92a..ba716854c 100644 --- a/app/operators/include/management/pages_common.php +++ b/app/operators/include/management/pages_common.php @@ -53,23 +53,26 @@ function createPassword($length, $chars) { /* convert byte to to size */ function toxbyte($size) { - $magnitudes = array( - "GB" => 1073741824, // Gigabytes - "MB" => 1048576, // Megabytes - "KB" => 1024 // Kilobytes - ); + if (!is_numeric($size) || $size <= 0) { + return "0 B"; + } + + $magnitudes = [ + "TB" => 1099511627776, // Terabytes + "GB" => 1073741824, // Gigabytes + "MB" => 1048576, // Megabytes + "KB" => 1024 // Kilobytes + ]; foreach ($magnitudes as $label => $magnitude) { - if ($size > $magnitude) { + if ($size >= $magnitude) { $ret = round($size / $magnitude, 2); return "$ret $label"; } } // Bytes - if (!empty($size) && $size <= 1024) { - return "$size B"; - } + return "$size B"; } // set of functions to ease the usage of escaping " chars in echo or print functions @@ -79,36 +82,59 @@ function printq($text) { print qq($text); } function printqn($text) { print qq($text)."\n"; } // function taken from dialup_admin -function time2str($time) { +function time2str($time, $abbreviate = false) { + // Check if $time is a valid number + if (!is_numeric($time) || $time < 0) { + return "(n/a)"; + } - $str = ""; // initialize variable $time = floor($time); - if (!$time) + + // Initialize the result string + if ($time == 0) { return "0 seconds"; - $d = $time/86400; - $d = floor($d); - if ($d){ - $str .= "$d days, "; - $time = $time % 86400; } - $h = $time/3600; - $h = floor($h); - if ($h){ - $str .= "$h hours, "; - $time = $time % 3600; + + $str = ""; + + // Define labels + $labels = $abbreviate + ? ['d' => 'd', 'h' => 'h', 'm' => 'm', 's' => 's'] + : ['d' => ' days', 'h' => ' hours', 'm' => ' minutes', 's' => ' seconds']; + + // Calculate days + $d = floor($time / 86400); + if ($d > 0) { + $str .= sprintf("%d%s, ", $d, $labels['d']); + $time %= 86400; + } + + // Calculate hours + $h = floor($time / 3600); + if ($h > 0) { + $str .= sprintf("%d%s, ", $h, $labels['h']); + $time %= 3600; + } + + // Calculate minutes + $m = floor($time / 60); + if ($m > 0) { + $str .= sprintf("%d%s, ", $m, $labels['m']); + $time %= 60; } - $m = $time/60; - $m = floor($m); - if ($m){ - $str .= "$m minutes, "; - $time = $time % 60; + + // Calculate seconds + if ($time > 0) { + $str .= sprintf("%d%s, ", $time, $labels['s']); } - if ($time) - $str .= "$time seconds, "; - $str = preg_replace("/, $/",'',$str); + + // Remove the trailing comma and space + $str = rtrim($str, ", "); + return $str; } + // return next billing date (Y-m-d format) based on // the billing recurring period and billing schedule type function getNextBillingDate($planRecurringBillingSchedule = "Fixed", $planRecurringPeriod, $billDates = null) { diff --git a/app/operators/include/management/pages_numbering.php b/app/operators/include/management/pages_numbering.php index 6fccb5917..3b7779488 100644 --- a/app/operators/include/management/pages_numbering.php +++ b/app/operators/include/management/pages_numbering.php @@ -120,8 +120,27 @@ function setupLinks($pageNum, $maxPage, $orderBy, $orderType, $request1="", $req echo setupLinks_str($pageNum, $maxPage, $orderBy, $orderType, $request1, $request2, $request3); } +function get_link_href($partial_query_string, $pageNum="", $orderBy="", $orderType="asc") { + // partial_query_string should be valid! + $href = sprintf("?orderType=%s", $orderType); + + if (!empty($orderBy)) { + $href .= sprintf("&orderBy=%s", $orderBy); + } + + if (is_numeric($pageNum)) { + $href .= sprintf("&page=%d", $pageNum); + } + + if (!empty($partial_query_string)) { + $href .= $partial_query_string; + } + + return $href; +} + // this is an utility function used for printing a "go to " link in the function setupNumbering_str() -function print_link($aPageNum, $pageNum, $orderBy, $orderType, $request1="", $request2="", $request3="") { +function print_link($aPageNum, $pageNum, $orderBy, $orderType, $request1="", $request2="", $request3="") { $link_format = '
  • %s
  • '; $selected_link_format = '
  • %s
  • '; @@ -162,7 +181,7 @@ function setupNumbering_str($numrows, $rowsPerPage, $pageNum, $orderBy, $orderTy $pageNum = 1; } - $result = '