aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Fincham <michael@hotplate.co.nz>2018-10-31 13:18:23 +1300
committerGitHub <noreply@github.com>2018-10-31 13:18:23 +1300
commitefb05b62f9644c9dbd73a07e3fa72953d9b9dae0 (patch)
tree89c64a7b7c7f26e0069b38000b1fa3749ddd151e
parent73f50c2255920ef6c042ae72d26229f53b8822df (diff)
downloadznc-python-imapauth-efb05b62f9644c9dbd73a07e3fa72953d9b9dae0.tar.gz
znc-python-imapauth-efb05b62f9644c9dbd73a07e3fa72953d9b9dae0.tar.bz2
znc-python-imapauth-efb05b62f9644c9dbd73a07e3fa72953d9b9dae0.zip
Create pyimapauth.py
-rw-r--r--pyimapauth.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/pyimapauth.py b/pyimapauth.py
new file mode 100644
index 0000000..7a632d4
--- /dev/null
+++ b/pyimapauth.py
@@ -0,0 +1,37 @@
+import imaplib
+
+import znc
+
+class catalystauth(znc.Module):
+ description = "Python IMAP authentication"
+ module_types = [znc.CModInfo.GlobalModule]
+
+ def OnLoginAttempt(self, auth):
+ username = auth.GetUsername()
+ password = auth.GetPassword()
+ imap_username = "%s@example.com" % username
+ connection = imaplib.IMAP4_SSL("mail.example.com")
+ try:
+ connection.login(imap_username, password)
+ except Exception as e:
+ auth.RefuseLogin("Catalyst authentication failed")
+ return znc.HALT
+ else:
+ connection.logout()
+
+ user = znc.CZNC.Get().FindUser(username)
+ if user is None:
+ template_user = znc.CZNC.Get().FindUser("template")
+ new_user = znc.CUser(username)
+ str_err = znc.String()
+ new_user.Clone(template_user, str_err)
+ new_user.SetNick(username)
+ new_user.SetAltNick(username)
+ new_user.SetIdent(username)
+ if znc.CZNC.Get().AddUser(new_user, str_err):
+ new_user.thisown = 0
+ auth.AcceptLogin(new_user)
+ else:
+ auth.AcceptLogin(user)
+
+ return znc.HALT