mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-04 04:43:56 +08:00
🍉 Sync 2026-08-30 11:16:17
This commit is contained in:
1 parent
85339c08e1
commit
84eac136c8
127 files changed
+3726
-86808
No files matched your search
@@ -34,9 +34,17 @@
|
||||
"path": "mosdns/update"
|
||||
}
|
||||
},
|
||||
"admin/services/mosdns/statistics": {
|
||||
"title": "Statistics",
|
||||
"order": 25,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "mosdns/statistics"
|
||||
}
|
||||
},
|
||||
"admin/services/mosdns/logs": {
|
||||
"title": "Logs",
|
||||
"order": 25,
|
||||
"order": 30,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "mosdns/logs"
|
||||
|
||||
@@ -149,8 +149,8 @@ function update_adlist() {
|
||||
|
||||
print(`Downloading ${mirror}${url}\n`);
|
||||
stdout.flush();
|
||||
let curl_res = exec_sys(`curl --connect-timeout 5 -m 90 --ipv4 -kfSLo "${ad_tmpdir}/${filename}" "${mirror}${url}"`);
|
||||
if (curl_res.code !== 0) download_failed = true;
|
||||
let dl_res = exec_sys(`wget -4 -q --no-check-certificate -T 90 -t 2 -O "${ad_tmpdir}/${filename}" "${mirror}${url}"`);
|
||||
if (dl_res.code !== 0) download_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ function update_geodat() {
|
||||
|
||||
print(`Downloading ${geoip_url}.sha256sum\n`);
|
||||
stdout.flush();
|
||||
if (exec_sys(`curl --connect-timeout 5 -m 20 --ipv4 -kfSLo "${tmpdir}/geoip.dat.sha256sum" "${geoip_url}.sha256sum"`).code !== 0) {
|
||||
if (exec_sys(`wget -4 -q --no-check-certificate -T 20 -t 2 -O "${tmpdir}/geoip.dat.sha256sum" "${geoip_url}.sha256sum"`).code !== 0) {
|
||||
exec_sys(`rm -rf "${tmpdir}"`);
|
||||
die("Failed to download geoip.dat.sha256sum");
|
||||
}
|
||||
@@ -209,7 +209,7 @@ function update_geodat() {
|
||||
} else {
|
||||
print(`Downloading ${geoip_url}\n`);
|
||||
stdout.flush();
|
||||
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geoip.dat" "${geoip_url}"`).code !== 0) {
|
||||
if (exec_sys(`wget -4 -q --no-check-certificate -T 120 -t 2 -O "${tmpdir}/geoip.dat" "${geoip_url}"`).code !== 0) {
|
||||
exec_sys(`rm -rf "${tmpdir}"`);
|
||||
die("Failed to download geoip.dat");
|
||||
}
|
||||
@@ -227,7 +227,7 @@ function update_geodat() {
|
||||
|
||||
print(`Downloading ${geosite_url}.sha256sum\n`);
|
||||
stdout.flush();
|
||||
if (exec_sys(`curl --connect-timeout 5 -m 20 --ipv4 -kfSLo "${tmpdir}/geosite.dat.sha256sum" "${geosite_url}.sha256sum"`).code !== 0) {
|
||||
if (exec_sys(`wget -4 -q --no-check-certificate -T 20 -t 2 -O "${tmpdir}/geosite.dat.sha256sum" "${geosite_url}.sha256sum"`).code !== 0) {
|
||||
exec_sys(`rm -rf "${tmpdir}"`);
|
||||
die("Failed to download geosite.dat.sha256sum");
|
||||
}
|
||||
@@ -244,7 +244,7 @@ function update_geodat() {
|
||||
} else {
|
||||
print(`Downloading ${geosite_url}\n`);
|
||||
stdout.flush();
|
||||
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geosite.dat" "${geosite_url}"`).code !== 0) {
|
||||
if (exec_sys(`wget -4 -q --no-check-certificate -T 120 -t 2 -O "${tmpdir}/geosite.dat" "${geosite_url}"`).code !== 0) {
|
||||
exec_sys(`rm -rf "${tmpdir}"`);
|
||||
die("Failed to download geosite.dat");
|
||||
}
|
||||
|
||||
@@ -16,10 +16,15 @@
|
||||
"service": [ "list" ],
|
||||
"luci.mosdns": [
|
||||
"clean_log",
|
||||
"clear_query_logs",
|
||||
"flush_cache",
|
||||
"get_history",
|
||||
"get_logs",
|
||||
"get_stats",
|
||||
"get_top",
|
||||
"get_update_log",
|
||||
"get_version",
|
||||
"print_log",
|
||||
"get_update_log",
|
||||
"start_update"
|
||||
]
|
||||
},
|
||||
@@ -35,7 +40,8 @@
|
||||
"/var/mosdns/*": [ "write" ]
|
||||
},
|
||||
"ubus": {
|
||||
"file": [ "write" ]
|
||||
"file": [ "write" ],
|
||||
"luci.mosdns": [ "clear_query_logs" ]
|
||||
},
|
||||
"uci": [ "mosdns" ]
|
||||
}
|
||||
|
||||
@@ -58,16 +58,85 @@ function get_logfile_path_internal() {
|
||||
}
|
||||
}
|
||||
|
||||
function parse_json_safe(str) {
|
||||
if (!str || str == "")
|
||||
return null;
|
||||
|
||||
try {
|
||||
return json(str);
|
||||
} catch(e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function call_mosdns_api(endpoint, method) {
|
||||
try {
|
||||
let uci_cursor = cursor();
|
||||
uci_cursor.load('mosdns');
|
||||
let port = uci_cursor.get('mosdns', 'config', 'listen_port_api') || '9091';
|
||||
let http_method = method ? method : 'GET';
|
||||
let post_flag = (http_method === 'POST') ? '--post-data=""' : '';
|
||||
let cmd = `wget -q -O - ${post_flag} "http://127.0.0.1:${port}/plugins/stats_collector${endpoint}"`;
|
||||
let res = exec_sys(cmd);
|
||||
if (res.code === 0 && res.stdout != "") {
|
||||
let json_val = parse_json_safe(res.stdout);
|
||||
if (json_val) return json_val;
|
||||
}
|
||||
return { error: "MosDNS API unreachable" };
|
||||
} catch (e) {
|
||||
return { error: String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
const methods = {
|
||||
get_stats: {
|
||||
call: function() {
|
||||
return call_mosdns_api('/api/v1/stats', 'GET');
|
||||
}
|
||||
},
|
||||
|
||||
get_history: {
|
||||
args: { points: 24 },
|
||||
call: function(request) {
|
||||
let points = request?.args?.points || 24;
|
||||
return call_mosdns_api(`/api/v1/history?points=${points}`, 'GET');
|
||||
}
|
||||
},
|
||||
|
||||
get_top: {
|
||||
args: { limit: 10 },
|
||||
call: function(request) {
|
||||
let limit = request?.args?.limit || 10;
|
||||
return call_mosdns_api(`/api/v1/top?limit=${limit}`, 'GET');
|
||||
}
|
||||
},
|
||||
|
||||
get_logs: {
|
||||
args: { limit: 50, offset: 0, search: '', filter: 'all' },
|
||||
call: function(request) {
|
||||
let limit = request?.args?.limit || 50;
|
||||
let offset = request?.args?.offset || 0;
|
||||
let search = request?.args?.search || '';
|
||||
let filter = request?.args?.filter || 'all';
|
||||
return call_mosdns_api(`/api/v1/logs?limit=${limit}&offset=${offset}&search=${search}&filter=${filter}`, 'GET');
|
||||
}
|
||||
},
|
||||
|
||||
clear_query_logs: {
|
||||
call: function() {
|
||||
return call_mosdns_api('/api/v1/logs/clear', 'POST');
|
||||
}
|
||||
},
|
||||
|
||||
flush_cache: {
|
||||
call: function() {
|
||||
try {
|
||||
let uci_cursor = cursor();
|
||||
uci_cursor.load('mosdns');
|
||||
let port = uci_cursor.get('mosdns', 'config', 'listen_port_api');
|
||||
let port = uci_cursor.get('mosdns', 'config', 'listen_port_api') || '9091';
|
||||
if (!port) return { error: "API listen port not configured." };
|
||||
|
||||
let res = exec_sys(`curl -s 127.0.0.1:${port}/plugins/lazy_cache/flush`);
|
||||
let res = exec_sys(`wget -q -O - "http://127.0.0.1:${port}/plugins/lazy_cache/flush"`);
|
||||
if (res.code === 0) {
|
||||
return { success: true };
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user