mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-10-30 18:07:52 +00:00
uspot: track client sessionid and provide it to UAM
This commit moves session id creation outside of radius_init() and stores the identifier in ctx and client data, making it available to various handlers. The id is added to the list of uam_url parameters to be sent to the backend. Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
This commit is contained in:
committed by
John Crispin
parent
ecc8829a01
commit
b44c7b09db
@@ -68,6 +68,16 @@ return {
|
||||
this.syslog(ctx, msg);
|
||||
},
|
||||
|
||||
// session id generator
|
||||
session_init: function() {
|
||||
let math = require('math');
|
||||
let sessionid = '';
|
||||
|
||||
for (let i = 0; i < 16; i++)
|
||||
sessionid += sprintf('%d', math.rand() % 10);
|
||||
return sessionid;
|
||||
},
|
||||
|
||||
// mac re-formater
|
||||
format_mac: function(format, mac) {
|
||||
switch(format) {
|
||||
@@ -163,19 +173,13 @@ return {
|
||||
},
|
||||
|
||||
// generate the default radius auth payload
|
||||
radius_init: function(ctx, acct_session) {
|
||||
let math = require('math');
|
||||
if (!acct_session) {
|
||||
acct_session = '';
|
||||
|
||||
for (let i = 0; i < 16; i++)
|
||||
acct_session += sprintf('%d', math.rand() % 10);
|
||||
}
|
||||
|
||||
radius_init: function(ctx) {
|
||||
if (!ctx.sessionid)
|
||||
ctx.sessionid = this.session_init();
|
||||
let payload = {
|
||||
server: sprintf('%s:%s:%s', ctx.config.auth_server, ctx.config.auth_port, ctx.config.auth_secret),
|
||||
acct_server: sprintf('%s:%s:%s', ctx.config.acct_server, ctx.config.acct_port, ctx.config.acct_secret),
|
||||
acct_session,
|
||||
acct_session: ctx.sessionid,
|
||||
client_ip: ctx.env.REMOTE_ADDR,
|
||||
called_station: ctx.config.nasmac + ':' + ctx.ssid,
|
||||
calling_station: ctx.format_mac,
|
||||
@@ -210,7 +214,8 @@ return {
|
||||
'&ip=' + ctx.env.REMOTE_ADDR +
|
||||
'&called=' + ctx.config.nasmac +
|
||||
'&nasid=' + ctx.config.nasid +
|
||||
'&ssid=' + ctx.ssid;
|
||||
'&ssid=' + ctx.ssid +
|
||||
'&sessionid=' + ctx.sessionid;
|
||||
if (ctx.query_string?.redir)
|
||||
uam_url += '&userurl=' + ctx.query_string.redir;
|
||||
if (ctx.config.uam_secret)
|
||||
@@ -268,8 +273,20 @@ return {
|
||||
});
|
||||
connected.data.ssid = hapd.ssid;
|
||||
}
|
||||
if (!connected.data.sessionid) {
|
||||
let sessionid = this.session_init();
|
||||
ctx.ubus.call('spotfilter', 'client_set', {
|
||||
interface: ctx.spotfilter,
|
||||
address: ctx.mac,
|
||||
data: {
|
||||
sessionid: sessionid
|
||||
}
|
||||
});
|
||||
connected.data.sessionid = sessionid;
|
||||
}
|
||||
ctx.device = connected.device;
|
||||
ctx.ssid = connected.data.ssid;
|
||||
ctx.sessionid = connected.data.sessionid;
|
||||
|
||||
// split QUERY_STRING
|
||||
if (env.QUERY_STRING)
|
||||
|
||||
@@ -39,7 +39,7 @@ function auth_client(ctx) {
|
||||
ctx.query_string.userurl = portal.uam_url(ctx, 'success');
|
||||
portal.allow_client(ctx, { radius: { reply: radius.reply, request: payload } } );
|
||||
|
||||
payload = portal.radius_init(ctx, payload.acct_session);
|
||||
payload = portal.radius_init(ctx);
|
||||
payload.acct = true;
|
||||
payload.username = ctx.query_string.username;
|
||||
payload.acct_type = 1;
|
||||
|
||||
Reference in New Issue
Block a user