33
44from offspot_config .utils .yaml import yaml_load
55
6- from adminui .constants import DOCKER_COMPOSE_PATH , HOSTAPD_CONF_PATH
6+ from adminui .constants import DOCKER_COMPOSE_PATH , HOSTAPD_CONF_PATH , logger
77from adminui .context import Context
88from adminui .hostbridge import bridge
99from adminui .utils import read_offspot_conf
@@ -32,6 +32,11 @@ class ComposeData:
3232
3333 kiwix_prefix : str = "browse"
3434
35+ has_clock : bool = False
36+ has_filemanager : bool = False
37+ has_zimmanager : bool = False
38+ has_metrics : bool = False
39+
3540
3641@dataclass
3742class WifiConf :
@@ -57,29 +62,61 @@ def get_from_compose() -> ComposeData:
5762 svc_names = compose ["services" ]["reverse-proxy" ]["environment" ]["SERVICES" ].split (
5863 ","
5964 )
65+
66+ has_clock = has_filemanager = has_zimmanager = has_metrics = False
6067 kiwix_prefix = "kiwix"
6168 for svc_name in svc_names :
62- if svc_name .endswith (":kiwix" ):
69+ svc_id = svc_name .rsplit (":" , 1 )[- 1 ]
70+ if svc_id == "kiwix" :
6371 kiwix_prefix = svc_name .split (":" , 1 )[0 ]
6472
65- return ComposeData (tld = tld , domain = domain , kiwix_prefix = kiwix_prefix )
73+ if svc_id == "hwclock" :
74+ has_clock = True
75+ if svc_id == "zim-manager" :
76+ has_zimmanager = True
77+ if svc_id == "resources" :
78+ has_filemanager = True
79+ if svc_id == "metrics" :
80+ has_metrics = True
81+
82+ return ComposeData (
83+ tld = tld ,
84+ domain = domain ,
85+ kiwix_prefix = kiwix_prefix ,
86+ has_clock = has_clock ,
87+ has_zimmanager = has_zimmanager ,
88+ has_filemanager = has_filemanager ,
89+ has_metrics = has_metrics ,
90+ )
6691
6792
6893def get_capabilities_from_config () -> Capabilities :
69- yaml_config = read_offspot_conf ()
70- cap = yaml_config .get ("capabilities" , {})
71- # only SSID change ATM
72- return Capabilities (change_ssid = cap .get ("change_ssid" ))
94+ capabilities = Capabilities ()
95+ try :
96+ yaml_config = read_offspot_conf ()
97+ except Exception as exc :
98+ logger .error (f"Failed to read capabilities from config: { exc } " )
99+ logger .exception (exc )
100+ else :
101+ cap = yaml_config .get ("capabilities" , {})
102+ # only SSID change ATM
103+ capabilities .change_ssid = cap .get ("change_ssid" )
104+ return capabilities
73105
74106
75107def get_wifi_conf_from_offspot_yaml () -> WifiConf :
76108 """read offspot.yaml for updated-not-applied changes to WiFi conf"""
77109 conf = WifiConf ()
78- yaml_config = read_offspot_conf ()
79- ap = yaml_config .get ("ap" , {})
80- conf .profile = ap .get ("profile" , conf .profile )
81- conf .ssid = ap .get ("ssid" , conf .ssid )
82- conf .passphrase = ap .get ("passphrase" , conf .passphrase )
110+ try :
111+ yaml_config = read_offspot_conf ()
112+ except Exception as exc :
113+ logger .error (f"Failed to read offspot config: { exc } " )
114+ logger .exception (exc )
115+ else :
116+ ap = yaml_config .get ("ap" , {})
117+ conf .profile = ap .get ("profile" , conf .profile )
118+ conf .ssid = ap .get ("ssid" , conf .ssid )
119+ conf .passphrase = ap .get ("passphrase" , conf .passphrase )
83120 return conf
84121
85122
@@ -135,6 +172,10 @@ def prepare_context():
135172 tld = compose_data .tld ,
136173 domain = compose_data .domain ,
137174 kiwix_prefix = compose_data .kiwix_prefix ,
175+ has_clock = compose_data .has_clock ,
176+ has_zimmanager = compose_data .has_zimmanager ,
177+ has_filemanager = compose_data .has_filemanager ,
178+ has_metrics = compose_data .has_metrics ,
138179 can_change_ssid = capabilities .change_ssid ,
139180 wifi_profile = wifi_conf .profile ,
140181 wifi_ssid = wifi_conf .ssid ,
0 commit comments