diff --git a/feeds/ucentral/ucentral-schema/files/etc/ucentral/examples/admin_ui.json b/feeds/ucentral/ucentral-schema/files/etc/ucentral/examples/admin_ui.json new file mode 100644 index 000000000..319219b6a --- /dev/null +++ b/feeds/ucentral/ucentral-schema/files/etc/ucentral/examples/admin_ui.json @@ -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 + } + } +} diff --git a/feeds/ucentral/ucentral-schema/files/etc/ucentral/ucentral.cfg.0000000001 b/feeds/ucentral/ucentral-schema/files/etc/ucentral/ucentral.cfg.0000000001 index f63f1b4fa..592b0d28f 100644 --- a/feeds/ucentral/ucentral-schema/files/etc/ucentral/ucentral.cfg.0000000001 +++ b/feeds/ucentral/ucentral-schema/files/etc/ucentral/ucentral.cfg.0000000001 @@ -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, } } } diff --git a/feeds/ucentral/ucentral-state/Makefile b/feeds/ucentral/ucentral-state/Makefile index b7966efd8..f2a9d874a 100644 --- a/feeds/ucentral/ucentral-state/Makefile +++ b/feeds/ucentral/ucentral-state/Makefile @@ -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)) diff --git a/feeds/ucentral/ucentral-state/files/ucentral-state b/feeds/ucentral/ucentral-state/files/ucentral-state index c30243841..a1c4544ad 100755 --- a/feeds/ucentral/ucentral-state/files/ucentral-state +++ b/feeds/ucentral/ucentral-state/files/ucentral-state @@ -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(); diff --git a/feeds/ucentral/ucentral-state/files/ucentral-state.config b/feeds/ucentral/ucentral-state/files/ucentral-state.config new file mode 100644 index 000000000..c9821b7c2 --- /dev/null +++ b/feeds/ucentral/ucentral-state/files/ucentral-state.config @@ -0,0 +1,7 @@ +config admin ui + +config stats stats + option interval 600 + +config health health + option interval 120