From 3eaf7afcf5f2aa05221d06cb2800d4f093822a7a Mon Sep 17 00:00:00 2001 From: Egor Date: Tue, 23 Jan 2024 12:38:25 +0200 Subject: [PATCH] add irccloud authentication lua script --- lua/init.lua | 3 +++ lua/irccloud.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/irc.c | 3 +++ 3 files changed, 57 insertions(+) create mode 100644 lua/irccloud.lua diff --git a/lua/init.lua b/lua/init.lua index d71d3d9..004fde6 100644 --- a/lua/init.lua +++ b/lua/init.lua @@ -43,6 +43,7 @@ local function fold_sendtox(a, b) end hook_setfold("sendtochannel", fold_sendtox) hook_setfold("sendtoclient", fold_sendtox) +hook_setfold("newuser", fold_sendtox) function commands.echo(client, source, command, args) client_notice(client, "client = "..tostring(client)) @@ -125,3 +126,5 @@ function commands.spam(client, source, command, args) client_notice(client, "new spam protection level: "..tostring(spamlevel)) end end + +dofile "lua/irccloud.lua" diff --git a/lua/irccloud.lua b/lua/irccloud.lua new file mode 100644 index 0000000..e2cd4cf --- /dev/null +++ b/lua/irccloud.lua @@ -0,0 +1,51 @@ +-- irccloud authentication support +local function parseipv6(s) + if not s:match("^[0-9a-fA-F:]*") then + return nil + end + local part1 = {} + local part2 = {} + local part = part1 + local i = 1 + repeat + local j = s:find(":", i, true) or 0 + local sub = s:sub(i, j-1) + if sub == "" then + part = part2 + else + part[#part + 1] = sub + end + i = j + 1 + until i == 1 + local c = {} + for i = 1, 8 do + if i <= #part1 then + c[i] = tonumber(part1[i], 16) + elseif i + #part2 - 8 >= 1 then + c[i] = tonumber(part2[i + #part2 - 8], 16) + else + c[i] = 0 + end + end + local netid = c[1]<<48 | c[2]<<32 | c[3]<<16 | c[4] + local ifaceid = c[5]<<48 | c[6]<<32 | c[7]<<16 | c[8] + return netid, ifaceid +end + +local function isirccloudnetwork(netid) + -- https://www.irccloud.com/networks + -- 2a03:5180:f::/62, 2a03:5180:f:4::/63, 2a03:5180:f:6::/64 + return netid >= 0x2a035180000f0000 and netid <= 0x2a035180000f0006 +end + +local uidmap = { + [635723] = "samson", +} + +hook_add("newuser", "irccloud_auth", function(hook, cl1, cl2, chan, txt) + local netid, ifaceid = parseipv6(cl1.peername) + print(netid, ifaceid) + if netid and isirccloudnetwork(netid) and uidmap[ifaceid] then + client_chghost(cl1, uidmap[ifaceid], cl1.hostname) + end +end) diff --git a/src/irc.c b/src/irc.c index 43a90ef..c86e01a 100644 --- a/src/irc.c +++ b/src/irc.c @@ -1248,6 +1248,9 @@ void newUser(struct client_data *client) { sendLUSERS(client); rpl_umodeis(client), sendbuf(client); sendMOTD(client); +#ifdef HAS_LUA + admin_hook("newuser", client, 0, 0, 0); +#endif // send CTCP VERSION and CTCP TIME msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1VERSION\1"), sendbuf(client); msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1TIME\1"), sendbuf(client); -- 2.56.0