diff --git a/commands/getstr.py b/commands/getstr.py new file mode 100644 index 0000000..205088e --- /dev/null +++ b/commands/getstr.py @@ -0,0 +1,33 @@ +import main + +from utils.get import getRelay + +class GetstrCommand: + def __init__(self, *args): + self.getstr(*args) + + def getstr(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): + if authed: + if length == 3: + net = spl[1] + num = spl[2] + if not net in main.network.keys(): + failure("Network does not exist: %s" % net) + return + if not num.isdigit(): + failure("Must be a number, not %s" % num) + return + num = int(num) + alias = main.alias[num]["nick"].lower() + host, port = getRelay(num) + password = main.config["Relay"]["Password"] + connstr = f"/connect -ssl {host} {port}" + authstr = f"/quote PASS {alias}/{net}:{password}" + obj.send(connstr) + obj.send(authstr) + + else: + incUsage("getstr") + return + else: + incUsage(None) diff --git a/conf/templates/help.json b/conf/templates/help.json index 2d40b4b..3f79c9a 100644 --- a/conf/templates/help.json +++ b/conf/templates/help.json @@ -33,5 +33,6 @@ "authcheck": "authcheck []", "recheckauth": "recheckauth []", "blacklist": "blacklist ", - "email": "email [(domain)|] []" + "email": "email [(domain)|] []", + "getstr": "getstr " } diff --git a/core/bot.py b/core/bot.py index cab516b..36fc7c4 100644 --- a/core/bot.py +++ b/core/bot.py @@ -480,6 +480,8 @@ class IRCBot(IRCClient): chankeep.initialList(self.net, self.num, listinfo) def recheckList(self): + if not main.config["ChanKeep"]["Enabled"]: + return allRelays = chankeep.allRelaysActive(self.net) debug(f"recheckList() all relays for {self.net} {allRelays}") if allRelays: @@ -526,10 +528,11 @@ class IRCBot(IRCClient): if net_inst_chanlimit: if self.chanlimit > net_inst_chanlimit: self.chanlimit = net_inst_chanlimit - warn(f"Chanlimit on {self.net} too high, setting to {self.chanlimit}") + # warn(f"Chanlimit on {self.net} too high, setting to {self.chanlimit}") if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation - self.recheckList() + if main.config["ChanKeep"]["Enabled"]: + self.recheckList() def seed_prefix(self, prefix): prefix = prefix.replace(")", "") @@ -618,6 +621,8 @@ class IRCBot(IRCClient): def regPing(self, negativepass=None): if self.authenticated: return + if not regproc.needToRegister(self.net): + self.authenticated = True sinst = regproc.substitute(self.net, self.num) if not sinst: error(f"regPing() {self.net}: registration ping failed for {self.num}") @@ -630,7 +635,7 @@ class IRCBot(IRCClient): if negativepass is True: if self._negativePass is None: self._negativePass = True - debug(f"regPing() {self.net}: positive registration check - {self.num}") + debug(f"regPing() {self.net}: negpass:True positive registration check - {self.num}") if sinst["ping"]: debug("Sending ping - %s - %i" % (self.net, self.num)) self.msg(sinst["entity"], sinst["pingmsg"]) @@ -644,11 +649,13 @@ class IRCBot(IRCClient): if sinst["negative"]: self._negativePass = None self.msg(sinst["entity"], sinst["negativemsg"]) + debug(f"regPing() {self.net}: sent negativemsg '{sinst['negativemsg']}' to {sinst['entity']} - {self.num}") return else: self._negativePass = True if sinst["ping"]: self.msg(sinst["entity"], sinst["pingmsg"]) + debug(f"regPing() {self.net}: sent ping '{sinst['pingmsg']}' to {sinst['entity']} - {self.num}") return else: self.authenticated = True diff --git a/modules/chankeep.py b/modules/chankeep.py index ef5a52d..896928c 100644 --- a/modules/chankeep.py +++ b/modules/chankeep.py @@ -16,7 +16,7 @@ def getEnabledRelays(net): :return: list of enabled relay numbers """ enabledRelays = [x for x in main.network[net].relays.keys() if main.network[net].relays[x]["enabled"]] - debug(f"getEnabledRelays() {net}: {enabledRelays}") + # debug(f"getEnabledRelays() {net}: {enabledRelays}") return enabledRelays @@ -34,7 +34,7 @@ def getConnectedRelays(net): if name in main.IRCPool.keys(): if main.IRCPool[name].isconnected: connectedRelays.append(i) - debug(f"getConnectedRelays() {net}: {connectedRelays}") + # debug(f"getConnectedRelays() {net}: {connectedRelays}") return connectedRelays @@ -50,15 +50,15 @@ def getActiveRelays(net): for i in enabledRelays: name = net + str(i) if name in main.IRCPool.keys(): - debug( - ( - f"getActiveRelays() {net}: {i} auth:{main.IRCPool[name].authenticated} " - f"conn:{main.IRCPool[name].isconnected}" - ) - ) + # debug( + # ( + # f"getActiveRelays() {net}: {i} auth:{main.IRCPool[name].authenticated} " + # f"conn:{main.IRCPool[name].isconnected}" + # ) + # ) if main.IRCPool[name].authenticated and main.IRCPool[name].isconnected: activeRelays.append(i) - debug(f"getActiveRelays() {net}: {activeRelays}") + # debug(f"getActiveRelays() {net}: {activeRelays}") return activeRelays @@ -84,7 +84,7 @@ def allRelaysActive(net): activeRelays = getActiveRelays(net) enabledRelays = getEnabledRelays(net) relaysActive = len(activeRelays) == len(enabledRelays) - debug(f"allRelaysActive() {net}: {relaysActive} ({activeRelays}/{enabledRelays})") + # debug(f"allRelaysActive() {net}: {relaysActive} ({activeRelays}/{enabledRelays})") return relaysActive diff --git a/modules/helpers.py b/modules/helpers.py index 33b484f..8d419ae 100644 --- a/modules/helpers.py +++ b/modules/helpers.py @@ -12,16 +12,16 @@ def get_first_relay(net): """ cur_relay = 0 max_relay = len(main.network[net].relays.keys()) + 1 - debug(f"get_first_relay() {net}: max_relay:{max_relay}") + # debug(f"get_first_relay() {net}: max_relay:{max_relay}") activeRelays = chankeep.getActiveRelays(net) - debug(f"get_first_relay() {net}: activeRelays:{activeRelays}") + # debug(f"get_first_relay() {net}: activeRelays:{activeRelays}") while cur_relay != max_relay: cur_relay += 1 if cur_relay not in activeRelays: continue name = net + str(cur_relay) if name in main.IRCPool.keys(): - debug(f"get_first_relay() {net}: found relay {name}") + # debug(f"get_first_relay() {net}: found relay {name}") return main.IRCPool[name] return None diff --git a/modules/regproc.py b/modules/regproc.py index 6037ddd..364b375 100644 --- a/modules/regproc.py +++ b/modules/regproc.py @@ -146,6 +146,8 @@ def get_unregistered_relays(net=None): def registerTest(c): sinst = substitute(c["net"], c["num"]) name = c["net"] + str(c["num"]) + net = c["net"] + num = c["num"] if sinst["check"] is False: return if "msg" in c.keys() and not c["msg"] is None: @@ -157,24 +159,28 @@ def registerTest(c): confirmRegistration( c["net"], c["num"], negativepass=False ) # Not passed negative check, report back + debug(f"registerTest() {net} - {num} not passed negative:checknegativemsg check, {sinst['checknegativemsg']} present in message") return if sinst["checkendnegative"] in c["msg"]: confirmRegistration( c["net"], c["num"], negativepass=True ) # Passed the negative check, report back + debug(f"registerTest() {net} - {num} passed negative:checkendnegative check, {sinst['checkendnegative']} present in message") return if sinst["ping"]: if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]: confirmRegistration(c["net"], c["num"]) + debug(f"registerTest() {net} - {num} passed ping:checkmsg2 check, {sinst['checkmsg2']} present in message") return - if sinst["checktype"] == "msg": - if "msg" in c.keys(): + if sinst["checktype"] == "msg": if sinst["checkmsg"] in c["msg"]: confirmRegistration(c["net"], c["num"]) + debug(f"registerTest() {net} - {num} passed checktype:msg:checkmsg check, {sinst['checkmsg']} present in message") return elif sinst["checktype"] == "mode": if c["type"] == "self": if c["mtype"] == "mode": if sinst["checkmode"] in c["mode"] and c["status"] is True: confirmRegistration(c["net"], c["num"]) + debug(f"registerTest() {net} - {num} passed checktype:mode:checkmost check, {sinst['checkmode']} present in mode") return