luci-app-mosdns: init at 97867ea
This commit is contained in:
parent
6c536e3c19
commit
90cc8ca0d2
44 changed files with 2546 additions and 0 deletions
53
luci-app-mosdns/luasrc/controller/mosdns.lua
Normal file
53
luci-app-mosdns/luasrc/controller/mosdns.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
local sys = require "luci.sys"
|
||||
local http = require "luci.http"
|
||||
|
||||
module("luci.controller.mosdns", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/mosdns") then
|
||||
return
|
||||
end
|
||||
|
||||
local page = entry({"admin", "services", "mosdns"}, alias("admin", "services", "mosdns", "basic"), _("MosDNS"), 30)
|
||||
page.dependent = true
|
||||
page.acl_depends = { "luci-app-mosdns" }
|
||||
|
||||
entry({"admin", "services", "mosdns", "basic"}, cbi("mosdns/basic"), _("Basic Setting"), 1).leaf = true
|
||||
entry({"admin", "services", "mosdns", "rule_list"}, cbi("mosdns/rule_list"), _("Rule List"), 2).leaf = true
|
||||
entry({"admin", "services", "mosdns", "update"}, cbi("mosdns/update"), _("Geodata Update"), 3).leaf = true
|
||||
entry({"admin", "services", "mosdns", "log"}, cbi("mosdns/log"), _("Logs"), 4).leaf = true
|
||||
entry({"admin", "services", "mosdns", "status"}, call("act_status")).leaf = true
|
||||
entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true
|
||||
entry({"admin", "services", "mosdns", "clear_log"}, call("clear_log")).leaf = true
|
||||
entry({"admin", "services", "mosdns", "geo_update"}, call("geo_update")).leaf = true
|
||||
entry({"admin", "services", "mosdns", "flush_cache"}, call("flush_cache")).leaf = true
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
e.running = sys.call("pgrep -f mosdns >/dev/null") == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
||||
|
||||
function get_log()
|
||||
http.write(sys.exec("cat $(/usr/share/mosdns/mosdns.sh logfile)"))
|
||||
end
|
||||
|
||||
function clear_log()
|
||||
sys.call("cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)")
|
||||
end
|
||||
|
||||
function geo_update()
|
||||
local e = {}
|
||||
e.updating = sys.call("/usr/share/mosdns/mosdns.sh geodata >/dev/null") == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
||||
|
||||
function flush_cache()
|
||||
local e = {}
|
||||
e.flushing = sys.call("/usr/share/mosdns/mosdns.sh flush >/dev/null") == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
243
luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua
Normal file
243
luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua
Normal file
|
@ -0,0 +1,243 @@
|
|||
local fs = require "nixio.fs"
|
||||
local sys = require "luci.sys"
|
||||
|
||||
if fs.access("/usr/bin/mosdns") then
|
||||
mosdns_version = sys.exec("/usr/share/mosdns/mosdns.sh version")
|
||||
else
|
||||
mosdns_version = "Unknown Version"
|
||||
end
|
||||
m = Map("mosdns")
|
||||
m.title = translate("MosDNS") .. " " .. mosdns_version
|
||||
m.description = translate("MosDNS is a plugin-based DNS forwarder/traffic splitter.")
|
||||
|
||||
m:section(SimpleSection).template = "mosdns/mosdns_status"
|
||||
|
||||
s = m:section(TypedSection, "mosdns")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
s:tab("basic", translate("Basic Options"))
|
||||
|
||||
o = s:taboption("basic", Flag, "enabled", translate("Enabled"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:taboption("basic", ListValue, "configfile", translate("Config File"))
|
||||
o:value("/var/etc/mosdns.json", translate("Default Config"))
|
||||
o:value("/etc/mosdns/config_custom.yaml", translate("Custom Config"))
|
||||
o.default = "/var/etc/mosdns.json"
|
||||
|
||||
o = s:taboption("basic", Value, "listen_port", translate("Listen port"))
|
||||
o.datatype = "and(port,min(1))"
|
||||
o.default = 5335
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("basic", ListValue, "log_level", translate("Log Level"))
|
||||
o:value("debug", translate("Debug"))
|
||||
o:value("info", translate("Info"))
|
||||
o:value("warn", translate("Warning"))
|
||||
o:value("error", translate("Error"))
|
||||
o.default = "info"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("basic", Value, "log_file", translate("Log File"))
|
||||
o.placeholder = "/var/log/mosdns.log"
|
||||
o.default = "/var/log/mosdns.log"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("basic", Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS"))
|
||||
o.default = true
|
||||
|
||||
o = s:taboption("basic", Flag, "prefer_ipv4", translate("Remote DNS prefer IPv4"), translate("IPv4 is preferred for remote DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only"))
|
||||
o:depends( "configfile", "/var/etc/mosdns.json")
|
||||
o.default = true
|
||||
|
||||
o = s:taboption("basic", Flag, "custom_local_dns", translate("Custom China DNS"), translate("Follow WAN interface DNS if not enabled"))
|
||||
o:depends( "configfile", "/var/etc/mosdns.json")
|
||||
o.default = false
|
||||
|
||||
o = s:taboption("basic", Flag, "apple_optimization", translate("Apple domains optimization"), translate("For Apple domains equipped with Chinese mainland CDN, always responsive to Chinese CDN IP addresses"))
|
||||
o:depends("custom_local_dns", "1")
|
||||
o.default = false
|
||||
|
||||
o = s:taboption("basic", DynamicList, "local_dns", translate("China DNS server"))
|
||||
o:value("119.29.29.29", translate("Tencent Public DNS (119.29.29.29)"))
|
||||
o:value("119.28.28.28", translate("Tencent Public DNS (119.28.28.28)"))
|
||||
o:value("223.5.5.5", translate("Aliyun Public DNS (223.5.5.5)"))
|
||||
o:value("223.6.6.6", translate("Aliyun Public DNS (223.6.6.6)"))
|
||||
o:value("114.114.114.114", translate("Xinfeng Public DNS (114.114.114.114)"))
|
||||
o:value("114.114.115.115", translate("Xinfeng Public DNS (114.114.115.115)"))
|
||||
o:value("180.76.76.76", translate("Baidu Public DNS (180.76.76.76)"))
|
||||
o:value("https://doh.pub/dns-query", translate("Tencent Public DNS (DNS over HTTPS)"))
|
||||
o:value("quic://dns.alidns.com", translate("Aliyun Public DNS (DNS over QUIC)"))
|
||||
o:value("https://dns.alidns.com/dns-query", translate("Aliyun Public DNS (DNS over HTTPS)"))
|
||||
o:value("h3://dns.alidns.com/dns-query", translate("Aliyun Public DNS (DNS over HTTPS/3)"))
|
||||
o:value("https://doh.360.cn/dns-query", translate("360 Public DNS (DNS over HTTPS)"))
|
||||
o:depends("custom_local_dns", "1")
|
||||
|
||||
o = s:taboption("basic", DynamicList, "remote_dns", translate("Remote DNS server"))
|
||||
o:value("tls://1.1.1.1", translate("CloudFlare Public DNS (1.1.1.1)"))
|
||||
o:value("tls://1.0.0.1", translate("CloudFlare Public DNS (1.0.0.1)"))
|
||||
o:value("tls://8.8.8.8", translate("Google Public DNS (8.8.8.8)"))
|
||||
o:value("tls://8.8.4.4", translate("Google Public DNS (8.8.4.4)"))
|
||||
o:value("tls://9.9.9.9", translate("Quad9 Public DNS (9.9.9.9)"))
|
||||
o:value("tls://149.112.112.112", translate("Quad9 Public DNS (149.112.112.112)"))
|
||||
o:value("tls://208.67.222.222", translate("Cisco Public DNS (208.67.222.222)"))
|
||||
o:value("tls://208.67.220.220", translate("Cisco Public DNS (208.67.220.220)"))
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("basic", ListValue, "bootstrap_dns", translate("Bootstrap DNS servers"), translate("Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams"))
|
||||
o:value("119.29.29.29", translate("Tencent Public DNS (119.29.29.29)"))
|
||||
o:value("119.28.28.28", translate("Tencent Public DNS (119.28.28.28)"))
|
||||
o:value("223.5.5.5", translate("Aliyun Public DNS (223.5.5.5)"))
|
||||
o:value("223.6.6.6", translate("Aliyun Public DNS (223.6.6.6)"))
|
||||
o:value("114.114.114.114", translate("Xinfeng Public DNS (114.114.114.114)"))
|
||||
o:value("114.114.115.115", translate("Xinfeng Public DNS (114.114.115.115)"))
|
||||
o:value("180.76.76.76", translate("Baidu Public DNS (180.76.76.76)"))
|
||||
o:value("8.8.8.8", translate("Google Public DNS (8.8.8.8)"))
|
||||
o:value("1.1.1.1", translate("CloudFlare Public DNS (1.1.1.1)"))
|
||||
o.default = "119.29.29.29"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
s:tab("advanced", translate("Advanced Options"))
|
||||
|
||||
o = s:taboption("advanced", Value, "concurrent", translate("Concurrent"), translate("DNS query request concurrency, The number of upstream DNS servers that are allowed to initiate requests at the same time"))
|
||||
o.datatype = "and(uinteger,min(1),max(3))"
|
||||
o.default = "2"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "idle_timeout", translate("Idle Timeout"), translate("DoH/TCP/DoT Connection Multiplexing idle timeout (default 30 seconds)"))
|
||||
o.datatype = "and(uinteger,min(1))"
|
||||
o.default = "30"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Flag, "enable_pipeline", translate("TCP/DoT Connection Multiplexing"), translate("Enable TCP/DoT RFC 7766 new Query Pipelining connection multiplexing mode"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Flag, "insecure_skip_verify", translate("Disable TLS Certificate"), translate("Disable TLS Servers certificate validation, Can be useful if system CA certificate expires or the system time is out of order"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "remote_ecs_ip", translate("IP Address"), translate("Please provide the IP address you use when accessing foreign websites. This IP subnet (0/24) will be used as the ECS address for Remote DNS requests") .. '<br />' .. translate("This feature is typically used when using a self-built DNS server as an Remote DNS upstream (requires support from the upstream server)"))
|
||||
o.datatype = "ipaddr"
|
||||
o:depends("enable_ecs_remote", "1")
|
||||
|
||||
o = s:taboption("advanced", Flag, "dns_leak", translate("Prevent DNS Leaks"), translate("Enable this option fallback policy forces forwarding to remote DNS"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"), translate("DNS cache size (in piece). To disable caching, please set to 0."))
|
||||
o.datatype = "and(uinteger,min(0))"
|
||||
o.default = "8000"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "lazy_cache_ttl", translate("Lazy Cache TTL"), translate("Lazy cache survival time (in second). To disable Lazy Cache, please set to 0."))
|
||||
o.datatype = "and(uinteger,min(0))"
|
||||
o.default = "86400"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "dump_interval", translate("Auto Save Cache Interval"))
|
||||
o.datatype = "and(uinteger,min(0))"
|
||||
o.default = "3600"
|
||||
o:depends("dump_file", "1")
|
||||
|
||||
o = s:taboption("advanced", Value, "minimal_ttl", translate("Minimum TTL"), translate("Modify the Minimum TTL value (seconds) for DNS answer results, 0 indicating no modification"))
|
||||
o.datatype = "and(uinteger,min(0),max(604800))"
|
||||
o.default = "0"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Value, "maximum_ttl", translate("Maximum TTL"), translate("Modify the Maximum TTL value (seconds) for DNS answer results, 0 indicating no modification"))
|
||||
o.datatype = "and(uinteger,min(0),max(604800))"
|
||||
o.default = "0"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("advanced", Flag, "adblock", translate("Enable DNS ADblock"))
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
o.default = false
|
||||
|
||||
o = s:taboption("advanced", DynamicList, "ad_source", translate("ADblock Source"), translate("When using custom rule sources, please use rule types supported by MosDNS (domain lists).") .. '<br />' .. translate("Support for local files, such as: file:///var/mosdns/example.txt"))
|
||||
o:depends("adblock", "1")
|
||||
o.default = "geosite.dat"
|
||||
o:value("geosite.dat", "v2ray-geosite")
|
||||
o:value("https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt", "anti-AD")
|
||||
o:value("https://raw.githubusercontent.com/Cats-Team/AdRules/main/mosdns_adrules.txt", "Cats-Team/AdRules")
|
||||
o:value("https://raw.githubusercontent.com/neodevpro/neodevhost/master/domain", "NEO DEV HOST")
|
||||
|
||||
o = s:taboption("basic", Button, "_reload", translate("Restart-Service"), translate("Restart the MosDNS process to take effect of new configuration"))
|
||||
o.write = function()
|
||||
sys.exec("/etc/init.d/mosdns reload")
|
||||
end
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
o = s:taboption("basic", TextValue, "config_custom", translate("Configuration Editor"))
|
||||
o.template = "cbi/tvalue"
|
||||
o.rows = 25
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
function o.cfgvalue(self, section)
|
||||
return fs.readfile("/etc/mosdns/config_custom.yaml")
|
||||
end
|
||||
function o.write(self, section, value)
|
||||
value = value:gsub("\r\n?", "\n")
|
||||
fs.writefile("/etc/mosdns/config_custom.yaml", value)
|
||||
end
|
||||
-- codemirror
|
||||
o = s:taboption("basic", DummyValue, "")
|
||||
o.template = "mosdns/mosdns_editor"
|
||||
|
||||
s:tab("cloudflare", translate("Cloudflare Options"))
|
||||
o = s:taboption("cloudflare", Flag, "cloudflare", translate("Enabled"), translate("Match the parsing result with the Cloudflare IP ranges, and when there is a successful match, use the 'Custom IP' as the parsing result (experimental feature)"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("cloudflare", DynamicList, "cloudflare_ip", translate("Custom IP"))
|
||||
o.datatype = "ipaddr"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
o = s:taboption("cloudflare", TextValue, "cloudflare_cidr", translate("Cloudflare IP Ranges"))
|
||||
o.description = translate("IPv4 CIDR:") .. [[<a href="https://www.cloudflare.com/ips-v4" target="_blank">https://www.cloudflare.com/ips-v4</a>]] .. '<br />' .. translate("IPv6 CIDR:") .. [[<a href="https://www.cloudflare.com/ips-v6" target="_blank">https://www.cloudflare.com/ips-v6</a>]]
|
||||
o.template = "cbi/tvalue"
|
||||
o.rows = 15
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
function o.cfgvalue(self, section)
|
||||
return fs.readfile("/etc/mosdns/rule/cloudflare-cidr.txt")
|
||||
end
|
||||
function o.write(self, section, value)
|
||||
value = value:gsub("\r\n?", "\n")
|
||||
fs.writefile("/etc/mosdns/rule/cloudflare-cidr.txt", value)
|
||||
end
|
||||
|
||||
s:tab("api", translate("API Options"))
|
||||
|
||||
o = s:taboption("api", Value, "listen_port_api", translate("API Listen port"))
|
||||
o.datatype = "and(port,min(1))"
|
||||
o.default = 9091
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
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.template = "mosdns/mosdns_flush_cache"
|
||||
o:depends("configfile", "/var/etc/mosdns.json")
|
||||
|
||||
s:tab("geodata", translate("GeoData Export"))
|
||||
|
||||
o = s:taboption("geodata", DynamicList, "geosite_tags", translate("GeoSite Tags"), translate("Enter the GeoSite.dat category to be exported, Allow add multiple tags") .. '<br />' .. translate("Export directory: /var/mosdns"))
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
o = s:taboption("geodata", DynamicList, "geoip_tags", translate("GeoIP Tags"), translate("Enter the GeoIP.dat category to be exported, Allow add multiple tags") .. '<br />' .. translate("Export directory: /var/mosdns"))
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
return m
|
5
luci-app-mosdns/luasrc/model/cbi/mosdns/log.lua
Normal file
5
luci-app-mosdns/luasrc/model/cbi/mosdns/log.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
m = Map("mosdns")
|
||||
|
||||
m:append(Template("mosdns/mosdns_log"))
|
||||
|
||||
return m
|
99
luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua
Normal file
99
luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua
Normal file
|
@ -0,0 +1,99 @@
|
|||
local datatypes = require "luci.cbi.datatypes"
|
||||
|
||||
local white_list_file = "/etc/mosdns/rule/whitelist.txt"
|
||||
local block_list_file = "/etc/mosdns/rule/blocklist.txt"
|
||||
local grey_list_file = "/etc/mosdns/rule/greylist.txt"
|
||||
local hosts_list_file = "/etc/mosdns/rule/hosts.txt"
|
||||
local redirect_list_file = "/etc/mosdns/rule/redirect.txt"
|
||||
local local_ptr_file = "/etc/mosdns/rule/local-ptr.txt"
|
||||
local ddns_list_file = "/etc/mosdns/rule/ddnslist.txt"
|
||||
|
||||
m = Map("mosdns")
|
||||
|
||||
s = m:section(TypedSection, "mosdns", translate("Rule Settings"))
|
||||
s.anonymous = true
|
||||
|
||||
s:tab("white_list", translate("White Lists"))
|
||||
s:tab("block_list", translate("Block Lists"))
|
||||
s:tab("grey_list", translate("Grey Lists"))
|
||||
s:tab("ddns_list", translate("DDNS Lists"))
|
||||
s:tab("hosts_list", translate("Hosts"))
|
||||
s:tab("redirect_list", translate("Redirect"))
|
||||
s:tab("local_ptr_list", translate("Block PTR"))
|
||||
|
||||
o = s:taboption("white_list", TextValue, "whitelist", "", "<font color='red'>" .. translate("These domain names allow DNS resolution with the highest priority. Please input the domain names of websites, every line can input only one website domain. For example: hm.baidu.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(white_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(white_list_file , value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(white_list_file , "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("block_list", TextValue, "blocklist", "", "<font color='red'>" .. translate("These domains are blocked from DNS resolution. Please input the domain names of websites, every line can input only one website domain. For example: baidu.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(block_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(block_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(block_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("grey_list", TextValue, "greylist", "", "<font color='red'>" .. translate("These domains are always resolved using remote DNS. Please input the domain names of websites, every line can input only one website domain. For example: google.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(grey_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(grey_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(grey_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("ddns_list", TextValue, "ddns", "", "<font color='red'>" .. translate("These domains are always resolved using local DNS. And force TTL 5 seconds, DNS resolution results will not enter the cache. For example: myddns.example.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(ddns_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(ddns_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(ddns_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("hosts_list", TextValue, "hosts", "", "<font color='red'>" .. translate("Hosts For example: baidu.com 10.0.0.1") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(hosts_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(hosts_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(hosts_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("redirect_list", TextValue, "redirect", "", "<font color='red'>" .. translate("The domain name to redirect the request to. Requests domain A, but returns records for domain B. example: a.com b.com") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(redirect_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(redirect_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(redirect_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("local_ptr_list", TextValue, "local_ptr", "", "<font color='red'>" .. translate("These domains are blocked from PTR requests") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(local_ptr_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(local_ptr_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(local_ptr_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
luci.sys.exec("/etc/init.d/mosdns reload")
|
||||
end
|
||||
|
||||
return m
|
37
luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua
Normal file
37
luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
m = Map("mosdns")
|
||||
|
||||
s = m:section(TypedSection, "mosdns", translate("Update GeoIP & GeoSite dat"))
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
o = s:option(Flag, "geo_auto_update", translate("Enable Auto Database Update"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(ListValue, "geo_update_week_time", translate("Update Cycle"))
|
||||
o:value("*", translate("Every Day"))
|
||||
o:value("1", translate("Every Monday"))
|
||||
o:value("2", translate("Every Tuesday"))
|
||||
o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("7", translate("Every Sunday"))
|
||||
o.default = "3"
|
||||
|
||||
o = s:option(ListValue, "geo_update_day_time", translate("Update Time"))
|
||||
for t = 0, 23 do
|
||||
o:value(t, t..":00")
|
||||
end
|
||||
default = 3
|
||||
|
||||
o = s:option(Value, "github_proxy", translate("GitHub Proxy"), translate("Update data files with GitHub Proxy, leave blank to disable proxy downloads."))
|
||||
o:value("https://gh-proxy.com", translate("https://gh-proxy.com"))
|
||||
o:value("https://ghps.cc", translate("https://ghps.cc"))
|
||||
o.rmempty = true
|
||||
o.default = ""
|
||||
|
||||
o = s:option(Button, "geo_update_database", translate("Database Update"))
|
||||
o.rawhtml = true
|
||||
o.template = "mosdns/mosdns_geo_update"
|
||||
|
||||
return m
|
21
luci-app-mosdns/luasrc/view/mosdns/mosdns_editor.htm
Normal file
21
luci-app-mosdns/luasrc/view/mosdns/mosdns_editor.htm
Normal file
|
@ -0,0 +1,21 @@
|
|||
<%+cbi/valueheader%>
|
||||
<script src="/luci-static/resources/mosdns/lib/codemirror.js"></script>
|
||||
<script src="/luci-static/resources/mosdns/addon/fold/foldcode.js"></script>
|
||||
<script src="/luci-static/resources/mosdns/addon/fold/foldgutter.js"></script>
|
||||
<script src="/luci-static/resources/mosdns/addon/fold/indent-fold.js"></script>
|
||||
<script src="/luci-static/resources/mosdns/mode/yaml/yaml.js"></script>
|
||||
<link rel="stylesheet" href="/luci-static/resources/mosdns/addon/fold/foldgutter.css" />
|
||||
<link rel="stylesheet" href="/luci-static/resources/mosdns/lib/codemirror.css" />
|
||||
<link rel="stylesheet" href="/luci-static/resources/mosdns/theme/dracula.css" />
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("cbid.mosdns.config.config_custom"), {
|
||||
mode: "text/yaml",
|
||||
styleActiveLine: true,
|
||||
lineNumbers: true,
|
||||
theme: "dracula",
|
||||
lineWrapping: true,
|
||||
matchBrackets: true
|
||||
}
|
||||
);//]]>
|
||||
</script>
|
||||
<%+cbi/valuefooter%>
|
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
Normal file
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
Normal file
|
@ -0,0 +1,34 @@
|
|||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function flush_cache(btn, dataname)
|
||||
{
|
||||
btn.disabled = true;
|
||||
btn.value = '<%:Flushing...%> ';
|
||||
st=dataname;
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "mosdns", "flush_cache")%>',
|
||||
{ set:st },
|
||||
function(x,data)
|
||||
{
|
||||
var tb = document.getElementById(dataname+'-status');
|
||||
if (tb)
|
||||
{
|
||||
switch (data.flushing)
|
||||
{
|
||||
case true:
|
||||
tb.innerHTML = "<font color='green'>" + "<%:Flushing Success%>" + "</font>";
|
||||
break;
|
||||
case false:
|
||||
tb.innerHTML = "<font color='red'>" + "<%:Flushing Failed, Please check if MosDNS is enabled%>" + "</font>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.value = '<%:Flush Cache%>';
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
//]]></script>
|
||||
<input type="button" class="btn cbi-button-action" value="<%:Flush Cache%>" onclick="return flush_cache(this,'<%=self.option%>')" />
|
||||
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
||||
<%+cbi/valuefooter%>
|
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_geo_update.htm
Normal file
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_geo_update.htm
Normal file
|
@ -0,0 +1,34 @@
|
|||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function update_data(btn, dataname)
|
||||
{
|
||||
btn.disabled = true;
|
||||
btn.value = '<%:Updating...%> ';
|
||||
st=dataname;
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "mosdns", "geo_update")%>',
|
||||
{ set:st },
|
||||
function(x,data)
|
||||
{
|
||||
var tb = document.getElementById(dataname+'-status');
|
||||
if (tb)
|
||||
{
|
||||
switch (data.updating)
|
||||
{
|
||||
case true:
|
||||
tb.innerHTML = "<font color='green'>" + "<%:Update success%>" + "</font>";
|
||||
break;
|
||||
case false:
|
||||
tb.innerHTML = "<font color='red'>" + "<%:Update failed, Please check the network status%>" + "</font>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.value = '<%:Check And Update%>';
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
//]]></script>
|
||||
<input type="button" class="btn cbi-button-action" value="<%:Check And Update%>" onclick="return update_data(this,'<%=self.option%>')" />
|
||||
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
||||
<%+cbi/valuefooter%>
|
33
luci-app-mosdns/luasrc/view/mosdns/mosdns_log.htm
Normal file
33
luci-app-mosdns/luasrc/view/mosdns/mosdns_log.htm
Normal file
|
@ -0,0 +1,33 @@
|
|||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function clear_log(btn) {
|
||||
XHR.get('<%=url([[admin]], [[services]], [[mosdns]], [[clear_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = "";
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
}
|
||||
location.reload();
|
||||
}
|
||||
);
|
||||
}
|
||||
var scrolled = false;
|
||||
XHR.poll(2, '<%=url([[admin]], [[services]], [[mosdns]], [[get_log]])%>', null,
|
||||
function(x, data) {
|
||||
if(x && x.status == 200) {
|
||||
var log_textarea = document.getElementById('log_textarea');
|
||||
log_textarea.innerHTML = x.responseText;
|
||||
if (!scrolled) {
|
||||
log_textarea.scrollTop = log_textarea.scrollHeight;
|
||||
scrolled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<fieldset class="cbi-section" id="_log_fieldset">
|
||||
<input class="btn cbi-button-action" type="button" onclick="clear_log()" value="<%:Clear logs%>" style="margin-left: 10px; margin-top: 10px;">
|
||||
<textarea id="log_textarea" class="cbi-input-textarea" style="width: calc(100% - 20px); height: 645px; margin: 10px;" data-update="change" rows="5" wrap="off" readonly="readonly"></textarea>
|
||||
</fieldset>
|
28
luci-app-mosdns/luasrc/view/mosdns/mosdns_status.htm
Normal file
28
luci-app-mosdns/luasrc/view/mosdns/mosdns_status.htm
Normal file
|
@ -0,0 +1,28 @@
|
|||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
XHR.poll(3, '<%=url([[admin]], [[services]], [[mosdns]], [[status]])%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('mosdns_status');
|
||||
if (data && tb) {
|
||||
if (data.running) {
|
||||
var links = '<em><b style=color:green>MosDNS <%:RUNNING%></b></em>';
|
||||
tb.innerHTML = links;
|
||||
} else {
|
||||
tb.innerHTML = '<em><b style=color:red>MosDNS <%:NOT RUNNING%></b></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<style>
|
||||
.mar-10 {
|
||||
margin-left: 50px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="mosdns_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
Loading…
Add table
Add a link
Reference in a new issue