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

Merge remote branch 'randerson/validuntil-002' into randerson-nigel-validity-window

parents 1796a7b5 faf660f1
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,8 @@ my @attributeReplyIgnoreList = ( ...@@ -51,7 +51,8 @@ my @attributeReplyIgnoreList = (
'SMRadius-Capping-Traffic-Limit', 'SMRadius-Capping-Traffic-Limit',
'SMRadius-Capping-Uptime-Limit', 'SMRadius-Capping-Uptime-Limit',
'SMRadius-Validity-ValidFrom', 'SMRadius-Validity-ValidFrom',
'SMRadius-Validity-ValidTo' 'SMRadius-Validity-ValidTo',
'SMRadius-Validity-ValidWindow'
); );
my @attributeVReplyIgnoreList = ( my @attributeVReplyIgnoreList = (
); );
......
...@@ -44,12 +44,14 @@ our $pluginInfo = { ...@@ -44,12 +44,14 @@ our $pluginInfo = {
# Authentication hook # Authentication hook
'Feature_Post-Authentication_hook' => \&checkValidity, 'Feature_Post-Authentication_hook' => \&checkValidity,
'Feature_Post-Accounting_hook' => \&checkValidity
}; };
# Some constants # Some constants
my $VALID_FROM_KEY = 'SMRadius-Validity-ValidFrom'; my $VALID_FROM_KEY = 'SMRadius-Validity-ValidFrom';
my $VALID_TO_KEY = 'SMRadius-Validity-ValidTo'; my $VALID_TO_KEY = 'SMRadius-Validity-ValidTo';
my $VALID_WINDOW_KEY = 'SMRadius-Validity-ValidWindow';
## @internal ## @internal
...@@ -154,6 +156,57 @@ sub checkValidity ...@@ -154,6 +156,57 @@ sub checkValidity
} }
} }
# Get validity window
my $validWindow;
if (defined($user->{'Attributes'}->{$VALID_WINDOW_KEY})) {
$server->log(LOG_DEBUG,"[MOD_FEATURE_VALIDITY] '".$VALID_WINDOW_KEY."' is defined");
# Operator: :=
if (defined($user->{'Attributes'}->{$VALID_WINDOW_KEY}->{':='})) {
# Is it a number?
if ($user->{'Attributes'}->{$VALID_WINDOW_KEY}->{':='}->{'Value'} =~ /^\d+$/) {
$validWindow = $user->{'Attributes'}->{$VALID_WINDOW_KEY}->{':='}->{'Value'};
} else {
$server->log(LOG_NOTICE,"[MOD_FEATURE_VALIDITY] '".$user->{'Attributes'}->{$VALID_WINDOW_KEY}->{':='}->{'Value'}.
"' is NOT an integer");
}
} else {
$server->log(LOG_NOTICE,"[MOD_FEATURE_VALIDITY] No valid operators for attribute '$VALID_WINDOW_KEY'");
}
}
# Loop with plugins to find anything supporting getting user data
my $user_data;
foreach my $module (@{$server->{'module_list'}}) {
# Do we have the correct plugin?
if ($module->{'Users_data_get'}) {
$server->log(LOG_INFO,"[MOD_FEATURE_VALIDITY] Found plugin: '".$module->{'Name'}."'");
# Fetch users data
my $res = $module->{'Users_data_get'}($server,$user,'global','FirstLogin');
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_VALIDITY] No user data found for user '".$packet->attr('User-Name')."'");
return MOD_RES_SKIP;
}
$user_data = $res;
}
}
# Check if this user should be disconnected
if (defined($validWindow) && defined($user_data)) {
my $validUntil = $validWindow + $user_data->{'Value'};
if (!defined($validUntil)) {
$server->log(LOG_DEBUG,"[MOD_FEATURE_VALIDITY] Failed to calculate end of valid window using "
.niceUndef($validWindow)." and ".niceUndef($user_data->{'Value'}));
# If current time after start of valid pariod
} elsif ($now > $validUntil) {
my $pretty_dt = DateTime->from_epoch( epoch => $validUntil )->strftime('%Y-%m-%d %H:%M:%S');
$server->log(LOG_DEBUG,"[MOD_FEATURE_VALIDITY] Current date outside valid window end date: '".$pretty_dt."', rejecting");
# Date not within valid window, must be disconnected
return MOD_RES_NACK;
}
}
return MOD_RES_ACK; return MOD_RES_ACK;
} }
......
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