Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
smradius
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smradius
smradius
Commits
62f57dae
Commit
62f57dae
authored
May 15, 2019
by
Nigel Kukard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added variable period usage accounting
parent
01dd85b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
5 deletions
+47
-5
lib/smradius/modules/accounting/mod_accounting_sql.pm
lib/smradius/modules/accounting/mod_accounting_sql.pm
+47
-5
No files found.
lib/smradius/modules/accounting/mod_accounting_sql.pm
View file @
62f57dae
# SQL accounting database
# Copyright (C) 2007-201
6
, AllWorldIT
# Copyright (C) 2007-201
9
, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
...
...
@@ -206,6 +206,20 @@ sub init
AND PeriodKey = %{query.PeriodKey}
';
$config
->
{'
accounting_usage_query_period
'}
=
'
SELECT
SUM(AcctInputOctets) AS AcctInputOctets,
SUM(AcctOutputOctets) AS AcctOutputOctets,
SUM(AcctInputGigawords) AS AcctInputGigawords,
SUM(AcctOutputGigawords) AS AcctOutputGigawords,
SUM(AcctSessionTime) AS AcctSessionTime
FROM
@TP@accounting
WHERE
Username = %{user.Username}
AND EventTimestamp > %{query.PeriodKey}
';
$config
->
{'
accounting_select_duplicates_query
'}
=
'
SELECT
ID
...
...
@@ -280,6 +294,15 @@ sub init
$config
->
{'
accounting_usage_query
'}
=
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query
'};
}
}
if
(
defined
(
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query_period
'})
&&
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query_period
'}
ne
"")
{
if
(
ref
(
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query_period
'})
eq
"
ARRAY
")
{
$config
->
{'
accounting_usage_query_period
'}
=
join
('
',
@
{
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query_period
'}});
}
else
{
$config
->
{'
accounting_usage_query_period
'}
=
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_usage_query_period
'};
}
}
if
(
defined
(
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_select_duplicates_query
'})
&&
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_select_duplicates_query
'}
ne
"")
{
if
(
ref
(
$scfg
->
{'
mod_accounting_sql
'}
->
{'
accounting_select_duplicates_query
'})
eq
"
ARRAY
")
{
...
...
@@ -327,9 +350,10 @@ sub init
# Function to get radius user data usage
# The 'period' parameter is optional and is the number of days to return usage for
sub
getUsage
{
my
(
$server
,
$user
,
$packet
)
=
@_
;
my
(
$server
,
$user
,
$packet
,
$period
)
=
@_
;
# Build template
my
$template
;
...
...
@@ -341,9 +365,27 @@ sub getUsage
$template
->
{'
user
'}
->
{'
ID
'}
=
$user
->
{'
ID
'};
$template
->
{'
user
'}
->
{'
Username
'}
=
$user
->
{'
Username
'};
# Current PeriodKey
# Current PeriodKey
, this is used for non-$period queries
my
$now
=
DateTime
->
now
->
set_time_zone
(
$server
->
{'
smradius
'}
->
{'
event_timezone
'});
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$now
->
strftime
("
%Y-%m
");
# Query template to use below
my
$queryTemplate
;
# If we're doing a query for a specific period
if
(
defined
(
$period
))
{
# We need to switch out the query to the period query
$queryTemplate
=
"
accounting_usage_query_period
";
# Grab a clone of now, and create the start date DateTime object
my
$startDate
=
$now
->
clone
->
subtract
(
'
days
'
=>
$period
);
# And we add the start date
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$startDate
->
ymd
();
# If not, we just use PeriodKey as normal...
}
else
{
# Set the normal PeriodKey query template to use
$queryTemplate
=
"
accounting_usage_query
";
# And set the period key to this month
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$now
->
strftime
("
%Y-%m
");
}
# If we using caching, check how old the result is
if
(
defined
(
$config
->
{'
accounting_usage_cache_time
'}))
{
...
...
@@ -355,7 +397,7 @@ sub getUsage
}
# Replace template entries
my
(
@dbDoParams
)
=
templateReplace
(
$config
->
{
'
accounting_usage_query
'
},
$template
);
my
(
@dbDoParams
)
=
templateReplace
(
$config
->
{
$queryTemplate
},
$template
);
# Fetch data
my
$sth
=
DBSelect
(
@dbDoParams
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment