Commit 972bfaa3 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

WORKAROUND: Added caveat_captrafzero to swap 0 and -undef- around in traffic capping situations

This appears to be broken login in previous versions and people should
be updating.
parent 5c444813
...@@ -75,6 +75,7 @@ sub init ...@@ -75,6 +75,7 @@ sub init
# Defaults # Defaults
$config->{'enable_mikrotik'} = 0; $config->{'enable_mikrotik'} = 0;
$config->{'caveat_captrafzero'} = 0;
# Setup SQL queries # Setup SQL queries
if (defined($scfg->{'mod_feature_capping'})) { if (defined($scfg->{'mod_feature_capping'})) {
...@@ -89,6 +90,16 @@ sub init ...@@ -89,6 +90,16 @@ sub init
} else { } else {
$server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Value for 'enable_mikrotik' is invalid"); $server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Value for 'enable_mikrotik' is invalid");
} }
if (defined(my $val = isBoolean($scfg->{'mod_feature_capping'}{'caveat_captrafzero'}))) {
if ($val) {
$server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Caveat to swap '0' and -undef- for ".
"SMRadius-Capping-Traffic-Limit ENABLED");
$config->{'caveat_captrafzero'} = $val;
}
} else {
$server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Value for 'caveat_captrafzero' is invalid");
}
} }
} }
...@@ -123,6 +134,15 @@ sub post_auth_hook ...@@ -123,6 +134,15 @@ sub post_auth_hook
my $uptimeLimit = _getAttributeKeyLimit($server,$user,$UPTIME_LIMIT_ATTRIBUTE); my $uptimeLimit = _getAttributeKeyLimit($server,$user,$UPTIME_LIMIT_ATTRIBUTE);
my $trafficLimit = _getAttributeKeyLimit($server,$user,$TRAFFIC_LIMIT_ATTRIBUTE); my $trafficLimit = _getAttributeKeyLimit($server,$user,$TRAFFIC_LIMIT_ATTRIBUTE);
# Swap around 0 and undef if we need to apply the captrafzero caveat
if ($config->{'caveat_captrafzero'}) {
if (!defined($trafficLimit)) {
$trafficLimit = 0;
} elsif ($trafficLimit == 0) {
$trafficLimit = undef;
}
}
# #
# Get current traffic and uptime usage # Get current traffic and uptime usage
...@@ -227,8 +247,8 @@ sub post_auth_hook ...@@ -227,8 +247,8 @@ sub post_auth_hook
# Check if we've exceeded our limits # Check if we've exceeded our limits
# #
# Uptime.. # Uptime...
if (!defined($uptimeLimit) || $uptimeLimit > 0) { if (defined($uptimeLimit)) {
# Check session time has not exceeded what we're allowed # Check session time has not exceeded what we're allowed
if ($accountingUsage->{'TotalSessionTime'} >= $uptimeLimitWithTopups) { if ($accountingUsage->{'TotalSessionTime'} >= $uptimeLimitWithTopups) {
...@@ -253,7 +273,7 @@ sub post_auth_hook ...@@ -253,7 +273,7 @@ sub post_auth_hook
} }
# Traffic # Traffic
if (!defined($trafficLimit) || $trafficLimit > 0) { if (defined($trafficLimit)) {
# Capped # Capped
if ($accountingUsage->{'TotalDataUsage'} >= $trafficLimitWithTopups) { if ($accountingUsage->{'TotalDataUsage'} >= $trafficLimitWithTopups) {
...@@ -330,6 +350,14 @@ sub post_acct_hook ...@@ -330,6 +350,14 @@ sub post_acct_hook
my $uptimeLimit = _getAttributeKeyLimit($server,$user,$UPTIME_LIMIT_ATTRIBUTE); my $uptimeLimit = _getAttributeKeyLimit($server,$user,$UPTIME_LIMIT_ATTRIBUTE);
my $trafficLimit = _getAttributeKeyLimit($server,$user,$TRAFFIC_LIMIT_ATTRIBUTE); my $trafficLimit = _getAttributeKeyLimit($server,$user,$TRAFFIC_LIMIT_ATTRIBUTE);
# Swap around 0 and undef if we need to apply the captrafzero caveat
if ($config->{'caveat_captrafzero'}) {
if (!defined($trafficLimit)) {
$trafficLimit = 0;
} elsif ($trafficLimit == 0) {
$trafficLimit = undef;
}
}
# #
# Get current traffic and uptime usage # Get current traffic and uptime usage
...@@ -422,7 +450,7 @@ sub post_acct_hook ...@@ -422,7 +450,7 @@ sub post_acct_hook
# #
# Uptime.. # Uptime..
if (!defined($uptimeLimit) || $uptimeLimit > 0) { if (defined($uptimeLimit)) {
# Capped # Capped
if ($accountingUsage->{'TotalSessionTime'} >= $uptimeLimitWithTopups) { if ($accountingUsage->{'TotalSessionTime'} >= $uptimeLimitWithTopups) {
...@@ -433,7 +461,7 @@ sub post_acct_hook ...@@ -433,7 +461,7 @@ sub post_acct_hook
} }
# Traffic # Traffic
if (!defined($trafficLimit) || $trafficLimit > 0) { if (defined($trafficLimit)) {
# Capped # Capped
if ($accountingUsage->{'TotalDataUsage'} >= $trafficLimitWithTopups) { if ($accountingUsage->{'TotalDataUsage'} >= $trafficLimitWithTopups) {
...@@ -514,10 +542,10 @@ sub _logUsage ...@@ -514,10 +542,10 @@ sub _logUsage
my $typeKey = ucfirst($type); my $typeKey = ucfirst($type);
# Check if our limit is defined # Check if our limit is defined
if (defined($limit) && !$limit) { if (defined($limit) && $limit == 0) {
$limit = '-none-';
} else {
$limit = '-topup-'; $limit = '-topup-';
} else {
$limit = '-none-';
} }
$server->log(LOG_INFO,"[MOD_FEATURE_CAPPING] Capping information [type: %s, total: %s, limit: %s, topups: %s]", $server->log(LOG_INFO,"[MOD_FEATURE_CAPPING] Capping information [type: %s, total: %s, limit: %s, topups: %s]",
......
...@@ -544,6 +544,10 @@ EOT ...@@ -544,6 +544,10 @@ EOT
# MOD_FEATURE_CAPPING # MOD_FEATURE_CAPPING
[mod_feature_capping] [mod_feature_capping]
# Enable Mikrotik-specific return vattributes # Enable Mikrotik-specific return vattributes
#enable_mikrotik=1 #enable_mikrotik=1
# Enable caveat for SMRadius-Capping-Traffic-Limit having the meaning of 0 and -undef- swapped up to v1.0.x
#caveat_captrafzero=1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment