'use strict'; 'require fs'; 'require form'; 'require tools.widgets as widgets'; 'require uci'; 'require ui'; 'require view'; 'require view.zapret.tools as tools'; return view.extend({ parsers: { }, appStatusCode: null, depends: function(elem, key, array, empty=true) { if (empty && array.length === 0) { elem.depends(key, '_dummy'); } else { array.forEach(e => elem.depends(key, e)); } }, validateIpPort: function(section, value) { return (/^$|^([0-9]{1,3}\.){3}[0-9]{1,3}(#[\d]{2,5})?$/.test(value)) ? true : _('Expecting:') + ` ${_('One of the following:')}\n - ${_('valid IP address')}\n - ${_('valid address#port')}\n`; }, validateUrl: function(section, value) { return (/^$|^https?:\/\/[\w.-]+(:[0-9]{2,5})?[\w\/~.&?+=-]*$/.test(value)) ? true : _('Expecting:') + ` ${_('valid URL')}\n`; }, load: function() { return Promise.all([ { code: -1}, // L.resolveDefault(fs.exec(tools.execPath, [ 'raw-status' ]), 1), null, // L.resolveDefault(fs.list(tools.parsersDir), null), uci.load(tools.appName), ]).catch(e => { ui.addNotification(null, E('p', _('Unable to read the contents') + ': %s '.format(e.message) )); }); }, render: function(data) { if (!data) { return; } this.appStatusCode = data[0].code; let m, s, o, tabname; m = new form.Map(tools.appName, _('Zapret') + ' - ' + _('Settings')); s = m.section(form.NamedSection, 'config'); s.anonymous = true; s.addremove = false; /* Main settings tab */ tabname = 'main_settings'; s.tab(tabname, _('Main settings')); o = s.taboption(tabname, form.ListValue, 'FWTYPE', _('FWTYPE')); o.value('nftables', 'nftables'); //o.value('iptables', 'iptables'); //o.value('ipfw', 'ipfw'); o = s.taboption(tabname, form.Flag, 'POSTNAT', _('POSTNAT')); o.rmempty = false; o.default = 1; o = s.taboption(tabname, form.ListValue, 'FLOWOFFLOAD', _('FLOWOFFLOAD')); o.value('donttouch', 'donttouch'); o.value('none', 'none'); o.value('software', 'software'); o.value('hardware', 'hardware'); o = s.taboption(tabname, form.Flag, 'INIT_APPLY_FW', _('INIT_APPLY_FW')); o.rmempty = false; o.default = 0; o = s.taboption(tabname, form.Flag, 'DISABLE_IPV4', _('DISABLE_IPV4')); o.rmempty = false; o.default = 1; o = s.taboption(tabname, form.Flag, 'DISABLE_IPV6', _('DISABLE_IPV6')); o.rmempty = false; o.default = 0; o = s.taboption(tabname, form.Flag, 'FILTER_TTL_EXPIRED_ICMP', 'FILTER_TTL_EXPIRED_ICMP'); o.rmempty = false; o.default = 1; //o = s.taboption(tabname, form.ListValue, 'MODE_FILTER', _('MODE_FILTER')); //o.value('none', 'none'); //o.value('ipset', 'ipset'); //o.value('hostlist', 'hostlist'); //o.value('autohostlist', 'autohostlist'); o = s.taboption(tabname, form.Value, 'WS_USER', _('WS_USER')); o.rmempty = false; o.datatype = 'string'; o = s.taboption(tabname, form.Flag, 'DAEMON_LOG_ENABLE', _('DAEMON_LOG_ENABLE')); o.rmempty = false; o.default = 0; /* NFQWS_OPT_DESYNC tab */ tabname = 'nfqws_params'; s.tab(tabname, _('NFQWS options')); let add_delim = function(sec, url = null) { let o = sec.taboption(tabname, form.DummyValue, '_hr'); o.rawhtml = true; o.default = '
youtube.com
googlevideo.com',
15
).show();
o = s.taboption(tabname, form.Button, '_user_entries_btn', _('User hostname entries domain.net
sub.domain.com
facebook.com',
15
).show();
o = s.taboption(tabname, form.Button, '_user_excluded_entries_btn', _('User excluded hostname entries'));
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = tools.hostsUserExcludeFN;
o.onclick = () => new tools.fileEditDialog(
tools.hostsUserExcludeFN,
_('User excluded entries'),
_('One hostname per line.domain.net
sub.domain.com
gosuslugi.ru',
15
).show();
add_delim(s);
o = s.taboption(tabname, form.Button, '_ip_exclude_filter_btn', _('Excluded IP entries'));
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = tools.iplstExcludeFN;
o.onclick = () => new tools.fileEditDialog(
tools.iplstExcludeFN,
_('Excluded IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line128.199.0.0/16
34.217.90.52
162.13.190.77',
15
).show();
o = s.taboption(tabname, form.Button, '_user_ip_filter_btn', _('User IP entries'));
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = tools.iplstUserFN;
o.onclick = () => new tools.fileEditDialog(
tools.iplstUserFN,
_('User IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line128.199.0.0/16
34.217.90.52
162.13.190.77',
15
).show();
o = s.taboption(tabname, form.Button, '_user_excluded_ip_filter_btn', _('User excluded IP entries'));
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = tools.iplstUserExcludeFN;
o.onclick = () => new tools.fileEditDialog(
tools.iplstUserExcludeFN,
_('User excluded IP filter'),
_('Patterns can be strings or regular expressions. Each pattern in a separate line128.199.0.0/16
34.217.90.52
162.13.190.77',
15
).show();
add_delim(s);
for (let num = 1; num <= tools.custFileMax; num++) {
let fn = tools.custFileTemplate.format(num.toString());
let name = _('Custom file #' + num);
o = s.taboption(tabname, form.Button, '_cust_file%d_btn'.format(num), name);
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = fn;
o.onclick = () => new tools.fileEditDialog(fn, name, '', '', 15).show();
}
/* custom.d files */
tabname = 'custom_d_tab';
s.tab(tabname, 'custom.d');
o = s.taboption(tabname, form.Flag, 'DISABLE_CUSTOM', _('Use custom.d scripts'));
o.rmempty = false;
o.default = '0';
o.validate = function(section_id, value) { return true; };
o.load = function(section_id) {
return uci.load(tools.appName).then(L.bind(function() {
var v = uci.get(tools.appName, section_id, 'DISABLE_CUSTOM');
return (v === '1') ? '0' : '1';
}, this));
};
o.write = function(section_id, value) {
return uci.set(tools.appName, section_id, 'DISABLE_CUSTOM', value === '1' ? '0' : '1');
};
add_delim(s);
for (let i = 0; i < tools.customdPrefixList.length; i++) {
let num = tools.customdPrefixList[i];
let fn = tools.customdFileFormat.format(num.toString());
let name = _('custom.d script #' + num);
o = s.taboption(tabname, form.Button, '_customd_file%d_btn'.format(num), name);
o.inputtitle = _('Edit');
o.inputstyle = 'edit btn';
o.description = fn;
let desc = '';
if (num == tools.discord_num) {
desc = _('Example') + ': ';
for (let k = 0; k < tools.discord_url.length; k++) {
let url = tools.discord_url[k];
if (k > 0) desc += '