koishi-plugin-jscn-aaaquery 1.0.2 → 1.0.3
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.d.ts +1 -0
- package/lib/index.js +207 -75
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -28,9 +28,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
28
|
var import_koishi = require("koishi");
|
|
29
29
|
var name = "jscn-aaaquery";
|
|
30
30
|
var Config = import_koishi.Schema.object({
|
|
31
|
-
loginName: import_koishi.Schema.string().required().description("运维系统登录账号"),
|
|
32
|
-
password: import_koishi.Schema.string().required().description("运维系统登录密码"),
|
|
33
|
-
baseUrl: import_koishi.Schema.string().default("http://172.16.251.75:8090/nms/api").description("运维系统API地址")
|
|
31
|
+
loginName: import_koishi.Schema.string().required().description("运维系统登录账号").default("admin"),
|
|
32
|
+
password: import_koishi.Schema.string().required().description("运维系统登录密码").default("admin"),
|
|
33
|
+
baseUrl: import_koishi.Schema.string().default("http://172.16.251.75:8090/nms/api").description("运维系统API地址"),
|
|
34
|
+
// 添加RADIUS API的配置项
|
|
35
|
+
radiusApiUrl: import_koishi.Schema.string().description("RADIUS API基础URL").default("http://111.208.114.248:28210/api/radius")
|
|
34
36
|
});
|
|
35
37
|
function apply(ctx, config) {
|
|
36
38
|
let currentToken = null;
|
|
@@ -203,7 +205,7 @@ function apply(ctx, config) {
|
|
|
203
205
|
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
204
206
|
if (response.status === 200 && response.data) {
|
|
205
207
|
if (!isAccountResponseComplete(response.data)) {
|
|
206
|
-
throw new Error("
|
|
208
|
+
throw new Error("账号信息有误,请检查账号是否正确");
|
|
207
209
|
}
|
|
208
210
|
setCache("account", { account: formattedAccount }, response.data);
|
|
209
211
|
return response.data;
|
|
@@ -486,82 +488,168 @@ function apply(ctx, config) {
|
|
|
486
488
|
});
|
|
487
489
|
}
|
|
488
490
|
__name(queryOrderLog, "queryOrderLog");
|
|
489
|
-
|
|
490
|
-
const
|
|
491
|
-
if (
|
|
492
|
-
|
|
491
|
+
async function queryRadiusUser(account) {
|
|
492
|
+
const cachedData = getFromCache("radiusUser", { account });
|
|
493
|
+
if (cachedData) {
|
|
494
|
+
console.log("使用缓存的RADIUS用户信息");
|
|
495
|
+
return cachedData;
|
|
493
496
|
}
|
|
494
|
-
|
|
495
|
-
console.log("处理后的内容:", cleanInput);
|
|
496
|
-
if (isValidMacAddress(cleanInput)) {
|
|
497
|
+
return addToQueue("radiusUser", { account }, async () => {
|
|
497
498
|
try {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
`CCName: ${ccname}`,
|
|
519
|
-
"",
|
|
520
|
-
"📝 工单信息",
|
|
521
|
-
"--------------------------------",
|
|
522
|
-
order ? [
|
|
523
|
-
`工单编号: ${order.orderId}`,
|
|
524
|
-
`创建时间: ${order.createDate}`,
|
|
525
|
-
`更新时间: ${order.updateDate}`
|
|
526
|
-
].join("\n") : "无工单信息",
|
|
527
|
-
"",
|
|
528
|
-
"🔧 业务配置信息",
|
|
529
|
-
"--------------------------------"
|
|
530
|
-
];
|
|
531
|
-
vlanInfo.forEach((info) => {
|
|
532
|
-
messages.push(
|
|
533
|
-
`端口 ${info.LAN}:`,
|
|
534
|
-
` VLAN: ${info.actualVlan}`
|
|
535
|
-
);
|
|
536
|
-
});
|
|
537
|
-
return messages.join("\n");
|
|
499
|
+
console.log("开始查询RADIUS用户信息...");
|
|
500
|
+
const response = await ctx.http.post(
|
|
501
|
+
`${config.radiusApiUrl}/userquery`,
|
|
502
|
+
{
|
|
503
|
+
login_name: account,
|
|
504
|
+
org_code: "403",
|
|
505
|
+
// 固定值
|
|
506
|
+
channel: "ALL"
|
|
507
|
+
// 固定值
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
headers: {
|
|
511
|
+
"Content-Type": "application/json",
|
|
512
|
+
"Accept": "application/json"
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
517
|
+
setCache("radiusUser", { account }, response);
|
|
518
|
+
return response;
|
|
538
519
|
} catch (error) {
|
|
539
|
-
console.error("
|
|
540
|
-
|
|
520
|
+
console.error("查询RADIUS用户错误详情:", error);
|
|
521
|
+
if (error.response) {
|
|
522
|
+
console.error("错误响应:", error.response.data);
|
|
523
|
+
}
|
|
524
|
+
throw error;
|
|
541
525
|
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
return
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
__name(queryRadiusUser, "queryRadiusUser");
|
|
529
|
+
function formatRadiusTime(timeString) {
|
|
530
|
+
if (!timeString || timeString.length < 14) return "未知时间";
|
|
531
|
+
const year = timeString.substring(0, 4);
|
|
532
|
+
const month = timeString.substring(4, 6);
|
|
533
|
+
const day = timeString.substring(6, 8);
|
|
534
|
+
const hour = timeString.substring(8, 10);
|
|
535
|
+
const minute = timeString.substring(10, 12);
|
|
536
|
+
const second = timeString.substring(12, 14);
|
|
537
|
+
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
538
|
+
}
|
|
539
|
+
__name(formatRadiusTime, "formatRadiusTime");
|
|
540
|
+
function translateOrderStatus(status) {
|
|
541
|
+
switch (status) {
|
|
542
|
+
case "active":
|
|
543
|
+
return "有效";
|
|
544
|
+
case "inactive":
|
|
545
|
+
return "无效";
|
|
546
|
+
case "suspend":
|
|
547
|
+
return "暂停";
|
|
548
|
+
default:
|
|
549
|
+
return status;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
__name(translateOrderStatus, "translateOrderStatus");
|
|
553
|
+
function translateUserStatus(status) {
|
|
554
|
+
switch (status) {
|
|
555
|
+
case "active":
|
|
556
|
+
return "正常";
|
|
557
|
+
case "inactive":
|
|
558
|
+
return "停用";
|
|
559
|
+
case "suspend":
|
|
560
|
+
return "暂停";
|
|
561
|
+
default:
|
|
562
|
+
return status;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
__name(translateUserStatus, "translateUserStatus");
|
|
566
|
+
ctx.middleware(async (session, next) => {
|
|
567
|
+
console.log("原始消息:", session.content);
|
|
568
|
+
const input = session.content.trim();
|
|
569
|
+
console.log("接收到消息:", input);
|
|
570
|
+
try {
|
|
571
|
+
if (input.includes(" ") || /[\u4e00-\u9fa5]/.test(input)) {
|
|
572
|
+
console.log("消息包含空格或中文,跳过智能查询");
|
|
573
|
+
return next();
|
|
574
|
+
}
|
|
575
|
+
const cleanInput = formatMacAddress(input);
|
|
576
|
+
console.log("处理后的内容:", cleanInput);
|
|
577
|
+
if (isValidMacAddress(cleanInput)) {
|
|
578
|
+
console.log("内容是合法的MAC地址,开始查询");
|
|
579
|
+
try {
|
|
580
|
+
const onuList = await queryOnuList(cleanInput);
|
|
581
|
+
if (!onuList) {
|
|
582
|
+
return "未找到该MAC地址的设备信息";
|
|
583
|
+
}
|
|
584
|
+
const onuDetail = await queryOnuDetailInfo(onuList.id);
|
|
585
|
+
const ccname = await queryCCName(cleanInput);
|
|
586
|
+
const order = await queryOnuOrder(onuDetail);
|
|
587
|
+
const vlanInfo = await queryOnuDetailVlanInfo(onuList.id);
|
|
588
|
+
const messages = [
|
|
589
|
+
"📊 终端基本信息",
|
|
590
|
+
"--------------------------------",
|
|
591
|
+
`MAC地址: ${cleanInput}`,
|
|
592
|
+
`状态:${onuDetail.status === 1 ? "在线" : "不在线"}`,
|
|
593
|
+
`机房: ${onuDetail.roomName}`,
|
|
594
|
+
`设备名称: ${onuDetail.deviceName}`,
|
|
595
|
+
`OLT IP: ${onuDetail.oltIp}`,
|
|
596
|
+
`PON端口: ${onuDetail.portName}`,
|
|
597
|
+
`端口逻辑号: ${onuDetail.logicId}`,
|
|
598
|
+
`发射光功率: ${onuDetail.onuSendPower}dBm`,
|
|
599
|
+
`接收光功率: ${onuDetail.onuReceivePower}dBm`,
|
|
600
|
+
`CCName: ${ccname}`,
|
|
601
|
+
"",
|
|
602
|
+
"📝 工单信息",
|
|
603
|
+
"--------------------------------",
|
|
604
|
+
order ? [
|
|
605
|
+
`工单编号: ${order.orderId}`,
|
|
606
|
+
`创建时间: ${order.createDate}`,
|
|
607
|
+
`更新时间: ${order.updateDate}`
|
|
608
|
+
].join("\n") : "无工单信息",
|
|
609
|
+
"",
|
|
610
|
+
"🔧 业务配置信息",
|
|
611
|
+
"--------------------------------"
|
|
612
|
+
];
|
|
613
|
+
vlanInfo.forEach((info) => {
|
|
614
|
+
messages.push(
|
|
615
|
+
`端口 ${info.LAN}:`,
|
|
616
|
+
` VLAN: ${info.actualVlan}`
|
|
617
|
+
);
|
|
618
|
+
});
|
|
619
|
+
return messages.join("\n");
|
|
620
|
+
} catch (error) {
|
|
621
|
+
console.error("查询MAC地址过程出错:", error);
|
|
622
|
+
return "查询失败,请稍后重试";
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
console.log("内容不是MAC地址,尝试作为账号查询");
|
|
626
|
+
try {
|
|
627
|
+
const accountInfo = await queryAccount(input);
|
|
628
|
+
const message = [
|
|
629
|
+
"📊 账号查询结果",
|
|
630
|
+
"--------------------------------",
|
|
631
|
+
`账号: ${accountInfo.accessUserName}`,
|
|
632
|
+
`状态: ${accountInfo.onlineStatus}`,
|
|
633
|
+
`认证: ${accountInfo.isPass}`,
|
|
634
|
+
`IP地址: ${accountInfo.userIp}`,
|
|
635
|
+
`MAC地址: ${accountInfo.mac}`,
|
|
636
|
+
`最大上行: ${accountInfo.maxUpSpeed}Mbps`,
|
|
637
|
+
`最大下行: ${accountInfo.maxDownSpeed}Mbps`,
|
|
638
|
+
`接入域: ${accountInfo.accessDomain}`,
|
|
639
|
+
`开始时间: ${accountInfo.startTime}`,
|
|
640
|
+
`在线时长: ${accountInfo.startTimeSum}分钟`,
|
|
641
|
+
`设备名称: ${accountInfo.nickName}`
|
|
642
|
+
].join("\n");
|
|
643
|
+
return message;
|
|
644
|
+
} catch (error) {
|
|
645
|
+
console.error("查询账号过程出错:", error);
|
|
646
|
+
console.log("账号查询失败,交给其他中间件处理");
|
|
647
|
+
return next();
|
|
648
|
+
}
|
|
564
649
|
}
|
|
650
|
+
} catch (error) {
|
|
651
|
+
console.error("智能查询过程出错:", error);
|
|
652
|
+
return next();
|
|
565
653
|
}
|
|
566
654
|
});
|
|
567
655
|
ctx.command("账号查询 <account:string>", "查询宽带账号状态").action(async (_, account) => {
|
|
@@ -831,6 +919,50 @@ function apply(ctx, config) {
|
|
|
831
919
|
return "查询失败,请稍后重试";
|
|
832
920
|
}
|
|
833
921
|
});
|
|
922
|
+
ctx.command("用户查询 <account:string>", "查询RADIUS用户信息").action(async (_, account) => {
|
|
923
|
+
if (!account) return "请输入要查询的账号";
|
|
924
|
+
try {
|
|
925
|
+
const radiusUserInfo = await queryRadiusUser(account);
|
|
926
|
+
if (radiusUserInfo.code !== "000000" || !radiusUserInfo.data) {
|
|
927
|
+
return `查询失败: ${radiusUserInfo.message || "未知错误"}`;
|
|
928
|
+
}
|
|
929
|
+
const { user, orders } = radiusUserInfo.data;
|
|
930
|
+
const messages = [
|
|
931
|
+
"📊 RADIUS用户信息",
|
|
932
|
+
"--------------------------------",
|
|
933
|
+
`账号: ${user.login_name}`,
|
|
934
|
+
`密码: ${user.password}`,
|
|
935
|
+
`状态: ${translateUserStatus(user.user_status)}`,
|
|
936
|
+
`漫游状态: ${user.roam_status === "0" ? "允许漫游" : "禁止漫游"}`,
|
|
937
|
+
`分公司标识: ${user.org_code}`,
|
|
938
|
+
`BOSS分公司标识: ${user.boss_org_code}`,
|
|
939
|
+
`用户VLAN: ${user.user_vlan}`,
|
|
940
|
+
"",
|
|
941
|
+
"📝 订购信息",
|
|
942
|
+
"--------------------------------"
|
|
943
|
+
];
|
|
944
|
+
if (orders && orders.length > 0) {
|
|
945
|
+
orders.forEach((order, index) => {
|
|
946
|
+
messages.push(
|
|
947
|
+
`订购 #${index + 1}:`,
|
|
948
|
+
` 订购序列号: ${order.order_id}`,
|
|
949
|
+
` 订购状态: ${translateOrderStatus(order.order_status)}`,
|
|
950
|
+
` 服务名称: ${order.service_name}`,
|
|
951
|
+
` 并发数: ${order.online_num}`,
|
|
952
|
+
` 生效时间: ${formatRadiusTime(order.valid_date)}`,
|
|
953
|
+
` 失效时间: ${formatRadiusTime(order.expire_date)}`,
|
|
954
|
+
""
|
|
955
|
+
);
|
|
956
|
+
});
|
|
957
|
+
} else {
|
|
958
|
+
messages.push("无订购信息");
|
|
959
|
+
}
|
|
960
|
+
return messages.join("\n");
|
|
961
|
+
} catch (error) {
|
|
962
|
+
console.error("查询过程出错:", error);
|
|
963
|
+
return error.message || "查询失败,请稍后重试";
|
|
964
|
+
}
|
|
965
|
+
});
|
|
834
966
|
}
|
|
835
967
|
__name(apply, "apply");
|
|
836
968
|
// Annotate the CommonJS export names for ESM import in node:
|