From ffb43da96e46d9990cdbf43300cedb60f07db5e6 Mon Sep 17 00:00:00 2001 From: Siyuan Miao Date: Tue, 8 Apr 2025 16:05:04 +0200 Subject: [PATCH] no longer need to reboot to start / stop tls service --- config.go | 2 + jsonrpc.go | 4 +- main.go | 6 +- .../devices.$id.settings.access._index.tsx | 56 +++++------- web_tls.go | 85 ++++++++++++++++++- 5 files changed, 112 insertions(+), 41 deletions(-) diff --git a/config.go b/config.go index 7c8437d..83cdb30 100644 --- a/config.go +++ b/config.go @@ -109,6 +109,8 @@ func SaveConfig() error { configLock.Lock() defer configLock.Unlock() + logger.Tracef("Saving config to %s", configPath) + file, err := os.Create(configPath) if err != nil { return fmt.Errorf("failed to create config file: %w", err) diff --git a/jsonrpc.go b/jsonrpc.go index b4dadd3..d8ffdac 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -405,8 +405,8 @@ func rpcGetTLSState() TLSState { return getTLSState() } -func rpcSetTLSState(tlsState TLSState) error { - err := setTLSState(tlsState) +func rpcSetTLSState(state TLSState) error { + err := setTLSState(state) if err != nil { return fmt.Errorf("failed to set TLS state: %w", err) } diff --git a/main.go b/main.go index d8934a8..feb1d3b 100644 --- a/main.go +++ b/main.go @@ -70,10 +70,12 @@ func Main() { //go RunFuseServer() go RunWebServer() + go RunWebSecureServer() + // Web secure server is started only if TLS mode is enabled if config.TLSMode != "" { - initCertStore() - go RunWebSecureServer() + startWebSecureServer() } + // As websocket client already checks if the cloud token is set, we can start it here. go RunWebsocketClient() diff --git a/ui/src/routes/devices.$id.settings.access._index.tsx b/ui/src/routes/devices.$id.settings.access._index.tsx index 6d3a26d..389071e 100644 --- a/ui/src/routes/devices.$id.settings.access._index.tsx +++ b/ui/src/routes/devices.$id.settings.access._index.tsx @@ -161,7 +161,12 @@ export default function SettingsAccessIndexRoute() { }; const handleTlsUpdate = useCallback(() => { - send("setTLSState", { state: { mode: tlsMode, certificate: tlsCert, privateKey: tlsKey } as TLSState }, resp => { + const state = { mode: tlsMode } as TLSState; + if (tlsMode !== "disabled") { + state.certificate = tlsCert; + state.privateKey = tlsKey; + } + send("setTLSState", { state }, resp => { if ("error" in resp) { notifications.error(`Failed to update TLS settings: ${resp.error.data || "Unknown error"}`); return; @@ -171,17 +176,6 @@ export default function SettingsAccessIndexRoute() { }); }, [send, tlsMode, tlsCert, tlsKey]); - const handleReboot = useCallback(() => { - send("reboot", { force: false }, resp => { - if ("error" in resp) { - notifications.error(`Failed to reboot: ${resp.error.data || "Unknown error"}`); - return; - } - - notifications.success("Device will restart shortly, it might take a few seconds to boot up again."); - }); - }, [send]); - // Fetch device ID and cloud state on component mount useEffect(() => { getCloudState(); @@ -211,8 +205,8 @@ export default function SettingsAccessIndexRoute() { - Select the TLS mode for your device (beta)
- changing this setting might restart the device + Select the TLS mode for your device experimental
+ The feature might not work as expected, please report any issues if you encounter any. } >
-
-

- If TLS wasn't enabled before, you'll need to reboot the device to apply the changes.
-

- -
-
-
- {tlsMode === "custom" && (
@@ -282,6 +255,19 @@ export default function SettingsAccessIndexRoute() {
)} + + +
+
+
+
+