diff --git a/feeds/ucentral/uspot/files/usr/share/uspot/common.uc b/feeds/ucentral/uspot/files/usr/share/uspot/common.uc index 79dd48581..ed7a50035 100644 --- a/feeds/ucentral/uspot/files/usr/share/uspot/common.uc +++ b/feeds/ucentral/uspot/files/usr/share/uspot/common.uc @@ -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) diff --git a/feeds/ucentral/uspot/files/usr/share/uspot/handler-uam.uc b/feeds/ucentral/uspot/files/usr/share/uspot/handler-uam.uc index b89077298..bc2fea608 100644 --- a/feeds/ucentral/uspot/files/usr/share/uspot/handler-uam.uc +++ b/feeds/ucentral/uspot/files/usr/share/uspot/handler-uam.uc @@ -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;