Skip to content
Snippets Groups Projects
Commit 2f7c725d authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added Mikrotik-specific vendor attribute returns on FEATURE_CAPPING module

parent 15e200c1
No related branches found
No related tags found
No related merge requests found
...@@ -21,10 +21,14 @@ use strict; ...@@ -21,10 +21,14 @@ use strict;
use warnings; use warnings;
# Modules we need # Modules we need
use smradius::attributes;
use smradius::constants; use smradius::constants;
use smradius::logging; use smradius::logging;
use smradius::util; use smradius::util;
use POSIX qw(floor);
# Exporter stuff # Exporter stuff
require Exporter; require Exporter;
our (@ISA,@EXPORT,@EXPORT_OK); our (@ISA,@EXPORT,@EXPORT_OK);
...@@ -55,11 +59,30 @@ my $UPTIME_LIMIT_KEY = 'SMRadius-Capping-Uptime-Limit'; ...@@ -55,11 +59,30 @@ my $UPTIME_LIMIT_KEY = 'SMRadius-Capping-Uptime-Limit';
my $TRAFFIC_TOPUPS_KEY = 'SMRadius-Capping-Traffic-Topup'; my $TRAFFIC_TOPUPS_KEY = 'SMRadius-Capping-Traffic-Topup';
my $TIME_TOPUPS_KEY = 'SMRadius-Capping-Uptime-Topup'; my $TIME_TOPUPS_KEY = 'SMRadius-Capping-Uptime-Topup';
my $config;
## @internal ## @internal
# Initialize module # Initialize module
sub init sub init
{ {
my $server = shift; my $server = shift;
my $scfg = $server->{'inifile'};
# Setup SQL queries
if (defined($scfg->{'mod_feature_capping'})) {
# Pull in config
if ($scfg->{'mod_feature_capping'}{'enable_mikrotik'} =~ /^\s*(yes|true|1)\s*$/i) {
$server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Mikrotik-specific vendor return attributes ENABLED");
$config->{'enable_mikrotik'} = $scfg->{'mod_feature_capping'}{'enable_mikrotik'};
# Default?
} elsif ($scfg->{'mod_feature_capping'}{'enable_mikrotik'} =~ /^\s*(no|false|0)\s*$/i) {
$config->{'enable_mikrotik'} = undef;
} else {
$server->log(LOG_NOTICE,"[MOD_FEATURE_CAPPING] Value for 'enable_mikrotik' is invalid");
}
}
} }
...@@ -278,6 +301,18 @@ sub post_auth_hook ...@@ -278,6 +301,18 @@ sub post_auth_hook
$server->log(LOG_DEBUG,"[MOD_FEATURE_CAPPING] Usage of ".$accountingUsage->{'TotalSessionTime'}. $server->log(LOG_DEBUG,"[MOD_FEATURE_CAPPING] Usage of ".$accountingUsage->{'TotalSessionTime'}.
"Min exceeds allowed limit of ".$alteredUptimeLimit."Min. Capped."); "Min exceeds allowed limit of ".$alteredUptimeLimit."Min. Capped.");
return MOD_RES_NACK; return MOD_RES_NACK;
# Setup limits
} else {
# Check if we returning Mikrotik vattributes
if (defined($config->{'enable_mikrotik'})) {
# Setup reply attributes for Mikrotik HotSpots
my %attribute = (
'Name' => 'Session-Timeout',
'Operator' => '=',
'Value' => $alteredUptimeLimit - $accountingUsage->{'TotalSessionTime'}
);
setReplyAttribute($server,$user->{'ReplyAttributes'},\%attribute);
}
} }
} }
...@@ -289,6 +324,36 @@ sub post_auth_hook ...@@ -289,6 +324,36 @@ sub post_auth_hook
$server->log(LOG_DEBUG,"[MOD_FEATURE_CAPPING] Usage of ".$accountingUsage->{'TotalDataUsage'}. $server->log(LOG_DEBUG,"[MOD_FEATURE_CAPPING] Usage of ".$accountingUsage->{'TotalDataUsage'}.
"Mb exceeds allowed limit of ".$alteredTrafficLimit."Mb. Capped."); "Mb exceeds allowed limit of ".$alteredTrafficLimit."Mb. Capped.");
return MOD_RES_NACK; return MOD_RES_NACK;
# Setup limits
} else {
# Check if we returning Mikrotik vattributes
if (defined($config->{'enable_mikrotik'})) {
# Get remaining traffic
my $remainingTraffic = $alteredTrafficLimit - $accountingUsage->{'TotalDataUsage'};
my $remainingTrafficLimit = ( $remainingTraffic % 4096 ) * 1024;# * 1024;
my $remainingTrafficGigawords = floor($remainingTraffic / 4096);
# Setup reply attributes for Mikrotik HotSpots
for my $attrName ('Recv','Xmit','Total') {
my %attribute = (
'Vendor' => 14988,
'Name' => "Mikrotik-$attrName-Limit",
'Operator' => '=',
# Gigawords leftovers
'Value' => $remainingTrafficLimit
);
setReplyVAttribute($server,$user->{'ReplyVAttributes'},\%attribute);
%attribute = (
'Vendor' => 14988,
'Name' => "Mikrotik-$attrName-Limit-Gigawords",
'Operator' => '=',
# Gigawords
'Value' => $remainingTrafficGigawords
);
setReplyVAttribute($server,$user->{'ReplyVAttributes'},\%attribute);
}
}
} }
} }
......
...@@ -512,3 +512,10 @@ update_user_stats_query=<<EOT ...@@ -512,3 +512,10 @@ update_user_stats_query=<<EOT
WHERE WHERE
Username = %{request.User-Name} Username = %{request.User-Name}
EOT EOT
# MOD_FEATURE_CAPPING
[mod_feature_capping]
# Enable Mikrotik-specific return vattributes
#enable_mikrotik=1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment