luci-app-mosdns: Add Enable API support

This commit is contained in:
sbwml 2023-03-27 09:28:01 +08:00
parent 9d98b22173
commit 9d76341fb8
4 changed files with 26 additions and 0 deletions

View File

@ -158,4 +158,15 @@ function o.write(self, section, value)
fs.writefile("/etc/mosdns/config_custom.yaml", value)
end
s:tab("api", translate("API Setting"))
o = s:taboption("api", Flag, "enabled_api", translate("Enabled API"))
o:depends("configfile", "/etc/mosdns/config.yaml")
o.default = false
o = s:taboption("api", Value, "listen_port_api", translate("API Listen port"))
o.datatype = "and(port,min(1))"
o.default = 9091
o:depends("configfile", "/etc/mosdns/config.yaml")
return m

View File

@ -25,6 +25,12 @@ msgstr "启用"
msgid "Listen port"
msgstr "监听端口"
msgid "Enabled API"
msgstr "启用 API"
msgid "API Listen port"
msgstr "API 监听端口"
msgid "Log Level"
msgstr "日志等级"

View File

@ -53,6 +53,8 @@ get_config() {
config_get remote_dns $1 remote_dns "tls://8.8.8.8 tls://1.1.1.1"
config_get custom_local_dns $1 custom_local_dns 0
config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29"
config_get enabled_api $1 enabled_api 0
config_get listen_port_api $1 listen_port_api 9091
}
init_yaml() {
@ -72,6 +74,8 @@ init_yaml() {
echo "${local_dns}" > $TMPDIR/local_dns.txt
echo "${remote_dns}" > $TMPDIR/remote_dns.txt
sed -i -e '/- addr: local_dns/{r '$TMPDIR/local_dns.txt -e';d};/- addr: remote_dns/{r '$TMPDIR/remote_dns.txt -e';d}' $CONF
[ "$enabled_api" -eq 1 ] && sed -i "s/api_port/$listen_port_api/g" $CONF
[ "$enabled_api" -eq 0 ] && sed -i "/api:/d;/http:/d;" $CONF
[ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: $DUMP_FILE\n dump_interval: $dump_interval" $CONF
[ "$dump_file" -eq 1 ] && [ ! -f $DUMP_FILE ] && cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
[ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE

View File

@ -2,6 +2,11 @@ log:
level: log_level
file: "log_file"
api:
http: "0.0.0.0:api_port"
include: []
plugins:
- tag: geosite_cn
type: domain_set