-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
111 lines (98 loc) · 3.96 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { ServerToServerClient, User, generateUID } from "unrealircd-s2s-client";
let sid = "999";
let client = new ServerToServerClient({
port: 6900,
host: "tor1.ca.crxb.cc",
hostname: "test.dev.crxb.cc",
authMethod: "spkifp",
sid: sid,
keyPath: "./key.pem",
certPath: "./cert.pem",
tlsOptions: { rejectUnauthorized: false },
});
client.onRaw = (raw) => {
console.log(raw);
};
let AuthServUID = generateUID(sid);
let AuthServ: User = {
nickname: "AuthServ",
hopcount: 0,
username: "AuthServ",
timestamp: Math.floor(Date.now() / 1000),
hostname: "127.0.0.1",
uid: AuthServUID,
usermodes: "qrtwzBSZ",
servicestamp: "*",
virtualhost: "test.dev.crxb.cc",
cloakedhost: "test.dev.crxb.cc",
ip: btoa("\x7F\x00\x00\x01"),
gecos: "AuthServ",
memberships: { "#services": { uid: AuthServUID, prefix: "*" } },
};
client.onSync = () => {
client.registerUser(AuthServ);
client.sendMessage(AuthServ.uid, "#services", "Hello, World!");
};
let approvedFingerprints: string[] = [];
client.onMessage = (from, to, message) => {
let source = client.users[from] || client.usersByNick[from];
if (!source) {
source = client.serverToUser(client.servers[from]);
}
if (to === "#services") {
if (message.startsWith("approve")) {
let [_, nickname] = message.split(" ");
let user = client.usersByNick[nickname];
if (!user && nickname.length > 40) {
approvedFingerprints.push(nickname);
client.sendMessage(AuthServ.uid, source.uid, `Fingerprint ${nickname} approved.`);
return;
} else if (!user) {
client.sendMessage(AuthServ.uid, source.uid, `User ${nickname} not found or invalid CertFP.`);
return;
}
if (!user.moddata?.certfp) {
client.sendMessage(AuthServ.uid, source.uid, `User ${nickname} does not have a certificate fingerprint.`);
return;
}
approvedFingerprints.push(user.moddata.certfp);
client.sendMessage(AuthServ.uid, "#services", `User ${nickname} approved.`);
client.sendMessage(AuthServ.uid, user.uid, `You have been approved by ${source.nickname}.`);
}
}
if (to === AuthServ.uid || to === AuthServ.nickname) {
if (message.startsWith("certfp")) {
let certfp = source.moddata?.certfp;
if (!certfp) {
client.sendMessage(AuthServ.uid, source.uid, "You do not have a certificate fingerprint.");
return;
}
client.sendMessage(AuthServ.uid, source.uid, `Your certificate fingerprint is: ${certfp}`);
}
if (message.startsWith("register")) {
let certfp = source.moddata?.certfp;
if (!certfp) {
client.sendMessage(AuthServ.uid, source.uid, "You do not have a certificate fingerprint.");
return;
}
client.sendMessage(AuthServ.uid, "#services", `${source.nickname} Requests approval for fingerprint ${certfp}`);
client.sendMessage(AuthServ.uid, source.uid, "Your request has been sent.");
}
if (message.startsWith("identify")) {
let certfp = source.moddata?.certfp;
if (!certfp) {
client.sendMessage(AuthServ.uid, source.uid, "You do not have a certificate fingerprint.");
return;
}
if (approvedFingerprints.includes(certfp)) {
client.write(`SVSMODE ${source.uid} +r`);
client.sendMessage(AuthServ.uid, "#services", `${source.nickname} has successfully authenticated.`);
client.sendMessage(AuthServ.uid, source.uid, "You are now identified.");
} else {
client.sendMessage(AuthServ.uid, source.uid, "You are not approved.");
}
}
console.log(`<${source.nickname}> ${message}`);
}
};
client.connect();