update 2026-08-30 11:09:43

This commit is contained in:
action committed 2026-08-30 11:09:43 +08:00
1 parent b09780b109
commit a8ecc43b8a
29 files changed
+1484 -49

No files matched your search

+6 -1
View File
@@ -8,7 +8,7 @@ config mosdns 'config'
option geo_update_day_time '2'
option geoip_type 'geoip-only-cn-private'
option configfile '/var/etc/mosdns.json'
option log_level 'info'
option log_level 'error'
option log_file '/var/log/mosdns.log'
option log_size '1'
option cache '1'
@@ -30,4 +30,9 @@ config mosdns 'config'
option lazy_cache_ttl '86400'
option dump_file '0'
option reject_type65 '1'
option stats_collector '1'
option stats_capacity '2000'
option stats_dump_file '0'
option stats_dump_interval '600'
+24 -1
View File
@@ -34,7 +34,7 @@ get_config() {
config_get listen_address $1 listen_address "0.0.0.0"
config_get log_file $1 log_file "/var/log/mosdns.log"
config_get log_size $1 log_size "1"
config_get log_level $1 log_level "info"
config_get log_level $1 log_level "error"
config_get minimal_ttl $1 minimal_ttl 0
config_get maximum_ttl $1 maximum_ttl 0
config_get redirect $1 redirect 0
@@ -57,6 +57,10 @@ get_config() {
config_get cloudflare $1 cloudflare 0
config_get cloudflare_ip $1 cloudflare_ip ""
config_get reject_type65 $1 reject_type65 "0"
config_get stats_collector $1 stats_collector 1
config_get stats_capacity $1 stats_capacity 2000
config_get stats_dump_file $1 stats_dump_file 0
config_get stats_dump_interval $1 stats_dump_interval 600
}
generate_config() {
@@ -79,6 +83,20 @@ generate_config() {
json_close_array
# plugins
json_add_array "plugins"
# plugin: stats_collector
[ "$stats_collector" -eq 1 ] && {
json_add_object
json_add_string "tag" "stats_collector"
json_add_string "type" "stats_api"
json_add_object "args"
json_add_int "capacity" "$stats_capacity"
[ "$stats_dump_file" -eq 1 ] && {
json_add_string "dump_file" "/etc/mosdns/stats.dump"
json_add_int "dump_interval" "$stats_dump_interval"
}
json_close_object
json_close_object
}
# plugin: geosite_cn
json_add_object
json_add_string "tag" "geosite_cn"
@@ -589,6 +607,11 @@ generate_config() {
json_add_string "tag" "main_sequence"
json_add_string "type" "sequence"
json_add_array "args"
[ "$stats_collector" -eq 1 ] && {
json_add_object
json_add_string "exec" "\$stats_collector"
json_close_object
}
json_add_object
json_add_string "exec" "\$hosts"
json_close_object
@@ -9,6 +9,14 @@ api:
include: []
plugins:
# 统计收集器
- tag: stats_collector
type: stats_api
args:
capacity: 2000 # 查询日志环缓冲区容量 (FIFO 覆盖)
dump_file: "/etc/mosdns/stats.dump" # 数据持久化转存文件路径,不设置则不转存
dump_interval: 600 # 周期性转储间隔(秒)
# 国内域名
- tag: geosite_cn
type: domain_set
@@ -120,6 +128,7 @@ plugins:
- tag: main_sequence
type: sequence
args:
- exec: $stats_collector # 执行全局统计控制器
- exec: $lazy_cache
- exec: jump has_resp_sequence
- exec: $query_is_local_domain
@@ -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 {