Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
smradius
smradius
Commits
342a2ab5
Commit
342a2ab5
authored
Sep 13, 2012
by
Nigel Kukard
Browse files
Clear user-data we add when cron runs at monthend
Change-Id: I37b3472609c56a6e15d2998f4c9f2e2490979522
parent
b19e3f05
Changes
2
Hide whitespace changes
Inline
Side-by-side
smadmin
View file @
342a2ab5
...
...
@@ -46,6 +46,7 @@ GetOptions(
"config:s"
,
"cleanup-date:s"
,
"cleanup"
,
"reset-userdata"
,
"debug"
,
);
...
...
@@ -92,6 +93,9 @@ my $server;
#
We
must
cleanup
if
($
opts
{
'cleanup'
})
{
#
Check
if
we
need
to
reset
user
data
my
$
reset_userdata
=
defined
($
opts
{
'reset-userdata'
})
?
1
:
0
;
loadModules
();
#
Pull
where
we
are
now
and
default
to
that
,
if
we
truncate
the
day
we
mess
up
the
timezone
calculations
...
...
@@ -116,7 +120,7 @@ if ($opts{'cleanup'}) {
#
If
we
have
a
cleanup
module
,
run
it
if
(
defined
($
module
->{
'Cleanup'
}))
{
$
server
->
log
(
LOG_INFO
,
" -> running cleanup..."
);
$
module
->{
'Cleanup'
}($
server
,$
cleanupMonth
->
epoch
());
$
module
->{
'Cleanup'
}($
server
,$
cleanupMonth
->
epoch
()
,$
reset_userdata
);
}
}
...
...
smradius/modules/userdb/mod_userdb_sql.pm
View file @
342a2ab5
...
...
@@ -511,7 +511,7 @@ sub data_get
# Clean up of old user variables
sub
cleanup
{
my
(
$server
,
$runForDate
)
=
@_
;
my
(
$server
,
$runForDate
,
$resetUserData
)
=
@_
;
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => Removing old user data
");
# Begin operation
...
...
@@ -534,9 +534,32 @@ sub cleanup
return
;
}
if
(
$resetUserData
)
{
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => Resetting user data counters
");
# Perform query
my
$sth
=
DBDo
('
UPDATE
@TP@users_data
SET
Value = 0
WHERE
Name =
'
.
DBQuote
('
CurrentMonthTotalTraffic
')
.
'
OR Name =
'
.
DBQuote
('
CurrentMonthTotalUptime
')
.
'
');
# Error and rollback
if
(
!
$sth
)
{
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => Database has been rolled back, no data reset
");
DBRollback
();
return
;
}
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => User data counters have been reset
");
}
# Commit
DBCommit
();
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => Old user data
have been deleted
");
$server
->
log
(
LOG_NOTICE
,"
[MOD_USERDB_SQL] Cleanup => Old user data
cleaned up
");
}
...
...
Write
Preview
Supports
Markdown
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