ucentral-state: add admin_ui support

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-09-20 08:39:02 +02:00
parent ce20001751
commit 39ca4eedaa
5 changed files with 158 additions and 5 deletions

View File

@@ -0,0 +1,109 @@
{
"uuid": 2,
"radios": [
{
"band": "2G",
"country": "US",
"channel-mode": "HE",
"channel-width": 20,
"channel": 1
}, {
"band": "5G",
"country": "US",
"channel-mode": "HE",
"channel-width": 80,
"channel": 36
}
],
"interfaces": [
{
"name": "WAN",
"role": "upstream",
"services": [ "lldp" ],
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
},
"ssids": [
{
"name": "OpenWifi",
"wifi-bands": [
"2G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
}
}
]
},
{
"name": "LAN",
"role": "downstream",
"services": [ "ssh", "lldp" ],
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"subnet": "192.168.1.1/24",
"dhcp": {
"lease-first": 10,
"lease-count": 100,
"lease-time": "6h"
}
},
"ssids": [
{
"name": "OpenWifi",
"wifi-bands": [
"2G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
}
}
]
}
],
"metrics": {
"statistics": {
"interval": 120,
"types": [ "ssids", "lldp", "clients" ]
},
"health": {
"interval": 120
}
},
"services": {
"lldp": {
"describe": "uCentral",
"location": "universe"
},
"ssh": {
"port": 22
},
"admin-ui": {
"wifi-ssid": "Maverick",
"wifi-key": "aaaaaaaa",
"offline-trigger": 60
}
}
}

View File

@@ -5,12 +5,13 @@
"band": "2G",
"country": "US",
"channel-mode": "HE",
"channel-width": 40
"channel-width": 20
}, {
"band": "5G",
"country": "US",
"channel-mode": "HE",
"channel-width": 80
"channel-width": 80,
"channel": 36
}
],
@@ -68,6 +69,11 @@
"services": {
"ssh": {
"port": 22
},
"admin-ui": {
"wifi-ssid": "Maverick",
"wifi-bands": [ "5G" ],
"offline-trigger": 30,
}
}
}

View File

@@ -23,6 +23,7 @@ define Package/ucentral-state/install
$(INSTALL_BIN) ./files/ucentral-state $(1)/usr/sbin/
$(INSTALL_BIN) ./files/ucentral-pstore $(1)/usr/sbin/
$(INSTALL_BIN) ./files/ucentral-state.init $(1)/etc/init.d/ucentral-state
$(INSTALL_BIN) ./files/ucentral-state.config $(1)/etc/config/state
endef
$(eval $(call BuildPackage,ucentral-state))

View File

@@ -14,6 +14,11 @@ uloop.init();
let ubus = libubus.connect();
let uci = libuci.cursor();
let config;
let offline_timer;
function self_healing() {
}
let healthcheck;
healthcheck = {
@@ -31,6 +36,7 @@ healthcheck = {
complete: function() {
printf('healtcheck completed\n');
healthcheck.run(healthcheck.delay);
self_healing();
},
spawn: function() {
@@ -63,11 +69,31 @@ state = {
},
};
function offline_handler() {
printf('going offline\n');
ubus.call('network.interface.admin_ui', 'up');
}
function online_handler() {
printf('going online\n');
ubus.call('network.interface.admin_ui', 'down');
if (offline_timer)
offline_timer.cancel();
}
function config_load() {
uci.load('ustats');
config = uci.get_all('ustats');
printf('loading config\n');
uci.load('state');
config = uci.get_all('state');
healthcheck.run((config?.health?.interval || 0) * 1000);
state.run((config?.stats?.interval || 0) * 1000);
let status = ubus.call('ucentral', 'status');
if (status?.connected)
online_handler();
else if (config.ui.offline_trigger)
offline_timer = uloop.timer(config.ui.offline_trigger * 1000, offline_handler);
}
function led_write(led, property, value) {
@@ -105,11 +131,13 @@ function blink_timeout() {
}
let state_handler = {
connect: function() {
offline: function() {
let led = led_find('led-running');
if (!led)
return ubus.STATUS_INVALID_ARGUMENT;
led_write(led, 'trigger', 'heartbeat');
if (config.ui.offline_trigger)
offline_timer = uloop.timer(config.ui.offline_trigger * 1000, offline_handler);
return 0;
},
@@ -118,6 +146,7 @@ let state_handler = {
if (!led)
return ubus.STATUS_INVALID_ARGUMENT;
led_write(led, 'trigger', 'default-on');
online_handler();
return 0;
},
@@ -168,5 +197,6 @@ let ubus_methods = {
ubus.publish('state', ubus_methods);
config_load();
uloop.run();
uloop.done();

View File

@@ -0,0 +1,7 @@
config admin ui
config stats stats
option interval 600
config health health
option interval 120