]> PatchyGit - patchyircd.git/commitdiff
add irccloud authentication lua script
authorEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 10:38:25 +0000 (12:38 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 11:15:04 +0000 (13:15 +0200)
lua/init.lua
lua/irccloud.lua [new file with mode: 0644]
src/irc.c

index d71d3d9..004fde6 100644 (file)
@@ -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 (file)
index 0000000..e2cd4cf
--- /dev/null
@@ -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)
index 43a90ef..c86e01a 100644 (file)
--- 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);