Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
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
shail
smradius
Commits
3a6d6cfa
Commit
3a6d6cfa
authored
15 years ago
by
Robert Anderson
Browse files
Options
Downloads
Patches
Plain Diff
Correctly handle large numbers for topups cleanup function
parent
f15d81f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smradius/modules/system/mod_config_sql_topups.pm
+41
-44
41 additions, 44 deletions
smradius/modules/system/mod_config_sql_topups.pm
with
41 additions
and
44 deletions
smradius/modules/system/mod_config_sql_topups.pm
+
41
−
44
View file @
3a6d6cfa
...
...
@@ -336,19 +336,16 @@ sub cleanup
# Get traffic and uptime usage for last month
my
$sth
=
DBSelect
('
SELECT
Username,
SUM(AcctSessionTime) as AcctSessionTime,
SUM(AcctInputOctets) as AcctInputOctets,
SUM(AcctInputGigawords) as AcctInputGigawords,
SUM(AcctOutputOctets) as AcctOutputOctets,
SUM(AcctOutputGigawords) as AcctOutputGigawords
AcctSessionTime,
AcctInputOctets,
AcctInputGigawords,
AcctOutputOctets,
AcctOutputGigawords
FROM
@TP@accounting
WHERE
PeriodKey = ?
AND Username = ?
GROUP BY
Username
',
$prevPeriodKey
,
$userName
);
...
...
@@ -359,41 +356,41 @@ sub cleanup
goto
FAIL_ROLLBACK
;
}
my
$row
=
$sth
->
fetchrow_hashref
();
if
(
$sth
->
rows
>
0
)
{
$row
=
hashifyLCtoMC
(
$row
,
qw(Username AcctSessionTime AcctInputOctets AcctInputGigawords AcctOutputOctets AcctOutputGigawords)
);
}
# Our usage hash
my
%usageTotals
;
$usageTotals
{'
TotalTimeUsage
'}
=
0
;
$usageTotals
{'
TotalDataInput
'}
=
0
;
$usageTotals
{'
TotalDataOutput
'}
=
0
;
# Add up traffic
my
$totalData
=
0
;
if
(
defined
(
$row
->
{'
AcctInputOctets
'})
&&
$row
->
{'
AcctInputOctets
'}
>
0
)
{
$totalData
+=
$row
->
{'
AcctInputOctets
'}
/ 1024 /
1024
;
}
if
(
defined
(
$row
->
{'
AcctInputGigawords
'})
&&
$row
->
{'
AcctInputGigawords
'}
>
0
)
{
$totalData
+=
$row
->
{'
AcctInputGigawords
'}
*
4096
;
}
if
(
defined
(
$row
->
{'
AcctOutputOctets
'})
&&
$row
->
{'
AcctOutputOctets
'}
>
0
)
{
$totalData
+=
$row
->
{'
AcctOutputOctets
'}
/ 1024 /
1024
;
}
if
(
defined
(
$row
->
{'
AcctOutputGigawords
'})
&&
$row
->
{'
AcctOutputGigawords
'}
>
0
)
{
$totalData
+=
$row
->
{'
AcctOutputGigawords
'}
*
4096
;
}
# Pull in usage and add up
while
(
my
$row
=
hashifyLCtoMC
(
$sth
->
fetchrow_hashref
(),
qw(AcctSessionTime AcctInputOctets AcctInputGigawords AcctOutputOctets AcctOutputGigawords)
))
{
# Add up uptime
my
$totalTime
=
0
;
if
(
defined
(
$row
->
{'
AcctSessionTime
'})
&&
$row
->
{'
AcctSessionTime
'}
>
0
)
{
$totalTime
=
$row
->
{'
AcctSessionTime
'}
/
60
;
# Look for session time
if
(
defined
(
$row
->
{'
AcctSessionTime
'})
&&
$row
->
{'
AcctSessionTime
'}
>
0
)
{
$usageTotals
{'
TotalTimeUsage
'}
+=
ceil
(
$row
->
{'
AcctSessionTime
'}
/
60
);
}
# Add input usage if we have any
if
(
defined
(
$row
->
{'
AcctInputOctets
'})
&&
$row
->
{'
AcctInputOctets
'}
>
0
)
{
$usageTotals
{'
TotalDataInput
'}
+=
ceil
(
$row
->
{'
AcctInputOctets
'}
/ 1024 /
1024
);
}
if
(
defined
(
$row
->
{'
AcctInputGigawords
'})
&&
$row
->
{'
AcctInputGigawords
'}
>
0
)
{
$usageTotals
{'
TotalDataInput
'}
+=
ceil
(
$row
->
{'
AcctInputGigawords
'}
*
4096
);
}
# Add output usage if we have any
if
(
defined
(
$row
->
{'
AcctOutputOctets
'})
&&
$row
->
{'
AcctOutputOctets
'}
>
0
)
{
$usageTotals
{'
TotalDataOutput
'}
+=
ceil
(
$row
->
{'
AcctOutputOctets
'}
/ 1024 /
1024
);
}
if
(
defined
(
$row
->
{'
AcctOutputGigawords
'})
&&
$row
->
{'
AcctOutputGigawords
'}
>
0
)
{
$usageTotals
{'
TotalDataOutput
'}
+=
ceil
(
$row
->
{'
AcctOutputGigawords
'}
*
4096
);
}
}
DBFreeRes
(
$sth
);
# Rounding up
my
$totalTrafficUsage
=
ceil
(
$totalData
);
my
$totalUptimeUsage
=
ceil
(
$totalTime
);
# Finished for now
DBFreeRes
(
$sth
);
$usageTotals
{'
TotalDataUsage
'}
=
$usageTotals
{'
TotalDataInput
'}
+
$usageTotals
{'
TotalDataOutput
'};
$usageTotals
{'
TotalTimeUsage
'}
=
$usageTotals
{'
TotalTimeUsage
'};
# Get user traffic and uptime limits from group attributes
# FIXME - Support for realm config
...
...
@@ -418,7 +415,7 @@ sub cleanup
# Store limits in capRecord hash
my
%capRecord
;
while
(
$row
=
$sth
->
fetchrow_hashref
())
{
while
(
my
$row
=
$sth
->
fetchrow_hashref
())
{
$row
=
hashifyLCtoMC
(
$row
,
qw(Name Value)
...
...
@@ -463,7 +460,7 @@ sub cleanup
}
# Store limits in capRecord hash
while
(
$row
=
$sth
->
fetchrow_hashref
())
{
while
(
my
$row
=
$sth
->
fetchrow_hashref
())
{
$row
=
hashifyLCtoMC
(
$row
,
qw(Name Value)
...
...
@@ -624,7 +621,7 @@ sub cleanup
my
$trafficOverUsage
=
0
;
if
(
defined
(
$capRecord
{'
TrafficLimit
'}))
{
# Check traffic used against cap
$trafficOverUsage
=
$
totalTraffic
Usage
-
$capRecord
{'
TrafficLimit
'};
$trafficOverUsage
=
$
usageTotals
{'
TotalData
Usage
'}
-
$capRecord
{'
TrafficLimit
'};
# If there is no limit, this may be a prepaid user
}
else
{
$capRecord
{'
TrafficLimit
'}
=
0
;
...
...
@@ -634,7 +631,7 @@ sub cleanup
foreach
my
$topup
(
@trafficTopups
)
{
$capRecord
{'
TrafficLimit
'}
+=
$topup
->
{'
Value
'};
}
$trafficOverUsage
=
$
totalTraffic
Usage
-
$capRecord
{'
TrafficLimit
'};
$trafficOverUsage
=
$
usageTotals
{'
TotalData
Usage
'}
-
$capRecord
{'
TrafficLimit
'};
}
# User has started using topup bandwidth..
...
...
@@ -735,7 +732,7 @@ sub cleanup
if
(
defined
(
$capRecord
{'
UptimeLimit
'}))
{
# Check traffic used against cap
$uptimeOverUsage
=
$
t
otal
Upt
imeUsage
-
$capRecord
{'
UptimeLimit
'};
$uptimeOverUsage
=
$
usageTotals
{'
T
otal
T
imeUsage
'}
-
$capRecord
{'
UptimeLimit
'};
# If there is no limit, this may be a prepaid user
}
else
{
$capRecord
{'
UptimeLimit
'}
=
0
;
...
...
@@ -745,7 +742,7 @@ sub cleanup
foreach
my
$topup
(
@uptimeTopups
)
{
$capRecord
{'
UptimeLimit
'}
+=
$topup
->
{'
Value
'};
}
$uptimeOverUsage
=
$
t
otal
Upt
imeUsage
-
$capRecord
{'
UptimeLimit
'};
$uptimeOverUsage
=
$
usageTotals
{'
T
otal
T
imeUsage
'}
-
$capRecord
{'
UptimeLimit
'};
}
# User has started using topup uptime..
...
...
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