mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-10-31 18:38:10 +00:00
ucentral-event: add wired events
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
@@ -2,5 +2,6 @@
|
|||||||
"ssh",
|
"ssh",
|
||||||
"health","health.dns", "health.dhcp", "health.radius", "health.memory",
|
"health","health.dns", "health.dhcp", "health.radius", "health.memory",
|
||||||
"client", "client.join", "client.leave", "client.key-mismatch",
|
"client", "client.join", "client.leave", "client.key-mismatch",
|
||||||
"wifi", "wifi.start", "wifi.stop"
|
"wifi", "wifi.start", "wifi.stop",
|
||||||
|
"wired", "wired.carrier-up", "wired.carrier-down"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,6 +7,14 @@ import * as libuci from 'uci';
|
|||||||
import * as uloop from 'uloop';
|
import * as uloop from 'uloop';
|
||||||
import * as nl80211 from 'nl80211';
|
import * as nl80211 from 'nl80211';
|
||||||
import * as rtnl from 'rtnl';
|
import * as rtnl from 'rtnl';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
let capab = {};
|
||||||
|
let capabfile = fs.open("/etc/ucentral/capabilities.json", "r");
|
||||||
|
if (capabfile) {
|
||||||
|
capab = json(capabfile.read("all"));
|
||||||
|
capabfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
uloop.init();
|
uloop.init();
|
||||||
|
|
||||||
@@ -20,6 +28,7 @@ let log_subscriber;
|
|||||||
let ratelimit = false;
|
let ratelimit = false;
|
||||||
let config;
|
let config;
|
||||||
let wan_ports;
|
let wan_ports;
|
||||||
|
let carrier = {};
|
||||||
|
|
||||||
function config_load() {
|
function config_load() {
|
||||||
uci.load('event');
|
uci.load('event');
|
||||||
@@ -255,8 +264,27 @@ function nl_cb(msg) {
|
|||||||
event('client', 'leave', payload);
|
event('client', 'leave', payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ifname_lookup(prefix, ifname, list) {
|
||||||
|
let idx = index(list, ifname);
|
||||||
|
if (idx < 0)
|
||||||
|
return;
|
||||||
|
return prefix + (idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
function rtnl_cb(msg) {
|
function rtnl_cb(msg) {
|
||||||
printf('%.J\n', msg);
|
if (!exists(msg.msg, "carrier"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
let name = ifname_lookup('LAN', msg.msg?.ifname, capab.network?.lan);
|
||||||
|
if (!name)
|
||||||
|
name = ifname_lookup('WAN', msg.msg?.ifname, capab.network?.wan);
|
||||||
|
if (name) {
|
||||||
|
let verb = msg.msg.carrier ? 'carrier-up' : 'carrier-down';
|
||||||
|
if (carrier[name] == verb)
|
||||||
|
return;
|
||||||
|
carrier[name] = verb;
|
||||||
|
event('wired', verb, { name });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ubus_methods = {
|
let ubus_methods = {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
"types": [ "ssh", "health", "wifi" ]
|
"types": [ "ssh", "health", "wifi" ]
|
||||||
},
|
},
|
||||||
"realtime": {
|
"realtime": {
|
||||||
"types": [ "client.join", "client.leave", "client.key-mismatch" ]
|
"types": [ "client.join", "client.leave", "client.key-mismatch", "wired" ]
|
||||||
},
|
},
|
||||||
"health": {
|
"health": {
|
||||||
"interval": 120
|
"interval": 120
|
||||||
|
|||||||
Reference in New Issue
Block a user