mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2026-01-04 07:38:50 +03:00
Compare commits
18 Commits
v65-202410
...
v65-202410
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3154d3f5f6 | ||
|
|
7e901513c5 | ||
|
|
5373d5dd2a | ||
|
|
836b324a0b | ||
|
|
2db3bd7514 | ||
|
|
0b20fe4a93 | ||
|
|
5f3dfe04ab | ||
|
|
030b243bd6 | ||
|
|
f72a82bfe7 | ||
|
|
ed09612065 | ||
|
|
144b9369b9 | ||
|
|
79af08d99e | ||
|
|
8d915f3e1d | ||
|
|
241a733eec | ||
|
|
6cfcaf2a03 | ||
|
|
2e58533b4e | ||
|
|
6999144837 | ||
|
|
a6b89f3c2f |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -209,7 +209,7 @@ jobs:
|
||||
run: |
|
||||
mkdir -p public
|
||||
find . -name "ipk-openwrt-$BRANCH-*.tar" -exec tar -xvf {} --wildcards '*.ipk' \;
|
||||
find $BRANCH -mindepth 1 -type d -exec sh -c 'zip -0 ./public/zapret_${TAG}_$(basename {}).ipk.zip -j {} {}/*' \;
|
||||
find $BRANCH -mindepth 1 -type d -exec sh -c 'zip -0 ./public/zapret_${TAG}_$(basename {}).zip -j {} {}/*' \;
|
||||
ls -lh ./public/*.zip
|
||||
|
||||
- name: Upload assets
|
||||
|
||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
[](https://github.com/remittor/zapret-openwrt/actions/workflows/build.yml)
|
||||
# zapret-openwrt
|
||||
|
||||
[Instructions for installing](https://github.com/remittor/zapret-openwrt/wiki/Installing-zapret‐openwrt-package)
|
||||
|
||||
[Download page](https://github.com/remittor/zapret-openwrt/releases)
|
||||
@@ -5,7 +5,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-zapret
|
||||
PKG_RELEASE:=20241016
|
||||
PKG_RELEASE:=20241025
|
||||
PKG_VERSION:=65-$(PKG_RELEASE)
|
||||
PKG_LICENSE:=MIT
|
||||
|
||||
@@ -13,7 +13,19 @@ LUCI_TITLE:=LuCI support for zapret
|
||||
LUCI_DEPENDS:=+zapret
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
#include ../../luci.mk
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
rm -f /tmp/luci-index*
|
||||
rm -rf /tmp/luci-modulecache/
|
||||
#killall -HUP rpcd 2>/dev/null
|
||||
/etc/init.d/rpcd reload
|
||||
/sbin/luci-reload
|
||||
/etc/init.d/uhttpd reload
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
@@ -14,111 +14,98 @@ const btn_style_warning = 'btn cbi-button-negative';
|
||||
const btn_style_success = 'btn cbi-button-success important';
|
||||
|
||||
return view.extend({
|
||||
disableButtons: function(flag, btn, elems = [ ]) {
|
||||
let btn_start = elems[1] || document.getElementById("btn_start");
|
||||
//let btn_destroy = elems[4] || document.getElementById("btn_destroy");
|
||||
let btn_enable = elems[2] || document.getElementById("btn_enable");
|
||||
let btn_update = elems[3] || document.getElementById("btn_update");
|
||||
|
||||
btn_start.disabled = flag;
|
||||
btn_update.disabled = true; // TODO
|
||||
//btn_destroy.disabled = flag;
|
||||
if (btn === btn_update) {
|
||||
btn_enable.disabled = false;
|
||||
} else {
|
||||
btn_enable.disabled = flag;
|
||||
}
|
||||
get_svc_buttons: function(elems = { }) {
|
||||
return {
|
||||
enable : elems.btn_enable || document.getElementById('btn_enable'),
|
||||
disable : elems.btn_disable || document.getElementById('btn_disable'),
|
||||
start : elems.btn_start || document.getElementById('btn_start'),
|
||||
restart : elems.btn_restart || document.getElementById('btn_restart'),
|
||||
stop : elems.btn_stop || document.getElementById('btn_stop'),
|
||||
update : elems.btn_update || document.getElementById('btn_update'),
|
||||
};
|
||||
},
|
||||
|
||||
disableButtons: function(flag, button, elems = { }) {
|
||||
let btn = this.get_svc_buttons(elems);
|
||||
btn.enable.disabled = flag;
|
||||
btn.disable.disabled = flag;
|
||||
btn.start.disabled = flag;
|
||||
btn.restart.disabled = flag;
|
||||
btn.stop.disabled = flag;
|
||||
btn.update.disabled = true; // TODO
|
||||
},
|
||||
|
||||
getAppStatus: function() {
|
||||
return Promise.all([
|
||||
{ code: -1 }, //fs.exec(tools.execPath, [ 'raw-status' ]),
|
||||
{ code: -1 }, //fs.exec(tools.execPath, [ 'vpn-route-status' ]),
|
||||
tools.getInitStatus(tools.appName),
|
||||
//L.resolveDefault(fs.read(tools.tokenFile), 0),
|
||||
uci.load(tools.appName),
|
||||
tools.getInitState(tools.appName), // svc_state
|
||||
fs.exec(tools.execPath, [ 'info' ]), // svc_info
|
||||
fs.exec('/bin/ps'), // process list
|
||||
fs.exec('/bin/opkg', [ 'list-installed', '*zapret*' ]), // installed packages
|
||||
uci.load(tools.appName), // config
|
||||
]).catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
||||
+ ': %s [ %s | %s | %s ]'.format(
|
||||
e.message, tools.execPath, 'tools.getInitStatus', 'uci.zapret'
|
||||
e.message, tools.execPath, 'tools.getInitState', 'uci.zapret'
|
||||
)));
|
||||
});
|
||||
},
|
||||
|
||||
setAppStatus: function(status_array, elems = [ ], force_app_code = 0) {
|
||||
let section = uci.get(tools.appName, 'config');
|
||||
if (!status_array || section == null || typeof(section) !== 'object') {
|
||||
(elems[0] || document.getElementById("status")).innerHTML = tools.makeStatusString(1);
|
||||
setAppStatus: function(status_array, elems = { }, force_app_status = 0) {
|
||||
let cfg = uci.get(tools.appName, 'config');
|
||||
if (!status_array || cfg == null || typeof(cfg) !== 'object') {
|
||||
let elem_status = elems.status || document.getElementById("status");
|
||||
elem_status.innerHTML = tools.makeStatusString(null);
|
||||
ui.addNotification(null, E('p', _('Unable to read the contents') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
|
||||
let app_status_code = (force_app_code) ? force_app_code : status_array[0].code;
|
||||
let vpn_route_status_code = status_array[1].code;
|
||||
let enabled_flag = status_array[2];
|
||||
let z_fwtype = section.FWTYPE;
|
||||
let z_mode = section.MODE;
|
||||
let bllist_preset = 'user_only';
|
||||
|
||||
let btn_enable = elems[2] || document.getElementById('btn_enable');
|
||||
/*
|
||||
if (enabled_flag == true) {
|
||||
btn_enable.onclick = ui.createHandlerFn(this, this.serviceAction, 'disable', 'btn_enable');
|
||||
btn_enable.textContent = _('Enabled');
|
||||
btn_enable.className = btn_style_positive;
|
||||
} else {
|
||||
btn_enable.onclick = ui.createHandlerFn(this, this.serviceAction, 'enable', 'btn_enable');
|
||||
btn_enable.textContent = _('Disabled');
|
||||
btn_enable.className = btn_style_negative;
|
||||
}
|
||||
*/
|
||||
let btn_start = elems[1] || document.getElementById('btn_start');
|
||||
let btn_update = elems[3] || document.getElementById('btn_update');
|
||||
//let btn_destroy = elems[4] || document.getElementById('btn_destroy');
|
||||
|
||||
let btnStartStateOn = () => {
|
||||
//btn_start.onclick = ui.createHandlerFn(this, this.appAction, 'stop', 'btn_start');
|
||||
//btn_start.textContent = _('Enabled');
|
||||
//btn_start.className = btn_style_positive;
|
||||
};
|
||||
|
||||
let btnStartStateOff = () => {
|
||||
//btn_start.onclick = ui.createHandlerFn(this, this.appAction, 'start', 'btn_start');
|
||||
//btn_start.textContent = _('Disabled');
|
||||
//btn_start.className = btn_style_negative;
|
||||
};
|
||||
|
||||
if (app_status_code == -1) {
|
||||
this.disableButtons(false, null, elems);
|
||||
btnStartStateOn();
|
||||
}
|
||||
else if (app_status_code == 0) {
|
||||
this.disableButtons(false, null, elems);
|
||||
btnStartStateOn();
|
||||
//btn_destroy.disabled = false;
|
||||
btn_update.disabled = false;
|
||||
}
|
||||
else if (app_status_code == 2) {
|
||||
this.disableButtons(false, null, elems);
|
||||
btnStartStateOff();
|
||||
btn_update.disabled = true;
|
||||
}
|
||||
else if (app_status_code == 3) {
|
||||
btnStartStateOff();
|
||||
this.disableButtons(true, btn_start, elems);
|
||||
}
|
||||
else if (app_status_code == 4) {
|
||||
btnStartStateOn();
|
||||
this.disableButtons(true, btn_update, elems);
|
||||
}
|
||||
else {
|
||||
ui.addNotification(null, E('p', _('Error')
|
||||
+ ' %s: return code = %s'.format(tools.execPath, app_status_code)));
|
||||
let svc_autorun = status_array[0] ? true : false;
|
||||
let svc_info = status_array[1]; // stdout: JSON as text
|
||||
let proc_list = status_array[2]; // stdout: multiline text
|
||||
let pkg_list = status_array[3]; // stdout: installed packages
|
||||
if (svc_info.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to read the service info') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
if (proc_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to read process list') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
if (pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
this.disableButtons(true, null, elems);
|
||||
return;
|
||||
}
|
||||
let svcinfo;
|
||||
if (force_app_status) {
|
||||
svcinfo = force_app_status;
|
||||
} else {
|
||||
svcinfo = tools.decode_svc_info(svc_autorun, svc_info, proc_list, cfg);
|
||||
}
|
||||
let btn = this.get_svc_buttons(elems);
|
||||
btn.update.disabled = true; // TODO
|
||||
|
||||
(elems[0] || document.getElementById("status")).innerHTML = tools.makeStatusString(app_status_code, z_fwtype, bllist_preset);
|
||||
if (Number.isInteger(svcinfo)) {
|
||||
ui.addNotification(null, E('p', _('Error')
|
||||
+ ' %s: return code = %s'.format('decode_svc_info', svcinfo + ' ')));
|
||||
this.disableButtons(true, null, elems);
|
||||
} else {
|
||||
btn.enable.disabled = (svc_autorun) ? true : false;
|
||||
btn.disable.disabled = (svc_autorun) ? false : true;
|
||||
if (svcinfo.dmn.total == 0) {
|
||||
btn.start.disabled = false;
|
||||
btn.restart.disabled = true;
|
||||
btn.stop.disabled = true;
|
||||
} else {
|
||||
btn.start.disabled = true;
|
||||
btn.restart.disabled = false;
|
||||
btn.stop.disabled = false;
|
||||
}
|
||||
}
|
||||
let elem_status = elems.status || document.getElementById("status");
|
||||
elem_status.innerHTML = tools.makeStatusString(svcinfo, cfg.FWTYPE, 'user_only');
|
||||
|
||||
if (!poll.active()) {
|
||||
poll.start();
|
||||
@@ -130,12 +117,33 @@ return view.extend({
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
}
|
||||
|
||||
poll.stop();
|
||||
|
||||
let _this = this;
|
||||
|
||||
return fs.exec('/opt/zapret/sync_config.sh')
|
||||
return tools.handleServiceAction(tools.appName, action)
|
||||
.then(() => {
|
||||
return _this.getAppStatus().then(
|
||||
(status_array) => {
|
||||
_this.setAppStatus(status_array);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to run service action.') + ' Error: ' + e.message));
|
||||
});
|
||||
},
|
||||
|
||||
serviceActionEx: function(action, button) {
|
||||
if (button) {
|
||||
let elem = document.getElementById(button);
|
||||
this.disableButtons(true, elem);
|
||||
}
|
||||
poll.stop();
|
||||
|
||||
let _this = this;
|
||||
|
||||
return fs.exec(tools.syncCfgPath)
|
||||
.then(function(res) {
|
||||
if (res.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to run sync_config.sh script.') + ' res.code = ' + res.code));
|
||||
@@ -145,13 +153,7 @@ return view.extend({
|
||||
}
|
||||
);
|
||||
}
|
||||
return tools.handleServiceAction(tools.appName, action).then(() => {
|
||||
return _this.getAppStatus().then(
|
||||
(status_array) => {
|
||||
_this.setAppStatus(status_array);
|
||||
}
|
||||
);
|
||||
});
|
||||
return _this.serviceAction(action, null);
|
||||
})
|
||||
.catch(e => {
|
||||
ui.addNotification(null, E('p', _('Unable to run sync_config.sh script.') + ' Error: ' + e.message));
|
||||
@@ -225,8 +227,13 @@ return view.extend({
|
||||
if (!status_array) {
|
||||
return;
|
||||
}
|
||||
let cfg = uci.get(tools.appName, 'config');
|
||||
|
||||
let section = uci.get(tools.appName, 'config');
|
||||
let pkg_list = status_array[3];
|
||||
if (pkg_list === undefined || typeof(pkg_list) !== 'object' || pkg_list.code != 0) {
|
||||
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': setAppStatus()'));
|
||||
return;
|
||||
}
|
||||
|
||||
let status_string = E('div', {
|
||||
'id' : 'status',
|
||||
@@ -236,15 +243,15 @@ return view.extend({
|
||||
|
||||
let layout = E('div', { 'class': 'cbi-section-node' });
|
||||
|
||||
function layout_append(title, descr, elem) {
|
||||
function layout_append(title, descr, elems) {
|
||||
descr = (descr) ? E('div', { 'class': 'cbi-value-description' }, descr) : '';
|
||||
let elist;
|
||||
if (elem instanceof E) {
|
||||
elist = [ elem ];
|
||||
} else {
|
||||
elist = elem;
|
||||
let elist = elems;
|
||||
let elem_list = [ ];
|
||||
for (let i = 0; i < elist.length; i++) {
|
||||
elem_list.push(elist[i]);
|
||||
elem_list.push(' ');
|
||||
}
|
||||
let vlist = [ E('div', {}, elist ) ];
|
||||
let vlist = [ E('div', {}, elem_list ) ];
|
||||
for (let i = 0; i < elist.length; i++) {
|
||||
let input = E('input', {
|
||||
'id' : elist[i].id + '_hidden',
|
||||
@@ -252,9 +259,10 @@ return view.extend({
|
||||
});
|
||||
vlist.push(input);
|
||||
}
|
||||
let elem_name = (elist.length == 1) ? elist[0].id + '_hidden' : null;
|
||||
layout.append(
|
||||
E('div', { 'class': 'cbi-value' }, [
|
||||
E('label', { 'class': 'cbi-value-title', 'for': elem.id + '_hidden' || null }, title),
|
||||
E('label', { 'class': 'cbi-value-title', 'for': elem_name }, title),
|
||||
E('div', { 'class': 'cbi-value-field' }, vlist),
|
||||
])
|
||||
);
|
||||
@@ -272,35 +280,59 @@ return view.extend({
|
||||
btn_enable.onclick = ui.createHandlerFn(this, this.serviceAction, 'enable', 'btn_enable');
|
||||
let btn_disable = create_btn('btn_disable', btn_style_warning, _('Disable'));
|
||||
btn_disable.onclick = ui.createHandlerFn(this, this.serviceAction, 'disable', 'btn_disable');
|
||||
layout_append(_('Service Status'), null, [ btn_enable, btn_disable ] );
|
||||
layout_append(_('Service autorun control'), null, [ btn_enable, btn_disable ] );
|
||||
|
||||
let btn_start = create_btn('btn_start', btn_style_action, _('Start'));
|
||||
btn_start.onclick = ui.createHandlerFn(this, this.serviceAction, 'start', 'btn_start');
|
||||
btn_start.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'start', 'btn_start');
|
||||
let btn_restart = create_btn('btn_restart', btn_style_action, _('Restart'));
|
||||
btn_restart.onclick = ui.createHandlerFn(this, this.serviceAction, 'restart', 'btn_restart');
|
||||
btn_restart.onclick = ui.createHandlerFn(this, this.serviceActionEx, 'restart', 'btn_restart');
|
||||
let btn_stop = create_btn('btn_stop', btn_style_warning, _('Stop'));
|
||||
btn_stop.onclick = ui.createHandlerFn(this, this.serviceAction, 'stop', 'btn_stop');
|
||||
layout_append(_('Service Control'), null, [ btn_start, btn_restart, btn_stop ] );
|
||||
layout_append(_('Service daemons control'), null, [ btn_start, btn_restart, btn_stop ] );
|
||||
|
||||
let btn_update = create_btn('btn_update', btn_style_action, _('Update'));
|
||||
btn_update.onclick = ui.createHandlerFn(this, () => { this.appAction('update', 'btn_update') });
|
||||
layout_append(_('Update blacklist'), null, btn_update);
|
||||
layout_append(_('Update blacklist'), null, [ btn_update ] );
|
||||
|
||||
let btn_destroy = create_btn('btn_destroy', btn_style_negative, _('Shutdown'));
|
||||
btn_destroy.onclick = L.bind(this.dialogDestroy, this);
|
||||
//layout_append(_('Shutdown'), _('Complete service shutdown'), btn_destroy);
|
||||
|
||||
//let elems = [ status_string, btn_start, btn_enable, btn_update, btn_destroy ];
|
||||
let elems = [ status_string, btn_start, btn_enable, btn_update ];
|
||||
let elems = {
|
||||
"status": status_string,
|
||||
"btn_enable": btn_enable,
|
||||
"btn_disable": btn_disable,
|
||||
"btn_start": btn_start,
|
||||
"btn_restart": btn_restart,
|
||||
"btn_stop": btn_stop,
|
||||
"btn_update": btn_update,
|
||||
};
|
||||
this.setAppStatus(status_array, elems);
|
||||
|
||||
poll.add(L.bind(this.statusPoll, this));
|
||||
|
||||
let page_title = _('Zapret');
|
||||
let pkgdict = tools.decode_pkg_list(pkg_list.stdout);
|
||||
page_title += '   ';
|
||||
if (pkgdict['zapret'] === undefined || pkgdict['zapret'] == '') {
|
||||
page_title += 'unknown version';
|
||||
} else {
|
||||
page_title += 'v' + pkgdict['zapret'];
|
||||
}
|
||||
let aux1 = E('em');
|
||||
let aux2 = E('em');
|
||||
if (pkgdict['zapret'] != pkgdict['luci-app-zapret']) {
|
||||
let errtxt = 'LuCI APP v' + pkgdict['luci-app-zapret'] + ' [ incorrect version! ]';
|
||||
aux1 = E('div', { 'class': 'label-status error' }, errtxt);
|
||||
aux2 = E('div', { }, ' ');
|
||||
}
|
||||
|
||||
let url1 = 'https://github.com/bol-van/zapret';
|
||||
let url2 = 'https://github.com/remittor/zapret-openwrt';
|
||||
|
||||
return E([
|
||||
E('h2', { 'class': 'fade-in' }, _('Zapret')),
|
||||
E('h2', { 'class': 'fade-in' }, page_title),
|
||||
aux1,
|
||||
aux2,
|
||||
E('div', { 'class': 'cbi-section-descr fade-in' },
|
||||
E('a', { 'href': url1, 'target': '_blank' }, url1),
|
||||
),
|
||||
@@ -309,7 +341,6 @@ return view.extend({
|
||||
),
|
||||
E('div', { 'class': 'cbi-section fade-in' }, [
|
||||
status_string,
|
||||
E('hr'),
|
||||
]),
|
||||
E('div', { 'class': 'cbi-section fade-in' },
|
||||
layout
|
||||
|
||||
@@ -100,14 +100,26 @@ return view.extend({
|
||||
o.rmempty = false;
|
||||
o.default = 0;
|
||||
|
||||
o = s.taboption(tabname, form.Value, 'HTTP_PORTS', _('HTTP_PORTS'));
|
||||
o.rmempty = false;
|
||||
o.datatype = 'string';
|
||||
|
||||
o = s.taboption(tabname, form.Flag, 'MODE_HTTPS', _('MODE_HTTPS'));
|
||||
o.rmempty = false;
|
||||
o.default = 0;
|
||||
|
||||
o = s.taboption(tabname, form.Value, 'HTTPS_PORTS', _('HTTPS_PORTS'));
|
||||
o.rmempty = false;
|
||||
o.datatype = 'string';
|
||||
|
||||
o = s.taboption(tabname, form.Flag, 'MODE_QUIC', _('MODE_QUIC'));
|
||||
o.rmempty = false;
|
||||
o.default = 0;
|
||||
|
||||
o = s.taboption(tabname, form.Value, 'QUIC_PORTS', _('QUIC_PORTS'));
|
||||
o.rmempty = false;
|
||||
o.datatype = 'string';
|
||||
|
||||
o = s.taboption(tabname, form.Value, 'DESYNC_MARK', _('DESYNC_MARK'));
|
||||
//o.description = _("nfqws option for DPI desync attack");
|
||||
o.rmempty = false;
|
||||
|
||||
@@ -36,7 +36,9 @@ document.head.append(E('style', {'type': 'text/css'},
|
||||
|
||||
return baseclass.extend({
|
||||
appName : 'zapret',
|
||||
execPath : '/opt/zapret/init.d/openwrt/zapret',
|
||||
execPath : '/etc/init.d/zapret',
|
||||
syncCfgPath : '/opt/zapret/sync_config.sh',
|
||||
|
||||
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',
|
||||
@@ -45,13 +47,23 @@ return baseclass.extend({
|
||||
custFileMax : 4,
|
||||
custFileTemplate : '/opt/zapret/ipset/cust%s.txt',
|
||||
|
||||
infoLabelRunning : '<span class="label-status running">' + _('Running') + '</span>',
|
||||
infoLabelStarting : '<span class="label-status starting">' + _('Starting') + '</span>',
|
||||
infoLabelRunning : '<span class="label-status running">' + _('Enabled') + '</span>',
|
||||
infoLabelUpdating : '<span class="label-status updating">' + _('Updating') + '</span>',
|
||||
infoLabelStopped : '<span class="label-status stopped">' + _('Disabled') + '</span>',
|
||||
infoLabelError : '<span class="label-status error">' + _('Error') + '</span>',
|
||||
infoLabelStopped : '<span class="label-status stopped">' + _('Stopped') + '</span>',
|
||||
infoLabelDisabled : '<span class="label-status stopped">' + _('Disabled') + '</span>',
|
||||
infoLabelError : '<span class="label-status error">' + _('Error') + '</span>',
|
||||
|
||||
callInitStatus: rpc.declare({
|
||||
infoLabelUpdating : '<span class="label-status updating">' + _('Updating') + '</span>',
|
||||
|
||||
statusDict: {
|
||||
error : { code: 0, name: _('Error') , label: this.infoLabelError },
|
||||
disabled : { code: 1, name: _('Disabled') , label: this.infoLabelDisabled },
|
||||
stopped : { code: 2, name: _('Stopped') , label: this.infoLabelStopped },
|
||||
starting : { code: 3, name: _('Starting') , label: this.infoLabelStarting },
|
||||
running : { code: 4, name: _('Running') , label: this.infoLabelRunning },
|
||||
},
|
||||
|
||||
callInitState: rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'getInitList',
|
||||
params: [ 'name' ],
|
||||
@@ -65,10 +77,10 @@ return baseclass.extend({
|
||||
expect: { result: false }
|
||||
}),
|
||||
|
||||
getInitStatus: function(name) {
|
||||
return this.callInitStatus(name).then(res => {
|
||||
getInitState: function(name) {
|
||||
return this.callInitState(name).then(res => {
|
||||
if (res) {
|
||||
return res[name].enabled;
|
||||
return res[name].enabled ? true : false;
|
||||
} else {
|
||||
throw _('Command failed');
|
||||
}
|
||||
@@ -92,72 +104,145 @@ return baseclass.extend({
|
||||
return (v && typeof(v) === 'string') ? v.trim().replace(/\r?\n/g, '') : v;
|
||||
},
|
||||
|
||||
makeStatusString: function(app_status_code, fwtype, bllist_preset) {
|
||||
let app_status_label;
|
||||
let spinning = '';
|
||||
/*
|
||||
switch(app_status_code) {
|
||||
case 0:
|
||||
app_status_label = this.infoLabelRunning;
|
||||
break;
|
||||
case 2:
|
||||
app_status_label = this.infoLabelStopped;
|
||||
break;
|
||||
case 3:
|
||||
app_status_label = this.infoLabelStarting;
|
||||
spinning = ' spinning';
|
||||
break;
|
||||
case 4:
|
||||
app_status_label = this.infoLabelUpdating;
|
||||
spinning = ' spinning';
|
||||
break;
|
||||
default:
|
||||
app_status_label = this.infoLabelError;
|
||||
return `<table class="table">
|
||||
<tr class="tr">
|
||||
<td class="td left" style="min-width:33%%">
|
||||
${_('Status')}:
|
||||
</td>
|
||||
<td class="td left">
|
||||
${app_status_label}
|
||||
</td>
|
||||
</tr>
|
||||
</table>`;
|
||||
decode_pkg_list: function(pkg_list) {
|
||||
let pkg_dict = { };
|
||||
let lines = pkg_list.trim().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
let line = lines[i].trim();
|
||||
if (line.length >= 4) {
|
||||
let word_list = line.split(' - ');
|
||||
let name = word_list[0].trim();
|
||||
let ver = word_list[1].trim();
|
||||
pkg_dict[name] = ver;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return `<table class="table">
|
||||
return pkg_dict;
|
||||
},
|
||||
|
||||
get_pid_list: function(proc_list) {
|
||||
let plist = [ ];
|
||||
let lines = proc_list.trim().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
let line = lines[i].trim();
|
||||
if (line.length > 5) {
|
||||
let word_list = line.split(/\s+/);
|
||||
let pid = word_list[0];
|
||||
let isnum = /^\d+$/.test(pid);
|
||||
if (isnum) {
|
||||
plist.push(parseInt(pid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return plist;
|
||||
},
|
||||
|
||||
decode_svc_info: function(svc_autorun, svc_info, proc_list, cfg) {
|
||||
let result = {
|
||||
"autorun": svc_autorun,
|
||||
"dmn": {
|
||||
total: 0,
|
||||
running: 0,
|
||||
working: 0,
|
||||
},
|
||||
"status": this.statusDict.error,
|
||||
};
|
||||
if (svc_info.code != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (proc_list.code != 0) {
|
||||
return -2;
|
||||
}
|
||||
let plist = this.get_pid_list(proc_list.stdout);
|
||||
|
||||
let jdata = JSON.parse(svc_info.stdout);
|
||||
if (typeof(jdata) !== 'object') {
|
||||
return -3;
|
||||
}
|
||||
if (typeof(jdata.zapret) == 'object') {
|
||||
let dmn_list = jdata.zapret.instances;
|
||||
if (typeof(dmn_list) !== 'object') {
|
||||
return -4;
|
||||
}
|
||||
for (const [dmn_name, daemon] of Object.entries(dmn_list)) {
|
||||
result.dmn.total += 1;
|
||||
if (daemon.running) {
|
||||
result.dmn.running += 1;
|
||||
}
|
||||
if (daemon.pid !== undefined && daemon.pid != null) {
|
||||
if (plist.includes(daemon.pid)) {
|
||||
result.dmn.working += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//console.log('SVC_DAEMONS: ' + result.dmn.working + ' / ' + result.dmn.total);
|
||||
if (result.dmn.total == 0) {
|
||||
result.status = (!svc_autorun) ? this.statusDict.disabled : this.statusDict.stopped;
|
||||
} else {
|
||||
result.status = (!result.dmn.working) ? this.statusDict.started : this.statusDict.running;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
makeStatusString: function(svcinfo, fwtype, bllist_preset) {
|
||||
let svc_autorun = _('Unknown');
|
||||
let svc_daemons = _('Unknown');
|
||||
|
||||
if (typeof(svcinfo) == 'object') {
|
||||
svc_autorun = (svcinfo.autorun) ? _('Enabled') : _('Disabled');
|
||||
if (svcinfo.dmn.total == 0) {
|
||||
svc_daemons = _('Stopped');
|
||||
} else {
|
||||
svc_daemons = (!svcinfo.dmn.working) ? _('Starting') : _('Running');
|
||||
svc_daemons += ' [' + svcinfo.dmn.working + '/' + svcinfo.dmn.total + ']';
|
||||
}
|
||||
}
|
||||
let update_mode = _('user entries only');
|
||||
|
||||
let td_name_width = 40;
|
||||
let td_name_style = `style="width: ${td_name_width}%; min-width:${td_name_width}%; max-width:${td_name_width}%;"`;
|
||||
let out = `
|
||||
<table class="table">
|
||||
<tr class="tr">
|
||||
<td class="td left" style="min-width:33%%">
|
||||
${_('Status')}:
|
||||
<td class="td left" ${td_name_style}>
|
||||
${_('Service autorun status')}:
|
||||
</td>
|
||||
<td class="td left%s">
|
||||
%s %s
|
||||
<td class="td left">
|
||||
${svc_autorun}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="tr">
|
||||
<td class="td left">
|
||||
<td class="td left" ${td_name_style}>
|
||||
${_('Service daemons status')}:
|
||||
</td>
|
||||
<td class="td left %s">
|
||||
${svc_daemons}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="tr">
|
||||
<td class="td left" ${td_name_style}>
|
||||
${_('FW type')}:
|
||||
</td>
|
||||
<td class="td left">
|
||||
%s
|
||||
${fwtype}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="tr">
|
||||
<td class="td left">
|
||||
<td class="td left" ${td_name_style}>
|
||||
${_('Blacklist update mode')}:
|
||||
</td>
|
||||
<td class="td left">
|
||||
%s
|
||||
${update_mode}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
`.format(
|
||||
spinning,
|
||||
app_status_label,
|
||||
'',
|
||||
fwtype,
|
||||
_('user entries only')
|
||||
);
|
||||
<tr class="tr">
|
||||
<td class="td left" ${td_name_style}>
|
||||
</td>
|
||||
<td class="td left">
|
||||
</td>
|
||||
</tr>
|
||||
</table>`;
|
||||
return out;
|
||||
},
|
||||
|
||||
fileEditDialog: baseclass.extend({
|
||||
@@ -270,7 +355,11 @@ return baseclass.extend({
|
||||
},
|
||||
|
||||
load: function() {
|
||||
return uci.get('zapret', this.cfgsec, this.cfgparam);
|
||||
let value = uci.get('zapret', this.cfgsec, this.cfgparam);
|
||||
if (typeof(value) === 'string') {
|
||||
return value.trim();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
|
||||
render: function(content) {
|
||||
@@ -309,7 +398,9 @@ return baseclass.extend({
|
||||
handleSave: function(ev) {
|
||||
let txt = document.getElementById('widget.modal_content');
|
||||
let value = txt.value.trim().replace(/\r\n/g, ' ').replace(/\r/g, ' ').replace(/\n/g, ' ').trim();
|
||||
|
||||
if (value == "") {
|
||||
value = "\t";
|
||||
}
|
||||
uci.set('zapret', this.cfgsec, this.cfgparam, value);
|
||||
uci.save();
|
||||
let elem = document.getElementById("cbi-zapret-" + this.cfgsec + "-_" + this.cfgparam);
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
"/opt/zapret/ipset/*": [ "read" ],
|
||||
"/etc/crontabs/root": [ "read" ],
|
||||
"/etc/init.d/zapret*": [ "exec" ],
|
||||
"/bin/ps*": [ "exec" ],
|
||||
"/bin/opkg*": [ "exec" ],
|
||||
"/opt/zapret/sync_config.sh*": [ "exec" ]
|
||||
},
|
||||
"uci": [ "zapret", "network" ],
|
||||
|
||||
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=zapret-ip2net
|
||||
PKG_VERSION:=65
|
||||
PKG_RELEASE:=20241016
|
||||
PKG_RELEASE:=20241025
|
||||
|
||||
PKG_MAINTAINER:=bol-van
|
||||
PKG_LICENSE:=MIT
|
||||
@@ -10,8 +10,8 @@ PKG_LICENSE_FILES:=docs/LICENSE.txt
|
||||
|
||||
PKG_SOURCE_URL:=https://github.com/bol-van/zapret.git
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=fc0b8266e3e02c62af699b18c032800b0032866f
|
||||
PKG_SOURCE_DATE:=2024-10-16
|
||||
PKG_SOURCE_VERSION:=2c68d1c94f293470bf3a87b28c4d15242e22218c
|
||||
PKG_SOURCE_DATE:=2024-10-25
|
||||
|
||||
#PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
#PKG_SOURCE_URL:=https://github.com/bol-van/zapret/archive/refs/tags/v$(PKG_VERSION).tar.gz?
|
||||
|
||||
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=zapret-mdig
|
||||
PKG_VERSION:=65
|
||||
PKG_RELEASE:=20241016
|
||||
PKG_RELEASE:=20241025
|
||||
|
||||
PKG_MAINTAINER:=bol-van
|
||||
PKG_LICENSE:=MIT
|
||||
@@ -10,8 +10,8 @@ PKG_LICENSE_FILES:=docs/LICENSE.txt
|
||||
|
||||
PKG_SOURCE_URL:=https://github.com/bol-van/zapret.git
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=fc0b8266e3e02c62af699b18c032800b0032866f
|
||||
PKG_SOURCE_DATE:=2024-10-16
|
||||
PKG_SOURCE_VERSION:=2c68d1c94f293470bf3a87b28c4d15242e22218c
|
||||
PKG_SOURCE_DATE:=2024-10-25
|
||||
|
||||
#PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
#PKG_SOURCE_URL:=https://github.com/bol-van/zapret/archive/refs/tags/v$(PKG_VERSION).tar.gz?
|
||||
|
||||
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=zapret-tpws
|
||||
PKG_VERSION:=65
|
||||
PKG_RELEASE:=20241016
|
||||
PKG_RELEASE:=20241025
|
||||
|
||||
PKG_MAINTAINER:=bol-van
|
||||
PKG_LICENSE:=MIT
|
||||
@@ -10,8 +10,8 @@ PKG_LICENSE_FILES:=docs/LICENSE.txt
|
||||
|
||||
PKG_SOURCE_URL:=https://github.com/bol-van/zapret.git
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=fc0b8266e3e02c62af699b18c032800b0032866f
|
||||
PKG_SOURCE_DATE:=2024-10-16
|
||||
PKG_SOURCE_VERSION:=2c68d1c94f293470bf3a87b28c4d15242e22218c
|
||||
PKG_SOURCE_DATE:=2024-10-25
|
||||
|
||||
#PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
#PKG_SOURCE_URL:=https://github.com/bol-van/zapret/archive/refs/tags/v$(PKG_VERSION).tar.gz?
|
||||
|
||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=zapret
|
||||
PKG_VERSION:=65
|
||||
PKG_RELEASE:=20241016
|
||||
PKG_RELEASE:=20241025
|
||||
|
||||
PKG_MAINTAINER:=bol-van
|
||||
PKG_LICENSE:=MIT
|
||||
@@ -14,8 +14,8 @@ PKG_LICENSE_FILES:=docs/LICENSE.txt
|
||||
|
||||
PKG_SOURCE_URL:=https://github.com/bol-van/zapret.git
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=fc0b8266e3e02c62af699b18c032800b0032866f
|
||||
PKG_SOURCE_DATE:=2024-10-16
|
||||
PKG_SOURCE_VERSION:=2c68d1c94f293470bf3a87b28c4d15242e22218c
|
||||
PKG_SOURCE_DATE:=2024-10-25
|
||||
|
||||
#PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
#PKG_SOURCE_URL:=https://github.com/bol-van/zapret/archive/refs/tags/v$(PKG_VERSION).tar.gz?
|
||||
@@ -78,9 +78,7 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/init.d/openwrt/90-zapret $(1)/etc/hotplug.d/iface/90-zapret
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/init.d/openwrt/zapret $(1)/etc/init.d/zapret
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./zapret.config $(1)/etc/config/zapret
|
||||
$(INSTALL_CONF) ./config $(1)/opt/zapret/config
|
||||
$(INSTALL_CONF) ./config.default $(1)/opt/zapret/config.default
|
||||
#$(INSTALL_CONF) ./ipset/zapret-hosts-auto.txt $(1)/opt/zapret/ipset/zapret-hosts-auto.txt
|
||||
$(INSTALL_CONF) ./ipset/zapret-hosts-user.txt $(1)/opt/zapret/ipset/zapret-hosts-user.txt
|
||||
$(INSTALL_CONF) ./ipset/zapret-hosts-user-exclude.txt $(1)/opt/zapret/ipset/zapret-hosts-user-exclude.txt
|
||||
@@ -90,17 +88,23 @@ define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_CONF) ./ipset/zapret-ip-user.txt $(1)/opt/zapret/ipset/zapret-ip-user.txt
|
||||
$(INSTALL_CONF) ./ipset/zapret-ip-user-exclude.txt $(1)/opt/zapret/ipset/zapret-ip-user-exclude.txt
|
||||
$(INSTALL_CONF) ./ipset/zapret-ip-user-ipban.txt $(1)/opt/zapret/ipset/zapret-ip-user-ipban.txt
|
||||
$(INSTALL_CONF) ./ipset/cust1.txt $(1)/opt/zapret/ipset/cust1.txt
|
||||
$(INSTALL_CONF) ./ipset/cust2.txt $(1)/opt/zapret/ipset/cust2.txt
|
||||
$(INSTALL_CONF) ./ipset/cust3.txt $(1)/opt/zapret/ipset/cust3.txt
|
||||
$(INSTALL_CONF) ./ipset/cust4.txt $(1)/opt/zapret/ipset/cust4.txt
|
||||
$(INSTALL_BIN) ./sync_config.sh $(1)/opt/zapret/sync_config.sh
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./uci-def-cfg.sh $(1)/etc/uci-defaults/zapret-uci-def-cfg.sh
|
||||
$(INSTALL_BIN) ./uci-def-cfg.sh $(1)/opt/zapret/uci-def-cfg.sh
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/preinst
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
if [ -f "/etc/init.d/zapret" ]; then
|
||||
SCRIPT=$$( readlink /etc/init.d/zapret )
|
||||
if [ -n "$${SCRIPT}" ]; then
|
||||
echo "Please uninstall original zapret utility!"
|
||||
exit 44
|
||||
fi
|
||||
fi
|
||||
if [ "$${PKG_UPGRADE}" = "1" ]; then
|
||||
# stop service if PKG_UPGRADE
|
||||
[ -x "/etc/init.d/zapret" ] && /etc/init.d/zapret stop >/dev/null 2>&1
|
||||
@@ -113,32 +117,26 @@ define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
NEWCFGNAME=zapret-opkg
|
||||
NEWCFGFILE=/etc/config/$${NEWCFGNAME}
|
||||
if [ -f "$${NEWCFGFILE}" ]; then
|
||||
uci -m -f /etc/config/zapret import "$${NEWCFGNAME}"
|
||||
uci commit "$${NEWCFGNAME}"
|
||||
uci -m -f "$${NEWCFGFILE}" import zapret
|
||||
uci commit zapret
|
||||
rm -f "$${NEWCFGFILE}"
|
||||
echo "File /etc/config/zapret merged from IPK"
|
||||
ZAPRET_CONFIG=/opt/zapret/config
|
||||
ZAPRET_CONFIG_DEF="/opt/zapret/config.default"
|
||||
# check existing uci-config
|
||||
[ -f "/etc/config/zapret" ] && ZAPRET_CFG_EXISTS=1 || ZAPRET_CFG_EXISTS=0
|
||||
# create or merge uci-config
|
||||
/opt/zapret/uci-def-cfg.sh
|
||||
[ "$${ZAPRET_CFG_EXISTS}" = "1" ] && echo "Config /etc/config/zapret merged with default uci-config"
|
||||
# remove uci-default script from system dir (used into /etc/init.d/boot)
|
||||
rm -f /etc/uci-defaults/zapret-uci-def-cfg.sh
|
||||
# creating main config if its not exists
|
||||
if [ ! -f "$${ZAPRET_CONFIG}" ]; then
|
||||
cp -f "$${ZAPRET_CONFIG_DEF}" "$${ZAPRET_CONFIG}"
|
||||
/opt/zapret/sync_config.sh
|
||||
fi
|
||||
NEWCONFIG=/opt/zapret/config-opkg
|
||||
if [ -f "$${NEWCONFIG}" ]; then
|
||||
# backup current main config
|
||||
mv -f /opt/zapret/config /opt/zapret/config.backup
|
||||
# renew main config
|
||||
mv -f "$${NEWCONFIG}" /opt/zapret/config
|
||||
echo "File /opt/zapret/config replaced from IPK"
|
||||
fi
|
||||
# synchnonize main config
|
||||
/opt/zapret/sync_config.sh
|
||||
# enable main service
|
||||
/etc/init.d/zapret enable
|
||||
# stop all
|
||||
/etc/init.d/zapret stop_fw
|
||||
/etc/init.d/zapret stop_daemons
|
||||
ps w | grep '/opt/zapret/nfq/nfqws' | grep -v grep | awk '{print $1}' | xargs -r kill -9
|
||||
ps w | grep '/opt/zapret/nfq/nfqws' | grep -v grep | awk '{print $$1}' | xargs -r kill -9
|
||||
# start main service
|
||||
/etc/init.d/zapret start
|
||||
# restart firewall
|
||||
@@ -162,7 +160,7 @@ if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
. "$${ZAPRET_BASE}/common/installer.sh"
|
||||
/etc/init.d/zapret disable
|
||||
/etc/init.d/zapret stop
|
||||
ps w | grep '/opt/zapret/nfq/nfqws' | grep -v grep | awk '{print $1}' | xargs -r kill -9
|
||||
ps w | grep '/opt/zapret/nfq/nfqws' | grep -v grep | awk '{print $$1}' | xargs -r kill -9
|
||||
remove_openwrt_firewall
|
||||
nft_del_table
|
||||
restart_openwrt_firewall
|
||||
@@ -175,7 +173,7 @@ define Package/$(PKG_NAME)/postrm
|
||||
# check if we are on real system
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
[ -f "/etc/config/zapret-opkg" ] && rm -f "/etc/config/zapret-opkg"
|
||||
[ -f "/opt/zapret/config" ] && cp -f /opt/zapret/config "/opt/zapret/config.backup2"
|
||||
[ -f "/opt/zapret/config" ] && cp -f /opt/zapret/config "/opt/zapret/config.backup"
|
||||
#rm -rf /opt/zapret
|
||||
#echo "Directory /opt/zapret removed!"
|
||||
fi
|
||||
|
||||
@@ -42,9 +42,9 @@ GZIP_LISTS=0
|
||||
#LISTS_RELOAD="pfctl -f /etc/pf.conf"
|
||||
|
||||
# override ports
|
||||
#HTTP_PORTS=80-81,85
|
||||
#HTTPS_PORTS=443,500-501
|
||||
#QUIC_PORTS=443,444
|
||||
HTTP_PORTS=80
|
||||
HTTPS_PORTS=443
|
||||
QUIC_PORTS=443
|
||||
|
||||
# CHOOSE OPERATION MODE
|
||||
# MODE : nfqws,tpws,tpws-socks,filter,custom
|
||||
@@ -141,4 +141,3 @@ DISABLE_IPV6=1
|
||||
# possible values : get_user.sh get_antizapret.sh get_combined.sh get_reestr.sh get_hostlist.sh
|
||||
# comment if not required
|
||||
#GETLIST=get_antizapret_domains.sh
|
||||
#GETLIST=get_antifilter_ipsmart.sh
|
||||
@@ -4,14 +4,40 @@
|
||||
EXEDIR=/opt/zapret
|
||||
ZAPRET_BASE=/opt/zapret
|
||||
ZAPRET_CONFIG="$ZAPRET_BASE/config"
|
||||
ZAPRET_CONFIG_DEF="$ZAPRET_BASE/config.default"
|
||||
ZAPRET_CFG=/etc/config/zapret
|
||||
|
||||
ZAPRET_CFG_SEC_NAME="$( uci -q get zapret.config )"
|
||||
|
||||
if [ -z "$ZAPRET_CFG_SEC_NAME" ]; then
|
||||
# wrong uci-config
|
||||
return 1
|
||||
fi
|
||||
|
||||
function get_sed_compat
|
||||
{
|
||||
local str=$( ( echo $1|sed -r 's/([\$\.\*\/\[\\^])/\\\1/g'|sed 's/[]]/\\]/g' )>&1 )
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
function uncomment_param
|
||||
{
|
||||
local param=$1
|
||||
local fname=${2:-$ZAPRET_CONFIG}
|
||||
sed -i "/^#$param=/s/^#//" $fname
|
||||
}
|
||||
|
||||
function append_param
|
||||
{
|
||||
local param=$1
|
||||
local fname=${2:-$ZAPRET_CONFIG}
|
||||
grep -q "^$param=" $fname
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "" >> $fname
|
||||
echo "$param=" >> $fname
|
||||
fi
|
||||
}
|
||||
|
||||
function set_param_value
|
||||
{
|
||||
local param=$1
|
||||
@@ -32,14 +58,28 @@ function sync_param
|
||||
{
|
||||
local param=$1
|
||||
local vtype=$2
|
||||
local value=$( uci -q get zapret.@main[0].$param )
|
||||
local value="$( uci -q get zapret.config.$param )"
|
||||
uncomment_param $param
|
||||
append_param $param
|
||||
local TAB="$( echo -n -e '\t' )"
|
||||
if [ "$value" = "$TAB" ]; then
|
||||
value=""
|
||||
fi
|
||||
if [ "$vtype" = "str" ]; then
|
||||
set_param_value_str $param "$value"
|
||||
else
|
||||
set_param_value $param $value
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if [ ! -f "$ZAPRET_CONFIG" ]; then
|
||||
if [ ! -f "$ZAPRET_CONFIG_DEF" ]; then
|
||||
touch "$ZAPRET_CONFIG"
|
||||
else
|
||||
cp -f "$ZAPRET_CONFIG_DEF" "$ZAPRET_CONFIG"
|
||||
fi
|
||||
fi
|
||||
|
||||
sync_param MODE
|
||||
sync_param FLOWOFFLOAD
|
||||
sync_param INIT_APPLY_FW
|
||||
@@ -52,16 +92,19 @@ sync_param NFQWS_OPT_DESYNC str
|
||||
sync_param NFQWS_OPT_DESYNC_SUFFIX str
|
||||
sync_param MODE_HTTP
|
||||
sync_param MODE_HTTP_KEEPALIVE
|
||||
sync_param HTTP_PORTS
|
||||
sync_param NFQWS_OPT_DESYNC_HTTP str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTP_SUFFIX str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTP6 str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTP6_SUFFIX str
|
||||
sync_param MODE_HTTPS
|
||||
sync_param HTTPS_PORTS
|
||||
sync_param NFQWS_OPT_DESYNC_HTTPS str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTPS_SUFFIX str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTPS6 str
|
||||
sync_param NFQWS_OPT_DESYNC_HTTPS6_SUFFIX str
|
||||
sync_param MODE_QUIC
|
||||
sync_param QUIC_PORTS
|
||||
sync_param NFQWS_OPT_DESYNC_QUIC str
|
||||
sync_param NFQWS_OPT_DESYNC_QUIC_SUFFIX str
|
||||
sync_param NFQWS_OPT_DESYNC_QUIC6 str
|
||||
|
||||
120
zapret/uci-def-cfg.sh
Executable file
120
zapret/uci-def-cfg.sh
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/bin/sh
|
||||
# Copyright (c) 2024 remittor
|
||||
|
||||
SCRIPT_SOURCED=0
|
||||
case ${0##*/} in ash|-ash) SCRIPT_SOURCED=1;; esac
|
||||
#[[ $_ != $0 ]] && echo "Script is being sourced" || echo "Script is a subshell"
|
||||
|
||||
ZAPRET_BASE=/opt/zapret
|
||||
ZAPRET_CONFIG="$ZAPRET_BASE/config"
|
||||
ZAPRET_CONFIG_DEF="$ZAPRET_BASE/config.default"
|
||||
ZAPRET_CFG_FILE=/etc/config/zapret
|
||||
ZAPRET_CFG_NAME=zapret
|
||||
|
||||
CFG_OPT_FORCE=0
|
||||
CFG_OPT_MERGE=0
|
||||
CFG_OPT_SYNC_CFG=0
|
||||
|
||||
|
||||
function set_default_values
|
||||
{
|
||||
local cfgname=${1:-$ZAPRET_CFG_NAME}
|
||||
local TAB="$( echo -n -e '\t' )"
|
||||
uci batch <<-EOF
|
||||
set $cfgname.config.autostart='0'
|
||||
set $cfgname.config.FWTYPE='nftables'
|
||||
set $cfgname.config.MODE='nfqws'
|
||||
set $cfgname.config.FLOWOFFLOAD='none'
|
||||
set $cfgname.config.INIT_APPLY_FW='1'
|
||||
set $cfgname.config.DISABLE_IPV4='0'
|
||||
set $cfgname.config.DISABLE_IPV6='1'
|
||||
set $cfgname.config.MODE_FILTER='hostlist'
|
||||
set $cfgname.config.DESYNC_MARK='0x40000000'
|
||||
set $cfgname.config.DESYNC_MARK_POSTNAT='0x20000000'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC='--dpi-desync=fake,split2 --dpi-desync-ttl=7 --dpi-desync-ttl6=0 --dpi-desync-repeats=20 --dpi-desync-fooling=md5sig,badseq --dpi-desync-fake-tls=/opt/zapret/files/fake/tls_clienthello_www_google_com.bin'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_SUFFIX="$TAB"
|
||||
set $cfgname.config.MODE_HTTP='1'
|
||||
set $cfgname.config.MODE_HTTP_KEEPALIVE='0'
|
||||
set $cfgname.config.HTTP_PORTS='80'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTP="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTP_SUFFIX="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTP6="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTP6_SUFFIX="$TAB"
|
||||
set $cfgname.config.MODE_HTTPS='1'
|
||||
set $cfgname.config.HTTPS_PORTS='443'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTPS="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTPS_SUFFIX="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTPS6="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_HTTPS6_SUFFIX="$TAB"
|
||||
set $cfgname.config.MODE_QUIC='1'
|
||||
set $cfgname.config.QUIC_PORTS='443'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_QUIC='--dpi-desync=fake,split2 --dpi-desync-repeats=15 --dpi-desync-fake-quic=/opt/zapret/files/fake/quic_initial_www_google_com.bin --new --dpi-desync=fake --dpi-desync-repeats=15'
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_QUIC_SUFFIX="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_QUIC6="$TAB"
|
||||
set $cfgname.config.NFQWS_OPT_DESYNC_QUIC6_SUFFIX="$TAB"
|
||||
commit $cfgname
|
||||
EOF
|
||||
return 0
|
||||
}
|
||||
|
||||
function create_default_config
|
||||
{
|
||||
local cfgname=${1:-$ZAPRET_CFG_NAME}
|
||||
local cfgfile=/etc/config/$cfgname
|
||||
rm -f $cfgfile
|
||||
touch $cfgfile
|
||||
uci set $cfgname.config=main
|
||||
set_default_values $cfgname
|
||||
return 0
|
||||
}
|
||||
|
||||
function merge_config_with_def_values
|
||||
{
|
||||
local cfgname=${1:-$ZAPRET_CFG_NAME}
|
||||
local force=$2
|
||||
local cfgfile=/etc/config/$cfgname
|
||||
local NEWCFGNAME="zapret-default"
|
||||
local NEWCFGFILE="/etc/config/$NEWCFGNAME"
|
||||
|
||||
create_default_config "$NEWCFGNAME"
|
||||
[ ! -f "$NEWCFGFILE" ] && return 1
|
||||
|
||||
uci -m -f $cfgfile import "$NEWCFGNAME"
|
||||
uci commit "$NEWCFGNAME"
|
||||
uci -m -f "$NEWCFGFILE" import $cfgname
|
||||
uci commit $cfgname
|
||||
rm -f "$NEWCFGFILE"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
if [ "$SCRIPT_SOURCED" != "1" ]; then
|
||||
while getopts "fms" SCRIPT_OPT; do
|
||||
case $SCRIPT_OPT in
|
||||
f) CFG_OPT_FORCE=1;;
|
||||
m) CFG_OPT_MERGE=1;;
|
||||
s) CFG_OPT_SYNC_CFG=1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f "$ZAPRET_CFG_FILE" ]; then
|
||||
CFG_OPT_FORCE=1
|
||||
fi
|
||||
|
||||
if [ "$CFG_OPT_FORCE" = "1" ]; then
|
||||
create_default_config
|
||||
[ "$CFG_OPT_SYNC_CFG" = "1" ] && /opt/zapret/sync_config.sh
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
CFG_OPT_MERGE=1
|
||||
merge_config_with_def_values
|
||||
|
||||
if [ ! -f "$ZAPRET_CONFIG" ]; then
|
||||
# create main config
|
||||
/opt/zapret/sync_config.sh
|
||||
fi
|
||||
|
||||
return 0
|
||||
@@ -1,29 +0,0 @@
|
||||
config main 'config'
|
||||
option autostart '0'
|
||||
option FWTYPE 'nftables'
|
||||
option MODE 'nfqws'
|
||||
option FLOWOFFLOAD 'none'
|
||||
option INIT_APPLY_FW '1'
|
||||
option DISABLE_IPV4 '0'
|
||||
option DISABLE_IPV6 '1'
|
||||
option MODE_FILTER 'hostlist'
|
||||
option DESYNC_MARK '0x40000000'
|
||||
option DESYNC_MARK_POSTNAT '0x20000000'
|
||||
option NFQWS_OPT_DESYNC '--dpi-desync=fake,split2 --dpi-desync-ttl=7 --dpi-desync-ttl6=0 --dpi-desync-repeats=20 --dpi-desync-fooling=md5sig,badseq --dpi-desync-fake-tls=/opt/zapret/files/fake/tls_clienthello_www_google_com.bin'
|
||||
option NFQWS_OPT_DESYNC_SUFFIX ''
|
||||
option MODE_HTTP '1'
|
||||
option MODE_HTTP_KEEPALIVE '0'
|
||||
option NFQWS_OPT_DESYNC_HTTP ''
|
||||
option NFQWS_OPT_DESYNC_HTTP_SUFFIX ''
|
||||
option NFQWS_OPT_DESYNC_HTTP6 ''
|
||||
option NFQWS_OPT_DESYNC_HTTP6_SUFFIX ''
|
||||
option MODE_HTTPS '1'
|
||||
option NFQWS_OPT_DESYNC_HTTPS ''
|
||||
option NFQWS_OPT_DESYNC_HTTPS_SUFFIX ''
|
||||
option NFQWS_OPT_DESYNC_HTTPS6 ''
|
||||
option NFQWS_OPT_DESYNC_HTTPS6_SUFFIX ''
|
||||
option MODE_QUIC '1'
|
||||
option NFQWS_OPT_DESYNC_QUIC '--dpi-desync=fake,split2 --dpi-desync-repeats=15 --dpi-desync-fake-quic=/opt/zapret/files/fake/quic_initial_www_google_com.bin --new --dpi-desync=fake --dpi-desync-repeats=15'
|
||||
option NFQWS_OPT_DESYNC_QUIC_SUFFIX ''
|
||||
option NFQWS_OPT_DESYNC_QUIC6 ''
|
||||
option NFQWS_OPT_DESYNC_QUIC6_SUFFIX ''
|
||||
Reference in New Issue
Block a user