Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Added setting to enforce a readonly webdav.

nzbdav-dev51a54419daf3
diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.cs
index 9396d9cc..dc8b60e9 100644
--- a/backend/Config/ConfigManager.cs
+++ b/backend/Config/ConfigManager.cs
@@ -128,6 +128,13 @@ public class ConfigManager
);
}
+ public bool IsEnforceReadonlyWebdavEnabled()
+ {
+ var defaultValue = true;
+ var configValue = StringUtil.EmptyToNull(GetConfigValue("webdav.enforce-readonly"));
+ return (configValue != null ? bool.Parse(configValue) : defaultValue);
+ }
+
public class ConfigEventArgs : EventArgs
{
public Dictionary<string, string> ChangedConfig { get; set; } = new();
diff --git a/backend/WebDav/DatabaseStoreCollection.cs b/backend/WebDav/DatabaseStoreCollection.cs
index a66d283e..d1a46f98 100644
--- a/backend/WebDav/DatabaseStoreCollection.cs
+++ b/backend/WebDav/DatabaseStoreCollection.cs
@@ -68,6 +68,10 @@ public class DatabaseStoreCollection(
protected override async Task<DavStatusCode> DeleteItemAsync(DeleteItemRequest request)
{
+ // Cannot delete items if readonly-webdav is enabled
+ if (configManager.IsEnforceReadonlyWebdavEnabled())
+ return DavStatusCode.Forbidden;
+
// Cannot delete items from dav root.
if (davDirectory.Id == DavItem.Root.Id)
return DavStatusCode.Forbidden;
diff --git a/frontend/app/routes/settings/route.tsx b/frontend/app/routes/settings/route.tsx
index 264bdf0d..d55098fd 100644
--- a/frontend/app/routes/settings/route.tsx
+++ b/frontend/app/routes/settings/route.tsx
@@ -24,6 +24,7 @@ const defaultConfig = {
"webdav.user": "",
"webdav.pass": "",
"webdav.show-hidden-files": "false",
+ "webdav.enforce-readonly": "true",
"rclone.mount-dir": "",
"media.library-dir": "",
}
diff --git a/frontend/app/routes/settings/webdav/webdav.tsx b/frontend/app/routes/settings/webdav/webdav.tsx
index 8f3a058e..e5c42b5a 100644
--- a/frontend/app/routes/settings/webdav/webdav.tsx
+++ b/frontend/app/routes/settings/webdav/webdav.tsx
@@ -45,6 +45,21 @@ export function WebdavSettings({ config, setNewConfig }: SabnzbdSettingsProps) {
<Form.Check
className={styles.input}
type="checkbox"
+ id="readonly-checkbox"
+ aria-describedby="readonly-help"
+ label={`Enforce Read-Only`}
+ checked={config["webdav.enforce-readonly"] === "true"}
+ onChange={e => setNewConfig({ ...config, "webdav.enforce-readonly": "" + e.target.checked })} />
+ <Form.Text id="readonly-help" muted>
+ The WebDAV `/content` folder will be readonly when checked. WebDAV clients will not be able to delete files within this directory.
+ </Form.Text>
+ </Form.Group>
+ <hr />
+ <Form.Group>
+ <Form.Check
+ className={styles.input}
+ type="checkbox"
+ id="show-hidden-files-checkbox"
aria-describedby="show-hidden-files-help"
label={`Show hidden files on Dav Explorer`}
checked={config["webdav.show-hidden-files"] === "true"}
@@ -61,6 +76,7 @@ export function isWebdavSettingsUpdated(config: Record<string, string>, newConfi
return config["webdav.user"] !== newConfig["webdav.user"]
|| config["webdav.pass"] !== newConfig["webdav.pass"]
|| config["webdav.show-hidden-files"] !== newConfig["webdav.show-hidden-files"]
+ || config["webdav.enforce-readonly"] !== newConfig["webdav.enforce-readonly"]
}
export function isWebdavSettingsValid(newConfig: Record<string, string>) {