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) setLoading(true)
setError(null) setError(null)
const [samba, nfs] = await Promise.all([ const samba = await api.getSambaConfig().catch(() => ({ parameters: [] }))
api.getSambaGlobalConfig().catch(() => ({})),
api.getNfsGlobalConfig().catch(() => ({ exports: "" })),
])
const sambaStr = typeof samba === "object" ? JSON.stringify(samba, null, 2) : String(samba) // Convert parameters array to key=value format
const nfsStr = nfs?.exports || "" const sambaStr = samba.parameters
.map((p: any) => `${p.key} = ${p.value}`)
.join("\n")
setSambaConfig(sambaStr) setSambaConfig(sambaStr)
setSambaConfigOriginal(sambaStr) setSambaConfigOriginal(sambaStr)
setNfsConfig(nfsStr) setNfsConfig("")
setNfsConfigOriginal(nfsStr) setNfsConfigOriginal("")
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : "Failed to load configurations") setError(err instanceof Error ? err.message : "Failed to load configurations")
} finally { } finally {
@@ -65,11 +64,25 @@ export default function FileSharingPage() {
setError(null) setError(null)
setSuccess(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) setSambaConfigOriginal(sambaConfig)
setSambaEditing(false) setSambaEditing(false)
setSuccess("Samba configuration saved successfully") setSuccess("Samba configuration saved successfully. Changes applied to registry.")
setTimeout(() => setSuccess(null), 3000) setTimeout(() => setSuccess(null), 3000)
// Reload to show updated values
setTimeout(() => loadConfigs(), 500)
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : "Failed to save Samba configuration") setError(err instanceof Error ? err.message : "Failed to save Samba configuration")
} finally { } finally {
@@ -83,10 +96,7 @@ export default function FileSharingPage() {
setError(null) setError(null)
setSuccess(null) setSuccess(null)
await api.setNfsGlobalConfig(nfsConfig) setSuccess("NFS editing coming soon")
setNfsConfigOriginal(nfsConfig)
setNfsEditing(false)
setSuccess("NFS configuration saved successfully")
setTimeout(() => setSuccess(null), 3000) setTimeout(() => setSuccess(null), 3000)
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : "Failed to save NFS configuration") setError(err instanceof Error ? err.message : "Failed to save NFS configuration")
@@ -192,9 +202,13 @@ export default function FileSharingPage() {
{sambaConfig || "No Samba configuration available"} {sambaConfig || "No Samba configuration available"}
</pre> </pre>
)} )}
<p className="text-xs text-muted-foreground mt-4"> <div className="text-xs text-muted-foreground mt-4 space-y-2">
Edits will be applied to the [global] section of /etc/samba/smb.conf <p>Format: <code className="bg-muted px-2 py-1 rounded">key = value</code></p>
</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> </CardContent>
</Card> </Card>
)} )}