koishi-plugin-jscn-aaaquery 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +125 -31
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -647,40 +647,77 @@ function apply(ctx, config) {
|
|
|
647
647
|
__name(queryOrderLog, "queryOrderLog");
|
|
648
648
|
async function queryRadiusUser(account) {
|
|
649
649
|
return addToQueue("radiusUser", { account }, async () => {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
{
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
"Accept": "application/json"
|
|
650
|
+
const maxRetries = 2;
|
|
651
|
+
let lastError = null;
|
|
652
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
653
|
+
try {
|
|
654
|
+
console.log(`开始查询RADIUS用户信息... (第${attempt}次尝试)`);
|
|
655
|
+
console.log(`RADIUS API地址: ${config.radiusApiUrl}/userquery`);
|
|
656
|
+
const response = await ctx.http.post(
|
|
657
|
+
`${config.radiusApiUrl}/userquery`,
|
|
658
|
+
{
|
|
659
|
+
login_name: account,
|
|
660
|
+
org_code: "403",
|
|
661
|
+
// 固定值
|
|
662
|
+
channel: "ALL"
|
|
663
|
+
// 固定值
|
|
665
664
|
},
|
|
666
|
-
|
|
667
|
-
|
|
665
|
+
{
|
|
666
|
+
headers: {
|
|
667
|
+
"Content-Type": "application/json",
|
|
668
|
+
"Accept": "application/json",
|
|
669
|
+
"User-Agent": "JSCN-AAAQuery/1.0"
|
|
670
|
+
},
|
|
671
|
+
timeout: 15e3
|
|
672
|
+
// 减少超时时间到15秒
|
|
673
|
+
}
|
|
674
|
+
);
|
|
675
|
+
console.log("RADIUS查询成功,响应:", JSON.stringify(response, null, 2));
|
|
676
|
+
return response;
|
|
677
|
+
} catch (error) {
|
|
678
|
+
lastError = error;
|
|
679
|
+
console.error(`RADIUS查询第${attempt}次尝试失败:`, error.message || error);
|
|
680
|
+
if (error.code) {
|
|
681
|
+
console.error(`错误代码: ${error.code}`);
|
|
668
682
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
683
|
+
if (error.cause) {
|
|
684
|
+
console.error(`错误原因: ${error.cause.message || error.cause}`);
|
|
685
|
+
if (error.cause.code) {
|
|
686
|
+
console.error(`原因代码: ${error.cause.code}`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (error.response) {
|
|
690
|
+
console.error("HTTP响应状态:", error.response.status);
|
|
691
|
+
console.error("HTTP响应数据:", error.response.data);
|
|
692
|
+
}
|
|
693
|
+
const isNetworkError = error.code === "UND_ERR_CONNECT_TIMEOUT" || error.code === "UND_ERR_SOCKET" || error.message?.includes("fetch failed") || error.message?.includes("timeout") || error.message?.includes("network");
|
|
694
|
+
if (isNetworkError && attempt < maxRetries) {
|
|
695
|
+
console.log(`网络错误,${attempt < maxRetries ? "准备重试" : "重试次数已用完"}`);
|
|
696
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3 * attempt));
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
break;
|
|
676
700
|
}
|
|
677
|
-
const fallbackResponse = {
|
|
678
|
-
code: "ERROR",
|
|
679
|
-
message: `查询RADIUS系统失败: ${error.message || "未知错误,可能是网络连接问题"}`,
|
|
680
|
-
data: null
|
|
681
|
-
};
|
|
682
|
-
return fallbackResponse;
|
|
683
701
|
}
|
|
702
|
+
console.error("RADIUS查询最终失败,所有重试已用完");
|
|
703
|
+
let errorMessage = "查询RADIUS系统失败";
|
|
704
|
+
if (lastError?.code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
705
|
+
errorMessage = "RADIUS服务器连接超时,请检查网络连接或服务器状态";
|
|
706
|
+
} else if (lastError?.code === "UND_ERR_SOCKET") {
|
|
707
|
+
errorMessage = "RADIUS服务器网络连接失败,请检查网络配置";
|
|
708
|
+
} else if (lastError?.message?.includes("fetch failed")) {
|
|
709
|
+
errorMessage = "RADIUS服务器请求失败,可能是网络问题或服务器不可达";
|
|
710
|
+
} else if (lastError?.response?.status) {
|
|
711
|
+
errorMessage = `RADIUS服务器返回错误状态码: ${lastError.response.status}`;
|
|
712
|
+
} else {
|
|
713
|
+
errorMessage = `RADIUS查询失败: ${lastError?.message || "未知错误"}`;
|
|
714
|
+
}
|
|
715
|
+
const fallbackResponse = {
|
|
716
|
+
code: "ERROR",
|
|
717
|
+
message: errorMessage,
|
|
718
|
+
data: null
|
|
719
|
+
};
|
|
720
|
+
return fallbackResponse;
|
|
684
721
|
});
|
|
685
722
|
}
|
|
686
723
|
__name(queryRadiusUser, "queryRadiusUser");
|
|
@@ -1101,7 +1138,7 @@ function apply(ctx, config) {
|
|
|
1101
1138
|
);
|
|
1102
1139
|
} else if (accountInfo.onlineStatus === "离线" && accountInfo.isPass === "原因未知") {
|
|
1103
1140
|
message.push(
|
|
1104
|
-
|
|
1141
|
+
`未检索到该账号的拨号记录⚠️`,
|
|
1105
1142
|
`请尝试重新拨号或检查ONU配置和账号是否正确!`
|
|
1106
1143
|
);
|
|
1107
1144
|
} else if (accountInfo.onlineStatus === "离线" || accountInfo.onlineStatus === "不在线") {
|
|
@@ -1583,6 +1620,47 @@ function apply(ctx, config) {
|
|
|
1583
1620
|
const result = clearCache();
|
|
1584
1621
|
return formatOutputMessage(`✅ ${result}`);
|
|
1585
1622
|
});
|
|
1623
|
+
async function diagnoseNetwork() {
|
|
1624
|
+
const results = [];
|
|
1625
|
+
results.push("🌐 网络连接诊断");
|
|
1626
|
+
results.push(getSeparator());
|
|
1627
|
+
try {
|
|
1628
|
+
const radiusUrl = new URL(config.radiusApiUrl || "http://111.208.114.248:28210/api/radius");
|
|
1629
|
+
const host = radiusUrl.hostname;
|
|
1630
|
+
const port = radiusUrl.port || "80";
|
|
1631
|
+
results.push(`RADIUS服务器: ${host}:${port}`);
|
|
1632
|
+
try {
|
|
1633
|
+
const startTime = Date.now();
|
|
1634
|
+
const response = await ctx.http.get(`${config.radiusApiUrl}/health`, {
|
|
1635
|
+
timeout: 5e3,
|
|
1636
|
+
validateStatus: /* @__PURE__ */ __name(() => true, "validateStatus")
|
|
1637
|
+
// 接受任何状态码
|
|
1638
|
+
});
|
|
1639
|
+
const endTime = Date.now();
|
|
1640
|
+
const latency = endTime - startTime;
|
|
1641
|
+
results.push(`✅ 连接正常 (延迟: ${latency}ms)`);
|
|
1642
|
+
results.push(` 状态码: ${response.status || "N/A"}`);
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
results.push(`❌ 连接失败`);
|
|
1645
|
+
if (error.code === "UND_ERR_CONNECT_TIMEOUT") {
|
|
1646
|
+
results.push(` 原因: 连接超时`);
|
|
1647
|
+
} else if (error.code === "UND_ERR_SOCKET") {
|
|
1648
|
+
results.push(` 原因: 网络连接失败`);
|
|
1649
|
+
} else {
|
|
1650
|
+
results.push(` 原因: ${error.message || "未知错误"}`);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
results.push("");
|
|
1654
|
+
results.push("📋 当前配置");
|
|
1655
|
+
results.push(`RADIUS API地址: ${config.radiusApiUrl || "未配置"}`);
|
|
1656
|
+
results.push(`运维系统地址: ${config.baseUrl || "未配置"}`);
|
|
1657
|
+
} catch (error) {
|
|
1658
|
+
results.push(`❌ 诊断过程出错: ${error.message}`);
|
|
1659
|
+
}
|
|
1660
|
+
results.push(getSeparator());
|
|
1661
|
+
return results.join("\n");
|
|
1662
|
+
}
|
|
1663
|
+
__name(diagnoseNetwork, "diagnoseNetwork");
|
|
1586
1664
|
function getSystemStatus() {
|
|
1587
1665
|
updateCacheStats();
|
|
1588
1666
|
const hitRate = cacheStats.hits + cacheStats.misses > 0 ? Math.round(cacheStats.hits / (cacheStats.hits + cacheStats.misses) * 100) : 0;
|
|
@@ -1612,6 +1690,9 @@ function apply(ctx, config) {
|
|
|
1612
1690
|
ctx.command("系统状态").alias("/系统状态").action(async ({ session }) => {
|
|
1613
1691
|
return formatOutputMessage(getSystemStatus());
|
|
1614
1692
|
});
|
|
1693
|
+
ctx.command("网络诊断").alias("/网络诊断").action(async ({ session }) => {
|
|
1694
|
+
return formatOutputMessage(await diagnoseNetwork());
|
|
1695
|
+
});
|
|
1615
1696
|
ctx.command("使用说明", "显示插件的使用方法和命令说明").alias("/使用说明").action(async ({ session }) => {
|
|
1616
1697
|
const helpText = [
|
|
1617
1698
|
"📋 JSCN小帮手使用说明",
|
|
@@ -1655,6 +1736,19 @@ function apply(ctx, config) {
|
|
|
1655
1736
|
" 示例:",
|
|
1656
1737
|
" 输入 GDC8510019239048 → 触发账号查询",
|
|
1657
1738
|
" 输入 00:11:22:33:44:55 → 触发终端查询",
|
|
1739
|
+
"",
|
|
1740
|
+
"6. 系统管理",
|
|
1741
|
+
" 命令:系统状态",
|
|
1742
|
+
" 功能:查看系统运行状态、缓存统计、队列状态等。",
|
|
1743
|
+
"",
|
|
1744
|
+
" 命令:网络诊断",
|
|
1745
|
+
" 功能:诊断RADIUS服务器网络连接状态,帮助排查连接问题。",
|
|
1746
|
+
"",
|
|
1747
|
+
" 命令:缓存统计",
|
|
1748
|
+
" 功能:查看缓存使用情况和命中率统计。",
|
|
1749
|
+
"",
|
|
1750
|
+
" 命令:清理缓存",
|
|
1751
|
+
" 功能:清理所有缓存数据。",
|
|
1658
1752
|
getSeparator()
|
|
1659
1753
|
].join("\n");
|
|
1660
1754
|
return formatOutputMessage(helpText);
|