mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 16:44:23 +08:00
🗽 Sync 2026-08-09 22:41:21
This commit is contained in:
1 parent
0daa789835
commit
8d3eaa96b2
66 files changed
+4182
-3339
No files matched your search
@@ -9,16 +9,14 @@ import { access, open, popen } from 'fs';
|
||||
import { connect } from 'ubus';
|
||||
import { cursor } from 'uci';
|
||||
|
||||
const uci = cursor();
|
||||
const leasefilepath = uci.get('upnpd', 'config', 'upnp_lease_file') || '/var/run/miniupnpd.leases';
|
||||
|
||||
const methods = {
|
||||
get_status: {
|
||||
call: function(req) {
|
||||
const uci = cursor();
|
||||
const ubus = connect();
|
||||
const rules = [];
|
||||
const leases = [];
|
||||
const leasefile = open(leasefilepath, 'r');
|
||||
const leasefile = open(uci.get('upnpd', 'settings', 'lease_file') || '/var/run/miniupnpd.leases', 'r');
|
||||
if (leasefile) {
|
||||
for (let line = leasefile.read('line'); length(line); line = leasefile.read('line')) {
|
||||
const record = split(line, ':', 6);
|
||||
@@ -61,6 +59,23 @@ const methods = {
|
||||
}
|
||||
}
|
||||
ipt.close();
|
||||
|
||||
const iptipv6 = popen('ip6tables --line-numbers -xnvL MINIUPNPD 2>/dev/null');
|
||||
if (iptipv6) {
|
||||
for (let line = iptipv6.read('line'); length(line); line = iptipv6.read('line')) {
|
||||
let m = match(line, /^([0-9]+) .+ ([0-9a-f:]+) ([ut].p) dpt:([0-9]+)/);
|
||||
if (m) {
|
||||
push(rules, {
|
||||
num: '0',
|
||||
intaddr: arrtoip(iptoarr(m[2])),
|
||||
intport: +m[4],
|
||||
extport: +m[4],
|
||||
proto: uc(m[3])
|
||||
});
|
||||
}
|
||||
}
|
||||
iptipv6.close();
|
||||
}
|
||||
}
|
||||
|
||||
const nft = popen('nft --handle list chain inet fw4 upnp_prerouting 2>/dev/null');
|
||||
@@ -79,6 +94,27 @@ const methods = {
|
||||
}
|
||||
}
|
||||
nft.close();
|
||||
|
||||
const nftipv6 = popen('nft --handle list chain inet fw4 upnp_forward 2>/dev/null');
|
||||
if (nftipv6) {
|
||||
for (let line = nftipv6.read('line'), num = 1; length(line); line = nftipv6.read('line')) {
|
||||
let m = match(line, /^\t\tiif ".+" th dport ([0-9]+) @nh,192,128 0x([0-9a-f]+) @nh,48,8 (0x6|0x11) accept/);
|
||||
if (m) {
|
||||
push(rules, {
|
||||
num: '0',
|
||||
intaddr: arrtoip(iptoarr(join(':', [substr(m[2], 0, 4),
|
||||
substr(m[2], 4, 4), substr(m[2], 8, 4), substr(m[2], 12, 4), substr(m[2], 16, 4),
|
||||
substr(m[2], 20, 4), substr(m[2], 24, 4), substr(m[2], 28, 4)
|
||||
]))),
|
||||
intport: +m[1],
|
||||
extport: +m[1],
|
||||
proto: (m[3] == '0x6') ? 'TCP' : 'UDP'
|
||||
});
|
||||
num++;
|
||||
}
|
||||
}
|
||||
nftipv6.close();
|
||||
}
|
||||
}
|
||||
|
||||
return ubus.defer('luci-rpc', 'getHostHints', {}, function(rc, host_hints) {
|
||||
@@ -94,7 +130,7 @@ const methods = {
|
||||
}
|
||||
}
|
||||
for (let mac, hint in host_hints) {
|
||||
if (rule.intaddr in hint.ipaddrs) {
|
||||
if (rule.intaddr in hint.ipaddrs || rule.intaddr in hint.ip6addrs) {
|
||||
rule.host_hint = hint.name;
|
||||
break;
|
||||
}
|
||||
@@ -110,8 +146,10 @@ const methods = {
|
||||
call: function(req) {
|
||||
const idx = +req.args?.token;
|
||||
if (idx > 0) {
|
||||
if (access(leasefilepath)) {
|
||||
system(['sed', '-i', '-e', `${idx}d`, leasefilepath]);
|
||||
const uci = cursor();
|
||||
const leasefile = uci.get('upnpd', 'settings', 'lease_file') || '/var/run/miniupnpd.leases';
|
||||
if (access(leasefile)) {
|
||||
system(['sed', '-i', '-e', `${idx}d`, leasefile]);
|
||||
system(['/etc/init.d/miniupnpd', 'restart']);
|
||||
}
|
||||
return { result: 'OK' };
|
||||
|
||||
Reference in new issue
Block a user