uspot: properly terminate Acct when /logoff happens

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2022-11-28 12:22:23 +01:00
parent e61ab97815
commit 3795060bf2
2 changed files with 41 additions and 18 deletions

View File

@@ -60,6 +60,8 @@ function radius_stop(mac) {
if (!radius_available(mac)) if (!radius_available(mac))
return; return;
debug(mac, 'stopping accounting'); debug(mac, 'stopping accounting');
if (clients[mac].accounting)
clients[mac].timeout.cancel();
let payload = { let payload = {
acct: true, acct: true,
@@ -115,6 +117,16 @@ function radius_session_time(mac) {
radius_acct(mac, payload); radius_acct(mac, payload);
} }
function radius_logoff(mac) {
if (!radius_available(mac))
return;
let payload = {
acct_type: 2,
terminate_cause: 0,
};
radius_acct(mac, payload);
}
function radius_disconnect(mac) { function radius_disconnect(mac) {
if (!radius_available(mac)) if (!radius_available(mac))
return; return;
@@ -168,26 +180,31 @@ function client_add(mac, state) {
function client_remove(mac, reason) { function client_remove(mac, reason) {
syslog(mac, reason); syslog(mac, reason);
if (clients[mac]) { radius_stop(mac);
radius_stop(mac); delete clients[mac];
if (clients[mac].accounting)
clients[mac].timeout.cancel();
delete clients[mac];
}
ubus.call('spotfilter', 'client_remove', { ubus.call('spotfilter', 'client_remove', {
interface: "hotspot", interface: "hotspot",
address: mac address: mac
}); });
} }
function client_flush(mac) {
syslog(mac, 'logoff event');
radius_stop(mac);
ubus.call('spotfilter', 'client_set', {
interface: 'hotspot',
address: mac,
state: 0,
dns_state: 1,
accounting: [],
flush: true
});
}
function client_timeout(mac) { function client_timeout(mac) {
syslog(mac, 'session timeout'); syslog(mac, 'session timeout');
if (clients[mac]) { radius_stop(mac);
radius_stop(mac); delete clients[mac];
if (clients[mac].accounting)
clients[mac].timeout.cancel();
delete clients[mac];
}
ubus.call('spotfilter', 'client_set', { ubus.call('spotfilter', 'client_set', {
interface: "hotspot", interface: "hotspot",
state: 0, state: 0,
@@ -208,29 +225,33 @@ uloop.timer(1000, function() {
if (!clients[k]) if (!clients[k])
client_add(k, v); client_add(k, v);
for (let k, v in clients) for (let k, v in clients) {
if (list[k].data?.logoff) {
radius_logoff(k);
client_flush(k);
continue;
}
if (!list[k] || !list[k].state) { if (!list[k] || !list[k].state) {
radius_disconnect(k); radius_disconnect(k);
client_remove(k, 'disconnect event'); client_remove(k, 'disconnect event');
continue;
} }
for (let k, v in list) {
if (v.idle > get_idle_timeout(k)) { if (v.idle > get_idle_timeout(k)) {
if (clients[k]) if (clients[k])
radius_idle_time(k); radius_idle_time(k);
client_remove(k, 'idle event'); client_remove(k, 'idle event');
} }
let timeout = get_session_timeout(k); let timeout = get_session_timeout(k);
if (timeout && ((t - v.data.connect) > timeout)) { if (timeout && ((t - v.data.connect) > timeout)) {
if (clients[k]) if (clients[k])
radius_session_time(k); radius_session_time(k);
client_timeout(k); client_timeout(k);
} }
} }
this.set(5000); this.set(1000);
}); });
uloop.run(); uloop.run();

View File

@@ -119,7 +119,9 @@ return {
state: 0, state: 0,
dns_state: 1, dns_state: 1,
accounting: [], accounting: [],
flush: true, data: {
logoff : 1
}
}); });
if (uam) if (uam)