update 2024-08-17 15:12:49

This commit is contained in:
actions-user 2024-08-17 15:12:49 +08:00
parent 801710916e
commit 1e3e3464ed
36 changed files with 698 additions and 967 deletions

View File

@ -1,14 +1,12 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.6.0
PKG_VERSION:=1.5.23
PKG_RELEASE:=1
LUCI_TITLE:=LuCI Support for mosdns
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+mosdns +jsonfilter +curl +v2ray-geoip +v2ray-geosite +v2dat
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
LUCI_DEPENDS:=+mosdns +jsonfilter +luci-compat +curl +v2ray-geoip +v2ray-geosite +v2dat
define Package/$(PKG_NAME)/conffiles
/etc/config/mosdns

View File

@ -1,369 +0,0 @@
'use strict';
'require form';
'require fs';
'require poll';
'require rpc';
'require uci';
'require ui';
'require view';
var callServiceList = rpc.declare({
object: 'service',
method: 'list',
params: ['name'],
expect: { '': {} }
});
function getServiceStatus() {
return L.resolveDefault(callServiceList('mosdns'), {}).then(function (res) {
var isRunning = false;
try {
isRunning = res['mosdns']['instances']['mosdns']['running'];
} catch (e) { }
return isRunning;
});
}
function renderStatus(isRunning) {
var spanTemp = '<em><span style="color:%s"><strong>%s %s</strong></span></em>';
var renderHTML;
if (isRunning) {
renderHTML = spanTemp.format('green', _('MosDNS'), _('RUNNING'));
} else {
renderHTML = spanTemp.format('red', _('MosDNS'), _('NOT RUNNING'));
}
return renderHTML;
}
return view.extend({
load: function() {
return Promise.all([
L.resolveDefault(fs.exec('/usr/bin/mosdns', ['version']), null),
]);
},
handleFlushCache: function (m, section_id, ev) {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['flush'])
.then(function (lazy_cache) {
var res = lazy_cache.code;
if (res === 0) {
ui.addNotification(null, E('p', _('Flushing DNS Cache Success.')), 'info');
} else {
ui.addNotification(null, E('p', _('Flushing DNS Cache Failed, Please check if MosDNS is running.')), 'error');
}
});
},
render: function (basic) {
var m, s, o, v;
v = '';
if (basic[0] && basic[0].code === 0) {
v = basic[0].stdout.trim();
}
m = new form.Map('mosdns', _('MosDNS') + '&#160;' + v,
_('MosDNS is a plugin-based DNS forwarder/traffic splitter.'));
s = m.section(form.TypedSection);
s.anonymous = true;
s.render = function () {
poll.add(function () {
return L.resolveDefault(getServiceStatus()).then(function (res) {
var view = document.getElementById('service_status');
view.innerHTML = renderStatus(res);
});
});
return E('div', { class: 'cbi-section', id: 'status_bar' }, [
E('p', { id: 'service_status' }, _('Collecting data...'))
]);
}
s = m.section(form.NamedSection, 'config', 'mosdns');
s.tab('basic', _('Basic Options'));
s.tab("advanced", _("Advanced Options"));
s.tab("cloudflare", _("Cloudflare Options"));
s.tab("api", _("API Options"));
s.tab('geodata', _('GeoData Export'));
/* basic */
o = s.taboption('basic', form.Flag, 'enabled', _('Enabled'));
o.default = o.disabled;
o.rmempty = false;
o = s.taboption('basic', form.ListValue, 'configfile', _('Config File'));
o.value('/var/etc/mosdns.json', _('Default Config'));
o.value('/etc/mosdns/config_custom.yaml', _('Custom Config'));
o.default = '/var/etc/mosdns.json';
o = s.taboption('basic', form.Value, 'listen_port', _('Listen port'));
o.default = '5335';
o.datatype = 'port';
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('basic', form.ListValue, 'log_level', _('Log Level'));
o.value('debug', _('Debug'));
o.value('info', _('Info'));
o.value('warn', _('Warning'));
o.value('error', _('Error'));
o.default = 'info';
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('basic', form.Value, 'log_file', _('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', form.Flag, 'redirect', _('DNS Forward'), _('Forward Dnsmasq Domain Name resolution requests to MosDNS'));
o.default = false;
o = s.taboption('basic', form.Flag, 'prefer_ipv4', _('Remote DNS prefer IPv4'),
_('IPv4 is preferred for Remote / Streaming Media 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 = false;
o = s.taboption('basic', form.Flag, 'custom_local_dns', _('Custom China DNS'), _('Follow WAN interface DNS if not enabled'));
o.depends('configfile', '/var/etc/mosdns.json');
o.default = false;
o = s.taboption('basic', form.Flag, 'apple_optimization', _('Apple domains optimization'),
_('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', form.DynamicList, 'local_dns', _('China DNS server'));
o.value('119.29.29.29', _('Tencent Public DNS (119.29.29.29)'));
o.value('119.28.28.28', _('Tencent Public DNS (119.28.28.28)'));
o.value('223.5.5.5', _('Aliyun Public DNS (223.5.5.5)'));
o.value('223.6.6.6', _('Aliyun Public DNS (223.6.6.6)'));
o.value('180.184.1.1', _('TrafficRoute Public DNS (180.184.1.1)'));
o.value('180.184.2.2', _('TrafficRoute Public DNS (180.184.2.2)'));
o.value('114.114.114.114', _('Xinfeng Public DNS (114.114.114.114)'));
o.value('114.114.115.115', _('Xinfeng Public DNS (114.114.115.115)'));
o.value('180.76.76.76', _('Baidu Public DNS (180.76.76.76)'));
o.value('https://doh.pub/dns-query', _('Tencent Public DNS (DNS over HTTPS)'));
o.value('quic://dns.alidns.com', _('Aliyun Public DNS (DNS over QUIC)'));
o.value('https://dns.alidns.com/dns-query', _('Aliyun Public DNS (DNS over HTTPS)'));
o.value('h3://dns.alidns.com/dns-query', _('Aliyun Public DNS (DNS over HTTPS/3)'));
o.value('https://doh.360.cn/dns-query', _('360 Public DNS (DNS over HTTPS)'));
o.default = '119.29.29.29';
o.depends('custom_local_dns', '1');
o = s.taboption('basic', form.DynamicList, 'remote_dns', _('Remote DNS server'));
o.value('tls://1.1.1.1', _('CloudFlare Public DNS (1.1.1.1)'));
o.value('tls://1.0.0.1', _('CloudFlare Public DNS (1.0.0.1)'));
o.value('tls://8.8.8.8', _('Google Public DNS (8.8.8.8)'));
o.value('tls://8.8.4.4', _('Google Public DNS (8.8.4.4)'));
o.value('tls://9.9.9.9', _('Quad9 Public DNS (9.9.9.9)'));
o.value('tls://149.112.112.112', _('Quad9 Public DNS (149.112.112.112)'));
o.value('tls://208.67.222.222', _('Cisco Public DNS (208.67.222.222)'));
o.value('tls://208.67.220.220', _('Cisco Public DNS (208.67.220.220)'));
o.default = 'tls://8.8.8.8';
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('basic', form.Flag, 'custom_stream_media_dns', _('Custom Stream Media DNS'),
_('Netflix, Disney+, Hulu and streaming media rules list will use this DNS'));
o.depends('configfile', '/var/etc/mosdns.json');
o.default = false;
o = s.taboption('basic', form.DynamicList, 'stream_media_dns', _('Streaming Media DNS server'));
o.value('tls://1.1.1.1', _('CloudFlare Public DNS (1.1.1.1)'));
o.value('tls://1.0.0.1', _('CloudFlare Public DNS (1.0.0.1)'));
o.value('tls://8.8.8.8', _('Google Public DNS (8.8.8.8)'));
o.value('tls://8.8.4.4', _('Google Public DNS (8.8.4.4)'));
o.value('tls://9.9.9.9', _('Quad9 Public DNS (9.9.9.9)'));
o.value('tls://149.112.112.112', _('Quad9 Public DNS (149.112.112.112)'));
o.value('tls://208.67.222.222', _('Cisco Public DNS (208.67.222.222)'));
o.value('tls://208.67.220.220', _('Cisco Public DNS (208.67.220.220)'));
o.default = 'tls://8.8.8.8';
o.depends('custom_stream_media_dns', '1');
o = s.taboption('basic', form.ListValue, 'bootstrap_dns', _('Bootstrap DNS servers'),
_('Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams'));
o.value('119.29.29.29', _('Tencent Public DNS (119.29.29.29)'));
o.value('119.28.28.28', _('Tencent Public DNS (119.28.28.28)'));
o.value('223.5.5.5', _('Aliyun Public DNS (223.5.5.5)'));
o.value('223.6.6.6', _('Aliyun Public DNS (223.6.6.6)'));
o.value('114.114.114.114', _('Xinfeng Public DNS (114.114.114.114)'));
o.value('114.114.115.115', _('Xinfeng Public DNS (114.114.115.115)'));
o.value('180.76.76.76', _('Baidu Public DNS (180.76.76.76)'));
o.value('8.8.8.8', _('Google Public DNS (8.8.8.8)'));
o.value('1.1.1.1', _('CloudFlare Public DNS (1.1.1.1)'));
o.default = '119.29.29.29';
o.depends('configfile', '/var/etc/mosdns.json');
/* advanced */
o = s.taboption('advanced', form.Value, 'concurrent', _('Concurrent'),
_('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', form.Value, 'idle_timeout', _('Idle Timeout'),
_('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', form.Flag, 'enable_pipeline', _('TCP/DoT Connection Multiplexing'),
_('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', form.Flag, 'insecure_skip_verify', _('Disable TLS Certificate'),
_('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', form.Flag, 'enable_ecs_remote',
_('Enable EDNS client subnet'));
o.rmempty = false;
o.default = false;
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('advanced', form.Value, 'remote_ecs_ip', _('IP Address'),
_('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 / Streaming Media DNS requests') +
_('This feature is typically used when using a self-built DNS server as an Remote / Streaming Media DNS upstream (requires support from the upstream server)'));
o.datatype = 'ipaddr';
o.depends('enable_ecs_remote', '1');
o = s.taboption('advanced', form.Flag, 'dns_leak', _('Prevent DNS Leaks'),
_('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', form.Flag, 'cache', _('Enable DNS Cache'));
o.rmempty = false;
o.default = false;
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('advanced', form.Value, 'cache_size', _('DNS Cache Size'),
_('DNS cache size (in piece). To disable caching, please set to 0.'));
o.datatype = 'and(uinteger,min(0))';
o.default = 8000;
o.depends('cache', '1');
o = s.taboption('advanced', form.Value, 'lazy_cache_ttl', _('Lazy Cache TTL'),
_('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('cache', '1');
o = s.taboption('advanced', form.Flag, 'dump_file', _('Cache Dump'),
_('Save the cache locally and reload the cache dump on the next startup'));
o.rmempty = false;
o.default = false;
o.depends('cache', '1');
o = s.taboption('advanced', form.Value, 'dump_interval',
_('Auto Save Cache Interval'));
o.datatype = 'and(uinteger,min(0))';
o.default = 3600;
o.depends('dump_file', '1');
o = s.taboption('advanced', form.Value, 'minimal_ttl', _('Minimum TTL'),
_('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', form.Value, 'maximum_ttl', _('Maximum TTL'),
_('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', form.Flag, 'adblock', _('Enable DNS ADblock'));
o.depends('configfile', '/var/etc/mosdns.json');
o.default = false;
o = s.taboption('advanced', form.DynamicList, 'ad_source', _('ADblock Source'),
_('When using custom rule sources, please use rule types supported by MosDNS (domain lists).') +
'<br>' +
_('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')
/* cloudflare */
o = s.taboption('cloudflare', form.Flag, 'cloudflare', _('Enabled'),
_('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', form.DynamicList, 'cloudflare_ip', _('Custom IP'));
o.datatype = 'ipaddr';
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('cloudflare', form.TextValue, '_cloudflare',
_('Cloudflare IP Ranges'),
_('IPv4 CIDR: <a href="https://www.cloudflare.com/ips-v4" target="_blank">https://www.cloudflare.com/ips-v4</a> <br /> IPv6 CIDR: <a href="https://www.cloudflare.com/ips-v6" target="_blank">https://www.cloudflare.com/ips-v6</a>'));
o.rows = 15;
o.depends('configfile', '/var/etc/mosdns.json');
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/cloudflare-cidr.txt');
};
o.write = function (section_id, formvalue) {
return fs.write('/etc/mosdns/rule/cloudflare-cidr.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
return fs.exec('/etc/init.d/mosdns', ['restart']);
});
};
/* api */
o = s.taboption('api', form.Value, 'listen_port_api', _('API Listen port'));
o.datatype = 'and(port,min(1))';
o.default = 9091;
o.depends('configfile', '/var/etc/mosdns.json');
o = s.taboption('api', form.Button, '_flush_cache', null,
_('Flushing DNS Cache will clear any IP addresses or DNS records from MosDNS cache.'));
o.title = '&#160;';
o.inputtitle = _('Flush DNS Cache');
o.inputstyle = 'apply';
o.onclick = L.bind(this.handleFlushCache, this, m);
o.depends('cache', '1');
/* configuration */
o = s.taboption('basic', form.TextValue, '_custom', _('Configuration Editor'),
_('This is the content of the file \'/etc/mosdns/config_custom.yaml\' from which your MosDNS configuration will be generated. \
Only accepts configuration content in yaml format.'));
o.rows = 25;
o.depends('configfile', '/etc/mosdns/config_custom.yaml');
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/config_custom.yaml');
};
o.write = function (section_id, formvalue) {
return fs.write('/etc/mosdns/config_custom.yaml', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Configuration have been saved.')), 'info');
return fs.exec('/etc/init.d/mosdns', ['restart']);
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
};
o = s.taboption('geodata', form.DynamicList, 'geosite_tags', _('GeoSite Tags'),
_('Enter the GeoSite.dat category to be exported, Allow add multiple tags'),
_('Export directory: /var/mosdns'));
o.depends('configfile', '/etc/mosdns/config_custom.yaml');
o = s.taboption('geodata', form.DynamicList, 'geoip_tags', _('GeoIP Tags'),
_('Enter the GeoIP.dat category to be exported, Allow add multiple tags'),
_('Export directory: /var/mosdns'));
o.depends('configfile', '/etc/mosdns/config_custom.yaml');
return m.render();
}
});

View File

@ -1,77 +0,0 @@
'use strict';
'require dom';
'require fs';
'require poll';
'require view';
function pollLog(e) {
return Promise.all([
fs.exec_direct('/usr/share/mosdns/mosdns.sh', ['printlog']).then(function (res) {
return res.trim().split(/\n/).join('\n')
}),
]).then(function (data) {
var logTextarea = E('textarea', { 'class': 'cbi-input-textarea', 'wrap': 'off', 'readonly': 'readonly', 'style': 'width: calc(100% - 20px);height: 645px;margin: 10px;overflow-y: scroll;' }, [
data[0] || _('No log data.')
]);
// Store the current scroll position
var storedScrollTop = e.querySelector('textarea') ? e.querySelector('textarea').scrollTop : null;
dom.content(e, logTextarea);
// If the storedScrollTop is not null, it means we have a previous scroll position
if (storedScrollTop !== null) {
logTextarea.scrollTop = storedScrollTop;
}
// Add event listener to save the scroll position when scrolling stops
var timer;
logTextarea.addEventListener('scroll', function () {
clearTimeout(timer);
timer = setTimeout(function () {
storeScrollPosition(logTextarea.scrollTop);
}, 150);
});
function storeScrollPosition(scrollPos) {
localStorage.setItem("scrollPosition", JSON.stringify({ "log": scrollPos }));
}
});
};
return view.extend({
handleCleanLogs: function () {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['cleanlog'])
.catch(function (e) { ui.addNotification(null, E('p', e.message)) });
},
render: function () {
var log_textarea = E('div', { 'id': 'log_textarea' },
E('img', {
'src': L.resource(['icons/loading.gif']),
'alt': _('Loading'),
'style': 'vertical-align:middle'
}, _('Collecting data...'))
);
poll.add(pollLog.bind(this, log_textarea));
var clear_logs_button = E('input', { 'class': 'btn cbi-button-action', 'type': 'button', 'style': 'margin-left: 10px; margin-top: 10px;', 'value': _('Clear logs') });
clear_logs_button.addEventListener('click', this.handleCleanLogs.bind(this));
return E([
E('div', { 'class': 'cbi-map' }, [
E('h2', { 'name': 'content' }, '%s - %s'.format(_('MosDNS'), _('Log Data'))),
E('div', { 'class': 'cbi-section' }, [
clear_logs_button,
log_textarea,
E('div', { 'style': 'text-align:right' },
E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval))
)
])])
]);
},
handleSave: null,
handleSaveApply: null,
handleReset: null
});

View File

@ -1,251 +0,0 @@
'use strict';
'require form';
'require fs';
'require ui';
'require view';
return view.extend({
render: function () {
var m, s, o;
m = new form.Map("mosdns", _("Rule Settings"),
_('The list of rules only apply to \'Default Config\' profiles.'));
s = m.section(form.TypedSection);
s.anonymous = true;
s.sortable = true;
s.tab('whitelist', _('White Lists'));
s.tab('blocklist', _('Block Lists'));
s.tab('greylist', _('Grey Lists'));
s.tab('ddnslist', _('DDNS Lists'));
s.tab('hostslist', _('Hosts'));
s.tab('redirectlist', _('Redirect'));
s.tab('localptrlist', _('Block PTR'));
s.tab('streamingmedialist', _('Streaming Media'));
o = s.taboption('whitelist', form.TextValue, '_whitelist',
null,
'<font color=\'red\'>'
+ _('Added domain names always permit resolution using \'local DNS\' with the highest priority (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/whitelist.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/whitelist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('blocklist', form.TextValue, '_blocklist',
null,
'<font color=\'red\'>'
+ _('Added domain names will block DNS resolution (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/blocklist.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/blocklist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('greylist', form.TextValue, '_greylist',
null,
'<font color=\'red\'>'
+ _('Added domain names will always use \'Remote DNS\' for resolution (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/greylist.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/greylist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('ddnslist', form.TextValue, '_ddnslist',
null,
'<font color=\'red\'>'
+ _('Added domain names will always use \'Local DNS\' for resolution, with a forced TTL of 5 seconds, and results will not be cached (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/ddnslist.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/ddnslist.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('hostslist', form.TextValue, '_hostslist',
null,
'<font color=\'red\'>'
+ _('Custom Hosts rewrite, for example: baidu.com 10.0.0.1 (one rule per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/hosts.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/hosts.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('redirectlist', form.TextValue, '_redirectlist',
null,
'<font color=\'red\'>'
+ _('Redirecting requests for domain names. Request domain A, but return records for domain B, for example: baidu.com qq.com (one rule per line).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/redirect.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/redirect.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('localptrlist', form.TextValue, '_localptrlist',
null,
'<font color=\'red\'>'
+ _('Added domain names will block PTR requests (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/local-ptr.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/local-ptr.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
o = s.taboption('streamingmedialist', form.TextValue, '_streamingmedialist',
null,
'<font color=\'red\'>'
+ _('When enabling \'Custom Stream Media DNS\', added domains will always use the \'Streaming Media DNS server\' for resolution (one domain per line, supports domain matching rules).')
+ '</font>'
);
o.rows = 25;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/mosdns/rule/streaming.txt').catch(function (e) {
return "";
});
};
o.write = function (section_id, formvalue) {
return this.cfgvalue(section_id).then(function (value) {
if (value == formvalue) {
return;
}
return fs.write('/etc/mosdns/rule/streaming.txt', formvalue.trim().replace(/\r\n/g, '\n') + '\n')
.then(function (i) {
ui.addNotification(null, E('p', _('Rules have been saved.')), 'info');
})
.catch(function (e) {
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
});
});
};
return m.render();
},
handleSaveApply: function (ev) {
onclick = L.bind(this.handleSave, this, m);
return fs.exec('/etc/init.d/mosdns', ['restart']);
},
handleReset: null
});

View File

@ -1,65 +0,0 @@
'use strict';
'require form';
'require fs';
'require ui';
'require view';
return view.extend({
handleUpdate: function (m, section_id, ev) {
return fs.exec('/usr/share/mosdns/mosdns.sh', ['geodata'])
.then(function (i) {
var res = i.code;
if (res === 0) {
ui.addNotification(null, E('p', _('Update success')), 'info');
} else {
ui.addNotification(null, E('p', i.stderr + '<br />' + i.stdout), 'warn');
ui.addNotification(null, E('p', _('Update failed, Please check the network status')), 'error');
}
});
},
render: function () {
var m, s, o;
m = new form.Map('mosdns', _('Update GeoIP & GeoSite databases'),
_('Automatically update GeoIP and GeoSite databases as well as ad filtering rules through scheduled tasks.'));
s = m.section(form.TypedSection);
s.anonymous = true;
o = s.option(form.Flag, 'geo_auto_update', _('Enable Auto Database Update'));
o.rmempty = false;
o = s.option(form.ListValue, 'geo_update_week_time', _('Update Cycle'));
o.value('*', _('Every Day'));
o.value('1', _('Every Monday'));
o.value('2', _('Every Tuesday'));
o.value('3', _('Every Wednesday'));
o.value('4', _('Every Thursday'));
o.value('5', _('Every Friday'));
o.value('6', _('Every Saturday'));
o.value('7', _('Every Sunday'));
o.default = 3;
o = s.option(form.ListValue, 'geo_update_day_time', _('Update Time'));
for (let t = 0; t < 24; t++) {
o.value(t, t + ':00');
};
o.default = 3;
o = s.option(form.Value, 'github_proxy', _('GitHub Proxy'),
_('Update data files with GitHub Proxy, leave blank to disable proxy downloads.'));
o.value('https://hub.gitmirror.com', _('https://hub.gitmirror.com'));
o.rmempty = true;
o.default = '';
o = s.option(form.Button, '_udpate', null,
_('Check And Update GeoData.'));
o.title = _('Database Update');
o.inputtitle = _('Check And Update');
o.inputstyle = 'apply';
o.onclick = L.bind(this.handleUpdate, this, m);
return m.render();
}
});

View 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

View File

@ -0,0 +1,264 @@
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 / Streaming Media 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", Flag, "custom_stream_media_dns", translate("Custom Stream Media DNS"), translate("Netflix, Disney+, Hulu and streaming media rules list will use this DNS"))
o:depends( "configfile", "/var/etc/mosdns.json")
o.default = false
o = s:taboption("basic", DynamicList, "stream_media_dns", translate("Streaming Media 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.default = "tls://8.8.8.8"
o:depends("custom_stream_media_dns", "1")
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 / Streaming Media DNS requests") .. '<br />' .. translate("This feature is typically used when using a self-built DNS server as an Remote / Streaming Media 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", Flag, "cache", translate("Enable DNS Cache"))
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)."))
o.datatype = "and(uinteger,min(0))"
o.default = "8000"
o:depends("cache", "1")
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("cache", "1")
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("cache", "1")
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

View File

@ -0,0 +1,5 @@
m = Map("mosdns")
m:append(Template("mosdns/mosdns_log"))
return m

View File

@ -0,0 +1,111 @@
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"
local streaming_media_list_file = "/etc/mosdns/rule/streaming.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"))
s:tab("streaming_media_list", translate("Streaming Media"))
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
o = s:taboption("streaming_media_list", TextValue, "streaming_media", "", "<font color='red'>" .. translate("These domains are always resolved using Streaming Media DNS. Please input the domain names of websites, every line can input only one website domain. For example: netflix.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(streaming_media_list_file) or "" end
o.write = function(self, section, value) nixio.fs.writefile(streaming_media_list_file, value:gsub("\r\n", "\n")) end
o.remove = function(self, section, value) nixio.fs.writefile(streaming_media_list_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

View 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://hub.gitmirror.com", translate("https://hub.gitmirror.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

View 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%>

View 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%>

View 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%>

View 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>

View 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>

View File

@ -1,19 +1,3 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: PACKAGE VERSION\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "MosDNS"
msgstr "MosDNS"
msgid "MosDNS is a plugin-based DNS forwarder/traffic splitter."
msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。"
msgid "Basic Setting"
msgstr "基本设置"
@ -29,6 +13,9 @@ msgstr "Cloudflare 选项"
msgid "API Options"
msgstr "API 选项"
msgid "MosDNS is a plugin-based DNS forwarder/traffic splitter."
msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。"
msgid "RUNNING"
msgstr "运行中"
@ -47,17 +34,20 @@ msgstr "监听端口"
msgid "API Listen port"
msgstr "API 监听端口"
msgid "Flush DNS Cache"
msgstr "刷新 DNS 缓存"
msgid "Flush Cache"
msgstr "刷新缓存"
msgid "Flushing DNS Cache will clear any IP addresses or DNS records from MosDNS cache."
msgstr "刷新 DNS 缓存会清空 MosDNS 所有 IP 地址和 DNS 解析缓存"
msgid "Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"
msgstr "刷新缓存会清空 MosDNS 所有 IP 地址和 DNS 解析缓存"
msgid "Flushing DNS Cache Success."
msgstr "刷新 DNS 缓存成功"
msgid "Flushing..."
msgstr "正在刷新..."
msgid "Flushing DNS Cache Failed, Please check if MosDNS is running."
msgstr "刷新 DNS 缓存失败,请检查 MosDNS 状态是否在运行中。"
msgid "Flushing Success"
msgstr "刷新成功"
msgid "Flushing Failed, Please check if MosDNS is enabled"
msgstr "刷新失败,请检查 MosDNS 是否已启用"
msgid "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)"
msgstr "将解析结果与 Cloudflare IP 范围进行匹配,当匹配成功时,使用 “自选 IP” 作为解析结果(实验性功能)"
@ -89,27 +79,21 @@ msgstr "使用自定义规则来源时,请使用 MosDNS 支持的规则类型
msgid "Support for local files, such as: file:///var/mosdns/example.txt"
msgstr "支持本地文件例如file:///var/mosdns/example.txt"
msgid "Restart-Service"
msgstr "重启服务"
msgid "Restart the MosDNS process to take effect of new configuration"
msgstr "重启 MosDNS 进程使新配置文件生效"
msgid "Configuration Editor"
msgstr "配置编辑器"
msgid "Edit the MosDNS custom configuration file."
msgstr "编辑 MosDNS 自定义配置文件。"
msgid "Configuration have been saved."
msgstr "配置已保存。"
msgid "This is the content of the file '/etc/mosdns/config_custom.yaml' from which your MosDNS configuration will be generated. Only accepts configuration content in yaml format."
msgstr "这是文件 “/etc/mosdns/config_custom.yaml” 的内容,您的 MosDNS 配置将从此文件生成。仅接受 yaml 格式的配置内容。"
msgid "Geodata Update"
msgstr "更新数据库"
msgid "Update GeoIP & GeoSite databases"
msgid "Update GeoIP & GeoSite dat"
msgstr "更新广告规则、GeoIP & GeoSite 数据库"
msgid "Automatically update GeoIP and GeoSite databases as well as ad filtering rules through scheduled tasks."
msgstr "通过定时任务自动更新 GeoIP 和 GeoSite 数据库以及广告过滤规则。"
msgid "Update Time"
msgstr "更新时间"
@ -149,15 +133,15 @@ msgstr "通过 GitHub 代理更新数据文件,留空则禁用代理下载。"
msgid "Database Update"
msgstr "数据库更新"
msgid "Check And Update GeoData."
msgstr "检查并更新 GeoData 数据库。"
msgid "Check And Update"
msgstr "检查并更新"
msgid "Enable Auto Database Update"
msgstr "启用自动更新"
msgid "Updating..."
msgstr "正在更新..."
msgid "Update success"
msgstr "更新成功"
@ -218,12 +202,6 @@ msgstr "阿里云公共 DNS223.5.5.5"
msgid "Aliyun Public DNS (223.6.6.6)"
msgstr "阿里云公共 DNS223.6.6.6"
msgid "TrafficRoute Public DNS (180.184.1.1)"
msgstr "火山引擎公共 DNS180.184.1.1"
msgid "TrafficRoute Public DNS (180.184.2.2)"
msgstr "火山引擎公共 DNS180.184.2.2"
msgid "Xinfeng Public DNS (114.114.114.114)"
msgstr "信风公共 DNS114.114.114.114"
@ -356,67 +334,52 @@ msgstr "日志"
msgid "Clear logs"
msgstr "清空日志"
msgid "Log Data"
msgstr "日志数据"
msgid "No log data."
msgstr "无日志数据。"
msgid "Refresh every %s seconds."
msgstr "每 %s 秒刷新。"
msgid "Rules"
msgid "Rule List"
msgstr "规则列表"
msgid "Rule Settings"
msgstr "自定义规则列表"
msgid "Rules have been saved."
msgstr "规则已保存"
msgid "Unable to save contents: %s"
msgstr "无法保存内容:%s"
msgid "The list of rules only apply to 'Default Config' profiles."
msgstr "规则列表仅适用于 “内置预设” 配置文件。"
msgid "<br>The list of rules only apply to 'Default Config' profiles."
msgstr "<br>规则列表仅适用于 “内置预设” 配置文件"
msgid "White Lists"
msgstr "白名单"
msgid "Added domain names always permit resolution using 'local DNS' with the highest priority (one domain per line, supports domain matching rules)."
msgid "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."
msgstr "加入的域名始终允许使用 “本地 DNS” 进行解析,且优先级最高(每个域名一行,支持域名匹配规则)"
msgid "Block Lists"
msgstr "黑名单"
msgid "Added domain names will block DNS resolution (one domain per line, supports domain matching rules)."
msgid "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."
msgstr "加入的域名将屏蔽 DNS 解析(每个域名一行,支持域名匹配规则)"
msgid "Grey Lists"
msgstr "灰名单"
msgid "Added domain names will always use 'Remote DNS' for resolution (one domain per line, supports domain matching rules)."
msgid "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."
msgstr "加入的域名始终使用 “远程 DNS” 进行解析(每个域名一行,支持域名匹配规则)"
msgid "DDNS Lists"
msgstr "DDNS 域名"
msgid "Added domain names will always use 'Local DNS' for resolution, with a forced TTL of 5 seconds, and results will not be cached (one domain per line, supports domain matching rules)."
msgid "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."
msgstr "加入的域名始终使用 “本地 DNS” 进行解析,并且强制 TTL 5 秒,解析结果不会进入缓存(每个域名一行,支持域名匹配规则)"
msgid "Custom Hosts rewrite, for example: baidu.com 10.0.0.1 (one rule per line, supports domain matching rules)."
msgid "Hosts For example: baidu.com 10.0.0.1"
msgstr "自定义 Hosts 重写baidu.com 10.0.0.1(每个规则一行,支持域名匹配规则)"
msgid "Redirect"
msgstr "重定向"
msgid "Redirecting requests for domain names. Request domain A, but return records for domain B, for example: baidu.com qq.com (one rule per line)."
msgid "The domain name to redirect the request to. Requests domain A, but returns records for domain B. example: a.com b.com"
msgstr "重定向请求的域名。请求域名 A但返回域名 B 的记录baidu.com qq.com每个规则一行"
msgid "Block PTR"
msgstr "PTR 黑名单"
msgid "Added domain names will block PTR requests (one domain per line, supports domain matching rules)."
msgid "These domains are blocked from PTR requests"
msgstr "加入的域名将阻止 PTR 请求(每个域名一行,支持域名匹配规则)"
msgid "GeoData Export"
@ -449,5 +412,5 @@ msgstr "自定义 Netflix、Disney+、Hulu 以及 “流媒体” 规则列表
msgid "Streaming Media"
msgstr "流媒体"
msgid "When enabling 'Custom Stream Media DNS', added domains will always use the 'Streaming Media DNS server' for resolution (one domain per line, supports domain matching rules)."
msgid "These domains are always resolved using Streaming Media DNS. Please input the domain names of websites, every line can input only one website domain. For example: netflix.com."
msgstr "启用 “自定义流媒体 DNS” 时,加入的域名始终使用 “流媒体 DNS 服务器” 进行解析(每个域名一行,支持域名匹配规则)"

1
luci-app-mosdns/po/zh_Hans Symbolic link
View File

@ -0,0 +1 @@
zh-cn

View File

@ -5,25 +5,25 @@ config mosdns 'config'
option geo_auto_update '0'
option geo_update_week_time '*'
option geo_update_day_time '2'
option redirect '1'
option prefer_ipv4 '1'
option adblock '0'
option configfile '/var/etc/mosdns.json'
option log_level 'info'
option log_file '/var/log/mosdns.log'
option cache '1'
option concurrent '2'
option cache '0'
option concurrent '1'
option idle_timeout '30'
option minimal_ttl '0'
option maximum_ttl '0'
option enable_pipeline '1'
option custom_local_dns '0'
option enable_pipeline '0'
option insecure_skip_verify '0'
option dns_leak '0'
option cloudflare '0'
option listen_port_api '9091'
option custom_stream_media_dns '0'
option bootstrap_dns '119.29.29.29'
list remote_dns 'tls://8.8.8.8'
option redirect '1'
option prefer_ipv4 '1'
option enable_ecs_remote '0'
option cache_size '8000'
option lazy_cache_ttl '86400'
option dump_file '0'
list remote_dns 'tls://1.1.1.1'

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +0,0 @@
# MosDNS Rules

View File

@ -1,2 +1,11 @@
# MosDNS Rules
domain:bing.com
domain:live.com
domain:msn.com
domain:ntp.org
domain:office.com
domain:qlogo.cn
domain:qq.com
domain:redhat.com
keyword:douyin
keyword:microsoft
keyword:windows

View File

@ -1,45 +0,0 @@
{
"admin/services/mosdns": {
"title": "MosDNS",
"order": 30,
"action": {
"type": "firstchild"
},
"depends": {
"acl": [ "luci-app-mosdns" ],
"uci": { "mosdns": true }
}
},
"admin/services/mosdns/basic": {
"title": "Basic Setting",
"order": 10,
"action": {
"type": "view",
"path": "mosdns/basic"
}
},
"admin/services/mosdns/rules": {
"title": "Rules",
"order": 15,
"action": {
"type": "view",
"path": "mosdns/rules"
}
},
"admin/services/mosdns/update": {
"title": "Geodata Update",
"order": 20,
"action": {
"type": "view",
"path": "mosdns/update"
}
},
"admin/services/mosdns/logs": {
"title": "Logs",
"order": 25,
"action": {
"type": "view",
"path": "mosdns/logs"
}
}
}

View File

@ -2,7 +2,7 @@
script_action=${1}
logfile_path() {
logfile_path() (
configfile=$(uci -q get mosdns.config.configfile)
if [ "$configfile" = "/var/etc/mosdns.json" ]; then
uci -q get mosdns.config.log_file
@ -10,15 +10,7 @@ logfile_path() {
[ ! -f /etc/mosdns/config_custom.yaml ] && exit 1
awk '/^log:/{f=1;next}f==1{if($0~/file:/){print;exit}if($0~/^[^ ]/)exit}' /etc/mosdns/config_custom.yaml | grep -Eo "/[^'\"]+"
fi
}
print_logfile() {
cat $(logfile_path);
}
clean_logfile() {
true > $(logfile_path);
}
)
interface_dns() (
if [ "$(uci -q get mosdns.config.custom_local_dns)" = 1 ]; then
@ -84,12 +76,12 @@ adlist_update() {
else
mirror=""
fi
echo -e "Downloading $mirror$url"
echo -e "\e[1;32mDownloading $mirror$url\e[0m"
curl --connect-timeout 5 -m 90 --ipv4 -kfSLo "$AD_TMPDIR/$filename" "$mirror$url"
fi
done
if [ $? -ne 0 ]; then
echo -e "\e[1;31mRules download failed."
echo -e "\e[1;31mRules download failed.\e[0m"
rm -rf "$AD_TMPDIR" "$lock_file"
exit 1
else
@ -106,29 +98,29 @@ geodat_update() (
TMPDIR=$(mktemp -d) || exit 1
[ -n "$(uci -q get mosdns.config.github_proxy)" ] && mirror="$(uci -q get mosdns.config.github_proxy)/"
# geoip.dat - cn-private
echo -e "Downloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat"
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat\e[0m"
curl --connect-timeout 5 -m 60 --ipv4 -kfSLo "$TMPDIR/geoip.dat" ""$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat"
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
# checksum - geoip.dat
echo -e "Downloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat.sha256sum"
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat.sha256sum\e[0m"
curl --connect-timeout 5 -m 10 --ipv4 -kfSLo "$TMPDIR/geoip.dat.sha256sum" ""$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat.sha256sum"
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
if [ "$(sha256sum "$TMPDIR/geoip.dat" | awk '{print $1}')" != "$(cat "$TMPDIR/geoip.dat.sha256sum" | awk '{print $1}')" ]; then
echo -e "\e[1;31mgeoip.dat checksum error"
echo -e "\e[1;31mgeoip.dat checksum error\e[0m"
rm -rf "$TMPDIR"
exit 1
fi
# geosite.dat
echo -e "Downloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat\e[0m"
curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "$TMPDIR/geosite.dat" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
# checksum - geosite.dat
echo -e "Downloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat.sha256sum"
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat.sha256sum\e[0m"
curl --connect-timeout 5 -m 10 --ipv4 -kfSLo "$TMPDIR/geosite.dat.sha256sum" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat.sha256sum"
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
if [ "$(sha256sum "$TMPDIR/geosite.dat" | awk '{print $1}')" != "$(cat "$TMPDIR/geosite.dat.sha256sum" | awk '{print $1}')" ]; then
echo -e "\e[1;31mgeosite.dat checksum error"
echo -e "\e[1;31mgeosite.dat checksum error\e[0m"
rm -rf "$TMPDIR"
exit 1
fi
@ -158,8 +150,8 @@ v2dat_dump() {
# default config
v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat
v2dat unpack geosite -o /var/mosdns -f cn -f apple -f 'geolocation-!cn' $v2dat_dir/geosite.dat
[ "$adblock" = 1 ] && [ $(echo $ad_source | grep -c geosite.dat) -ge '1' ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $v2dat_dir/geosite.dat
[ "$streaming_media" = 1 ] && v2dat unpack geosite -o /var/mosdns -f netflix -f disney -f hulu $v2dat_dir/geosite.dat || \
[ "$adblock" -eq 1 ] && [ $(echo $ad_source | grep -c geosite.dat) -ge '1' ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $v2dat_dir/geosite.dat
[ "$streaming_media" -eq 1 ] && v2dat unpack geosite -o /var/mosdns -f netflix -f disney -f hulu $v2dat_dir/geosite.dat || \
touch /var/mosdns/geosite_disney.txt ; touch /var/mosdns/geosite_netflix.txt ; touch /var/mosdns/geosite_hulu.txt
else
# custom config
@ -194,12 +186,6 @@ case $script_action in
"v2dat_dump")
v2dat_dump
;;
"printlog")
print_logfile
;;
"cleanlog")
clean_logfile
;;
"version")
mosdns version
;;

View File

@ -2,45 +2,10 @@
"luci-app-mosdns": {
"description": "Grant UCI access for luci-app-mosdns",
"read": {
"file": {
"/etc/init.d/mosdns": [ "exec" ],
"/etc/mosdns/config_custom.yaml": [ "read" ],
"/etc/mosdns/rule/blocklist.txt": [ "read" ],
"/etc/mosdns/rule/cloudflare-cidr.txt": [ "read" ],
"/etc/mosdns/rule/ddnslist.txt": [ "read" ],
"/etc/mosdns/rule/greylist.txt": [ "read" ],
"/etc/mosdns/rule/hosts.txt": [ "read" ],
"/etc/mosdns/rule/local-ptr.txt": [ "read" ],
"/etc/mosdns/rule/redirect.txt": [ "read" ],
"/etc/mosdns/rule/streaming.txt": [ "read" ],
"/etc/mosdns/rule/whitelist.txt": [ "read" ],
"/usr/bin/mosdns": [ "exec" ],
"/usr/share/mosdns/mosdns.sh": [ "exec" ]
},
"ubus": {
"file": [ "read" ],
"service": [ "list" ]
},
"uci": [ "mosdns" ]
},
"write": {
"file": {
"/etc/mosdns/config_custom.yaml": [ "write" ],
"/etc/mosdns/rule/blocklist.txt": [ "write" ],
"/etc/mosdns/rule/cloudflare-cidr.txt": [ "write" ],
"/etc/mosdns/rule/ddnslist.txt": [ "write" ],
"/etc/mosdns/rule/greylist.txt": [ "write" ],
"/etc/mosdns/rule/hosts.txt": [ "write" ],
"/etc/mosdns/rule/local-ptr.txt": [ "write" ],
"/etc/mosdns/rule/redirect.txt": [ "write" ],
"/etc/mosdns/rule/streaming.txt": [ "write" ],
"/etc/mosdns/rule/whitelist.txt": [ "write" ]
},
"ubus": {
"file": [ "write" ]
},
"uci": [ "mosdns" ]
}
}
}

View File

@ -0,0 +1 @@
!function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)}(function(n){"use strict";function e(e,o,i,t){if(i&&i.call){var l=i;i=null}else l=r(e,i,"rangeFinder");"number"==typeof o&&(o=n.Pos(o,0));var f=r(e,i,"minFoldSize");function d(n){var r=l(e,o);if(!r||r.to.line-r.from.line<f)return null;for(var i=e.findMarksAt(r.from),d=0;d<i.length;++d)if(i[d].__isFold&&"fold"!==t){if(!n)return null;r.cleared=!0,i[d].clear()}return r}var u=d(!0);if(r(e,i,"scanUp"))for(;!u&&o.line>e.firstLine();)o=n.Pos(o.line-1,0),u=d(!1);if(u&&!u.cleared&&"unfold"!==t){var a=function(n,e){var o=r(n,e,"widget");if("string"==typeof o){var i=document.createTextNode(o);(o=document.createElement("span")).appendChild(i),o.className="CodeMirror-foldmarker"}else o&&(o=o.cloneNode(!0));return o}(e,i);n.on(a,"mousedown",function(e){c.clear(),n.e_preventDefault(e)});var c=e.markText(u.from,u.to,{replacedWith:a,clearOnEnter:r(e,i,"clearOnEnter"),__isFold:!0});c.on("clear",function(o,r){n.signal(e,"unfold",e,o,r)}),n.signal(e,"fold",e,u.from,u.to)}}n.newFoldFunction=function(n,o){return function(r,i){e(r,i,{rangeFinder:n,widget:o})}},n.defineExtension("foldCode",function(n,o,r){e(this,n,o,r)}),n.defineExtension("isFolded",function(n){for(var e=this.findMarksAt(n),o=0;o<e.length;++o)if(e[o].__isFold)return!0}),n.commands.toggleFold=function(n){n.foldCode(n.getCursor())},n.commands.fold=function(n){n.foldCode(n.getCursor(),null,"fold")},n.commands.unfold=function(n){n.foldCode(n.getCursor(),null,"unfold")},n.commands.foldAll=function(e){e.operation(function(){for(var o=e.firstLine(),r=e.lastLine();o<=r;o++)e.foldCode(n.Pos(o,0),null,"fold")})},n.commands.unfoldAll=function(e){e.operation(function(){for(var o=e.firstLine(),r=e.lastLine();o<=r;o++)e.foldCode(n.Pos(o,0),null,"unfold")})},n.registerHelper("fold","combine",function(){var n=Array.prototype.slice.call(arguments,0);return function(e,o){for(var r=0;r<n.length;++r){var i=n[r](e,o);if(i)return i}}}),n.registerHelper("fold","auto",function(n,e){for(var o=n.getHelpers(e,"fold"),r=0;r<o.length;r++){var i=o[r](n,e);if(i)return i}});var o={rangeFinder:n.fold.auto,widget:"↔",minFoldSize:0,scanUp:!1,clearOnEnter:!0};function r(n,e,r){if(e&&void 0!==e[r])return e[r];var i=n.options.foldOptions;return i&&void 0!==i[r]?i[r]:o[r]}n.defineOption("foldOptions",null),n.defineExtension("foldOption",function(n,e){return r(this,n,e)})});

View File

@ -0,0 +1 @@
.CodeMirror-foldmarker{color:blue;text-shadow:#b9f 1px 1px 2px,#b9f -1px -1px 2px,#b9f 1px -1px 2px,#b9f -1px 1px 2px;font-family:arial;line-height:.3;cursor:pointer}.CodeMirror-foldgutter{width:.7em}.CodeMirror-foldgutter-open,.CodeMirror-foldgutter-folded{cursor:pointer}.CodeMirror-foldgutter-open:after{content:"\25BE"}.CodeMirror-foldgutter-folded:after{content:"\25B8"}

View File

@ -0,0 +1 @@
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("./foldcode")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./foldcode"],t):t(CodeMirror)}(function(t){"use strict";t.defineOption("foldGutter",!1,function(o,e,r){r&&r!=t.Init&&(o.clearGutter(o.state.foldGutter.options.gutter),o.state.foldGutter=null,o.off("gutterClick",a),o.off("changes",d),o.off("viewportChange",u),o.off("fold",l),o.off("unfold",l),o.off("swapDoc",d)),e&&(o.state.foldGutter=new function(t){this.options=t,this.from=this.to=0}(function(t){!0===t&&(t={});null==t.gutter&&(t.gutter="CodeMirror-foldgutter");null==t.indicatorOpen&&(t.indicatorOpen="CodeMirror-foldgutter-open");null==t.indicatorFolded&&(t.indicatorFolded="CodeMirror-foldgutter-folded");return t}(e)),f(o),o.on("gutterClick",a),o.on("changes",d),o.on("viewportChange",u),o.on("fold",l),o.on("unfold",l),o.on("swapDoc",d))});var o=t.Pos;function e(t,e){for(var r=t.findMarks(o(e,0),o(e+1,0)),n=0;n<r.length;++n)if(r[n].__isFold){var i=r[n].find(-1);if(i&&i.line===e)return r[n]}}function r(t){if("string"==typeof t){var o=document.createElement("div");return o.className=t+" CodeMirror-guttermarker-subtle",o}return t.cloneNode(!0)}function n(t,n,f){var a=t.state.foldGutter.options,d=n-1,u=t.foldOption(a,"minFoldSize"),l=t.foldOption(a,"rangeFinder"),c="string"==typeof a.indicatorFolded&&i(a.indicatorFolded),s="string"==typeof a.indicatorOpen&&i(a.indicatorOpen);t.eachLine(n,f,function(n){++d;var i=null,f=n.gutterMarkers;if(f&&(f=f[a.gutter]),e(t,d)){if(c&&f&&c.test(f.className))return;i=r(a.indicatorFolded)}else{var p=o(d,0),m=l&&l(t,p);if(m&&m.to.line-m.from.line>=u){if(s&&f&&s.test(f.className))return;i=r(a.indicatorOpen)}}(i||f)&&t.setGutterMarker(n,a.gutter,i)})}function i(t){return new RegExp("(^|\\s)"+t+"(?:$|\\s)\\s*")}function f(t){var o=t.getViewport(),e=t.state.foldGutter;e&&(t.operation(function(){n(t,o.from,o.to)}),e.from=o.from,e.to=o.to)}function a(t,r,n){var i=t.state.foldGutter;if(i){var f=i.options;if(n==f.gutter){var a=e(t,r);a?a.clear():t.foldCode(o(r,0),f)}}}function d(t){var o=t.state.foldGutter;if(o){var e=o.options;o.from=o.to=0,clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){f(t)},e.foldOnChangeTimeSpan||600)}}function u(t){var o=t.state.foldGutter;if(o){var e=o.options;clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){var e=t.getViewport();o.from==o.to||e.from-o.to>20||o.from-e.to>20?f(t):t.operation(function(){e.from<o.from&&(n(t,e.from,o.from),o.from=e.from),e.to>o.to&&(n(t,o.to,e.to),o.to=e.to)})},e.updateViewportTimeSpan||400)}}function l(t,o){var e=t.state.foldGutter;if(e){var r=o.line;r>=e.from&&r<e.to&&n(t,r,r+1)}}});

View File

@ -0,0 +1 @@
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(n,t){var i=n.getLine(t),o=i.search(/\S/);return-1==o||/\bcomment\b/.test(n.getTokenTypeAt(e.Pos(t,o+1)))?-1:e.countColumn(i,null,n.getOption("tabSize"))}e.registerHelper("fold","indent",function(t,i){var o=n(t,i.line);if(!(o<0)){for(var r=null,l=i.line+1,f=t.lastLine();l<=f;++l){var u=n(t,l);if(-1==u);else{if(!(u>o))break;r=l}}return r?{from:e.Pos(i.line,t.getLine(i.line).length),to:e.Pos(r,t.getLine(r).length)}:void 0}})});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("yaml",function(){var e=new RegExp("\\b(("+["true","false","on","off","yes","no"].join(")|(")+"))$","i");return{token:function(i,t){var r=i.peek(),n=t.escaped;if(t.escaped=!1,"#"==r&&(0==i.pos||/\s/.test(i.string.charAt(i.pos-1))))return i.skipToEnd(),"comment";if(i.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))return"string";if(t.literal&&i.indentation()>t.keyCol)return i.skipToEnd(),"string";if(t.literal&&(t.literal=!1),i.sol()){if(t.keyCol=0,t.pair=!1,t.pairStart=!1,i.match(/---/))return"def";if(i.match(/\.\.\./))return"def";if(i.match(/\s*-\s+/))return"meta"}if(i.match(/^(\{|\}|\[|\])/))return"{"==r?t.inlinePairs++:"}"==r?t.inlinePairs--:"["==r?t.inlineList++:t.inlineList--,"meta";if(t.inlineList>0&&!n&&","==r)return i.next(),"meta";if(t.inlinePairs>0&&!n&&","==r)return t.keyCol=0,t.pair=!1,t.pairStart=!1,i.next(),"meta";if(t.pairStart){if(i.match(/^\s*(\||\>)\s*/))return t.literal=!0,"meta";if(i.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i))return"variable-2";if(0==t.inlinePairs&&i.match(/^\s*-?[0-9\.\,]+\s?$/))return"number";if(t.inlinePairs>0&&i.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/))return"number";if(i.match(e))return"keyword"}return!t.pair&&i.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)?(t.pair=!0,t.keyCol=i.indentation(),"atom"):t.pair&&i.match(/^:\s*/)?(t.pairStart=!0,"meta"):(t.pairStart=!1,t.escaped="\\"==r,i.next(),null)},startState:function(){return{pair:!1,pairStart:!1,keyCol:0,inlinePairs:0,inlineList:0,literal:!1,escaped:!1}},lineComment:"#",fold:"indent"}}),e.defineMIME("text/x-yaml","yaml"),e.defineMIME("text/yaml","yaml")});

View File

@ -0,0 +1 @@
.cm-s-dracula.CodeMirror,.cm-s-dracula .CodeMirror-gutters{background-color:#282a36 !important;color:#f8f8f2 !important;border:0}.cm-s-dracula .CodeMirror-gutters{color:#282a36}.cm-s-dracula .CodeMirror-cursor{border-left:solid thin #f8f8f0}.cm-s-dracula .CodeMirror-linenumber{color:#6d8a88}.cm-s-dracula .CodeMirror-selected{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::selection,.cm-s-dracula .CodeMirror-line>span::selection,.cm-s-dracula .CodeMirror-line>span>span::selection{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::-moz-selection,.cm-s-dracula .CodeMirror-line>span::-moz-selection,.cm-s-dracula .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,0.10)}.cm-s-dracula span.cm-comment{color:#6272a4}.cm-s-dracula span.cm-string,.cm-s-dracula span.cm-string-2{color:#f1fa8c}.cm-s-dracula span.cm-number{color:#bd93f9}.cm-s-dracula span.cm-variable{color:#50fa7b}.cm-s-dracula span.cm-variable-2{color:white}.cm-s-dracula span.cm-def{color:#50fa7b}.cm-s-dracula span.cm-operator{color:#ff79c6}.cm-s-dracula span.cm-keyword{color:#ff79c6}.cm-s-dracula span.cm-atom{color:#bd93f9}.cm-s-dracula span.cm-meta{color:#f8f8f2}.cm-s-dracula span.cm-tag{color:#ff79c6}.cm-s-dracula span.cm-attribute{color:#50fa7b}.cm-s-dracula span.cm-qualifier{color:#50fa7b}.cm-s-dracula span.cm-property{color:#66d9ef}.cm-s-dracula span.cm-builtin{color:#50fa7b}.cm-s-dracula span.cm-variable-3,.cm-s-dracula span.cm-type{color:#ffb86c}.cm-s-dracula .CodeMirror-activeline-background{background:rgba(255,255,255,0.1)}.cm-s-dracula .CodeMirror-matchingbracket{text-decoration:underline;color:white !important}