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 <patrick@perlbach24.de>
This commit is contained in:
2026-04-22 01:35:28 +02:00
parent 55ae3b79ae
commit 83375ceef1
+31 -17
View File
@@ -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"}
</pre>
)}
<p className="text-xs text-muted-foreground mt-4">
Edits will be applied to the [global] section of /etc/samba/smb.conf
</p>
<div className="text-xs text-muted-foreground mt-4 space-y-2">
<p>Format: <code className="bg-muted px-2 py-1 rounded">key = value</code></p>
<p> Add new parameters on new lines</p>
<p> Changes are applied immediately via net conf setparm</p>
<p> Comments starting with # or ; are ignored</p>
<p>Example: <code className="bg-muted px-2 py-1 rounded">log level = 2</code></p>
</div>
</CardContent>
</Card>
)}