Files
Mark-VIII/payload/user/remote_access/pager-webui/mk8_guard.py
T

36 lines
1.2 KiB
Python

"""Boot-time reconciliation of crash-prone PineAP settings."""
from server import (_apply_uci_wanted, _monitor_down, _raise_monitors,
PINEAPD_SAFE_UCI, device_run)
WANTED_EXTRA = {'pineapd.@pineapd[0].autossidpool': '0'}
POOL_CLEAR_MAX = 20
MONITORS = ('wlan0mon', 'wlan1mon')
def _pool_size():
rc, out, err = device_run(
['uci', 'get', 'pineapd.@ssidpool[0].ssid'])
if rc != 0 or not (out or '').strip():
return 0
return len(out.split())
def reconcile(clear_pool=True):
changed = _apply_uci_wanted(dict(PINEAPD_SAFE_UCI, **WANTED_EXTRA))
pool_cleared = False
if clear_pool and _pool_size() > POOL_CLEAR_MAX:
device_run(['uci', 'delete', 'pineapd.@ssidpool[0].ssid'])
pool_cleared = True
if changed or pool_cleared:
device_run(['uci', 'commit', 'pineapd'])
raised = _raise_monitors() if any(_monitor_down(m) for m in MONITORS) else []
return {'changed': changed, 'pool_cleared': pool_cleared,
'monitors_raised': raised}
def guard_report():
from server import _pending_uci
pending = _pending_uci(dict(PINEAPD_SAFE_UCI, **WANTED_EXTRA))
return {'in_sync': not pending, 'pending': pending,
'pool_size': _pool_size()}