luci: enable SSL protocol support & format code

This commit is contained in:
sbwml 2022-03-07 17:55:31 +08:00
parent 0030bc0f24
commit e2fd8f52ad
6 changed files with 75 additions and 16 deletions

View File

@ -4,3 +4,4 @@ config alist
option 'expiration' '60' option 'expiration' '60'
option 'cleanup_interval' '120' option 'cleanup_interval' '120'
option 'temp_dir' '/tmp' option 'temp_dir' '/tmp'
option 'ssl' '0'

View File

@ -11,6 +11,9 @@ get_config() {
config_get expiration $1 expiration 60 config_get expiration $1 expiration 60
config_get cleanup_interval $1 cleanup_interval 120 config_get cleanup_interval $1 cleanup_interval 120
config_get temp_dir $1 temp_dir "/tmp" config_get temp_dir $1 temp_dir "/tmp"
config_get ssl $1 ssl 0
config_get ssl_cert $1 ssl_cert ""
config_get ssl_key $1 ssl_key ""
} }
start_service() { start_service() {
@ -18,8 +21,13 @@ start_service() {
config_foreach get_config alist config_foreach get_config alist
[ $enabled != 1 ] && return 1 [ $enabled != 1 ] && return 1
mkdir -p $temp_dir mkdir -p $temp_dir
if [ "$ssl" -eq 1 ];then
SSL=true
else
SSL=false
fi
cat > $CONFIG <<EOF cat > $CONFIG <<EOF
{"address":"0.0.0.0","port":$port,"assets":"/","database":{"type":"sqlite3","user":"","password":"","host":"","port":0,"name":"","table_prefix":"x_","db_file":"/etc/alist/data.db","ssl_mode":"disable"},"scheme":{"https":false,"cert_file":"","key_file":""},"cache":{"expiration":$expiration,"cleanup_interval":$cleanup_interval},"temp_dir":"$temp_dir"} {"address":"0.0.0.0","port":$port,"assets":"/","database":{"type":"sqlite3","user":"","password":"","host":"","port":0,"name":"","table_prefix":"x_","db_file":"/etc/alist/data.db","ssl_mode":"disable"},"scheme":{"https":$SSL,"cert_file":"$ssl_cert","key_file":"$ssl_key"},"cache":{"expiration":$expiration,"cleanup_interval":$cleanup_interval},"temp_dir":"$temp_dir"}
EOF EOF
procd_open_instance procd_open_instance
procd_set_param command $PROG procd_set_param command $PROG

View File

@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for alist LUCI_TITLE:=LuCI support for alist
LUCI_DEPENDS:=+alist LUCI_DEPENDS:=+alist
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_VERSION:=1.0.2 PKG_VERSION:=1.0.3
PKG_RELEASE:=1 PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -4,19 +4,44 @@ m = Map("alist", translate("Alist"), translate("Alist is an file list program th
m:section(SimpleSection).template = "alist_status" m:section(SimpleSection).template = "alist_status"
s=m:section(TypedSection, "alist", translate("Global settings")) s = m:section(TypedSection, "alist", translate("Global settings"))
s.addremove=false s.addremove = false
s.anonymous=true s.anonymous = true
s:option(Flag, "enabled", translate("Enable")).rmempty=false o = s:option(Flag, "enabled", translate("Enable"))
s:option(Value, "port", translate("Port")).rmempty=false o.rmempty = false
s=m:section(TypedSection, "alist", translate("Cache settings")) o = s:option(Value, "port", translate("Port"))
s.addremove=false o.datatype = "and(port,min(1))"
s.anonymous=true o.rmempty = false
s:option(Value, "expiration", translate("Cache invalidation time (unit: minutes)")).rmempty=false o = s:option(Flag, "ssl", translate("Enable SSL"))
s:option(Value, "cleanup_interval", translate("Clear the invalidation cache interval")).rmempty=false o.rmempty=false
s:option(Value, "temp_dir", translate("Temp directory")).rmempty=false
o = s:option(Value,"ssl_cert", translate("SSL cert"), translate("SSL certificate file path"))
o:depends("ssl", "1")
o.datatype = "string"
o.rmempty = true
o = s:option(Value,"ssl_key", translate("SSL key"), translate("SSL key file path"))
o:depends("ssl", "1")
o.datatype = "string"
o.rmempty = true
s = m:section(TypedSection, "alist", translate("Cache settings"))
s.addremove = false
s.anonymous = true
o = s:option(Value, "expiration", translate("Cache invalidation time (unit: minutes)"))
o.datatype = "and(uinteger,min(1))"
o.rmempty = false
o = s:option(Value, "cleanup_interval", translate("Clear the invalidation cache interval (unit: minutes)"))
o.datatype = "and(uinteger,min(1))"
o.rmempty = false
o = s:option(Value, "temp_dir", translate("Temp directory"))
o.datatype = "string"
o.rmempty = false
return m return m

View File

@ -1,3 +1,13 @@
<%
local uci = require 'luci.model.uci'.cursor()
ssl = uci:get_first('alist', 'alist', 'ssl')
if ssl == '1' then
protocol="https://"
else
protocol="http://"
end
%>
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
XHR.poll(5, '<%=url("admin/nas/alist_status")%>', null, XHR.poll(5, '<%=url("admin/nas/alist_status")%>', null,
function(x, st) function(x, st)
@ -7,7 +17,7 @@
{ {
if (st.running) if (st.running)
{ {
tb.innerHTML = '<em style=\"color:green\"><b><%:The Alist service is running.%></b></em>' + "<input class=\"cbi-button-reload mar-10\" type=\"button\" value=\" <%:Click to open Alist%> \" onclick=\"window.open('http://" + window.location.hostname + ":" + st.port + "/')\"/>"; tb.innerHTML = '<em style=\"color:green\"><b><%:The Alist service is running.%></b></em>' + "<input class=\"cbi-button-reload mar-10\" type=\"button\" value=\" <%:Click to open Alist%> \" onclick=\"window.open('<%=protocol%>" + window.location.hostname + ":" + st.port + "/')\"/>";
} }
else else
{ {

View File

@ -16,14 +16,29 @@ msgstr "全局设置"
msgid "Port" msgid "Port"
msgstr "端口" msgstr "端口"
msgid "Enable SSL"
msgstr "启用 SSL"
msgid "SSL cert"
msgstr "SSL 证书"
msgid "SSL certificate file path"
msgstr "SSL 证书文件路径"
msgid "SSL key"
msgstr "SSL 密钥"
msgid "SSL key file path"
msgstr "SSL 密钥文件路径"
msgid "Cache settings" msgid "Cache settings"
msgstr "缓存设置" msgstr "缓存设置"
msgid "Cache invalidation time (unit: minutes)" msgid "Cache invalidation time (unit: minutes)"
msgstr "缓存失效时间(分钟)" msgstr "缓存失效时间(分钟)"
msgid "Clear the invalidation cache interval" msgid "Clear the invalidation cache interval (unit: minutes)"
msgstr "清理失效缓存间隔" msgstr "清理失效缓存间隔(分钟)"
msgid "Temp directory" msgid "Temp directory"
msgstr "临时目录" msgstr "临时目录"