-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathathemeauth.py
More file actions
119 lines (89 loc) · 3.76 KB
/
athemeauth.py
File metadata and controls
119 lines (89 loc) · 3.76 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
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
112
113
114
115
116
117
118
119
from xmlrpc.client import ServerProxy, Fault
import os
import znc
class Atheme:
def __init__(self, url):
self.url = url
self.proxy = ServerProxy(url)
self.cookie = "*"
self.username = "*"
self._privset = None
def login(self, username, password):
self.username = username
self.cookie = self.proxy.atheme.login(username, password)
self.privs()
def privs(self):
if self._privset is not None:
return self._privset
self._privset = self.proxy.atheme.privset(self.cookie, self.username).split()
return self._privset
class athemeauth(znc.Module):
module_types = [znc.CModInfo.GlobalModule]
def __init__(self):
pass
def OnLoginAttempt(self, auth):
username = auth.GetUsername()
password = auth.GetPassword()
atheme = Atheme("http://{}/xmlrpc".format(os.environ.get("ATHEME_SERVER", "127.0.0.1:8069")))
user = znc.CZNC.Get().FindUser(username)
if user != None:
if user.GetPass() != "::":
#Allow normal ZNC accounts to log in
return znc.CONTINUE
else:
try:
atheme.login(username, password)
with open("/tmp/znc-cookie-%s" % username, "w") as fout:
fout.write(atheme.cookie)
auth.AcceptLogin(user)
user.thisown = 0
except Fault:
return znc.CONTINUE
try:
atheme.login(username, password)
except Fault:
return znc.CONTINUE
if user == None:
myuser = znc.CUser(username)
nname = os.getenv("IRC_NETWORK_NAME")
nhost = os.getenv("IRC_NETWORK_DOMAIN")
bncsname = os.getenv("BNC_HOSTNAME")
ircserver = os.getenv("IRC_SERVER")
ircport = os.getenv("IRC_PORT")
auth.GetSocket().Write(":{} NOTICE * :*** Creating account for {}...\r\n".format(bncsname, username))
auth.GetSocket().Write(":{} NOTICE * :*** Thank you for supporting {}!\r\n".format(bncsname, nname))
baseuser = znc.CZNC.Get().FindUser("scrub")
baseuser.thisown = 0
s = znc.String()
s.thisown = 0
if not myuser.Clone(baseuser, s, False):
print("WTF?", s)
return znc.CONTINUE
if not znc.CZNC.Get().AddUser(myuser, s):
print("WTF?", s)
return znc.CONTINUE
user = myuser
user.SetPass("::", znc.CUser.HASH_NONE, "::")
#this is a new user, set up stuff
user.SetNick(username)
user.SetAltNick(username + "`")
user.SetIdent(username[:8])
user.SetRealName("{} hosted bnc user {}".format(nname, username))
user.SetDenySetBindHost(True)
user.SetQuitMsg("Shutting down!")
user.SetMaxNetworks(1)
user.SetAdmin(False)
#They are going to want a network to talk on.
user.AddNetwork(nname, s)
network = user.FindNetwork(nname)
network.AddServer("{} {}".format(ircserver, ircport))
network.AddChan("#bnc", True)
network.JoinChans()
with open("/tmp/znc-cookie-%s" % username, "w") as fout:
fout.write(atheme.cookie)
znc.CZNC.Get().WriteConfig()
auth.GetSocket().Write(":{} NOTICE * :*** Welcome to the {} BNC {}!\r\n".format(bncsname, nname, username))
auth.GetSocket().Write(":{} NOTICE * :*** Your IP address is {} and may be checked for proxies.\r\n".format(bncsname, auth.GetRemoteIP()))
auth.AcceptLogin(user)
user.thisown = 0
return znc.HALT