Fixing the logic for draft/account-registration=before-connect #7
@ -5,72 +5,55 @@ import os
|
|||||||
webircpass = os.getenv("WEBIRC_PASS")
|
webircpass = os.getenv("WEBIRC_PASS")
|
||||||
|
|
||||||
def ircregister(userip, username, password, email="*"):
|
def ircregister(userip, username, password, email="*"):
|
||||||
|
|
||||||
d = irctokens.StatefulDecoder()
|
d = irctokens.StatefulDecoder()
|
||||||
e = irctokens.StatefulEncoder()
|
e = irctokens.StatefulEncoder()
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
|
|
||||||
|
|
||||||
# Here we assume using this only on localhost i.e. loopback
|
# Here we assume using this only on localhost i.e. loopback
|
||||||
s.connect(("127.0.0.1", 6667))
|
s.connect(("127.0.0.1", 6667))
|
||||||
|
|
||||||
# define the send function
|
|
||||||
def _send(line):
|
def _send(line):
|
||||||
print(f"> {line.format()}")
|
print(f"> {line.format()}")
|
||||||
e.push(line)
|
e.push(line)
|
||||||
while e.pending():
|
while e.pending():
|
||||||
e.pop(s.send(e.pending()))
|
e.pop(s.send(e.pending()))
|
||||||
|
|
||||||
# Registering connection
|
|
||||||
|
|
||||||
# WEBIRC
|
|
||||||
_send(irctokens.build("WEBIRC", [ webircpass, "WebregGateway", userip, userip, "secure"]))
|
_send(irctokens.build("WEBIRC", [ webircpass, "WebregGateway", userip, userip, "secure"]))
|
||||||
|
|
||||||
# Check for "ERROR :Invalid WebIRC password"
|
|
||||||
# Should all of this this be under a try except block?
|
|
||||||
lines = d.push(s.recv(1024))
|
lines = d.push(s.recv(1024))
|
||||||
if lines == None:
|
if lines == None:
|
||||||
print("!disconnected")
|
print("!disconnected")
|
||||||
return "disconnected"
|
return "disconnected"
|
||||||
elif lines.command == "ERROR" and lines.params == "Invalid WebIRC password":
|
elif lines.command == "ERROR" and lines.params == "Invalid WebIRC password":
|
||||||
return "WebIRC bad password"
|
return "WebIRC bad password"
|
||||||
|
|
||||||
# Inform the server that we support
|
|
||||||
# CAP 3.2
|
|
||||||
_send(irctokens.build("CAP", ["LS", "302"]))
|
_send(irctokens.build("CAP", ["LS", "302"]))
|
||||||
|
while True:
|
||||||
|
lines = d.push(s.recv(1024))
|
||||||
|
if lines == None:
|
||||||
|
print("! disconnected")
|
||||||
|
break
|
||||||
|
for line in lines:
|
||||||
|
print(f"< {line.format()}")
|
||||||
# REGISTER can be attempted before-connect if server supports
|
# REGISTER can be attempted before-connect if server supports
|
||||||
# but if the server responds with the corresponding FAIL we
|
# but if the server responds with the corresponding FAIL we
|
||||||
# need to try again. We can also handle email-required using
|
# need to try again. We can also handle email-required using
|
||||||
# the same keys. How to access these key-value pairs?
|
# the same keys. How to access these key-value pairs?
|
||||||
# reference: https://ircv3.net/specs/extensions/account-registration.html
|
# reference: https://ircv3.net/specs/extensions/account-registration.html
|
||||||
|
# do we handle if email-req but not before-connect
|
||||||
# NICK and USER
|
# also how about when `custom-account-name` may be a value
|
||||||
_send(irctokens.build("USER", ["u", "0", "*", username]))
|
if 'draft/account-registration=before-connect' in line.params:
|
||||||
_send(irctokens.build("NICK", [username]))
|
|
||||||
|
|
||||||
# go through all cases
|
|
||||||
|
|
||||||
while True:
|
|
||||||
for line in lines:
|
|
||||||
print(f"< {line.format()}")
|
|
||||||
if line.command == "432":
|
|
||||||
return "ERR_ERRONEUSNICKNAME"
|
|
||||||
elif line.command == "433":
|
|
||||||
return "ERR_NICKNAMEINUSE"
|
|
||||||
_send(irctokens.build("CAP", ["REQ", "draft/account-registration"]))
|
_send(irctokens.build("CAP", ["REQ", "draft/account-registration"]))
|
||||||
if line.command == "CAP" and ("NAK" in line.params):
|
if line.command == "CAP" and ("NAK" in line.params):
|
||||||
return "CAP_REFUSED"
|
return "CAP_REFUSED"
|
||||||
elif line.command == "CAP" and ("ACK" in line.params):
|
elif line.command == "CAP" and ("ACK" in line.params):
|
||||||
to_send = irctokens.build("CAP", ["END"])
|
_send(irctokens.build("CAP", ["END"]))
|
||||||
_send(to_send)
|
_send(irctokens.build("USER", ["u", "0", "*", username]))
|
||||||
if line.command == "PING":
|
_send(irctokens.build("NICK", [username]))
|
||||||
to_send = irctokens.build("PONG", [line.params[0]])
|
if line.command == "432":
|
||||||
_send(to_send)
|
return "ERR_ERRONEUSNICKNAME"
|
||||||
if line.command == "001":
|
if line.command == "433":
|
||||||
# assuming no verif reqd.
|
return "ERR_NICKNAMEINUSE"
|
||||||
to_send = irctokens.build("REGISTER", ["*", email, password])
|
_send(irctokens.build("REGISTER", [username, "*", password]))
|
||||||
_send(to_send)
|
|
||||||
if line.command == "REGISTER" and ("SUCCESS" in line.params):
|
if line.command == "REGISTER" and ("SUCCESS" in line.params):
|
||||||
to_send = irctokens.build("QUIT")
|
_send(irctokens.build("QUIT"))
|
||||||
_send(to_send)
|
|
||||||
return "SUCCESS"
|
return "SUCCESS"
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
click==8.0.1
|
|
||||||
Flask==2.0.1
|
|
||||||
Flask-WTF==0.15.1
|
|
||||||
gunicorn==20.1.0
|
|
||||||
irctokens==2.0.0
|
|
||||||
itsdangerous==2.0.1
|
|
||||||
Jinja2==3.0.1
|
|
||||||
MarkupSafe==2.0.1
|
|
||||||
Werkzeug==2.0.1
|
|
||||||
WTForms==2.3.3
|
|
Loading…
Reference in New Issue
Block a user