-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathathemesasl.py
More file actions
32 lines (25 loc) · 1.05 KB
/
athemesasl.py
File metadata and controls
32 lines (25 loc) · 1.05 KB
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
import base64
import os
import znc
class athemesasl(znc.Module):
module_types = [znc.CModInfo.UserModule]
def __init__(self):
self.description = "Atheme SASL"
def OnServerCapAvailable(self, scap):
self.cookie = self.getCookie()
self.username = self.GetUser().GetUserName()
return scap == "sasl"
def OnServerCapResult(self, scap, success):
if scap == "sasl":
if success:
self.PutIRC("AUTHENTICATE AUTHCOOKIE")
self.PutIRC("AUTHENTICATE " +
self.makeSaslAuthString(self.username, self.cookie))
self.PutUser(":bnc.{} NOTICE * :*** Authenticated over Atheme XMLRPC".format(os.getenv("IRC_NETWORK_DOMAIN")))
def makeSaslAuthString(self, username, cookie):
return (base64.b64encode(bytes("%s\0%s\0%s" %
(username, username, cookie), "utf-8"))).decode("utf-8")
def getCookie(self):
with open("/tmp/znc-cookie-%s" %
self.GetUser().GetUserName(), "r") as fin:
return fin.readline()