Compare commits
No commits in common. "main" and "2024-01-18" have entirely different histories.
main
...
2024-01-18
135
.github/workflows/CI.yml
vendored
135
.github/workflows/CI.yml
vendored
@ -1,135 +0,0 @@
|
|||||||
name: 编译caddy二进制文件
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
env:
|
|
||||||
TZ: Asia/Shanghai
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- TARGET: amd64
|
|
||||||
OS: ubuntu-latest
|
|
||||||
AARCH: amd64
|
|
||||||
|
|
||||||
- TARGET: arm64
|
|
||||||
OS: ubuntu-latest
|
|
||||||
ARCH: arm64
|
|
||||||
|
|
||||||
- TARGET: mips
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: mips
|
|
||||||
|
|
||||||
- TARGET: mips64
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: mips64
|
|
||||||
|
|
||||||
- TARGET: mips64le
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: mips64le
|
|
||||||
|
|
||||||
- TARGET: mipsel
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: mipsle
|
|
||||||
|
|
||||||
- TARGET: ppc64le
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: ppc64le
|
|
||||||
|
|
||||||
- TARGET: s390x
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: s390x
|
|
||||||
|
|
||||||
- TARGET: arm
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARCH: arm
|
|
||||||
|
|
||||||
- TARGET: armv5l
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARM: 5
|
|
||||||
ARCH: arm
|
|
||||||
|
|
||||||
- TARGET: armv6
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARM: 6
|
|
||||||
ARCH: arm
|
|
||||||
|
|
||||||
- TARGET: armv7l
|
|
||||||
OS: ubuntu-latest
|
|
||||||
SOFT: softfloat
|
|
||||||
ARM: 7
|
|
||||||
ARCH: arm
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.OS }}
|
|
||||||
env:
|
|
||||||
TARGET: ${{ matrix.TARGET }}
|
|
||||||
OS: ${{ matrix.OS }}
|
|
||||||
SOFT: ${{ matrix.SOFT }}
|
|
||||||
ARM: ${{ matrix.ARM }}
|
|
||||||
ARCH: ${{ matrix.ARCH }}
|
|
||||||
steps:
|
|
||||||
- name: 获取最新Go
|
|
||||||
run: |
|
|
||||||
latest_version=$(curl -L -k -s https://golang.org/dl/?mode=json | grep -m 1 -o '"version": "[^"]*' | sed 's/"version": "//' | tr -d 'go" ')
|
|
||||||
echo "go版本=$latest_version"
|
|
||||||
echo "gotag=$latest_version" >> $GITHUB_ENV
|
|
||||||
- name: 安装go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.gotag }}
|
|
||||||
-
|
|
||||||
name: 检查代码仓库
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: 编译
|
|
||||||
run: |
|
|
||||||
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
|
|
||||||
wget -q -c https://github.com/upx/upx/releases/download/v4.2.2/upx-4.2.2-amd64_linux.tar.xz -P /opt
|
|
||||||
tar -xf /opt/upx-4.2.2-amd64_linux.tar.xz -C /opt
|
|
||||||
sudo cp -rf /opt/upx-4.2.2-amd64_linux/upx /usr/bin/upx
|
|
||||||
|
|
||||||
echo "开始构建"
|
|
||||||
mkdir -p /opt/caddy
|
|
||||||
cd /opt/caddy
|
|
||||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
|
||||||
|
|
||||||
GOOS=linux GOARCH=${ARCH} GOMIPS=${SOFT} GOARM=${ARM} xcaddy build \
|
|
||||||
--with github.com/mholt/caddy-webdav \
|
|
||||||
--with github.com/aksdb/caddy-cgi/v2
|
|
||||||
file caddy
|
|
||||||
du -k caddy
|
|
||||||
mv caddy caddy-${TARGET}
|
|
||||||
if [[ $TARGET != mips64 ]] && [[ $TARGET != mips64le ]] && [[ $TARGET != s390x ]] ;then
|
|
||||||
cp caddy-${TARGET} caddy-${TARGET}-upx
|
|
||||||
upx --lzma --best caddy-${TARGET}-upx
|
|
||||||
du -k caddy-${TARGET}-upx
|
|
||||||
fi
|
|
||||||
#sudo apt install qemu-user
|
|
||||||
#qemu-mipsel caddy -v
|
|
||||||
|
|
||||||
echo "build_time=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
|
|
||||||
echo "tag=$(date '+%Y-%m-%d')" >> $GITHUB_ENV
|
|
||||||
- name: 发布
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.c8 }}
|
|
||||||
body: |
|
|
||||||
> ### 编译时间 :${{ env.build_time }}
|
|
||||||
|
|
||||||
|
|
||||||
tag_name: ${{ env.tag }}
|
|
||||||
files: /opt/caddy/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@ -26,16 +26,15 @@ jobs:
|
|||||||
cd /opt/openwrt-sdk*/bin/packages/aarch64_generic/base
|
cd /opt/openwrt-sdk*/bin/packages/aarch64_generic/base
|
||||||
ls
|
ls
|
||||||
mv *.ipk luci-app-caddy_all.ipk
|
mv *.ipk luci-app-caddy_all.ipk
|
||||||
echo "build_time=$(date '+%Y年%m月%d日%H:%M:%S' | jq -sRr @uri)" >> $GITHUB_ENV
|
echo "build_time=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
|
||||||
echo "tag=$(date '+%Y-%m-%d')" >> $GITHUB_ENV
|
echo "tag=$(date '+%Y-%m-%d')" >> $GITHUB_ENV
|
||||||
- name: 发布
|
- name: 发布
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.c8 }}
|
token: ${{ secrets.c8 }}
|
||||||
body: |
|
body: |
|
||||||
> ### 
|
> ### 编译时间 :${{ env.build_time }}
|
||||||
|
|
||||||
二进制程序下载地址:[caddy](https://github.com/lmq8267/caddy/releases)
|
|
||||||
|
|
||||||
tag_name: ${{ env.tag }}
|
tag_name: ${{ env.tag }}
|
||||||
files: /opt/openwrt-sdk*/bin/packages/aarch64_generic/base/*
|
files: /opt/openwrt-sdk*/bin/packages/aarch64_generic/base/*
|
||||||
|
BIN
Image/普通启动.png
BIN
Image/普通启动.png
Binary file not shown.
Before Width: | Height: | Size: 99 KiB |
BIN
Image/自定义启动.png
BIN
Image/自定义启动.png
Binary file not shown.
Before Width: | Height: | Size: 104 KiB |
60
README.md
60
README.md
@ -1,60 +0,0 @@
|
|||||||
# luci-app-caddy
|
|
||||||
<p align="center">
|
|
||||||
<img alt="GitHub Created At" src="https://img.shields.io/github/created-at/lmq8267/luci-app-caddy?logo=github&label=%E5%88%9B%E5%BB%BA%E6%97%A5%E6%9C%9F">
|
|
||||||
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Flmq8267%2Fluci-app-caddy&count_bg=%2395C10D&title_bg=%23555555&icon=github.svg&icon_color=%238DC409&title=%E8%AE%BF%E9%97%AE%E6%95%B0&edge_flat=false"/></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/releases"><img src="https://img.shields.io/github/downloads/lmq8267/luci-app-caddy/total?logo=github&label=%E4%B8%8B%E8%BD%BD%E9%87%8F"></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/graphs/contributors"><img src="https://img.shields.io/github/contributors-anon/lmq8267/luci-app-caddy?logo=github&label=%E8%B4%A1%E7%8C%AE%E8%80%85"></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/releases/"><img src="https://img.shields.io/github/release/lmq8267/luci-app-caddy?logo=github&label=%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC"></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/issues"><img src="https://img.shields.io/github/issues-raw/lmq8267/luci-app-caddy?logo=github&label=%E9%97%AE%E9%A2%98"></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/discussions"><img src="https://img.shields.io/github/discussions/lmq8267/luci-app-caddy?logo=github&label=%E8%AE%A8%E8%AE%BA"></a>
|
|
||||||
<a href="GitHub repo size"><img src="https://img.shields.io/github/repo-size/lmq8267/luci-app-caddy?logo=github&label=%E4%BB%93%E5%BA%93%E5%A4%A7%E5%B0%8F"></a>
|
|
||||||
<a href="https://github.com/lmq8267/luci-app-caddy/actions?query=workflow%3ABuild"><img src="https://img.shields.io/github/actions/workflow/status/lmq8267/luci-app-caddy/build.yml?branch=main&logo=github&label=%E6%9E%84%E5%BB%BA%E7%8A%B6%E6%80%81" alt="Build status"></a>
|
|
||||||
|
|
||||||
项目地址:https://github.com/caddyserver/caddy
|
|
||||||
|
|
||||||
没有添加caddy二进制程序,需要下载或编译对应cpu架构的二进制程序手动上传至路由器,然后填写对应的程序路径。
|
|
||||||
caddy的大概 [命令参数](https://github.com/lmq8267/caddy/blob/main/README_caddy.md)
|
|
||||||
```shell
|
|
||||||
#查看添加了哪些插件命令
|
|
||||||
caddy list-modules -s
|
|
||||||
```
|
|
||||||
------------------------------------------------------
|
|
||||||
编译的大概步骤:抄自网上的方法, 也有我编译好的二进制文件[caddy](https://github.com/lmq8267/caddy/releases)文件服务器支持照片音视频预览播放 支持markdown[UI预览效果图](https://github.com/lmq8267/caddy/tree/main#ui%E9%A2%84%E8%A7%88)
|
|
||||||
还有OpenWrt的[github.com/fuqiang03/openwrt-caddy](https://github.com/fuqiang03/openwrt-caddy)Makefile
|
|
||||||
```shell
|
|
||||||
apt update
|
|
||||||
apt install xcaddy git libnss3 upx-ucl
|
|
||||||
```
|
|
||||||
|
|
||||||
不能安装xcaddy的可以
|
|
||||||
```shell
|
|
||||||
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
|
|
||||||
```
|
|
||||||
|
|
||||||
```shell
|
|
||||||
#下载安装go
|
|
||||||
wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz
|
|
||||||
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
|
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
|
||||||
|
|
||||||
#编译 需要什么插件自行添加了 以下只添加了caddy-webdav和caddy-cgi
|
|
||||||
GOOS=linux GOARCH=mipsle GOMIPS=softfloat ~/go/bin/xcaddy build \
|
|
||||||
--with github.com/mholt/caddy-webdav \
|
|
||||||
--with github.com/aksdb/caddy-cgi/v2
|
|
||||||
|
|
||||||
#编译出来可能体积很大 可以使用upx压缩一下
|
|
||||||
upx --lzma --best caddy
|
|
||||||
```
|
|
||||||
|
|
||||||
--------------------------------------------------------
|
|
||||||
### UI预览 ###
|
|
||||||
我只是用来做文件服务器,所以也就一般配置
|
|
||||||

|
|
||||||
|
|
||||||
其他功能可以自行修改编辑配置文件
|
|
||||||

|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
|
|
@ -16,7 +16,6 @@ function index()
|
|||||||
entry({"admin", "nas", "caddy", "caddy_status"}, call("caddy_status")).leaf = true
|
entry({"admin", "nas", "caddy", "caddy_status"}, call("caddy_status")).leaf = true
|
||||||
entry({"admin", "nas", "caddy", "get_log"}, call("get_log")).leaf = true
|
entry({"admin", "nas", "caddy", "get_log"}, call("get_log")).leaf = true
|
||||||
entry({"admin", "nas", "caddy", "clear_log"}, call("clear_log")).leaf = true
|
entry({"admin", "nas", "caddy", "clear_log"}, call("clear_log")).leaf = true
|
||||||
entry({"admin", "nas", "caddy", "admin_info"}, call("admin_info")).leaf = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function caddy_status()
|
function caddy_status()
|
||||||
@ -26,22 +25,13 @@ function caddy_status()
|
|||||||
local port = tonumber(uci:get_first("caddy", "caddy", "port"))
|
local port = tonumber(uci:get_first("caddy", "caddy", "port"))
|
||||||
e.port = (port or 12311)
|
e.port = (port or 12311)
|
||||||
e.running=luci.sys.call("pidof caddy >/dev/null")==0
|
e.running=luci.sys.call("pidof caddy >/dev/null")==0
|
||||||
local tagfile = io.open("/tmp/caddy_time", "r")
|
|
||||||
if tagfile then
|
local command1 = io.popen("[ -f /tmp/caddy_time ] && start_time=$(cat /tmp/caddy_time) && time=$(($(date +%s)-start_time)) && day=$((time/86400)) && [ $day -eq 0 ] && day='' || day=${day}天 && time=$(date -u -d @${time} +'%H小时%M分%S秒') && echo $day $time")
|
||||||
local tagcontent = tagfile:read("*all")
|
e.caddysta = command1:read("*all")
|
||||||
tagfile:close()
|
command1:close()
|
||||||
if tagcontent and tagcontent ~= "" then
|
|
||||||
os.execute("start_time=$(cat /tmp/caddy_time) && time=$(($(date +%s)-start_time)) && day=$((time/86400)) && [ $day -eq 0 ] && day='' || day=${day}天 && time=$(date -u -d @${time} +'%H小时%M分%S秒') && echo $day $time > /tmp/command_caddy 2>&1")
|
|
||||||
local command_output_file = io.open("/tmp/command_caddy", "r")
|
|
||||||
if command_output_file then
|
|
||||||
e.caddysta = command_output_file:read("*all")
|
|
||||||
command_output_file:close()
|
|
||||||
if e.caddysta == "" then
|
if e.caddysta == "" then
|
||||||
e.caddysta = "unknown"
|
e.caddysta = "unknown"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local command2 = io.popen('test ! -z "`pidof caddy`" && (top -b -n1 | grep -E "$(pidof caddy)" 2>/dev/null | grep -v grep | awk \'{for (i=1;i<=NF;i++) {if ($i ~ /caddy/) break; else cpu=i}} END {print $cpu}\')')
|
local command2 = io.popen('test ! -z "`pidof caddy`" && (top -b -n1 | grep -E "$(pidof caddy)" 2>/dev/null | grep -v grep | awk \'{for (i=1;i<=NF;i++) {if ($i ~ /caddy/) break; else cpu=i}} END {print $cpu}\')')
|
||||||
e.caddycpu = command2:read("*all")
|
e.caddycpu = command2:read("*all")
|
||||||
@ -75,17 +65,10 @@ function caddy_status()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function get_log()
|
function get_log()
|
||||||
luci.http.write(luci.sys.exec("[ -s $(uci -q get caddy.@caddy[0].log_dir) ] && cat $(uci -q get caddy.@caddy[0].log_dir)"))
|
luci.http.write(luci.sys.exec("test ! -z `pidof caddy` && cat $(uci -q get caddy.@caddy[0].log_dir)"))
|
||||||
end
|
end
|
||||||
|
|
||||||
function clear_log()
|
function clear_log()
|
||||||
luci.sys.call("cat /dev/null > $(uci -q get caddy.@caddy[0].log_dir)")
|
luci.sys.call("cat /dev/null > $(uci -q get caddy.@caddy[0].log_dir)")
|
||||||
end
|
end
|
||||||
|
|
||||||
function admin_info()
|
|
||||||
local validate = luci.sys.exec("$(uci -q get caddy.@caddy[0].bin_dir) validate --config /etc/caddy/Caddyfile --adapter caddyfile 2>&1")
|
|
||||||
|
|
||||||
luci.http.prepare_content("application/json")
|
|
||||||
luci.http.write_json({ validate = validate })
|
|
||||||
end
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local m, s
|
local m, s
|
||||||
|
local fs = require "luci.fs"
|
||||||
m = Map("caddy", translate("Caddy"), translate("Caddy 是一个可扩展的服务器平台,具有自动 HTTPS 功能的快速且可扩展的多平台 HTTP/1-2-3 Web 服务器") .. "<br/>" .. "项目地址:" .. [[<a href="https://github.com/caddyserver/caddy" target="_blank">]] .. translate("github.com/caddyserver/caddy") .. "</a> " .. " caddy文档:" .. [[<a href="https://caddyserver.com/docs/" target="_blank">]] .. translate("caddyserver.com/docs/") .. [[</a>]])
|
m = Map("caddy", translate("Caddy"), translate("Caddy 是一个可扩展的服务器平台,具有自动 HTTPS 功能的快速且可扩展的多平台 HTTP/1-2-3 Web 服务器") .. "<br/>" .. "项目地址:" .. [[<a href="https://github.com/caddyserver/caddy" target="_blank">]] .. translate("github.com/caddyserver/caddy") .. "</a> " .. " caddy文档:" .. [[<a href="https://caddyserver.com/docs/" target="_blank">]] .. translate("caddyserver.com/docs/") .. [[</a>]])
|
||||||
|
|
||||||
m:section(SimpleSection).template = "caddy/caddy_status"
|
m:section(SimpleSection).template = "caddy/caddy_status"
|
||||||
@ -11,15 +12,6 @@ o = s:option(Flag, "enabled", translate("Enabled"))
|
|||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
o.default = 0
|
o.default = 0
|
||||||
|
|
||||||
o = s:option(Button, "btnrm", translate("重启"))
|
|
||||||
o.inputtitle = translate("重启")
|
|
||||||
o.description = translate("在没有修改参数的情况下快速重新启动一次")
|
|
||||||
o.inputstyle = "apply"
|
|
||||||
o:depends("enabled", "1")
|
|
||||||
o.write = function()
|
|
||||||
os.execute("/etc/init.d/caddy restart")
|
|
||||||
end
|
|
||||||
|
|
||||||
e=s:option(ListValue,"cmd",translate("启动方式"),
|
e=s:option(ListValue,"cmd",translate("启动方式"),
|
||||||
translate("自定义配置文件启动,若不懂参数请勿选择自定义"))
|
translate("自定义配置文件启动,若不懂参数请勿选择自定义"))
|
||||||
e:value("默认")
|
e:value("默认")
|
||||||
@ -30,32 +22,18 @@ o = s:option(TextValue, "caddyfile", translate("Caddyfile配置文件"),
|
|||||||
o.rows = 3
|
o.rows = 3
|
||||||
o.wrap = "off"
|
o.wrap = "off"
|
||||||
o:depends("cmd", "自定义")
|
o:depends("cmd", "自定义")
|
||||||
|
o.cfgvalue = function(self, section)
|
||||||
|
return nixio.fs.readfile("/etc/caddy/Caddyfile") or ""
|
||||||
|
end
|
||||||
|
o.write = function(self, section, value)
|
||||||
|
fs.writefile("/etc/caddy/Caddyfile", value:gsub("\r\n", "\n"))
|
||||||
|
end
|
||||||
|
|
||||||
o = s:option(Value, "port", translate("端口"))
|
o = s:option(Value, "port", translate("端口"))
|
||||||
o.datatype = "and(port,min(1))"
|
o.datatype = "and(port,min(1))"
|
||||||
o.default = "12311"
|
o.default = "12311"
|
||||||
o:depends("cmd", "默认")
|
o:depends("cmd", "默认")
|
||||||
|
|
||||||
o = s:option(Flag,"file_pass", translate("启用 认证"))
|
|
||||||
o.datatype = "string"
|
|
||||||
o.default = "0"
|
|
||||||
o:depends("cmd", "默认")
|
|
||||||
|
|
||||||
o = s:option(Value,"file_username", translate("用户名"))
|
|
||||||
o.datatype = "string"
|
|
||||||
o.default = "admin"
|
|
||||||
o:depends("file_pass", "1")
|
|
||||||
|
|
||||||
o = s:option(Value,"file_password", translate("密码"))
|
|
||||||
o.datatype = "string"
|
|
||||||
o.password = true
|
|
||||||
o.default = "123456"
|
|
||||||
o:depends("file_pass", "1")
|
|
||||||
|
|
||||||
o = s:option(Flag, "filezip", translate("启用 压缩"))
|
|
||||||
o.default = 0
|
|
||||||
o:depends("cmd", "默认")
|
|
||||||
|
|
||||||
o = s:option(Flag, "log", translate("启用日志"))
|
o = s:option(Flag, "log", translate("启用日志"))
|
||||||
o.default = 1
|
o.default = 1
|
||||||
o:depends("cmd", "默认")
|
o:depends("cmd", "默认")
|
||||||
@ -77,6 +55,10 @@ o.datatype = "string"
|
|||||||
o.default = "/mnt"
|
o.default = "/mnt"
|
||||||
o:depends("cmd", "默认")
|
o:depends("cmd", "默认")
|
||||||
|
|
||||||
|
o = s:option(Flag, "ssl", translate("启用 SSL"))
|
||||||
|
o.default = "0"
|
||||||
|
o:depends("cmd", "默认")
|
||||||
|
|
||||||
o = s:option(Flag, "webdav", translate("启用 webdav"))
|
o = s:option(Flag, "webdav", translate("启用 webdav"))
|
||||||
o.default = "0"
|
o.default = "0"
|
||||||
o:depends("cmd", "默认")
|
o:depends("cmd", "默认")
|
||||||
@ -102,10 +84,6 @@ o.datatype = "and(port,min(1))"
|
|||||||
o.default = "12322"
|
o.default = "12322"
|
||||||
o:depends("webdav", "1")
|
o:depends("webdav", "1")
|
||||||
|
|
||||||
o = s:option(Flag, "webzip", translate("启用 压缩"))
|
|
||||||
o.default = 0
|
|
||||||
o:depends("webdav", "1")
|
|
||||||
|
|
||||||
o = s:option(Value, "webdav_data_dir", translate("webdav指向路径"),
|
o = s:option(Value, "webdav_data_dir", translate("webdav指向路径"),
|
||||||
translate("指向一个路径,使用webdav访问你的文件,默认为 /mnt<br>连接地址须加/dav后缀 如: 192.168.1.1:12311/dav"))
|
translate("指向一个路径,使用webdav访问你的文件,默认为 /mnt<br>连接地址须加/dav后缀 如: 192.168.1.1:12311/dav"))
|
||||||
o.datatype = "string"
|
o.datatype = "string"
|
||||||
@ -115,13 +93,10 @@ o.default = "/mnt"
|
|||||||
o = s:option(Flag, "allow_wan", translate("允许从外网访问"))
|
o = s:option(Flag, "allow_wan", translate("允许从外网访问"))
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
|
|
||||||
|
o = s:option(Flag, "cgi", translate("启用 cgi模块"))
|
||||||
|
o:depends("cmd", "默认")
|
||||||
|
|
||||||
o = s:option(Flag, "api", translate("启用 API接口"))
|
o = s:option(Flag, "api", translate("启用 API接口"))
|
||||||
o:depends("cmd", "默认")
|
o:depends("cmd", "默认")
|
||||||
|
|
||||||
o = s:option(Button, "admin_info", translate("检测配置文件"),
|
|
||||||
translate("验证Caddyfile配置文件是否正确,它会模拟启动caddy<br>但是并不会真的启动,会列出详细信息,以便修正配置文件"))
|
|
||||||
|
|
||||||
o.rawhtml = true
|
|
||||||
o.template = "caddy/admin_info"
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
<%+cbi/valueheader%>
|
|
||||||
<script type="text/javascript">//<![CDATA[
|
|
||||||
function admin_info(btn)
|
|
||||||
{
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.value = '<%:Collecting data...%>';
|
|
||||||
XHR.get('<%=luci.dispatcher.build_url("admin", "nas", "caddy", "admin_info")%>',
|
|
||||||
null,
|
|
||||||
function(x,rv)
|
|
||||||
{
|
|
||||||
var tb = document.getElementById('<%=self.option%>-status');
|
|
||||||
if (tb) {
|
|
||||||
rv.validate = rv.validate.replace(/{"level":/g, '<br>{"level":').replace(/Error/g, "<br>Error").replace(/Valid configuration/g, "<br><strong><font color='#008000'>当前配置文件正确!</font></strong>").replace(/warn/g, "<font color='#800080'>警告</font>").replace(/level/g, "<font color='#1E90FF'>等级</font>").replace(/info/g, "<font color='#00BFFF'>普通</font>").replace(/msg/g, "<font color='#FFA500'>信息</font>").replace(/error/g, "<font color='#DB7093'>错误</font>").replace(/Error:/g, "<font color='red'><strong>当前配置文件错误!</strong><br>错误位置信息:</font>");
|
|
||||||
tb.innerHTML = "<br><font color='#FF00FF'><%:状态:%></font>" + "<font color='#2F4F4F'>" + rv.validate + "</font>";
|
|
||||||
}
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.value = '<%:检测%>';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//]]></script>
|
|
||||||
<input type="button" class="btn cbi-button cbi-button-apply" value="<%:检测%>" onclick="return admin_info(this)" />
|
|
||||||
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
|
||||||
<%+cbi/valuefooter%>
|
|
@ -14,8 +14,8 @@
|
|||||||
var tb = document.getElementById('caddy_status');
|
var tb = document.getElementById('caddy_status');
|
||||||
if (st && tb) {
|
if (st && tb) {
|
||||||
|
|
||||||
var caddyStatus = st.running ? "<span style='color:green;'> 运行中</span><img src='https://www.right.com.cn/forum/data/attachment/album/202401/30/073058is17bcmu7z3nmn2b.gif' width='30px' alt=''>" : "<span style='color:red;'> 未运行</span>";
|
var caddyStatus = st.running ? "<span style='color:green;'> 运行中</span>" : "<span style='color:red;'> 未运行</span>";
|
||||||
var caddystaContent = st.running ? "已运行:" + "<span style='color:#DA70D6;'>" + st.caddysta + "</span>" : "";
|
var caddystaContent = st.running ? " " + " 已 运 行:" + "<span style='color:#DA70D6;'>" + st.caddysta + "</span>" : "";
|
||||||
var caddycpuContent = st.running ? "<br>" + "CPU占用:" + "<span style='color:#6A5ACD;'>" + st.caddycpu + "</span>" : "";
|
var caddycpuContent = st.running ? "<br>" + "CPU占用:" + "<span style='color:#6A5ACD;'>" + st.caddycpu + "</span>" : "";
|
||||||
var caddyramContent = st.running ? " " + " 内存占用:" + "<span style='color:#0000CD;'>" + st.caddyram + "</span>" : "";
|
var caddyramContent = st.running ? " " + " 内存占用:" + "<span style='color:#0000CD;'>" + st.caddyram + "</span>" : "";
|
||||||
var caddytagContent = st.running ? "<br>" + "当前版本:" + "<span style='color:#CD853F;'>" + st.caddytag + "</span>" : "";
|
var caddytagContent = st.running ? "<br>" + "当前版本:" + "<span style='color:#CD853F;'>" + st.caddytag + "</span>" : "";
|
||||||
|
@ -1,28 +1,20 @@
|
|||||||
# 此配置文件路径:/etc/caddy/Caddyfile
|
# 此配置文件路径:/etc/caddy/Caddyfile
|
||||||
|
|
||||||
{ # 全局配置
|
{ # 全局配置
|
||||||
# 启动 cgi 模块
|
order cgi before respond # 启动 cgi 模块 # 全局配置
|
||||||
order cgi before respond
|
order webdav before file_server # 启动 webdav 模块 # 全局配置
|
||||||
# 启动 webdav 模块
|
admin off # 关闭 API 端口 # 全局配置
|
||||||
order webdav before file_server
|
} # 全局配置
|
||||||
# 关闭 API 端口
|
|
||||||
admin off
|
|
||||||
}
|
|
||||||
|
|
||||||
:12311 {
|
:12311 {
|
||||||
#启用压缩
|
|
||||||
encode gzip
|
|
||||||
#认证,账号admin 密码123456
|
|
||||||
basicauth {
|
|
||||||
admin $2a$14$RdbOHzJhf5BaapSdlYTCbe.yWY9cEZjyDpfgwStY28K/qsM1tX8tu
|
|
||||||
}
|
|
||||||
#路径 /mnt
|
|
||||||
root * /mnt
|
root * /mnt
|
||||||
#文件服务器 端口12311
|
|
||||||
file_server browse
|
file_server browse
|
||||||
|
|
||||||
|
header {
|
||||||
|
Content-Type "text/plain; charset=utf-8"
|
||||||
|
}
|
||||||
|
|
||||||
log {
|
log {
|
||||||
#日志 路径/tmp/caddy/requests.log
|
|
||||||
output file /tmp/caddy/requests.log {
|
output file /tmp/caddy/requests.log {
|
||||||
roll_size 1MiB
|
roll_size 1MiB
|
||||||
roll_local_time
|
roll_local_time
|
||||||
@ -34,16 +26,7 @@ admin $2a$14$RdbOHzJhf5BaapSdlYTCbe.yWY9cEZjyDpfgwStY28K/qsM1tX8tu
|
|||||||
}
|
}
|
||||||
|
|
||||||
:12322 {
|
:12322 {
|
||||||
#启用压缩
|
webdav * {
|
||||||
encode gzip
|
root /mnt
|
||||||
#认证,账号admin 密码123456
|
|
||||||
basicauth {
|
|
||||||
admin $2a$14$RdbOHzJhf5BaapSdlYTCbe.yWY9cEZjyDpfgwStY28K/qsM1tX8tu
|
|
||||||
}
|
|
||||||
|
|
||||||
# webdav 路径根目录 端口12322
|
|
||||||
webdav /dav/* {
|
|
||||||
prefix /dav
|
|
||||||
root /
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,10 @@ config caddy
|
|||||||
option cmd '默认'
|
option cmd '默认'
|
||||||
option 'port' '12311'
|
option 'port' '12311'
|
||||||
option 'webdav' '0'
|
option 'webdav' '0'
|
||||||
option 'filezip' '0'
|
|
||||||
option 'webzip' '0'
|
|
||||||
option 'cgi' '0'
|
option 'cgi' '0'
|
||||||
option 'api' '0'
|
option 'api' '0'
|
||||||
option 'data_dir' '/mnt'
|
option 'data_dir' '/mnt'
|
||||||
option 'file_pass' '0'
|
option 'ssl' '0'
|
||||||
option 'log' '1'
|
option 'log' '1'
|
||||||
option 'log_dir' '/tmp/caddy/requests.log'
|
option 'log_dir' '/tmp/caddy/requests.log'
|
||||||
option allow_wan '0'
|
option allow_wan '0'
|
||||||
|
@ -15,16 +15,12 @@ get_config() {
|
|||||||
config_get webdav_data_dir $1 webdav_data_dir "/mnt"
|
config_get webdav_data_dir $1 webdav_data_dir "/mnt"
|
||||||
config_get log_dir $1 log_dir "/tmp/caddy/requests.log"
|
config_get log_dir $1 log_dir "/tmp/caddy/requests.log"
|
||||||
config_get caddy_file $1 caddy_file "/etc/caddy/Caddyfile"
|
config_get caddy_file $1 caddy_file "/etc/caddy/Caddyfile"
|
||||||
config_get caddyfile $1 caddyfile
|
|
||||||
config_get file_pass $1 file_pass 0
|
|
||||||
config_get file_username $1 file_username "admin"
|
|
||||||
config_get file_password $1 file_password "123456"
|
|
||||||
config_get webdav_pass $1 webdav_pass 0
|
config_get webdav_pass $1 webdav_pass 0
|
||||||
config_get webdav_username $1 webdav_username "admin"
|
config_get webdav_username $1 webdav_username "admin"
|
||||||
config_get webdav_password $1 webdav_password "123456"
|
config_get webdav_password $1 webdav_password "123456"
|
||||||
|
config_get ssl $1 ssl 0
|
||||||
|
config_get cgi $1 cgi 0
|
||||||
config_get api $1 api 0
|
config_get api $1 api 0
|
||||||
config_get filezip $1 filezip 0
|
|
||||||
config_get webzip $1 webzip 0
|
|
||||||
config_get allow_wan $1 allow_wan 0
|
config_get allow_wan $1 allow_wan 0
|
||||||
|
|
||||||
|
|
||||||
@ -54,8 +50,6 @@ start_service() {
|
|||||||
config_load caddy
|
config_load caddy
|
||||||
config_foreach get_config caddy
|
config_foreach get_config caddy
|
||||||
[ $enabled -ne 1 ] && return 1
|
[ $enabled -ne 1 ] && return 1
|
||||||
log_path="$(dirname $log_dir)"
|
|
||||||
mkdir -p $log_path
|
|
||||||
if [ ! -f "$PROG" ] ;then
|
if [ ! -f "$PROG" ] ;then
|
||||||
uci -q set caddy.@caddy[0].enabled=0
|
uci -q set caddy.@caddy[0].enabled=0
|
||||||
uci commit caddy
|
uci commit caddy
|
||||||
@ -63,7 +57,7 @@ start_service() {
|
|||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
chmod +x $PROG
|
chmod +x $PROG
|
||||||
if [[ "$($PROG -h 2>&1 | wc -l)" -lt 3 ]] ;then
|
if [ $(($($PROG -h | wc -l))) -lt 3 ] ;then
|
||||||
uci -q set caddy.@caddy[0].enabled=0
|
uci -q set caddy.@caddy[0].enabled=0
|
||||||
uci commit caddy
|
uci commit caddy
|
||||||
echo "$(TZ=UTC-8 date -R +%Y年%m月%d日\ %X) : $PROG 程序不完整或CPU架构不支持的程序,无法启动!" >>$log_dir 2>&1
|
echo "$(TZ=UTC-8 date -R +%Y年%m月%d日\ %X) : $PROG 程序不完整或CPU架构不支持的程序,无法启动!" >>$log_dir 2>&1
|
||||||
@ -73,7 +67,8 @@ start_service() {
|
|||||||
if [ "$cmd" = "默认" ] ;then
|
if [ "$cmd" = "默认" ] ;then
|
||||||
mkdir -p $data_dir
|
mkdir -p $data_dir
|
||||||
if [ "$log" -eq 1 ] ;then
|
if [ "$log" -eq 1 ] ;then
|
||||||
|
log_path="$(dirname $log_dir)"
|
||||||
|
mkdir -p $log_path
|
||||||
logs="log {
|
logs="log {
|
||||||
output file $log_dir {
|
output file $log_dir {
|
||||||
roll_size 1MiB
|
roll_size 1MiB
|
||||||
@ -81,50 +76,47 @@ start_service() {
|
|||||||
roll_keep 5
|
roll_keep 5
|
||||||
roll_keep_for 120h
|
roll_keep_for 120h
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
fi
|
|
||||||
if [ "$file_pass" -eq 1 ] ;then
|
|
||||||
filepassword="$($PROG hash-password --plaintext $file_password)"
|
|
||||||
filebasicauth="basicauth {
|
|
||||||
$file_username $filepassword
|
|
||||||
}"
|
|
||||||
fi
|
fi
|
||||||
if [ "$webdav" -eq 1 ] ;then
|
if [ "$webdav" -eq 1 ] ;then
|
||||||
mkdir -p $webdav_data_dir
|
mkdir -p $webdav_data_dir
|
||||||
if [ "$webdav_pass" -eq 1 ] ;then
|
if [ "$webdav_pass" -eq 1 ] ;then
|
||||||
password="$($PROG hash-password --plaintext $webdav_password)"
|
password="$($PROG hash-password --plaintext $webdav_password)"
|
||||||
basicauth="basicauth {
|
basicauth="basicauth /dav/* {
|
||||||
$webdav_username $password
|
$webdav_username $password
|
||||||
}"
|
}"
|
||||||
fi
|
fi
|
||||||
webdavs=":$webdav_port {
|
webdavs=":$webdav_port {
|
||||||
$basicauth
|
$basicauth
|
||||||
webdav * {
|
webdav * {
|
||||||
prefix /dav
|
prefix /dav
|
||||||
root $webdav_data_dir
|
root $webdav_data_dir
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
orderweb="order webdav before file_server # 启动 webdav 模块"
|
reder_web="order webdav before file_server # 启动 webdav 模块 # 全局配置"
|
||||||
fi
|
fi
|
||||||
if [ "$filezip" -eq 1 ] ;then
|
if [ "$ssl" -eq 1 ] ;then
|
||||||
filezips="encode gzip"
|
tsl="tls {
|
||||||
|
protocols tls1.1 tls1.2 tls1.3
|
||||||
|
}"
|
||||||
fi
|
fi
|
||||||
if [ "$webzip" -eq 1 ] ;then
|
if [ "$cgi" -eq 1 ] ;then
|
||||||
webzips="encode gzip"
|
cgis="order cgi before respond # 启动 cgi 模块 # 全局配置"
|
||||||
fi
|
fi
|
||||||
if [ "$api" != "1" ] ;then
|
if [ "$api" != "1" ] ;then
|
||||||
apis="admin off # 关闭 API 端口"
|
apis="admin off # 关闭 API 端口 # 全局配置"
|
||||||
fi
|
fi
|
||||||
if [ "$allow_wan" -eq "1" ]; then
|
if [ "$allow_wan" -eq "1" ]; then
|
||||||
external_access="allow"
|
external_access="allow"
|
||||||
else
|
else
|
||||||
external_access="deny"
|
external_access="deny"
|
||||||
fi
|
fi
|
||||||
if [ "$webdav" -eq 1 ] || [ "$api" != "1" ] ;then
|
if [ "$cgi" -eq 1 ] || [ "$webdav" -eq 1 ] || [ "$api" != "1" ] ;then
|
||||||
order="{ # 全局配置
|
order="{ # 全局配置
|
||||||
$orderweb
|
$cgis
|
||||||
$apis
|
$reder_web
|
||||||
} "
|
$apis
|
||||||
|
} # 全局配置"
|
||||||
fi
|
fi
|
||||||
set_firewall
|
set_firewall
|
||||||
|
|
||||||
@ -134,34 +126,20 @@ $apis
|
|||||||
$order
|
$order
|
||||||
|
|
||||||
:$port {
|
:$port {
|
||||||
$filezips
|
|
||||||
$filebasicauth
|
|
||||||
root * $data_dir
|
root * $data_dir
|
||||||
file_server browse
|
file_server browse
|
||||||
|
|
||||||
|
header {
|
||||||
|
Content-Type "text/plain; charset=utf-8"
|
||||||
|
}
|
||||||
|
|
||||||
$logs
|
$logs
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$webdavs
|
$webdavs
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
uci -q set caddy.@caddy[0].caddyfile="$(cat $caddy_file)"
|
|
||||||
uci commit caddy
|
|
||||||
else
|
|
||||||
caddyf="$(uci -q get caddy.@caddy[0].caddyfile)"
|
|
||||||
logpath="$(echo $caddyf | grep "output file" | awk -F 'output file' '{print $2}' | tr -d '{ ')"
|
|
||||||
[ ! -z "$logpath" ] && uci -q set caddy.@caddy[0].log_dir=$logpath && uci commit caddy
|
|
||||||
if [ ! -z "$caddyf" ] ;then
|
|
||||||
echo "$caddyf" >$caddy_file 2>&1
|
|
||||||
else
|
|
||||||
uci -q set caddy.@caddy[0].enabled=0
|
|
||||||
uci commit caddy
|
|
||||||
echo "$(TZ=UTC-8 date -R +%Y年%m月%d日\ %X) : $caddy_file 配置文件Caddyfile为空,无法启动!" >>$log_dir 2>&1
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
$PROG fmt --overwrite $caddy_file
|
|
||||||
procd_open_instance caddy
|
procd_open_instance caddy
|
||||||
procd_set_param command $PROG
|
procd_set_param command $PROG
|
||||||
procd_append_param command run
|
procd_append_param command run
|
||||||
|
Loading…
x
Reference in New Issue
Block a user