luci-app-webdav: Add read-only mode

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-11-06 15:03:38 +08:00
parent 4c322360a4
commit cfbd3fd271
3 changed files with 25 additions and 20 deletions

View File

@ -89,16 +89,20 @@ return view.extend({
o.default = '/mnt'; o.default = '/mnt';
o.rmempty = false; o.rmempty = false;
o = s.option(form.Flag, 'allow_wan', _('Allow Access From Internet')); o = s.option(form.Flag, 'read_only', _('Read-Only Mode'));
o.default = false;
o.rmempty = false;
o = s.option(form.Flag, 'firewall_accept', _('Open firewall port'));
o.rmempty = false; o.rmempty = false;
o = s.option(form.Flag, 'ssl', _('Enable SSL')); o = s.option(form.Flag, 'ssl', _('Enable SSL'));
o.rmempty = false; o.rmempty = false;
o = s.option(form.Value, 'cert_cer', _('Path to Certificate')); o = s.option(form.Value, 'cert_cer', _('SSL cert'), _('SSL certificate file path.'));
o.depends('ssl', '1'); o.depends('ssl', '1');
o = s.option(form.Value, 'cert_key', _('Path to Certificate Key')); o = s.option(form.Value, 'cert_key', _('SSL key'), _('SSL key file path.'));
o.depends('ssl', '1'); o.depends('ssl', '1');
o = s.option(form.Button, '_downloadreg', null, o = s.option(form.Button, '_downloadreg', null,

View File

@ -1,8 +1,8 @@
msgid "WebDav" msgid "WebDAV"
msgstr "WebDav" msgstr "WebDAV"
msgid "A lightweight, simple, and fast WebDAV server based on NGINX." msgid "A lightweight, simple, and fast WebDAV server based on NGINX."
msgstr "基于 NGINX 实现的一个轻巧、简单、快速的 WebDav 服务端。" msgstr "基于 NGINX 实现的一个轻巧、简单、快速的 WebDAV 服务端。"
msgid "Open Web Interface" msgid "Open Web Interface"
msgstr "打开 Web 界面" msgstr "打开 Web 界面"
@ -22,20 +22,23 @@ msgstr "密码"
msgid "Leave blank to disable auth." msgid "Leave blank to disable auth."
msgstr "留空以禁用身份验证。" msgstr "留空以禁用身份验证。"
msgid "Root Directory" msgid "WebDAV Directory"
msgstr "开放目录" msgstr "WebDAV 目录"
msgid "Allow Access From Internet" msgid "Read-Only Mode"
msgstr "允许从外网访问" msgstr "只读模式"
msgid "Open firewall port"
msgstr "打开防火墙端口"
msgid "Enable SSL" msgid "Enable SSL"
msgstr "启用 SSL" msgstr "启用 SSL"
msgid "Path to Certificate" msgid "SSL certificate file path."
msgstr "证书位置" msgstr "SSL 证书文件路径。"
msgid "Path to Certificate Key" msgid "SSL key file path."
msgstr "密钥位置" msgstr "SSL 密钥文件路径。"
msgid "Download Reg File" msgid "Download Reg File"
msgstr "下载注册表文件" msgstr "下载注册表文件"

View File

@ -14,7 +14,8 @@ get_config() {
config_get "username" "config" "username" config_get "username" "config" "username"
config_get "password" "config" "password" config_get "password" "config" "password"
config_get "root_dir" "config" "root_dir" "/mnt" config_get "root_dir" "config" "root_dir" "/mnt"
config_get "allow_wan" "config" "allow_wan" "0" config_get "read_only" "config" "read_only" "0"
config_get "firewall_accept" "config" "firewall_accept" "0"
config_get "ssl" "config" "ssl" "0" config_get "ssl" "config" "ssl" "0"
config_get "cert_cer" "config" "cert_cer" "" config_get "cert_cer" "config" "cert_cer" ""
config_get "cert_key" "config" "cert_key" "" config_get "cert_key" "config" "cert_key" ""
@ -50,7 +51,7 @@ start() {
get_config get_config
[ "$enable" -ne "1" ] && return 1 [ "$enable" -ne "1" ] && return 1
[ ! -d "$root_dir" ] && mkdir -p "$root_dir" [ ! -d "$root_dir" ] && mkdir -p "$root_dir"
if [ "$allow_wan" -eq "1" ]; then if [ "$firewall_accept" -eq "1" ]; then
listen_addr="0.0.0.0" listen_addr="0.0.0.0"
external_access="allow" external_access="allow"
else else
@ -66,20 +67,17 @@ start() {
else else
printf "\n\tlisten ${listen_addr}:${listen_port};" printf "\n\tlisten ${listen_addr}:${listen_port};"
fi fi
printf "\n\tserver_name _;" printf "\n\tserver_name _;"
printf "\n\tcharset utf-8,gbk;" printf "\n\tcharset utf-8,gbk;"
printf "\n\troot ${root_dir};" printf "\n\troot ${root_dir};"
printf "\n\taccess_log off;" printf "\n\taccess_log off;"
printf "\n\terror_log off;" printf "\n\terror_log off;"
if [ "$ssl" -eq "1" ]; then if [ "$ssl" -eq "1" ]; then
# SSL Certificate
printf "\n\tssl_certificate ${cert_cer};" printf "\n\tssl_certificate ${cert_cer};"
printf "\n\tssl_certificate_key ${cert_key};" printf "\n\tssl_certificate_key ${cert_key};"
printf "\n\tssl_session_timeout 1d;" printf "\n\tssl_session_timeout 1d;"
printf "\n\tssl_session_tickets on;" printf "\n\tssl_session_tickets on;"
printf "\n\tssl_session_cache shared:SSL:10m;" printf "\n\tssl_session_cache shared:SSL:10m;"
# modern configuration
printf "\n\tssl_protocols TLSv1.2 TLSv1.3;" printf "\n\tssl_protocols TLSv1.2 TLSv1.3;"
printf "\n\tssl_prefer_server_ciphers off;" printf "\n\tssl_prefer_server_ciphers off;"
printf "\n\tssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;" printf "\n\tssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;"
@ -97,7 +95,7 @@ start() {
printf "\n\t\tcreate_full_put_path on;" printf "\n\t\tcreate_full_put_path on;"
printf "\n\t\tdav_access user:rw group:rw all:r;" printf "\n\t\tdav_access user:rw group:rw all:r;"
printf "\n\t\tdav_ext_methods PROPFIND OPTIONS;" printf "\n\t\tdav_ext_methods PROPFIND OPTIONS;"
printf "\n\t\tdav_methods PUT DELETE MKCOL COPY MOVE;" [ "$read_only" -eq "1" ] && printf "\n\t\tdav_methods off;" || printf "\n\t\tdav_methods PUT DELETE MKCOL COPY MOVE;"
printf "\n\t}" printf "\n\t}"
printf "\n}\n" printf "\n}\n"
} > "${NGINX_DAV_CONF}" } > "${NGINX_DAV_CONF}"