mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-11-01 02:48:18 +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);
|
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
|
// mac re-formater
|
||||||
format_mac: function(format, mac) {
|
format_mac: function(format, mac) {
|
||||||
switch(format) {
|
switch(format) {
|
||||||
@@ -163,19 +173,13 @@ return {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// generate the default radius auth payload
|
// generate the default radius auth payload
|
||||||
radius_init: function(ctx, acct_session) {
|
radius_init: function(ctx) {
|
||||||
let math = require('math');
|
if (!ctx.sessionid)
|
||||||
if (!acct_session) {
|
ctx.sessionid = this.session_init();
|
||||||
acct_session = '';
|
|
||||||
|
|
||||||
for (let i = 0; i < 16; i++)
|
|
||||||
acct_session += sprintf('%d', math.rand() % 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
let payload = {
|
let payload = {
|
||||||
server: sprintf('%s:%s:%s', ctx.config.auth_server, ctx.config.auth_port, ctx.config.auth_secret),
|
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_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,
|
client_ip: ctx.env.REMOTE_ADDR,
|
||||||
called_station: ctx.config.nasmac + ':' + ctx.ssid,
|
called_station: ctx.config.nasmac + ':' + ctx.ssid,
|
||||||
calling_station: ctx.format_mac,
|
calling_station: ctx.format_mac,
|
||||||
@@ -210,7 +214,8 @@ return {
|
|||||||
'&ip=' + ctx.env.REMOTE_ADDR +
|
'&ip=' + ctx.env.REMOTE_ADDR +
|
||||||
'&called=' + ctx.config.nasmac +
|
'&called=' + ctx.config.nasmac +
|
||||||
'&nasid=' + ctx.config.nasid +
|
'&nasid=' + ctx.config.nasid +
|
||||||
'&ssid=' + ctx.ssid;
|
'&ssid=' + ctx.ssid +
|
||||||
|
'&sessionid=' + ctx.sessionid;
|
||||||
if (ctx.query_string?.redir)
|
if (ctx.query_string?.redir)
|
||||||
uam_url += '&userurl=' + ctx.query_string.redir;
|
uam_url += '&userurl=' + ctx.query_string.redir;
|
||||||
if (ctx.config.uam_secret)
|
if (ctx.config.uam_secret)
|
||||||
@@ -268,8 +273,20 @@ return {
|
|||||||
});
|
});
|
||||||
connected.data.ssid = hapd.ssid;
|
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.device = connected.device;
|
||||||
ctx.ssid = connected.data.ssid;
|
ctx.ssid = connected.data.ssid;
|
||||||
|
ctx.sessionid = connected.data.sessionid;
|
||||||
|
|
||||||
// split QUERY_STRING
|
// split QUERY_STRING
|
||||||
if (env.QUERY_STRING)
|
if (env.QUERY_STRING)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function auth_client(ctx) {
|
|||||||
ctx.query_string.userurl = portal.uam_url(ctx, 'success');
|
ctx.query_string.userurl = portal.uam_url(ctx, 'success');
|
||||||
portal.allow_client(ctx, { radius: { reply: radius.reply, request: payload } } );
|
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.acct = true;
|
||||||
payload.username = ctx.query_string.username;
|
payload.username = ctx.query_string.username;
|
||||||
payload.acct_type = 1;
|
payload.acct_type = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user