diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index 1bfdf2a..a21d464 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -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 diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index 82505c6..2227973 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -25,6 +25,12 @@ msgstr "启用" msgid "Listen port" msgstr "监听端口" +msgid "Enabled API" +msgstr "启用 API" + +msgid "API Listen port" +msgstr "API 监听端口" + msgid "Log Level" msgstr "日志等级" diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 4dae051..a740d3c 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -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 diff --git a/luci-app-mosdns/root/usr/share/mosdns/default.yaml b/luci-app-mosdns/root/usr/share/mosdns/default.yaml index 2a11784..bbe281f 100644 --- a/luci-app-mosdns/root/usr/share/mosdns/default.yaml +++ b/luci-app-mosdns/root/usr/share/mosdns/default.yaml @@ -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