Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
smradius
smradius
Commits
fd1632ff
Commit
fd1632ff
authored
8 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
BUGFIX: Fixed the name of attributes used and template components
parent
b6fc5fc4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!412
Bugfix branch merge
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/smradius/modules/accounting/mod_accounting_sql.pm
+54
-52
54 additions, 52 deletions
lib/smradius/modules/accounting/mod_accounting_sql.pm
smradiusd.conf
+21
-21
21 additions, 21 deletions
smradiusd.conf
with
75 additions
and
73 deletions
lib/smradius/modules/accounting/mod_accounting_sql.pm
+
54
−
52
View file @
fd1632ff
# SQL accounting database
# SQL accounting database
# Copyright (C) 2007-201
5
, AllWorldIT
# Copyright (C) 2007-201
6
, AllWorldIT
#
#
# This program is free software; you can redistribute it and/or modify
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
...
@@ -127,26 +127,26 @@ sub init
...
@@ -127,26 +127,26 @@ sub init
%{request.NAS-Identifier},
%{request.NAS-Identifier},
%{request.NAS-IP-Address},
%{request.NAS-IP-Address},
%{request.Acct-Delay-Time},
%{request.Acct-Delay-Time},
%{request.SessionTime},
%{request.
Acct-
Session
-
Time},
%{request.InputOctets},
%{request.
Acct-
Input
-
Octets},
%{request.InputGigawords},
%{request.
Acct-
Input
-
Gigawords},
%{request.InputPackets},
%{request.
Acct-
Input
-
Packets},
%{request.OutputOctets},
%{request.
Acct-
Output
-
Octets},
%{request.OutputGigawords},
%{request.
Acct-
Output
-
Gigawords},
%{request.OutputPackets},
%{request.
Acct-
Output
-
Packets},
%{query.PeriodKey}
%{query.PeriodKey}
)
)
';
';
$config
->
{'
accounting_update_get_records_query
'}
=
'
$config
->
{'
accounting_update_get_records_query
'}
=
'
SELECT
SELECT
SUM(AcctInputOctets) AS InputOctets,
SUM(AcctInputOctets) AS
Acct
InputOctets,
SUM(AcctInputPackets) AS InputPackets,
SUM(AcctInputPackets) AS
Acct
InputPackets,
SUM(AcctOutputOctets) AS OutputOctets,
SUM(AcctOutputOctets) AS
Acct
OutputOctets,
SUM(AcctOutputPackets) AS OutputPackets,
SUM(AcctOutputPackets) AS
Acct
OutputPackets,
SUM(AcctInputGigawords) AS InputGigawords,
SUM(AcctInputGigawords) AS
Acct
InputGigawords,
SUM(AcctOutputGigawords) AS OutputGigawords,
SUM(AcctOutputGigawords) AS
Acct
OutputGigawords,
SUM(AcctSessionTime) AS SessionTime,
SUM(AcctSessionTime) AS
Acct
SessionTime,
PeriodKey
PeriodKey
FROM
FROM
@TP@accounting
@TP@accounting
...
@@ -165,13 +165,13 @@ sub init
...
@@ -165,13 +165,13 @@ sub init
UPDATE
UPDATE
@TP@accounting
@TP@accounting
SET
SET
AcctSessionTime = %{query.SessionTime},
AcctSessionTime = %{query.
Acct-
Session
-
Time},
AcctInputOctets = %{query.InputOctets},
AcctInputOctets = %{query.
Acct-
Input
-
Octets},
AcctInputGigawords = %{query.InputGigawords},
AcctInputGigawords = %{query.
Acct-
Input
-
Gigawords},
AcctInputPackets = %{query.InputPackets},
AcctInputPackets = %{query.
Acct-
Input
-
Packets},
AcctOutputOctets = %{query.OutputOctets},
AcctOutputOctets = %{query.
Acct-
Output
-
Octets},
AcctOutputGigawords = %{query.OutputGigawords},
AcctOutputGigawords = %{query.
Acct-
Output
-
Gigawords},
AcctOutputPackets = %{query.OutputPackets},
AcctOutputPackets = %{query.
Acct-
Output
-
Packets},
AcctStatusType = %{request.Acct-Status-Type}
AcctStatusType = %{request.Acct-Status-Type}
WHERE
WHERE
Username = %{user.Username}
Username = %{user.Username}
...
@@ -408,7 +408,7 @@ sub getUsage
...
@@ -408,7 +408,7 @@ sub getUsage
# If we using caching and got here, it means that we must cache the result
# If we using caching and got here, it means that we must cache the result
if
(
defined
(
$config
->
{'
accounting_usage_cache_time
'}))
{
if
(
defined
(
$config
->
{'
accounting_usage_cache_time
'}))
{
$res
{'
CachedUntil
'}
=
$user
->
{'
_Internal
'}
->
{'
Timestamp-Unix
'}
+
$config
->
{'
accounting_usage_cache_time
'};
$res
{'
CachedUntil
'}
=
$user
->
{'
_Internal
'}
->
{'
Timestamp-Unix
'}
+
$config
->
{'
accounting_usage_cache_time
'};
# Cache the result
# Cache the result
cacheStoreComplexKeyPair
('
mod_accounting_sql(getUsage)
',
$user
->
{'
Username
'}
.
"
/
"
.
$template
->
{'
query
'}
->
{'
PeriodKey
'},
\
%res
);
cacheStoreComplexKeyPair
('
mod_accounting_sql(getUsage)
',
$user
->
{'
Username
'}
.
"
/
"
.
$template
->
{'
query
'}
->
{'
PeriodKey
'},
\
%res
);
}
}
...
@@ -429,6 +429,7 @@ sub acct_log
...
@@ -429,6 +429,7 @@ sub acct_log
{
{
my
(
$server
,
$user
,
$packet
)
=
@_
;
my
(
$server
,
$user
,
$packet
)
=
@_
;
# Build template
# Build template
my
$template
;
my
$template
;
foreach
my
$attr
(
$packet
->
attributes
)
{
foreach
my
$attr
(
$packet
->
attributes
)
{
...
@@ -447,11 +448,12 @@ sub acct_log
...
@@ -447,11 +448,12 @@ sub acct_log
# For our queries
# For our queries
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$periodKey
;
$template
->
{'
query
'}
->
{'
PeriodKey
'}
=
$periodKey
;
# Default to being a new period, only if we update on INTERIM or STOP do we set this to 0
my
$newPeriod
=
1
;
#
#
# U P D A T E & S T O P P A C K E T
# U P D A T E & S T O P P A C K E T
#
#
# If its a new period we're going to trigger START
my
$newPeriod
;
if
(
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
2
"
||
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
3
")
{
if
(
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
2
"
||
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
3
")
{
# Replace template entries
# Replace template entries
my
@dbDoParams
=
templateReplace
(
$config
->
{'
accounting_update_get_records_query
'},
$template
);
my
@dbDoParams
=
templateReplace
(
$config
->
{'
accounting_update_get_records_query
'},
$template
);
...
@@ -478,21 +480,22 @@ sub acct_log
...
@@ -478,21 +480,22 @@ sub acct_log
# Loop through previous records and subtract them from our session totals
# Loop through previous records and subtract them from our session totals
while
(
my
$sessionPart
=
hashifyLCtoMC
(
$sth
->
fetchrow_hashref
(),
while
(
my
$sessionPart
=
hashifyLCtoMC
(
$sth
->
fetchrow_hashref
(),
qw(InputOctets InputPackets OutputOctets OutputPackets InputGigawords OutputGigawords SessionTime PeriodKey)
qw(AcctInputOctets AcctInputPackets AcctOutputOctets AcctOutputPackets AcctInputGigawords AcctOutputGigawords
SessionTime PeriodKey)
))
{
))
{
# Convert this session usage to bytes
# Convert this session usage to bytes
my
$sessionInputBytes
=
Math::
BigInt
->
new
();
my
$sessionInputBytes
=
Math::
BigInt
->
new
();
$sessionInputBytes
->
badd
(
$sessionPart
->
{'
InputGigawods
'})
->
bmul
(
UINT_MAX
);
$sessionInputBytes
->
badd
(
$sessionPart
->
{'
Acct
InputGigawods
'})
->
bmul
(
UINT_MAX
);
$sessionInputBytes
->
badd
(
$sessionPart
->
{'
InputOctets
'});
$sessionInputBytes
->
badd
(
$sessionPart
->
{'
Acct
InputOctets
'});
my
$sessionOutputBytes
=
Math::
BigInt
->
new
();
my
$sessionOutputBytes
=
Math::
BigInt
->
new
();
$sessionOutputBytes
->
badd
(
$sessionPart
->
{'
OutputGigawods
'})
->
bmul
(
UINT_MAX
);
$sessionOutputBytes
->
badd
(
$sessionPart
->
{'
Acct
OutputGigawods
'})
->
bmul
(
UINT_MAX
);
$sessionOutputBytes
->
badd
(
$sessionPart
->
{'
OutputOctets
'});
$sessionOutputBytes
->
badd
(
$sessionPart
->
{'
Acct
OutputOctets
'});
# And packets
# And packets
my
$sessionInputPackets
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
InputPackets
'});
my
$sessionInputPackets
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
Acct
InputPackets
'});
my
$sessionOutputPackets
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
OutputPackets
'});
my
$sessionOutputPackets
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
Acct
OutputPackets
'});
# Finally session time
# Finally session time
my
$sessionSessionTime
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
SessionTime
'});
my
$sessionSessionTime
=
Math::
BigInt
->
new
(
$sessionPart
->
{'
Acct
SessionTime
'});
# Check if this record is from an earlier period
# Check if this record is from an earlier period
if
(
defined
(
$sessionPart
->
{'
PeriodKey
'})
&&
$sessionPart
->
{'
PeriodKey
'}
ne
$periodKey
)
{
if
(
defined
(
$sessionPart
->
{'
PeriodKey
'})
&&
$sessionPart
->
{'
PeriodKey
'}
ne
$periodKey
)
{
...
@@ -511,19 +514,19 @@ sub acct_log
...
@@ -511,19 +514,19 @@ sub acct_log
DBFreeRes
(
$sth
);
DBFreeRes
(
$sth
);
# Sanitize
# Sanitize
if
(
$totalInputBytes
->
is_neg
())
{
if
(
$totalInputBytes
->
is_neg
())
{
$totalInputBytes
->
bzero
();
$totalInputBytes
->
bzero
();
}
}
if
(
$totalOutputBytes
->
is_neg
())
{
if
(
$totalOutputBytes
->
is_neg
())
{
$totalOutputBytes
->
bzero
();
$totalOutputBytes
->
bzero
();
}
}
if
(
$totalInputPackets
->
is_neg
())
{
if
(
$totalInputPackets
->
is_neg
())
{
$totalInputPackets
->
bzero
();
$totalInputPackets
->
bzero
();
}
}
if
(
$totalOutputPackets
->
is_neg
())
{
if
(
$totalOutputPackets
->
is_neg
())
{
$totalOutputPackets
->
bzero
();
$totalOutputPackets
->
bzero
();
}
}
if
(
$totalSessionTime
->
is_neg
())
{
if
(
$totalSessionTime
->
is_neg
())
{
$totalSessionTime
->
bzero
();
$totalSessionTime
->
bzero
();
}
}
...
@@ -532,15 +535,15 @@ sub acct_log
...
@@ -532,15 +535,15 @@ sub acct_log
my
(
$outputGigawordsStr
,
$outputOctetsStr
)
=
$totalOutputBytes
->
bdiv
(
UINT_MAX
);
my
(
$outputGigawordsStr
,
$outputOctetsStr
)
=
$totalOutputBytes
->
bdiv
(
UINT_MAX
);
# Conversion to strings
# Conversion to strings
$template
->
{'
query
'}
->
{'
InputGigawords
'}
=
$inputGigawordsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Input
-
Gigawords
'}
=
$inputGigawordsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
InputOctets
'}
=
$inputOctetsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Input
-
Octets
'}
=
$inputOctetsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
OutputGigawords
'}
=
$outputGigawordsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Output
-
Gigawords
'}
=
$outputGigawordsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
OutputOctets
'}
=
$outputOctetsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Output
-
Octets
'}
=
$outputOctetsStr
->
bstr
();
$template
->
{'
query
'}
->
{'
InputPackets
'}
=
$totalInputPackets
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Input
-
Packets
'}
=
$totalInputPackets
->
bstr
();
$template
->
{'
query
'}
->
{'
OutputPackets
'}
=
$totalOutputPackets
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Output
-
Packets
'}
=
$totalOutputPackets
->
bstr
();
$template
->
{'
query
'}
->
{'
SessionTime
'}
=
$totalSessionTime
->
bstr
();
$template
->
{'
query
'}
->
{'
Acct-
Session
-
Time
'}
=
$totalSessionTime
->
bstr
();
# Replace template entries
# Replace template entries
...
@@ -559,7 +562,7 @@ sub acct_log
...
@@ -559,7 +562,7 @@ sub acct_log
# Be very sneaky .... if we updated something, this is obviously NOT a new period
# Be very sneaky .... if we updated something, this is obviously NOT a new period
$newPeriod
=
0
;
$newPeriod
=
0
;
# If we updated a few things ... possibly duplicates?
# If we updated a few things ... possibly duplicates?
if
(
$sth
>
1
)
{
if
(
$sth
>
1
)
{
fixDuplicates
(
$server
,
$template
);
fixDuplicates
(
$server
,
$template
);
}
}
}
}
...
@@ -575,7 +578,6 @@ sub acct_log
...
@@ -575,7 +578,6 @@ sub acct_log
if
(
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
1
"
||
$newPeriod
)
{
if
(
$packet
->
rawattr
('
Acct-Status-Type
')
eq
"
1
"
||
$newPeriod
)
{
# Replace template entries
# Replace template entries
my
@dbDoParams
=
templateReplace
(
$config
->
{'
accounting_start_query
'},
$template
);
my
@dbDoParams
=
templateReplace
(
$config
->
{'
accounting_start_query
'},
$template
);
# Insert into database
# Insert into database
my
$sth
=
DBDo
(
@dbDoParams
);
my
$sth
=
DBDo
(
@dbDoParams
);
if
(
!
$sth
)
{
if
(
!
$sth
)
{
...
@@ -592,7 +594,6 @@ sub acct_log
...
@@ -592,7 +594,6 @@ sub acct_log
$user
->
{'
_UserDB
'}
->
{'
Users_data_set
'}(
$server
,
$user
,'
global
','
FirstLogin
',
$user
->
{'
_Internal
'}
->
{'
Timestamp-Unix
'});
$user
->
{'
_UserDB
'}
->
{'
Users_data_set
'}(
$server
,
$user
,'
global
','
FirstLogin
',
$user
->
{'
_Internal
'}
->
{'
Timestamp-Unix
'});
}
}
}
}
}
}
...
@@ -613,6 +614,7 @@ sub acct_log
...
@@ -613,6 +614,7 @@ sub acct_log
}
}
}
}
return
MOD_RES_ACK
;
return
MOD_RES_ACK
;
}
}
...
@@ -682,7 +684,7 @@ sub cleanup
...
@@ -682,7 +684,7 @@ sub cleanup
# Last month..
# Last month..
my
$lastMonth
=
$thisMonth
->
clone
()
->
subtract
(
months
=>
1
);
my
$lastMonth
=
$thisMonth
->
clone
()
->
subtract
(
months
=>
1
);
my
$prevPeriodKey
=
$lastMonth
->
strftime
("
%Y-%m
");
my
$prevPeriodKey
=
$lastMonth
->
strftime
("
%Y-%m
");
# Begin transaction
# Begin transaction
DBBegin
();
DBBegin
();
...
...
This diff is collapsed.
Click to expand it.
smradiusd.conf
+
21
−
21
View file @
fd1632ff
...
@@ -306,26 +306,26 @@ accounting_start_query=<<EOT
...
@@ -306,26 +306,26 @@ accounting_start_query=<<EOT
%{
request
.
NAS
-
Identifier
},
%{
request
.
NAS
-
Identifier
},
%{
request
.
NAS
-
IP
-
Address
},
%{
request
.
NAS
-
IP
-
Address
},
%{
request
.
Acct
-
Delay
-
Time
},
%{
request
.
Acct
-
Delay
-
Time
},
%{
request
.
SessionTime
},
%{
request
.
Acct
-
Session
-
Time
},
%{
request
.
InputOctets
},
%{
request
.
Acct
-
Input
-
Octets
},
%{
request
.
InputGigawords
},
%{
request
.
Acct
-
Input
-
Gigawords
},
%{
request
.
InputPackets
},
%{
request
.
Acct
-
Input
-
Packets
},
%{
request
.
OutputOctets
},
%{
request
.
Acct
-
Output
-
Octets
},
%{
request
.
OutputGigawords
},
%{
request
.
Acct
-
Output
-
Gigawords
},
%{
request
.
OutputPackets
},
%{
request
.
Acct
-
Output
-
Packets
},
%{
query
.
PeriodKey
}
%{
query
.
PeriodKey
}
)
)
EOT
EOT
accounting_update_get_records_query
=<<
EOT
accounting_update_get_records_query
=<<
EOT
SELECT
SELECT
SUM
(
AcctInputOctets
)
AS
InputOctets
,
SUM
(
AcctInputOctets
)
AS
Acct
InputOctets
,
SUM
(
AcctInputPackets
)
AS
InputPackets
,
SUM
(
AcctInputPackets
)
AS
Acct
InputPackets
,
SUM
(
AcctOutputOctets
)
AS
OutputOctets
,
SUM
(
AcctOutputOctets
)
AS
Acct
OutputOctets
,
SUM
(
AcctOutputPackets
)
AS
OutputPackets
,
SUM
(
AcctOutputPackets
)
AS
Acct
OutputPackets
,
SUM
(
AcctInputGigawords
)
AS
InputGigawords
,
SUM
(
AcctInputGigawords
)
AS
Acct
InputGigawords
,
SUM
(
AcctOutputGigawords
)
AS
OutputGigawords
,
SUM
(
AcctOutputGigawords
)
AS
Acct
OutputGigawords
,
SUM
(
AcctSessionTime
)
AS
SessionTime
,
SUM
(
AcctSessionTime
)
AS
Acct
SessionTime
,
PeriodKey
PeriodKey
FROM
FROM
@
TP
@
accounting
@
TP
@
accounting
...
@@ -344,13 +344,13 @@ accounting_update_query=<<EOT
...
@@ -344,13 +344,13 @@ accounting_update_query=<<EOT
UPDATE
UPDATE
@
TP
@
accounting
@
TP
@
accounting
SET
SET
AcctSessionTime
= %{
query
.
SessionTime
},
AcctSessionTime
= %{
query
.
Acct
-
Session
-
Time
},
AcctInputOctets
= %{
query
.
InputOctets
},
AcctInputOctets
= %{
query
.
Acct
-
Input
-
Octets
},
AcctInputGigawords
= %{
query
.
InputGigawords
},
AcctInputGigawords
= %{
query
.
Acct
-
Input
-
Gigawords
},
AcctInputPackets
= %{
query
.
InputPackets
},
AcctInputPackets
= %{
query
.
Acct
-
Input
-
Packets
},
AcctOutputOctets
= %{
query
.
OutputOctets
},
AcctOutputOctets
= %{
query
.
Output
-
Octets
},
AcctOutputGigawords
= %{
query
.
OutputGigawords
},
AcctOutputGigawords
= %{
query
.
Output
-
Gigawords
},
AcctOutputPackets
= %{
query
.
OutputPackets
},
AcctOutputPackets
= %{
query
.
Output
-
Packets
},
AcctStatusType
= %{
request
.
Acct
-
Status
-
Type
}
AcctStatusType
= %{
request
.
Acct
-
Status
-
Type
}
WHERE
WHERE
Username
= %{
user
.
Username
}
Username
= %{
user
.
Username
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment