Add editable Samba global configuration with net conf setparm

Backend:
- Use 'net conf setparm' to update individual parameters
- Accept dictionary of key-value pairs in API

Frontend:
- Add Edit/Cancel/Save buttons to Samba Config tab
- Inline editing of configuration values
- Save changes back to registry

Changes are applied immediately via net conf setparm.

Co-Authored-By: Patrick <patrick@perlbach24.de>
This commit is contained in:
2026-04-22 01:31:14 +02:00
parent a373378691
commit 07cf45a481
4 changed files with 77 additions and 39 deletions
+56 -2
View File
@@ -23,6 +23,9 @@ export default function SharesPage() {
const [showNfsDialog, setShowNfsDialog] = useState(false)
const [deleteConfirm, setDeleteConfirm] = useState<{ type: "samba" | "nfs"; name: string } | null>(null)
const [deleting, setDeleting] = useState(false)
const [editMode, setEditMode] = useState(false)
const [editedConfig, setEditedConfig] = useState<{ [key: string]: string }>({})
const [saving, setSaving] = useState(false)
useEffect(() => {
const token = localStorage.getItem("access_token")
@@ -90,6 +93,29 @@ export default function SharesPage() {
setShowNfsDialog(false)
}
const handleEditMode = () => {
const configMap = sambaConfig.reduce((acc, param) => {
acc[param.key] = param.value
return acc
}, {} as { [key: string]: string })
setEditedConfig(configMap)
setEditMode(true)
}
const handleSaveConfig = async () => {
try {
setSaving(true)
await api.setSambaConfig(editedConfig)
setEditMode(false)
await loadShares()
setError(null)
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to save configuration")
} finally {
setSaving(false)
}
}
return (
<div className="min-h-screen bg-background">
<Header />
@@ -272,7 +298,24 @@ export default function SharesPage() {
{activeTab === "config" && (
<Card>
<CardHeader>
<CardTitle>Samba Global Configuration</CardTitle>
<div className="flex items-center justify-between">
<CardTitle>Samba Global Configuration</CardTitle>
{!editMode && sambaConfig.length > 0 && (
<Button size="sm" onClick={handleEditMode} variant="outline">
Edit Config
</Button>
)}
{editMode && (
<div className="flex gap-2">
<Button size="sm" onClick={handleSaveConfig} disabled={saving}>
{saving ? "Saving..." : "Save Changes"}
</Button>
<Button size="sm" onClick={() => setEditMode(false)} variant="outline" disabled={saving}>
Cancel
</Button>
</div>
)}
</div>
</CardHeader>
<CardContent>
{sambaConfig.length === 0 ? (
@@ -292,7 +335,18 @@ export default function SharesPage() {
{sambaConfig.map((param, idx) => (
<tr key={idx} className="border-b border-border/50 hover:bg-muted/30">
<td className="py-3 px-4 font-mono text-xs font-medium text-blue-600">{param.key}</td>
<td className="py-3 px-4 text-xs font-mono break-all">{param.value}</td>
<td className="py-3 px-4 text-xs">
{editMode ? (
<input
type="text"
value={editedConfig[param.key] || ""}
onChange={(e) => setEditedConfig({ ...editedConfig, [param.key]: e.target.value })}
className="w-full px-2 py-1 rounded border border-border bg-background text-xs font-mono"
/>
) : (
<span className="font-mono break-all">{param.value}</span>
)}
</td>
</tr>
))}
</tbody>