Improve authentication detection

Add a negative check in the event we are authenticated and registered,
but not confirmed, as this fools other checks.
This commit is contained in:
2020-10-31 16:49:37 +00:00
parent bdb3d059e3
commit 45f02c323b
6 changed files with 125 additions and 31 deletions

View File

@@ -160,6 +160,7 @@ class IRCBot(IRCClient):
self.servername = None
self._regAttempt = None
self._negativePass = None
def lineReceived(self, line):
if bytes != str and isinstance(line, bytes):
@@ -167,7 +168,6 @@ class IRCBot(IRCClient):
line = line.decode("utf-8", "replace")
line = lowDequote(line)
trace(self.net, self.num, line)
try:
prefix, command, params = parsemsg(line)
if command in numeric_to_symbolic:
@@ -618,14 +618,46 @@ class IRCBot(IRCClient):
self.topicUpdated(prefix, channel, newtopic)
# End of Twisted hackery
def regPing(self, negativepass=None):
if self.authenticated:
return
sinst = regproc.substitute(self.net, self.num)
if not self._negativePass == True:
if negativepass == False:
self._negativePass = False
return
if negativepass == True:
if self._negativePass == None:
self._negativePass = True
debug("Positive registration check - %s - %i" % (self.net, self.num))
if sinst["ping"]:
debug("Sending ping - %s - %i" % (self.net, self.num))
self.msg(sinst["entity"], sinst["pingmsg"])
return
else:
debug("Negative registration for %s - %i" % (self.net, self.num))
return
if sinst["check"]:
if sinst["negative"]:
self._negativePass = None
self.msg(sinst["entity"], sinst["negativemsg"])
return
else:
self._negativePass = True
if sinst["ping"]:
self.msg(sinst["entity"], sinst["pingmsg"])
return
else:
self.authenticated = True
warn("Won't send registration ping for %s - %i" % (self.net, self.num))
def signedOn(self):
log("signed on: %s - %i" % (self.net, self.num))
ctime = str(datetime.now().isoformat())
sendRelayNotification({"type": "conn", "net": self.net, "num": self.num, "status": "signedon", "time": ctime})
if not self.authenticated:
inst = regproc.selectInst(self.net)
if inst["ping"] and inst["check"]:
self.msg(inst["entity"], inst["pingmsg"])
reactor.callLater(10, self.regPing)
def joined(self, channel):
if not channel in self.channels: