'use strict'; 'require form'; 'require fs'; 'require ui'; 'require view'; return view.extend({ render() { let 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')); // --- White Lists --- o = s.taboption('whitelist', form.TextValue, '_whitelist', null, '' + _('Added domain names always permit resolution using \'local DNS\' with the highest priority (one domain per line, supports domain matching rules).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/whitelist.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/whitelist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/whitelist.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Block Lists --- o = s.taboption('blocklist', form.TextValue, '_blocklist', null, '' + _('Added domain names will block DNS resolution (one domain per line, supports domain matching rules).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/blocklist.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/blocklist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/blocklist.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Grey Lists --- o = s.taboption('greylist', form.TextValue, '_greylist', null, '' + _('Added domain names will always use \'Remote DNS\' for resolution (one domain per line, supports domain matching rules).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/greylist.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/greylist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/greylist.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- DDNS Lists --- o = s.taboption('ddnslist', form.TextValue, '_ddnslist', null, '' + _('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).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/ddnslist.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/ddnslist.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/ddnslist.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Hosts --- o = s.taboption('hostslist', form.TextValue, '_hostslist', null, '' + _('Custom Hosts rewrite, for example: baidu.com 10.0.0.1 (one rule per line, supports domain matching rules).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/hosts.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/hosts.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/hosts.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Redirect --- o = s.taboption('redirectlist', form.TextValue, '_redirectlist', null, '' + _('Redirecting requests for domain names. Request domain A, but return records for domain B, for example: baidu.com qq.com (one rule per line).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/redirect.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/redirect.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/redirect.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Block PTR --- o = s.taboption('localptrlist', form.TextValue, '_localptrlist', null, '' + _('Added domain names will block PTR requests (one domain per line, supports domain matching rules).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/local-ptr.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/local-ptr.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/local-ptr.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); // --- Streaming Media --- o = s.taboption('streamingmedialist', form.TextValue, '_streamingmedialist', null, '' + _('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).') + '' ); o.rows = 25; o.cfgvalue = section_id => fs.trimmed('/etc/mosdns/rule/streaming.txt').catch(e => ''); o.write = function(section_id, formvalue) { return this.cfgvalue(section_id).then(value => { if (value === formvalue) { return; } return fs.write('/etc/mosdns/rule/streaming.txt', (formvalue.trim() ? formvalue.trim().replace(/\r\n/g, '\n') + '\n' : '')) .catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); }); }; o.remove = section_id => fs.write('/etc/mosdns/rule/streaming.txt', '').catch(e => { ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); }); return m.render(); }, handleSaveApply(ev) { return this.handleSave(ev).then(() => { window.location.reload(); }); }, handleReset: null });