Skip to content
Snippets Groups Projects
Commit df887758 authored by Robert Anderson's avatar Robert Anderson
Browse files

Fixed server getting usage for current month when getUsage called from capping module

parent 286f5100
No related branches found
No related tags found
No related merge requests found
......@@ -165,6 +165,7 @@ sub init
@TP@accounting
WHERE
Username = %{request.User-Name}
AND EventTimestamp >= %{query.From}
';
# Setup SQL queries
......@@ -213,7 +214,7 @@ sub init
# Function to get radius user data usage
sub getUsage
{
my ($server,$user,$packet) = @_;
my ($server,$user,$packet,$month) = @_;
# Build template
my $template;
......@@ -221,9 +222,13 @@ sub getUsage
$template->{'request'}->{$attr} = $packet->rawattr($attr)
}
$template->{'user'} = $user;
# Query parameters
$template->{'query'}->{'From'} = $month;
# Replace template entries
my @dbDoParams = templateReplace($config->{'accounting_usage_query'},$template);
my ($queryString, @params) = templateReplace($config->{'accounting_usage_query'},$template);
# Add month to our params
my @dbDoParams = ($queryString, @params);
# Fetch data
my $sth = DBSelect(@dbDoParams);
......
......@@ -118,13 +118,14 @@ sub post_auth_hook
# Get the users' usage
my $accountingUsage;
my $month = DateTime->from_epoch( epoch => $user->{'_Internal'}->{'Timestamp-Unix'} )->strftime('%Y-%m');
# Loop with plugins to find anyting supporting getting of usage
foreach my $module (@{$server->{'module_list'}}) {
# Do we have the correct plugin?
if ($module->{'Accounting_getUsage'}) {
$server->log(LOG_INFO,"[MOD_FEATURE_CAPPING] Found plugin: '".$module->{'Name'}."'");
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet,$month);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$packet->attr('User-Name')."'");
return MOD_RES_SKIP;
......@@ -310,13 +311,14 @@ sub post_acct_hook
# Get the users' usage
my $accountingUsage;
my $month = DateTime->from_epoch( epoch => $user->{'_Internal'}->{'Timestamp-Unix'} )->strftime('%Y-%m');
# Loop with plugins to find anyting supporting getting of usage
foreach my $module (@{$server->{'module_list'}}) {
# Do we have the correct plugin?
if ($module->{'Accounting_getUsage'}) {
$server->log(LOG_INFO,"[MOD_FEATURE_CAPPING] Found plugin: '".$module->{'Name'}."'");
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet,$month);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$packet->attr('User-Name')."'");
return MOD_RES_SKIP;
......
......@@ -306,6 +306,7 @@ accounting_usage_query=<<EOT
@TP@accounting
WHERE
Username = %{request.User-Name}
AND EventTimestamp >= %{query.From}
EOT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment