diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/env.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/env.js new file mode 100644 index 0000000..8a72339 --- /dev/null +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/env.js @@ -0,0 +1,52 @@ +'use strict'; +'require baseclass'; + +return baseclass.extend({ + packager : { }, + appName : 'zapret', + AppName : 'Zapret', + execPath : '/etc/init.d/zapret', + syncCfgPath : '/opt/zapret/sync_config.sh', + defCfgPath : '/opt/zapret/def-cfg.sh', + defaultCfgPath : '/opt/zapret/restore-def-cfg.sh', + + hostsGoogleFN : '/opt/zapret/ipset/zapret-hosts-google.txt', + hostsUserFN : '/opt/zapret/ipset/zapret-hosts-user.txt', + hostsUserExcludeFN: '/opt/zapret/ipset/zapret-hosts-user-exclude.txt', + iplstExcludeFN : '/opt/zapret/ipset/zapret-ip-exclude.txt', + iplstUserFN : '/opt/zapret/ipset/zapret-ip-user.txt', + iplstUserExcludeFN: '/opt/zapret/ipset/zapret-ip-user-exclude.txt', + custFileMax : 4, + custFileTemplate : '/opt/zapret/ipset/cust%s.txt', + customdPrefixList : [ 10, 20, 50, 60, 90 ] , + customdFileFormat : '/opt/zapret/init.d/openwrt/custom.d/%s-script.sh', + discord_num : 50, + discord_url : [ 'https://github.com/bol-van/zapret/blob/4e8e3a9ed9dbeb1156db68dfaa7b353051c13797/init.d/custom.d.examples.linux/50-discord', + 'https://github.com/bol-van/zapret/blob/b251ea839cc8f04c45090314ef69fce69f2c00f2/init.d/custom.d.examples.linux/50-discord-media', + 'https://github.com/bol-van/zapret/blob/b251ea839cc8f04c45090314ef69fce69f2c00f2/init.d/custom.d.examples.linux/50-stun4all', + 'https://github.com/bol-van/zapret/tree/master/init.d/custom.d.examples.linux' + ], + nfqws_opt_url : 'https://github.com/remittor/zapret-openwrt/discussions/168', + + autoHostListFN : '/opt/zapret/ipset/zapret-hosts-auto.txt', + autoHostListDbgFN : '/opt/zapret/ipset/zapret-hosts-auto-debug.log', + + load_env: function(dst_obj) { + let env_proto = Object.getPrototypeOf(this); + Object.getOwnPropertyNames(env_proto).forEach(function(key) { + if (key === 'constructor' || key === 'load_env' || key.startsWith('__')) + return; + dst_obj[key] = env_proto[key]; + }); + dst_obj.packager = { }; + if (L.hasSystemFeature('apk')) { + dst_obj.packager.name = 'apk'; + dst_obj.packager.path = '/usr/bin/apk'; + dst_obj.packager.args = [ 'list', '-I', '*'+this.appName+'*' ]; + } else { + dst_obj.packager.name = 'opkg'; + dst_obj.packager.path = '/bin/opkg'; + dst_obj.packager.args = [ 'list-installed', '*'+this.appName+'*' ]; + } + } +}); diff --git a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js index 452a2d2..cb1e15a 100644 --- a/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js +++ b/luci-app-zapret/htdocs/luci-static/resources/view/zapret/tools.js @@ -4,6 +4,7 @@ 'require rpc'; 'require ui'; 'require uci'; +'require view.zapret.env as env_tools'; document.head.append(E('style', {'type': 'text/css'}, ` @@ -35,33 +36,11 @@ document.head.append(E('style', {'type': 'text/css'}, `)); return baseclass.extend({ - packager : null, - appName : 'zapret', - execPath : '/etc/init.d/zapret', - syncCfgPath : '/opt/zapret/sync_config.sh', - defCfgPath : '/opt/zapret/def-cfg.sh', - defaultCfgPath : '/opt/zapret/restore-def-cfg.sh', - - hostsGoogleFN : '/opt/zapret/ipset/zapret-hosts-google.txt', - hostsUserFN : '/opt/zapret/ipset/zapret-hosts-user.txt', - hostsUserExcludeFN: '/opt/zapret/ipset/zapret-hosts-user-exclude.txt', - iplstExcludeFN : '/opt/zapret/ipset/zapret-ip-exclude.txt', - iplstUserFN : '/opt/zapret/ipset/zapret-ip-user.txt', - iplstUserExcludeFN: '/opt/zapret/ipset/zapret-ip-user-exclude.txt', - custFileMax : 4, - custFileTemplate : '/opt/zapret/ipset/cust%s.txt', - customdPrefixList : [ 10, 20, 50, 60, 90 ] , - customdFileFormat : '/opt/zapret/init.d/openwrt/custom.d/%s-script.sh', - discord_num : 50, - discord_url : [ 'https://github.com/bol-van/zapret/blob/4e8e3a9ed9dbeb1156db68dfaa7b353051c13797/init.d/custom.d.examples.linux/50-discord', - 'https://github.com/bol-van/zapret/blob/b251ea839cc8f04c45090314ef69fce69f2c00f2/init.d/custom.d.examples.linux/50-discord-media', - 'https://github.com/bol-van/zapret/blob/b251ea839cc8f04c45090314ef69fce69f2c00f2/init.d/custom.d.examples.linux/50-stun4all', - 'https://github.com/bol-van/zapret/tree/master/init.d/custom.d.examples.linux' - ], - nfqws_opt_url : 'https://github.com/remittor/zapret-openwrt/discussions/168', - - autoHostListFN : '/opt/zapret/ipset/zapret-hosts-auto.txt', - autoHostListDbgFN : '/opt/zapret/ipset/zapret-hosts-auto-debug.log', + __init__() { + env_tools.load_env(this); + //console.log('appName: ' + this.appName); + //console.log('PACKAGER: ' + this.packager.name); + }, infoLabelRunning : '' + _('Running') + '', infoLabelStarting : '' + _('Starting') + '', @@ -100,24 +79,7 @@ return baseclass.extend({ expect: { result: false } }), - init_consts: function() { - if (!this.packager) { - this.packager = { }; - if (L.hasSystemFeature('apk')) { - this.packager.name = 'apk'; - this.packager.path = '/usr/bin/apk'; - this.packager.args = [ 'list', '-I', '*zapret*' ]; - } else { - this.packager.name = 'opkg'; - this.packager.path = '/bin/opkg'; - this.packager.args = [ 'list-installed', '*zapret*' ]; - } - //console.log('PACKAGER: ' + this.packager.name); - } - }, - getSvcInfo: function(svc_name = null) { - this.init_consts(); let name = (svc_name) ? svc_name : this.appName; let verbose = 1; return this.callServiceList(name, verbose).then(res => { @@ -128,7 +90,6 @@ return baseclass.extend({ }, getInitState: function(name) { - this.init_consts(); return this.callInitState(name).then(res => { if (res) { return res[name].enabled ? true : false; @@ -141,7 +102,6 @@ return baseclass.extend({ }, getStratList: function() { - this.init_consts(); let exec_cmd = '/bin/busybox'; let exec_arg = [ 'awk', '-F', '"', '/if \\[ "\\$strat" = "/ {print $4}', this.defCfgPath ]; return fs.exec(exec_cmd, exec_arg).then(res => {