Commit 637159bc authored by Robert Anderson's avatar Robert Anderson Committed by Nigel Kukard
Browse files

SMRadius-Username-Transform functionality

Using the attribute SMRadius-Username-Transform set for the configuration stage, a username sent by a client can be transformed using the attribute value, eg. @current=@replacement.
parent f08ef44e
......@@ -52,7 +52,8 @@ my @attributeReplyIgnoreList = (
'SMRadius-Capping-Uptime-Limit',
'SMRadius-Validity-ValidFrom',
'SMRadius-Validity-ValidTo',
'SMRadius-Validity-ValidWindow'
'SMRadius-Validity-ValidWindow',
'SMRadius-Username-Transform'
);
my @attributeVReplyIgnoreList = (
);
......
......@@ -110,7 +110,7 @@ sub init
)
VALUES
(
%{request.User-Name},
%{user.Username},
%{request.Service-Type},
%{request.Framed-Protocol},
%{request.NAS-Port},
......@@ -150,7 +150,7 @@ sub init
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -173,7 +173,7 @@ sub init
AcctOutputPackets = %{query.OutputPackets},
AcctStatusType = %{request.Acct-Status-Type}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -187,7 +187,7 @@ sub init
AcctStatusType = %{request.Acct-Status-Type},
AcctTerminateCause = %{request.Acct-Terminate-Cause}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -203,7 +203,7 @@ sub init
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND PeriodKey = %{query.PeriodKey}
';
......@@ -213,7 +213,7 @@ sub init
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......
......@@ -169,7 +169,7 @@ sub post_auth_hook
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......@@ -448,7 +448,7 @@ sub post_acct_hook
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_FEATURE_CAPPING] No usage data found for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......
......@@ -76,7 +76,7 @@ sub init
TotalUptime = %{query.TotalUptime},
NASIdentifier = %{request.NAS-Identifier}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
';
# Setup SQL queries
......@@ -127,7 +127,7 @@ sub updateUserStats
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_FEATURE_UPDATE_USER_STATS_SQL] No usage data found for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_FEATURE_UPDATE_USER_STATS_SQL] No usage data found for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......
......@@ -80,7 +80,7 @@ sub updateUserStats
# Fetch users session uptime & bandwidth used
my $res = $module->{'Accounting_getUsage'}($server,$user,$packet);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_USERS_DATA] No usage data found for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_USERS_DATA] No usage data found for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......@@ -100,7 +100,7 @@ sub updateUserStats
);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store current month traffic usage for user '"
.$packet->attr('User-Name')."'");
.$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......@@ -111,7 +111,7 @@ sub updateUserStats
);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store current month uptime usage for user '"
.$packet->attr('User-Name')."'");
.$user->{'Username'}."'");
return MOD_RES_SKIP;
}
......@@ -122,7 +122,7 @@ sub updateUserStats
$NASIdentifier
);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store NAS-Identifier for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store NAS-Identifier for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
}
......@@ -134,7 +134,7 @@ sub updateUserStats
$framedIPAddress
);
if (!defined($res)) {
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store Framed-IP-Address for user '".$packet->attr('User-Name')."'");
$server->log(LOG_ERR,"[MOD_USERS_DATA] Failed to store Framed-IP-Address for user '".$user->{'Username'}."'");
return MOD_RES_SKIP;
}
}
......
......@@ -194,7 +194,7 @@ sub checkValidity
}
} else {
$server->log(LOG_DEBUG,"[MOD_FEATURE_VALIDITY] No users_data 'global/FirstLogin' found for user '".$packet->attr('User-Name')."'");
$server->log(LOG_DEBUG,"[MOD_FEATURE_VALIDITY] No users_data 'global/FirstLogin' found for user '".$user->{'Username'}."'");
} # if (defined(my $res = $module->{'Users_data_get'}($server,$user,'global','FirstLogin'))) {
} else {
$server->log(LOG_WARN,"[MOD_FEATURE_VALIDITY] UserDB module '".$user->{'_UserDB'}->{'Name'}.
......
......@@ -150,7 +150,7 @@ sub getTopups
# Check to see if we have a username
my $username = $packet->attr('User-Name');
my $username = $user->{'Username'};
# Skip this module if we don't have a username
if (!defined($username)) {
......
......@@ -81,7 +81,7 @@ sub init
FROM
@TP@users
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
';
$config->{'userdb_get_group_attributes_query'} = '
......
......@@ -597,6 +597,30 @@ sub process_request {
}
}
# If we have a config attribute to transform username, use it
if (defined($user->{'ConfigAttributes'}->{'SMRadius-Username-Transform'})) {
$self->log(LOG_DEBUG,"[SMRADIUS] Attribute 'SMRadius-Username-Transform' exists, transforming username.");
# Get clients(NAS) username transform pattern
my $transform = shift(@{$user->{'ConfigAttributes'}->{'SMRadius-Username-Transform'}});
if ($transform =~ /^(@\S+)=(@\S+)$/i) {
# Set old and new, prevents warnings
my ($old,$new) = ($1,$2);
# Use client username transform on temp username
my $tempUsername = $user->{'Username'};
$tempUsername =~ s/$old/$new/;
# Override username
$user->{'Username'} = $tempUsername;
} else {
$self->log(LOG_DEBUG,"[SMRADIUS] No string replacement possible on pattern '".
$transform."', using username '".$user->{'Username'}."'");
}
}
# Get the user timer
my $timer1 = [gettimeofday];
......
......@@ -288,7 +288,7 @@ accounting_start_query=<<EOT
)
VALUES
(
%{request.User-Name},
%{user.Username},
%{request.Service-Type},
%{request.Framed-Protocol},
%{request.NAS-Port},
......@@ -328,7 +328,7 @@ accounting_update_get_records_query=<<EOT
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -351,7 +351,7 @@ accounting_update_query=<<EOT
AcctOutputPackets = %{query.OutputPackets},
AcctStatusType = %{request.Acct-Status-Type}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -365,7 +365,7 @@ accounting_stop_status_query=<<EOT
AcctStatusType = %{request.Acct-Status-Type},
AcctTerminateCause = %{request.Acct-Terminate-Cause}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -381,7 +381,7 @@ accounting_usage_query=<<EOT
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND PeriodKey = %{query.PeriodKey}
EOT
......@@ -391,7 +391,7 @@ accounting_select_duplicates_query=<<EOT
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND NASPortID = %{request.NAS-Port-Id}
......@@ -425,7 +425,7 @@ userdb_find_query=<<EOT
FROM
@TP@users
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
EOT
userdb_get_group_attributes_query=<<EOT
......@@ -510,7 +510,7 @@ update_user_stats_query=<<EOT
TotalUptime = %{query.TotalUptime},
NASIdentifier = %{request.NAS-Identifier}
WHERE
Username = %{request.User-Name}
Username = %{user.Username}
EOT
......
Markdown is supported
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