From 38db25803d1d4b67de352df5ba71230283891c0b Mon Sep 17 00:00:00 2001 From: GD-Slime <1289744583@qq.com> Date: Sun, 18 Jun 2023 11:40:42 +0800 Subject: [PATCH] mkdir luci-app-webd --- luci-app-webd/Makefile | 25 ++++ luci-app-webd/README.md | 3 + luci-app-webd/luasrc/controller/webd.lua | 17 +++ luci-app-webd/luasrc/model/cbi/webd.lua | 82 ++++++++++++ .../luasrc/view/webd/webd_status.htm | 27 ++++ luci-app-webd/po/zh-cn/webd.po | 80 ++++++++++++ luci-app-webd/po/zh_Hans/webd.po | 80 ++++++++++++ luci-app-webd/root/etc/config/webd | 13 ++ luci-app-webd/root/etc/init.d/webd | 120 ++++++++++++++++++ luci-app-webd/root/etc/uci-defaults/luci-webd | 11 ++ .../usr/share/rpcd/acl.d/luci-app-webd.json | 11 ++ 11 files changed, 469 insertions(+) create mode 100644 luci-app-webd/Makefile create mode 100644 luci-app-webd/README.md create mode 100644 luci-app-webd/luasrc/controller/webd.lua create mode 100644 luci-app-webd/luasrc/model/cbi/webd.lua create mode 100644 luci-app-webd/luasrc/view/webd/webd_status.htm create mode 100644 luci-app-webd/po/zh-cn/webd.po create mode 100644 luci-app-webd/po/zh_Hans/webd.po create mode 100644 luci-app-webd/root/etc/config/webd create mode 100644 luci-app-webd/root/etc/init.d/webd create mode 100644 luci-app-webd/root/etc/uci-defaults/luci-webd create mode 100644 luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json diff --git a/luci-app-webd/Makefile b/luci-app-webd/Makefile new file mode 100644 index 000000000..7ebeb2321 --- /dev/null +++ b/luci-app-webd/Makefile @@ -0,0 +1,25 @@ +# Copyright (C) 2020-2021 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-webd +PKG_VERSION:=1.3 +PKG_RELEASE:=3 + +LUCI_TITLE:=LuCI support for Webd Netdisk +LUCI_PKGARCH:=all + +LUCI_DEPENDS:= \ + +PACKAGE_$(PKG_NAME)_INCLUDE_WEBD_BINARY:webd + +define Package/$(PKG_NAME)/config + +config PACKAGE_$(PKG_NAME)_INCLUDE_WEBD_BINARY + bool "Include webd Binary" + default y + +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-webd/README.md b/luci-app-webd/README.md new file mode 100644 index 000000000..eda3ec5cd --- /dev/null +++ b/luci-app-webd/README.md @@ -0,0 +1,3 @@ +# luci-app-webd + +项目地址: https://webd.cf/ diff --git a/luci-app-webd/luasrc/controller/webd.lua b/luci-app-webd/luasrc/controller/webd.lua new file mode 100644 index 000000000..65bf78d04 --- /dev/null +++ b/luci-app-webd/luasrc/controller/webd.lua @@ -0,0 +1,17 @@ +module("luci.controller.webd",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/webd") then + return + end + + entry({"admin", "nas", "webd"}, cbi("webd"), _("Webd Netdisk"),99) + entry({"admin", "nas", "webd", "status"}, call("act_status")).leaf = true +end + +function act_status() + local e = {} + e.running = luci.sys.call("pgrep webd > /dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/luci-app-webd/luasrc/model/cbi/webd.lua b/luci-app-webd/luasrc/model/cbi/webd.lua new file mode 100644 index 000000000..386d48b58 --- /dev/null +++ b/luci-app-webd/luasrc/model/cbi/webd.lua @@ -0,0 +1,82 @@ +m = Map("webd", translate("Webd Netdisk"), +translate("Webd - A lightweight self hosted netdisk") +.. [[ ]] +.. translate("Official Website") +.. [[]] +) + +m:section(SimpleSection).template = "webd/webd_status" + +s = m:section(TypedSection, "webd", translate("Basic Settings"), translate("Set the basic settings of Webd Netdisk")) +s.anonymous = true + +enable = s:option(Flag, "enable", translate("Enable")) +enable.default = 0 + +port = s:option(Value, "webd_port", translate("Listening Port")) +port.datatype = "port" +port.default = "9212" +port.rmempty = false + +enable_ipv6 = s:option(Flag, "enable_ipv6", translate("Listen IPv6"), translatef("Listen both IPv4 and IPv6 Address")) +enable_ipv6.default = 0 + +root = s:option(Value, "webd_root", translate("Local Directory"), translatef("Directory of Webd Netdisk")) +root.default = "/mnt" +root.rmempty = false + +enable_recyclebin = s:option(Flag, "enable_recyclebin", translate("Recycle Bin"), translatef("Automatically create recycle bin directory")) +enable_recyclebin.default = 1 + +enable_anonymous = s:option(Flag, "enable_anonymous", translate("Enable Anonymous Access"), translatef("Anonymous access is allowed when enabled (Not Safe)")) +enable_anonymous.default = 0 + +anonymous_perm = s:option(MultiValue, "anonymous_perm", translate("Anonymous Permission")) +anonymous_perm:value("r", translate("Read files")) +anonymous_perm:value("l", translate("Obtain file list")) +anonymous_perm:value("u", translate("Upload files")) +anonymous_perm:value("m", translate("Remove files")) +anonymous_perm:value("S", translate("Show hidden files")) +anonymous_perm:value("T", translate("Play media")) +anonymous_perm:depends("enable_anonymous", "1") +anonymous_perm.description = translate("At least one permission must be choosed to allow anonymous access") + +webd_bin = s:option(Value, "webd_bin", translate("Binary Path"), translatef("Webd Netdisk binary Path")) +webd_bin.default = "/usr/bin/webd" +webd_bin.rmempty = false + +webd_conf = s:option(Value, "webd_conf", translate("Config Path"), translatef("Webd Netdisk config Path")) +webd_conf.default = "/etc/webd.conf" +webd_conf.rmempty = false + +s = m:section(TypedSection, "users", translate("User Settings"), translate("Set the username, password and permissions. Maximum for 2 accounts")) +s.anonymous = true +s.addremove = true +s.template = "cbi/tblsection" + +username = s:option(Value, "username", translate("Username")) +username.rmempty = false + +password = s:option(Value, "password", translate("Password")) +password.rmempty = false +password.password=false + +enable_read = s:option(Flag, "enable_read", translate("Read files")) +enable_read.default = 1 + +enable_read_list = s:option(Flag, "enable_read_list", translate("Obtain file list")) +enable_read_list.default = 1 + +enable_upload = s:option(Flag, "enable_upload", translate("Upload files")) +enable_upload.default = 1 + +enable_move = s:option(Flag, "enable_move", translate("Remove files")) +enable_move.default = 1 + +enable_showhide = s:option(Flag, "enable_showhide", translate("Show hidden files")) +enable_showhide.default = 0 + +enable_play = s:option(Flag, "enable_play", translate("Play media")) +enable_play.default = 1 + +return m diff --git a/luci-app-webd/luasrc/view/webd/webd_status.htm b/luci-app-webd/luasrc/view/webd/webd_status.htm new file mode 100644 index 000000000..2df3e910d --- /dev/null +++ b/luci-app-webd/luasrc/view/webd/webd_status.htm @@ -0,0 +1,27 @@ + + +
+

+ <%:Collecting data...%> +

+
\ No newline at end of file diff --git a/luci-app-webd/po/zh-cn/webd.po b/luci-app-webd/po/zh-cn/webd.po new file mode 100644 index 000000000..b5ded6714 --- /dev/null +++ b/luci-app-webd/po/zh-cn/webd.po @@ -0,0 +1,80 @@ +msgid "Webd Netdisk" +msgstr "Webd 网盘" + +msgid "Official Website" +msgstr "官网" + +msgid "Basic Settings" +msgstr "基础设置" + +msgid "Set the basic settings of Webd Netdisk" +msgstr "配置 Webd 网盘的基础设置" + +msgid "Listening Port" +msgstr "监听端口" + +msgid "Webd - A lightweight self hosted netdisk" +msgstr "Webd 是一款轻量级的 (self-hosted) 自建网盘软件, 界面简洁易用, 速度快资源占用低" + +msgid "Listen IPv6" +msgstr "监听 IPv6" + +msgid "Listen both IPv4 and IPv6 Address" +msgstr "同时监听 IPv4 和 IPv6 地址" + +msgid "Enable Anonymous Access" +msgstr "允许匿名访问" + +msgid "Anonymous Permission" +msgstr "匿名访问权限" + +msgid "Anonymous access is allowed when enabled (Not Safe)" +msgstr "启用后将允许匿名用户访问 (不安全)" + +msgid "At least one permission must be choosed to allow anonymous access" +msgstr "若要允许匿名访问则勾选至少一个权限" + +msgid "Binary Path" +msgstr "程序路径" + +msgid "Webd Netdisk binary Path" +msgstr "Webd 网盘二进制程序路径" + +msgid "Config Path" +msgstr "配置文件路径" + +msgid "Webd Netdisk config Path" +msgstr "Webd 网盘配置文件路径" + +msgid "Local Directory" +msgstr "本地路径" + +msgid "Directory of Webd Netdisk" +msgstr "Webd 网盘监听路径" + +msgid "Recycle Bin" +msgstr "回收站" + +msgid "Automatically create recycle bin directory" +msgstr "允许自动创建回收站目录" + +msgid "Set the username, password and permissions. Maximum for 2 accounts" +msgstr "设置用户名和密码, 以及单个用户的权限, 最多支持设置两个账号" + +msgid "Read files" +msgstr "读取文件" + +msgid "Obtain file list" +msgstr "获取文件列表" + +msgid "Upload files" +msgstr "上传文件" + +msgid "Remove files" +msgstr "删除或移动文件" + +msgid "Show hidden files" +msgstr "显示隐藏文件" + +msgid "Play media" +msgstr "播放媒体" diff --git a/luci-app-webd/po/zh_Hans/webd.po b/luci-app-webd/po/zh_Hans/webd.po new file mode 100644 index 000000000..b5ded6714 --- /dev/null +++ b/luci-app-webd/po/zh_Hans/webd.po @@ -0,0 +1,80 @@ +msgid "Webd Netdisk" +msgstr "Webd 网盘" + +msgid "Official Website" +msgstr "官网" + +msgid "Basic Settings" +msgstr "基础设置" + +msgid "Set the basic settings of Webd Netdisk" +msgstr "配置 Webd 网盘的基础设置" + +msgid "Listening Port" +msgstr "监听端口" + +msgid "Webd - A lightweight self hosted netdisk" +msgstr "Webd 是一款轻量级的 (self-hosted) 自建网盘软件, 界面简洁易用, 速度快资源占用低" + +msgid "Listen IPv6" +msgstr "监听 IPv6" + +msgid "Listen both IPv4 and IPv6 Address" +msgstr "同时监听 IPv4 和 IPv6 地址" + +msgid "Enable Anonymous Access" +msgstr "允许匿名访问" + +msgid "Anonymous Permission" +msgstr "匿名访问权限" + +msgid "Anonymous access is allowed when enabled (Not Safe)" +msgstr "启用后将允许匿名用户访问 (不安全)" + +msgid "At least one permission must be choosed to allow anonymous access" +msgstr "若要允许匿名访问则勾选至少一个权限" + +msgid "Binary Path" +msgstr "程序路径" + +msgid "Webd Netdisk binary Path" +msgstr "Webd 网盘二进制程序路径" + +msgid "Config Path" +msgstr "配置文件路径" + +msgid "Webd Netdisk config Path" +msgstr "Webd 网盘配置文件路径" + +msgid "Local Directory" +msgstr "本地路径" + +msgid "Directory of Webd Netdisk" +msgstr "Webd 网盘监听路径" + +msgid "Recycle Bin" +msgstr "回收站" + +msgid "Automatically create recycle bin directory" +msgstr "允许自动创建回收站目录" + +msgid "Set the username, password and permissions. Maximum for 2 accounts" +msgstr "设置用户名和密码, 以及单个用户的权限, 最多支持设置两个账号" + +msgid "Read files" +msgstr "读取文件" + +msgid "Obtain file list" +msgstr "获取文件列表" + +msgid "Upload files" +msgstr "上传文件" + +msgid "Remove files" +msgstr "删除或移动文件" + +msgid "Show hidden files" +msgstr "显示隐藏文件" + +msgid "Play media" +msgstr "播放媒体" diff --git a/luci-app-webd/root/etc/config/webd b/luci-app-webd/root/etc/config/webd new file mode 100644 index 000000000..acd693997 --- /dev/null +++ b/luci-app-webd/root/etc/config/webd @@ -0,0 +1,13 @@ + +config webd + option enable '0' + option webd_port '9212' + +config users + option enable_read '1' + option enable_read_list '1' + option enable_upload '1' + option enable_move '1' + option enable_showhide '0' + option username 'root' + option password 'password' diff --git a/luci-app-webd/root/etc/init.d/webd b/luci-app-webd/root/etc/init.d/webd new file mode 100644 index 000000000..65355c365 --- /dev/null +++ b/luci-app-webd/root/etc/init.d/webd @@ -0,0 +1,120 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 +LOGGER="logger -t [Webd]" + +start_service() { + local basic_list="enable webd_conf webd_bin webd_port webd_root enable_recyclebin enable_anonymous anonymous_perm enable_ipv6" + local users_list="enable_read enable_read_list enable_upload enable_move enable_showhide" + for i in $(echo $basic_list);do + local eval $i="$(uci_get_by_type webd 0 $i)" + done;unset i + if [ "$enable" == 1 ] + then + [ ! -r "$webd_root" -o ! -d "$webd_root" ] && EXIT "Unable to access $webd_root,exit ..." + [ ! -x "$webd_bin" ] && EXIT "Unable to access $webd_bin,exit ..." + if [ "$enable_recyclebin" == 1 -a ! -d "$webd_root/.Trash" ] + then + ${LOGGER} "Creating Recycle Bin directory ..." + mkdir -p $webd_root/.Trash || EXIT "Failed to create Recycle Bin directory,exit ..." + fi + ${LOGGER} "Removing old config file ..." + rm -f $webd_conf + touch -a $webd_conf || EXIT "Failed to create config,exit ..." + [ "$enable_ipv6" == 1 ] && webd_port="[::]:${webd_port}" + if [ "$enable_anonymous" != 0 ] + then + if [ -n "$anonymous_perm" ] + then + + unset enable_anonymous + for i in $(echo $anonymous_perm);do + enable_anonymous="$enable_anonymous$i" + done + unset i + else + enable_anonymous=0 + uci set webd.@webd[0].enable_anonymous=0 + uci commit webd + fi + fi + echo "Webd.Listen $webd_port" >> $webd_conf + echo "Webd.Root $webd_root" >> $webd_conf + echo "Webd.Guest $enable_anonymous" >> $webd_conf + + for u in 0 1;do + for i in $(echo $users_list);do + eval ${i}=$(uci_get_by_type users $u $i 0) + echo "$users_list" | grep -q $i + [ "$?" == 0 ] && eval perm_bin=$(eval echo '$'perm_bin)$(uci_get_by_type users $u $i) + done + unset i + username=$(uci_get_by_type users $u username) + password=$(uci_get_by_type users $u password) + if [ -n "$username" ] + then + eval perm=$(perm_converter $(eval echo '$'perm_bin) | tail -n 1) + if [ -n "$(eval echo '$'perm)" ] + then + ${LOGGER} "Creating account for User $username ..." + echo "Webd.User $(eval echo '$'perm) $username $password" >> $webd_conf + else + ${LOGGER} "Removing excessive user config ..." + uci delete webd.@users[$u] + uci commit webd + fi + unset perm_bin + fi + done + unset u + ${LOGGER} "Killing old processes ..." + ps -efww | grep "$webd_bin" | awk '{print $1}' | xargs kill -9 2> /dev/null + ${LOGGER} "Starting Webd Netdisk Service ..." + procd_open_instance + procd_set_param command $webd_bin -c $webd_conf + procd_set_param respawn + procd_close_instance + else + stop_service + ${LOGGER} "Webd Netdisk Service is now disabled ..." + fi +} + +stop_service() { + ${LOGGER} "Stopping Webd Netdisk Service ..." +} + +service_triggers() { + procd_add_reload_trigger "webd" +} + +uci_get_by_type() { + local ret=$(uci get webd.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} + +EXIT() { + ${LOGGER} $* + exit +} + +perm_converter() { + local u i=1 + echo $1 | egrep -o [0-1] | while read X + do + if [ "$X" == 1 ] + then + case $i in + 1)u=r;; + 2)u=l;; + 3)u=u;; + 4)u=m;; + 5)u=S;; + esac + [ -n "$u" ] && a="$a$u" + echo "$a" + fi + i=$(($i + 1)) + done +} diff --git a/luci-app-webd/root/etc/uci-defaults/luci-webd b/luci-app-webd/root/etc/uci-defaults/luci-webd new file mode 100644 index 000000000..41934849f --- /dev/null +++ b/luci-app-webd/root/etc/uci-defaults/luci-webd @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@webd[-1] + add ucitrack webd + set ucitrack.@webd[-1].init=webd + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json b/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json new file mode 100644 index 000000000..8247638a0 --- /dev/null +++ b/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json @@ -0,0 +1,11 @@ +{ + "luci-app-webd": { + "description": "Grant UCI access for luci-app-webd", + "read": { + "uci": [ "webd" ] + }, + "write": { + "uci": [ "webd" ] + } + } +}