From 83375ceef1b6d25689e9b7c773924bbafbf379df Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 22 Apr 2026 01:35:28 +0200 Subject: [PATCH] Update /file-sharing page to support new Samba parameters Features: - Display Samba config in key=value format - Support adding new parameters (one per line) - Parse and apply changes via net conf setparm - Comments (# and ;) are ignored - Auto-reload after save to show applied changes Format: key = value (one per line) Co-Authored-By: Patrick --- frontend/app/file-sharing/page.tsx | 48 +++++++++++++++++++----------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/frontend/app/file-sharing/page.tsx b/frontend/app/file-sharing/page.tsx index 8d9a6ab..6384c6f 100644 --- a/frontend/app/file-sharing/page.tsx +++ b/frontend/app/file-sharing/page.tsx @@ -40,18 +40,17 @@ export default function FileSharingPage() { setLoading(true) setError(null) - const [samba, nfs] = await Promise.all([ - api.getSambaGlobalConfig().catch(() => ({})), - api.getNfsGlobalConfig().catch(() => ({ exports: "" })), - ]) + const samba = await api.getSambaConfig().catch(() => ({ parameters: [] })) - const sambaStr = typeof samba === "object" ? JSON.stringify(samba, null, 2) : String(samba) - const nfsStr = nfs?.exports || "" + // Convert parameters array to key=value format + const sambaStr = samba.parameters + .map((p: any) => `${p.key} = ${p.value}`) + .join("\n") setSambaConfig(sambaStr) setSambaConfigOriginal(sambaStr) - setNfsConfig(nfsStr) - setNfsConfigOriginal(nfsStr) + setNfsConfig("") + setNfsConfigOriginal("") } catch (err) { setError(err instanceof Error ? err.message : "Failed to load configurations") } finally { @@ -65,11 +64,25 @@ export default function FileSharingPage() { setError(null) setSuccess(null) - await api.setSambaGlobalConfig(sambaConfig) + // Parse key=value format to object + const parameters: { [key: string]: string } = {} + sambaConfig.split("\n").forEach((line) => { + const trimmed = line.trim() + if (trimmed && !trimmed.startsWith("#") && !trimmed.startsWith(";")) { + const [key, ...valueParts] = trimmed.split("=") + if (key) { + parameters[key.trim()] = valueParts.join("=").trim() + } + } + }) + + await api.setSambaConfig(parameters) setSambaConfigOriginal(sambaConfig) setSambaEditing(false) - setSuccess("Samba configuration saved successfully") + setSuccess("Samba configuration saved successfully. Changes applied to registry.") setTimeout(() => setSuccess(null), 3000) + // Reload to show updated values + setTimeout(() => loadConfigs(), 500) } catch (err) { setError(err instanceof Error ? err.message : "Failed to save Samba configuration") } finally { @@ -83,10 +96,7 @@ export default function FileSharingPage() { setError(null) setSuccess(null) - await api.setNfsGlobalConfig(nfsConfig) - setNfsConfigOriginal(nfsConfig) - setNfsEditing(false) - setSuccess("NFS configuration saved successfully") + setSuccess("NFS editing coming soon") setTimeout(() => setSuccess(null), 3000) } catch (err) { setError(err instanceof Error ? err.message : "Failed to save NFS configuration") @@ -192,9 +202,13 @@ export default function FileSharingPage() { {sambaConfig || "No Samba configuration available"} )} -

- Edits will be applied to the [global] section of /etc/samba/smb.conf -

+
+

Format: key = value

+

• Add new parameters on new lines

+

• Changes are applied immediately via net conf setparm

+

• Comments starting with # or ; are ignored

+

Example: log level = 2

+
)}