"""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([s for s in out.strip().split('\n') if s]) 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()}