luci: Adapt code for APK support

This commit is contained in:
remittor
2024-11-21 10:39:54 +03:00
parent 51fc9739d8
commit 9719c11a58
8 changed files with 55 additions and 14 deletions

View File

@@ -5,8 +5,9 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-zapret
PKG_VERSION:=69-20241118
PKG_VERSION:=69.20241118
PKG_LICENSE:=MIT
PKG_MAINTAINER:=remittor <https://github.com/remittor>
LUCI_TITLE:=LuCI support for zapret
LUCI_DEPENDS:=+zapret
@@ -19,8 +20,8 @@ if [ -z "$${IPKG_INSTROOT}" ]; then
rm -rf /tmp/luci-modulecache/
#killall -HUP rpcd 2>/dev/null
/etc/init.d/rpcd reload
/sbin/luci-reload
/etc/init.d/uhttpd reload
[ -f "/sbin/luci-reload" ] && /sbin/luci-reload
[ -f "/etc/init.d/uhttpd" ] && /etc/init.d/uhttpd reload
fi
exit 0
endef

View File

@@ -47,7 +47,7 @@ return view.extend({
fs.exec(tools.execPath, [ 'enabled' ]), // svc_en
fs.exec(tools.execPath, [ 'info' ]), // svc_info
fs.exec('/bin/ps'), // process list
fs.exec('/bin/opkg', [ 'list-installed', '*zapret*' ]), // installed packages
fs.exec(tools.packager.path, tools.packager.args), // installed packages
uci.load(tools.appName), // config
]).catch(e => {
ui.addNotification(null, E('p', _('Unable to execute or read contents')
@@ -72,7 +72,7 @@ return view.extend({
let proc_list = status_array[3]; // stdout: multiline text
let pkg_list = status_array[4]; // stdout: installed packages
console.log('svc_en: ' + svc_en.code);
//console.log('svc_en: ' + svc_en.code);
svc_en = (svc_en.code == 0) ? true : false;
if (svc_info.code != 0) {

View File

@@ -35,6 +35,7 @@ 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',
@@ -82,7 +83,24 @@ 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);
}
},
getInitState: function(name) {
this.init_consts();
return this.callInitState(name).then(res => {
if (res) {
return res[name].enabled ? true : false;
@@ -114,12 +132,33 @@ return baseclass.extend({
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;
let name;
let ver;
if (this.packager.name == 'apk') {
let fullname = line.split(' ')[0];
let mpos = fullname.lastIndexOf("-");
if (mpos <= 0)
continue;
if (fullname.substring(mpos+1, mpos+2) == 'r') {
// release number
fullname = fullname.substring(0, mpos);
}
mpos = fullname.lastIndexOf("-");
if (mpos <= 0)
continue;
name = fullname.substring(0, mpos).trim();
ver = fullname.substring(mpos+1).trim();
} else {
if (!line.includes(' - '))
continue;
name = line.split(' - ')[0].trim();
ver = line.split(' - ')[1].trim();
let spos = ver.indexOf(" ");
if (spos > 0) {
ver = ver.substring(0, spos);
}
}
pkg_dict[name] = ver;
}
return pkg_dict;
},

View File

@@ -10,6 +10,7 @@
"/etc/init.d/zapret*": [ "exec" ],
"/bin/ps*": [ "exec" ],
"/bin/opkg*": [ "exec" ],
"/usr/bin/apk*": [ "exec" ],
"/opt/zapret/restore-def-cfg.sh*": [ "exec" ],
"/opt/zapret/sync_config.sh*": [ "exec" ]
},

View File

@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=zapret-ip2net
PKG_VERSION:=69-20241118
PKG_VERSION:=69.20241118
PKG_MAINTAINER:=bol-van
PKG_LICENSE:=MIT

View File

@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=zapret-mdig
PKG_VERSION:=69-20241118
PKG_VERSION:=69.20241118
PKG_MAINTAINER:=bol-van
PKG_LICENSE:=MIT

View File

@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=zapret-tpws
PKG_VERSION:=69-20241118
PKG_VERSION:=69.20241118
PKG_MAINTAINER:=bol-van
PKG_LICENSE:=MIT

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=zapret
PKG_VERSION:=69-20241118
PKG_VERSION:=69.20241118
PKG_MAINTAINER:=bol-van
PKG_LICENSE:=MIT