luci-app-mosdns: enable api options by default

This commit is contained in:
sbwml 2023-03-30 08:24:21 +08:00
parent aa7ee434b3
commit 2f7df2dd6f
5 changed files with 9 additions and 20 deletions

View File

@ -189,11 +189,7 @@ function o.write(self, section, value)
fs.writefile("/etc/mosdns/config_custom.yaml", value) fs.writefile("/etc/mosdns/config_custom.yaml", value)
end end
s:tab("api", translate("API Setting")) s:tab("api", translate("API Options"))
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 = s:taboption("api", Value, "listen_port_api", translate("API Listen port"))
o.datatype = "and(port,min(1))" o.datatype = "and(port,min(1))"
@ -203,7 +199,7 @@ o:depends("configfile", "/etc/mosdns/config.yaml")
o = s:taboption("api", Button, "flush_cache", translate("Flush Cache"), translate("Flushing Cache will clear any IP addresses or DNS records from MosDNS cache")) o = s:taboption("api", Button, "flush_cache", translate("Flush Cache"), translate("Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"))
o.rawhtml = true o.rawhtml = true
o.template = "mosdns/mosdns_flush_cache" o.template = "mosdns/mosdns_flush_cache"
o:depends("enabled_api", "1") o:depends("configfile", "/etc/mosdns/config.yaml")
s:tab("geodata", translate("GeoData Export")) s:tab("geodata", translate("GeoData Export"))

View File

@ -18,7 +18,7 @@
tb.innerHTML = "<font color='green'>" + "<%:Flushing Success%>" + "</font>"; tb.innerHTML = "<font color='green'>" + "<%:Flushing Success%>" + "</font>";
break; break;
case false: case false:
tb.innerHTML = "<font color='red'>" + "<%:Flushing Failed, Please check if the API is enabled%>" + "</font>"; tb.innerHTML = "<font color='red'>" + "<%:Flushing Failed, Please check if MosDNS is enabled%>" + "</font>";
break; break;
} }
} }

View File

@ -7,6 +7,9 @@ msgstr "基本选项"
msgid "Advanced Options" msgid "Advanced Options"
msgstr "高级选项" msgstr "高级选项"
msgid "API Options"
msgstr "API 选项"
msgid "MosDNS is a 'programmable' DNS forwarder." msgid "MosDNS is a 'programmable' DNS forwarder."
msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。" msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。"
@ -25,12 +28,6 @@ msgstr "启用"
msgid "Listen port" msgid "Listen port"
msgstr "监听端口" msgstr "监听端口"
msgid "API Setting"
msgstr "API 设置"
msgid "Enabled API"
msgstr "启用 API"
msgid "API Listen port" msgid "API Listen port"
msgstr "API 监听端口" msgstr "API 监听端口"
@ -46,8 +43,8 @@ msgstr "正在刷新..."
msgid "Flushing Success" msgid "Flushing Success"
msgstr "刷新成功" msgstr "刷新成功"
msgid "Flushing Failed, Please check if the API is enabled" msgid "Flushing Failed, Please check if MosDNS is enabled"
msgstr "刷新失败,请检查 API 是否已启用" msgstr "刷新失败,请检查 MosDNS 是否已启用"
msgid "Log Level" msgid "Log Level"
msgstr "日志等级" msgstr "日志等级"

View File

@ -22,7 +22,6 @@ config mosdns 'config'
option enable_pipeline '0' option enable_pipeline '0'
option insecure_skip_verify '0' option insecure_skip_verify '0'
option enable_http3 '0' option enable_http3 '0'
option enabled_api '0'
option listen_port_api '9091' option listen_port_api '9091'
option bootstrap_dns '119.29.29.29' option bootstrap_dns '119.29.29.29'
list remote_dns 'tls://8.8.8.8' list remote_dns 'tls://8.8.8.8'

View File

@ -52,7 +52,6 @@ get_config() {
config_get remote_dns $1 remote_dns "tls://8.8.8.8 tls://1.1.1.1" 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 custom_local_dns $1 custom_local_dns 0
config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29" 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 config_get listen_port_api $1 listen_port_api 9091
config_get concurrent $1 concurrent 1 config_get concurrent $1 concurrent 1
config_get max_conns $1 max_conns 2 config_get max_conns $1 max_conns 2
@ -77,13 +76,11 @@ init_yaml() {
s,cache_survival_time,$cache_survival_time,g; \ s,cache_survival_time,$cache_survival_time,g; \
s,minimal_ttl_custom,$minimal_ttl_custom,g; \ s,minimal_ttl_custom,$minimal_ttl_custom,g; \
s,maximum_ttl_custom,$maximum_ttl_custom,g; \ s,maximum_ttl_custom,$maximum_ttl_custom,g; \
s,concurrent_num,$concurrent,g; \ s,concurrent_num,$concurrent,g;s,api_port,$listen_port_api,g; \
s,adblock,$adlist,g;s,remote_dns_pipeline,$enable_pipeline,g" $DEFAULT_CONF > $CONF s,adblock,$adlist,g;s,remote_dns_pipeline,$enable_pipeline,g" $DEFAULT_CONF > $CONF
echo "${local_dns}" > $TMPDIR/local_dns.txt echo "${local_dns}" > $TMPDIR/local_dns.txt
echo "${remote_dns}" > $TMPDIR/remote_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 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 ] && 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 1 ] && [ ! -f $DUMP_FILE ] && cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
[ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE [ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE