From 7140ceb7221c31a4cc132834b264b3fb0e0a168f Mon Sep 17 00:00:00 2001 From: themylogin Date: Wed, 7 Aug 2024 09:20:32 +0200 Subject: [PATCH 1/3] Refresh Web UI URLs displayed in CLI on settings update --- .../plugins/network_/global_config.py | 12 +----------- .../middlewared/plugins/system/cli.py | 16 ++++++++++++++++ .../middlewared/plugins/system_general/update.py | 12 ++++++++---- 3 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 src/middlewared/middlewared/plugins/system/cli.py diff --git a/src/middlewared/middlewared/plugins/network_/global_config.py b/src/middlewared/middlewared/plugins/network_/global_config.py index 6aa7d2a654dab..eb68009b573cd 100644 --- a/src/middlewared/middlewared/plugins/network_/global_config.py +++ b/src/middlewared/middlewared/plugins/network_/global_config.py @@ -1,7 +1,4 @@ import ipaddress -import psutil -import contextlib -import signal import middlewared.sqlalchemy as sa from middlewared.service import ConfigService, private @@ -345,14 +342,7 @@ async def do_update(self, data): except Exception: self.logger.warning('Failed to generate resolv.conf on standby storage controller', exc_info=True) - def reload_cli(): - for process in psutil.process_iter(['pid', 'cmdline']): - cmdline = process.cmdline() - if len(cmdline) >= 2 and cmdline[1] == '/usr/bin/cli': - with contextlib.suppress(Exception): - process.send_signal(signal.SIGUSR1) - - await self.middleware.run_in_thread(reload_cli) + await self.middleware.call('system.reload_cli') # default gateways changed ipv4gw_changed = new_config['ipv4gateway'] != config['ipv4gateway'] diff --git a/src/middlewared/middlewared/plugins/system/cli.py b/src/middlewared/middlewared/plugins/system/cli.py new file mode 100644 index 0000000000000..6c3b6bfd52aff --- /dev/null +++ b/src/middlewared/middlewared/plugins/system/cli.py @@ -0,0 +1,16 @@ +import contextlib +import signal + +import psutil + +from middlewared.service import Service, private + + +class SystemService(Service): + @private + def reload_cli(self): + for process in psutil.process_iter(['pid', 'cmdline']): + cmdline = process.cmdline() + if len(cmdline) >= 2 and cmdline[1] == '/usr/bin/cli': + with contextlib.suppress(Exception): + process.send_signal(signal.SIGUSR1) diff --git a/src/middlewared/middlewared/plugins/system_general/update.py b/src/middlewared/middlewared/plugins/system_general/update.py index daa4d5bc2f108..10061ddea5d85 100644 --- a/src/middlewared/middlewared/plugins/system_general/update.py +++ b/src/middlewared/middlewared/plugins/system_general/update.py @@ -249,16 +249,16 @@ async def do_update(self, data): verrors = await self.validate_general_settings(new_config, 'general_settings_update') verrors.check() - keys = new_config.keys() - for key in list(keys): + db_config = new_config.copy() + for key in list(new_config.keys()): if key.startswith('ui_'): - new_config['gui' + key[3:]] = new_config.pop(key) + db_config['gui' + key[3:]] = db_config.pop(key) await self.middleware.call( 'datastore.update', self._config.datastore, config['id'], - new_config, + db_config, {'prefix': 'stg_'} ) @@ -288,6 +288,10 @@ async def do_update(self, data): if ui_restart_delay is not None: await self.middleware.call('system.general.ui_restart', ui_restart_delay) + if any(config[k] != new_config[k] for k in ['ui_port', 'ui_httpsport', 'ui_httpsredirect', 'ui_address', + 'ui_v6address']): + await self.middleware.call('system.reload_cli') + return await self.config() @private From 685d0be92a142f2b6ee303636587cff3b634d3f2 Mon Sep 17 00:00:00 2001 From: themylogin Date: Wed, 7 Aug 2024 09:22:32 +0200 Subject: [PATCH 2/3] Do not render all IPv4 addresses in Web UI URLs list if `::` is in the listen address list, but `0.0.0.0` is not --- src/middlewared/middlewared/plugins/system_general/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewared/middlewared/plugins/system_general/ui.py b/src/middlewared/middlewared/plugins/system_general/ui.py index 90d3e63395550..6b70ac6ce62ba 100644 --- a/src/middlewared/middlewared/plugins/system_general/ui.py +++ b/src/middlewared/middlewared/plugins/system_general/ui.py @@ -142,7 +142,7 @@ async def get_ui_urls(self): if https_port != 443: https_url += f':{https_port}' - if all_ip4 or all_ip6: + if (i['type'] == 'INET' and all_ip4) or (i['type'] == 'INET6' and all_ip6): urls.add(http_url) if https_url: urls.add(https_url) From f64e98504467913560cf912bb4dbc0a9e33f18ab Mon Sep 17 00:00:00 2001 From: themylogin Date: Thu, 8 Aug 2024 14:02:33 +0200 Subject: [PATCH 3/3] Address feedback --- .../middlewared/plugins/system_general/update.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/middlewared/middlewared/plugins/system_general/update.py b/src/middlewared/middlewared/plugins/system_general/update.py index 10061ddea5d85..fe58ec4d9457b 100644 --- a/src/middlewared/middlewared/plugins/system_general/update.py +++ b/src/middlewared/middlewared/plugins/system_general/update.py @@ -288,9 +288,10 @@ async def do_update(self, data): if ui_restart_delay is not None: await self.middleware.call('system.general.ui_restart', ui_restart_delay) - if any(config[k] != new_config[k] for k in ['ui_port', 'ui_httpsport', 'ui_httpsredirect', 'ui_address', - 'ui_v6address']): - await self.middleware.call('system.reload_cli') + for key in ('ui_port', 'ui_httpsport', 'ui_httpsredirect', 'ui_address', 'ui_v6address'): + if config[key] != new_config[key]: + await self.middleware.call('system.reload_cli') + break return await self.config()