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
3334893d
Commit
3334893d
authored
14 years ago
by
Robert Anderson
Browse files
Options
Downloads
Patches
Plain Diff
Renamed $userName to $username
Use built in DateTime methods Added SMAdminDepletedOn functionality and columns
parent
67f10471
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
database/core.tsql
+2
-0
2 additions, 0 deletions
database/core.tsql
smradius/modules/system/mod_config_sql_topups.pm
+25
-35
25 additions, 35 deletions
smradius/modules/system/mod_config_sql_topups.pm
with
27 additions
and
35 deletions
database/core.tsql
+
2
−
0
View file @
3334893d
...
@@ -168,6 +168,7 @@ CREATE TABLE @PREFIX@topups (
...
@@ -168,6 +168,7 @@ CREATE TABLE @PREFIX@topups (
Value @INT_UNSIGNED@,
Value @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0',
Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (UserID) REFERENCES @PREFIX@users(ID)
FOREIGN KEY (UserID) REFERENCES @PREFIX@users(ID)
) @CREATE_TABLE_SUFFIX@;
) @CREATE_TABLE_SUFFIX@;
...
@@ -183,6 +184,7 @@ CREATE TABLE @PREFIX@topups_summary (
...
@@ -183,6 +184,7 @@ CREATE TABLE @PREFIX@topups_summary (
Balance @INT_UNSIGNED@,
Balance @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0',
Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (TopupID) REFERENCES @PREFIX@topups(ID)
FOREIGN KEY (TopupID) REFERENCES @PREFIX@topups(ID)
) @CREATE_TABLE_SUFFIX@;
) @CREATE_TABLE_SUFFIX@;
...
...
This diff is collapsed.
Click to expand it.
smradius/modules/system/mod_config_sql_topups.pm
+
25
−
35
View file @
3334893d
...
@@ -299,39 +299,27 @@ sub cleanup
...
@@ -299,39 +299,27 @@ sub cleanup
# The datetime now
# The datetime now
my
$now
=
DateTime
->
now
->
set_time_zone
(
$server
->
{'
smradius
'}
->
{'
event_timezone
'});
my
$now
=
DateTime
->
now
->
set_time_zone
(
$server
->
{'
smradius
'}
->
{'
event_timezone
'});
# Make datetime
# This month..
my
$thisMonth
=
DateTime
->
new
(
year
=>
$now
->
year
,
month
=>
$now
->
month
,
day
=>
1
);
my
$thisMonth
=
DateTime
->
new
(
year
=>
$now
->
year
,
month
=>
$now
->
month
,
day
=>
1
);
# Get begin date of last month
# Last month..
my
(
$prevYear
,
$prevMonth
);
my
$lastMonth
=
$thisMonth
->
clone
()
->
subtract
(
months
=>
1
);
if
(
$now
->
month
==
1
)
{
$prevYear
=
$now
->
year
-
1
;
$prevMonth
=
12
;
}
else
{
$prevYear
=
$now
->
year
;
$prevMonth
=
$now
->
month
-
1
;
}
my
$lastMonth
=
DateTime
->
new
(
year
=>
$prevYear
,
month
=>
$prevMonth
,
day
=>
1
);
my
$prevPeriodKey
=
$lastMonth
->
strftime
("
%Y-%m
");
my
$prevPeriodKey
=
$lastMonth
->
strftime
("
%Y-%m
");
# Get begin date of next month
# Next month..
my
(
$folYear
,
$folMonth
);
my
$nextMonth
=
$thisMonth
->
clone
()
->
add
(
months
=>
1
);
if
(
$now
->
month
==
12
)
{
$folYear
=
$now
->
year
+
1
;
$folMonth
=
1
;
}
else
{
$folYear
=
$now
->
year
;
$folMonth
=
$now
->
month
+
1
;
}
my
$nextMonth
=
DateTime
->
new
(
year
=>
$folYear
,
month
=>
$folMonth
,
day
=>
1
);
my
$unix_nextMonth
=
$nextMonth
->
epoch
();
my
$unix_nextMonth
=
$nextMonth
->
epoch
();
# Get a timestamp for this user
my
$depletedTimestamp
=
$now
->
strftime
('
%Y-%m-%d %H:%M:%S
');
# Start of multiple queries
# Start of multiple queries
DBBegin
();
DBBegin
();
# Loop through users
# Loop through users
foreach
my
$userID
(
keys
%users
)
{
foreach
my
$userID
(
keys
%users
)
{
my
$user
N
ame
=
$users
{
$userID
};
my
$user
n
ame
=
$users
{
$userID
};
# TODO - in future we must be more dynamic, we may not be using SQL accunting
# TODO - in future we must be more dynamic, we may not be using SQL accunting
...
@@ -349,7 +337,7 @@ sub cleanup
...
@@ -349,7 +337,7 @@ sub cleanup
PeriodKey = ?
PeriodKey = ?
AND Username = ?
AND Username = ?
',
',
$prevPeriodKey
,
$user
N
ame
$prevPeriodKey
,
$user
n
ame
);
);
if
(
!
$sth
)
{
if
(
!
$sth
)
{
...
@@ -438,11 +426,11 @@ sub cleanup
...
@@ -438,11 +426,11 @@ sub cleanup
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
$capRecord
{'
TrafficLimit
'}
=
$row
->
{'
Value
'};
$capRecord
{'
TrafficLimit
'}
=
$row
->
{'
Value
'};
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Traffic-Limit value invalid for user '
"
.
$user
N
ame
.
"
'
");
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Traffic-Limit value invalid for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
N
ame
.
"
'
");
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
}
if
(
$row
->
{'
Name
'}
eq
'
SMRadius-Capping-Uptime-Limit
')
{
if
(
$row
->
{'
Name
'}
eq
'
SMRadius-Capping-Uptime-Limit
')
{
...
@@ -450,11 +438,11 @@ sub cleanup
...
@@ -450,11 +438,11 @@ sub cleanup
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
$capRecord
{'
UptimeLimit
'}
=
$row
->
{'
Value
'};
$capRecord
{'
UptimeLimit
'}
=
$row
->
{'
Value
'};
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Uptime-Limit value invalid for user '
"
.
$user
N
ame
.
"
'
");
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Uptime-Limit value invalid for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
N
ame
.
"
'
");
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
}
}
}
...
@@ -494,11 +482,11 @@ sub cleanup
...
@@ -494,11 +482,11 @@ sub cleanup
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
$capRecord
{'
TrafficLimit
'}
=
$row
->
{'
Value
'};
$capRecord
{'
TrafficLimit
'}
=
$row
->
{'
Value
'};
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Traffic-Limit value invalid for user '
"
.
$user
N
ame
.
"
'
");
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Traffic-Limit value invalid for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
N
ame
.
"
'
");
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
}
if
(
$row
->
{'
Name
'}
eq
'
SMRadius-Capping-Uptime-Limit
')
{
if
(
$row
->
{'
Name
'}
eq
'
SMRadius-Capping-Uptime-Limit
')
{
...
@@ -506,11 +494,11 @@ sub cleanup
...
@@ -506,11 +494,11 @@ sub cleanup
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
if
(
defined
(
$row
->
{'
Value
'})
&&
$row
->
{'
Value
'}
=~
/^[\d]+$/
)
{
$capRecord
{'
UptimeLimit
'}
=
$row
->
{'
Value
'};
$capRecord
{'
UptimeLimit
'}
=
$row
->
{'
Value
'};
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Uptime-Limit value invalid for user '
"
.
$user
N
ame
.
"
'
");
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => SMRadius-Capping-Uptime-Limit value invalid for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
else
{
}
else
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Incorrect '
"
.
$row
->
{'
Name
'}
.
"
' operator '
"
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
N
ame
.
"
'
");
.
$row
->
{'
Operator
'}
.
"
' used for user '
"
.
$user
n
ame
.
"
'
");
}
}
}
}
}
}
...
@@ -909,11 +897,12 @@ sub cleanup
...
@@ -909,11 +897,12 @@ sub cleanup
UPDATE
UPDATE
@TP@topups
@TP@topups
SET
SET
Depleted = 1
Depleted = 1,
SMAdminDepletedOn = ?
WHERE
WHERE
ID = ?
ID = ?
',
',
$topupID
$depletedTimestamp
,
$topupID
);
);
if
(
!
$sth
)
{
if
(
!
$sth
)
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups:
"
.
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups:
"
.
...
@@ -929,11 +918,12 @@ sub cleanup
...
@@ -929,11 +918,12 @@ sub cleanup
UPDATE
UPDATE
@TP@topups_summary
@TP@topups_summary
SET
SET
Depleted = 1
Depleted = 1,
SMAdminDepletedOn = ?
WHERE
WHERE
TopupID = ?
TopupID = ?
',
',
$topupID
$depletedTimestamp
,
$topupID
);
);
if
(
!
$sth
)
{
if
(
!
$sth
)
{
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups_summary:
"
.
$server
->
log
(
LOG_ERR
,"
[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups_summary:
"
.
...
...
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