Skip to content

Commit

Permalink
Improved accounting features and minor fixes (#539)
Browse files Browse the repository at this point in the history
* Update README.md

Clarification on which database should be used as backend

* Updated accounting features
  • Loading branch information
filippolauria authored Jul 3, 2024
1 parent dd97e49 commit 2777cb8
Show file tree
Hide file tree
Showing 20 changed files with 940 additions and 566 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions app/common/includes/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="d-flex justify-content-between">';
echo '<div class="row p-0 my-3">';

echo '<div class="col-4 d-flex justify-content-start align-items-center">';
if (isset($descriptors['start']) && is_array($descriptors['start'])) {
echo '<div>';

$start = $descriptors['start'];

if (isset($start['common_controls'])) {
Expand All @@ -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 '</div>';

}
echo '</div>';

echo '<div class="col-4 d-flex justify-content-center align-items-center">';
if (isset($descriptors['center']) && is_array($descriptors['center'])) {
$center = $descriptors['center'];

if (isset($center['draw']) && $center['draw']) {
echo '<div>';
print_page_numbering($center['params']);
echo '</div>';
}
}
echo '</div>';

echo '<div class="col-4 d-flex justify-content-end align-items-center">';
if (isset($descriptors['end']) && is_array($descriptors['end'])) {
echo '<div>';
print_additional_controls($descriptors['end']);
echo '</div>';
}
echo '</div>';

echo '</div>';
}
Expand Down
60 changes: 32 additions & 28 deletions app/common/includes/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/common/includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*********************************************************************************************************
*/
Expand All @@ -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';
86 changes: 36 additions & 50 deletions app/operators/acct-active.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "<h100> " . " $difference days since expired" . "</h100> ";
$datediff = datediff('d', $maxtimeexpiration, $currdate, false);
if ($datediff > 0) {
$status = '<span class="badge text-bg-danger">Expired</span>';
$usage = sprintf('<span class="badge text-bg-secondary">%s day(s)</span> since expiration', $datediff);
} else {
$usage = substr($difference, 1) . " days until expiration";
$status = '<span class="badge text-bg-success">Active</span>';
$usage = sprintf('<span class="badge text-bg-secondary">%s day(s)</span> until expiration', abs($datediff));
}
} else if ($attribute == "Max-All-Session") {
if ($status == "End") {
$usage = "<h100> " . abs($maxtimeexpiration - $usedtime) . " seconds overdue credit" . "</h100>";
} elseif ($attribute == "Max-All-Session") {
$time_left = abs($maxtimeexpiration - $usedtime);
$time_left_str = time2str($time_left, true);

if ($usedtime >= $maxtimeexpiration) {
$status = '<span class="badge text-bg-danger">Ended</span>';
$usage = sprintf('credit overdue: <span class="badge text-bg-secondary">%s</span>', $time_left_str);
} else {
$usage = abs($maxtimeexpiration - $usedtime) . " left on credit";
$status = '<span class="badge text-bg-success">Active</span>';
$usage = sprintf('credit left: <span class="badge text-bg-secondary">%s</span>', $time_left_str);
}
}
}

$ajax_id = "divContainerUserInfo_" . $count;
$param = sprintf('username=%s', urlencode($username));
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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();
?>
Loading

0 comments on commit 2777cb8

Please sign in to comment.