Reformat project
This commit is contained in:
parent
6c7d0d5c45
commit
f4c5323de1
|
@ -32,7 +32,7 @@ class AliasCommand:
|
||||||
failure("Must be a number, not %s" % spl[2])
|
failure("Must be a number, not %s" % spl[2])
|
||||||
return
|
return
|
||||||
num = int(spl[2])
|
num = int(spl[2])
|
||||||
if not num in main.alias.keys():
|
if num not in main.alias.keys():
|
||||||
failure("No such alias: %i" % num)
|
failure("No such alias: %i" % num)
|
||||||
return
|
return
|
||||||
failed = False
|
failed = False
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import main
|
import main
|
||||||
from core.bot import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
|
|
||||||
|
|
||||||
class AllCommand:
|
class AllCommand:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import main
|
import main
|
||||||
from core.bot import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
|
|
||||||
|
|
||||||
class AllcCommand:
|
class AllcCommand:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import main
|
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import main
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
from core.bot import deliverRelayCommands
|
|
||||||
|
|
||||||
|
|
||||||
class CmdCommand:
|
class CmdCommand:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import main
|
import main
|
||||||
from core.bot import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
|
|
||||||
|
|
||||||
class DisableCommand:
|
class DisableCommand:
|
||||||
|
@ -19,13 +19,13 @@ class DisableCommand:
|
||||||
name = spl[1] + spl[2]
|
name = spl[1] + spl[2]
|
||||||
if not spl[1] in main.IRCPool.keys():
|
if not spl[1] in main.IRCPool.keys():
|
||||||
info("Note - instance not running, proceeding anyway")
|
info("Note - instance not running, proceeding anyway")
|
||||||
if not relayNum in main.network[spl[1]].relays.keys():
|
if relayNum not in main.network[spl[1]].relays.keys():
|
||||||
failure("No such relay: %s in network %s" % (spl[2], spl[1]))
|
failure("No such relay: %s in network %s" % (spl[2], spl[1]))
|
||||||
return
|
return
|
||||||
main.network[spl[1]].relays[relayNum]["enabled"] = False
|
main.network[spl[1]].relays[relayNum]["enabled"] = False
|
||||||
user = main.alias[relayNum]["nick"]
|
user = main.alias[relayNum]["nick"]
|
||||||
network = spl[1]
|
network = spl[1]
|
||||||
relay = main.network[spl[1]].relays[relayNum]
|
# relay = main.network[spl[1]].relays[relayNum]
|
||||||
commands = {"status": ["Disconnect"]}
|
commands = {"status": ["Disconnect"]}
|
||||||
deliverRelayCommands(relayNum, commands, user=user + "/" + network)
|
deliverRelayCommands(relayNum, commands, user=user + "/" + network)
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
|
|
@ -17,7 +17,7 @@ class EmailCommand:
|
||||||
if "@" in domain:
|
if "@" in domain:
|
||||||
failure("Not a domain: %s" % domain)
|
failure("Not a domain: %s" % domain)
|
||||||
return
|
return
|
||||||
if not domain in main.irc["_"]["domains"]:
|
if domain not in main.irc["_"]["domains"]:
|
||||||
main.irc["_"]["domains"].append(domain)
|
main.irc["_"]["domains"].append(domain)
|
||||||
success("Successfully added domain %s to default config" % domain)
|
success("Successfully added domain %s to default config" % domain)
|
||||||
main.saveConf("irc")
|
main.saveConf("irc")
|
||||||
|
@ -41,7 +41,7 @@ class EmailCommand:
|
||||||
else:
|
else:
|
||||||
num = int(spl[2])
|
num = int(spl[2])
|
||||||
if spl[1] == "add":
|
if spl[1] == "add":
|
||||||
if not num in main.alias.keys():
|
if num not in main.alias.keys():
|
||||||
failure("No such alias: %i" % num)
|
failure("No such alias: %i" % num)
|
||||||
return
|
return
|
||||||
if not spl[3] in main.alias[num]["emails"]:
|
if not spl[3] in main.alias[num]["emails"]:
|
||||||
|
@ -53,7 +53,7 @@ class EmailCommand:
|
||||||
failure("Email already exists in alias %i: %s" % (num, spl[3]))
|
failure("Email already exists in alias %i: %s" % (num, spl[3]))
|
||||||
return
|
return
|
||||||
elif spl[1] == "del":
|
elif spl[1] == "del":
|
||||||
if not num in main.alias.keys():
|
if num not in main.alias.keys():
|
||||||
failure("No such alias: %i" % num)
|
failure("No such alias: %i" % num)
|
||||||
return
|
return
|
||||||
if spl[3] in main.alias[num]["emails"]:
|
if spl[3] in main.alias[num]["emails"]:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import main
|
import main
|
||||||
from core.bot import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
|
|
||||||
|
|
||||||
class EnableCommand:
|
class EnableCommand:
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
import main
|
|
||||||
|
|
||||||
|
|
||||||
class ExecCommand:
|
class ExecCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.exec(*args)
|
self.exec(*args)
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ListCommand:
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
for i in main.network.keys():
|
for i in main.network.keys():
|
||||||
if not 1 in main.network[i].relays.keys():
|
if 1 not in main.network[i].relays.keys():
|
||||||
info("Network has no first instance: %s" % i)
|
info("Network has no first instance: %s" % i)
|
||||||
continue
|
continue
|
||||||
if not i + "1" in main.IRCPool.keys():
|
if not i + "1" in main.IRCPool.keys():
|
||||||
|
@ -22,10 +22,10 @@ class ListCommand:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
failure("No such network: %s" % spl[1])
|
failure("No such network: %s" % spl[1])
|
||||||
return
|
return
|
||||||
if not 1 in main.network[spl[1]].relays.keys():
|
if 1 not in main.network[spl[1]].relays.keys():
|
||||||
failure("Network has no first instance")
|
failure("Network has no first instance")
|
||||||
return
|
return
|
||||||
if not spl[1] + "1" in main.IRCPool.keys():
|
if spl[1] + "1" not in main.IRCPool.keys():
|
||||||
failure("No IRC instance: %s - 1" % spl[1])
|
failure("No IRC instance: %s - 1" % spl[1])
|
||||||
return
|
return
|
||||||
main.IRCPool[spl[1] + "1"].list()
|
main.IRCPool[spl[1] + "1"].list()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import main
|
|
||||||
from utils.loaders.single_loader import loadSingle
|
from utils.loaders.single_loader import loadSingle
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +9,7 @@ class LoadmodCommand:
|
||||||
if authed:
|
if authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
rtrn = loadSingle(spl[1])
|
rtrn = loadSingle(spl[1])
|
||||||
if rtrn == True:
|
if rtrn is True:
|
||||||
success("Loaded module: %s" % spl[1])
|
success("Loaded module: %s" % spl[1])
|
||||||
return
|
return
|
||||||
elif rtrn == "RELOAD":
|
elif rtrn == "RELOAD":
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
import main
|
|
||||||
|
|
||||||
|
|
||||||
class LogoutCommand:
|
class LogoutCommand:
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.logout(*args)
|
self.logout(*args)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import main
|
import main
|
||||||
from yaml import dump
|
|
||||||
|
|
||||||
|
|
||||||
class ModCommand:
|
class ModCommand:
|
||||||
|
@ -16,8 +15,8 @@ class ModCommand:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setattr(main.network[spl[1]], spl[2], spl[3])
|
setattr(main.network[spl[1]], spl[2], spl[3])
|
||||||
except e:
|
except Exception as e:
|
||||||
failure("Something went wrong.")
|
failure(f"Something went wrong: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MsgCommand:
|
||||||
failure("Network does not exist: %s" % spl[1])
|
failure("Network does not exist: %s" % spl[1])
|
||||||
return
|
return
|
||||||
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
||||||
failure("Relay % does not exist on network %" % (spl[2], spl[1]))
|
failure("Relay %s does not exist on network %s" % (spl[2], spl[1]))
|
||||||
return
|
return
|
||||||
if not spl[1] + spl[2] in main.IRCPool.keys():
|
if not spl[1] + spl[2] in main.IRCPool.keys():
|
||||||
failure("Name has no instance: %s" % spl[1])
|
failure("Name has no instance: %s" % spl[1])
|
||||||
|
|
|
@ -8,9 +8,7 @@ class RecheckauthCommand:
|
||||||
def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
if authed:
|
if authed:
|
||||||
if length == 1:
|
if length == 1:
|
||||||
results = []
|
|
||||||
for i in main.IRCPool.keys():
|
for i in main.IRCPool.keys():
|
||||||
num = main.IRCPool[i].num
|
|
||||||
net = main.IRCPool[i].net
|
net = main.IRCPool[i].net
|
||||||
main.IRCPool[i].authenticated = False
|
main.IRCPool[i].authenticated = False
|
||||||
main.IRCPool[i].regPing()
|
main.IRCPool[i].regPing()
|
||||||
|
@ -20,9 +18,8 @@ class RecheckauthCommand:
|
||||||
if not spl[1] in main.network.keys():
|
if not spl[1] in main.network.keys():
|
||||||
failure("No such network: %s" % spl[1])
|
failure("No such network: %s" % spl[1])
|
||||||
return
|
return
|
||||||
results = []
|
|
||||||
for i in main.IRCPool.keys():
|
for i in main.IRCPool.keys():
|
||||||
num = main.IRCPool[i].num
|
# num = main.IRCPool[i].num
|
||||||
net = main.IRCPool[i].net
|
net = main.IRCPool[i].net
|
||||||
if not net == spl[1]:
|
if not net == spl[1]:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -26,7 +26,7 @@ class StatsCommand:
|
||||||
stats.append("User records: %s" % numWhoEntries)
|
stats.append("User records: %s" % numWhoEntries)
|
||||||
stats.append("Events/min: %s" % main.lastMinuteSample)
|
stats.append("Events/min: %s" % main.lastMinuteSample)
|
||||||
counterEvents = count.getEvents()
|
counterEvents = count.getEvents()
|
||||||
if counterEvents == None:
|
if counterEvents is None:
|
||||||
stats.append("No counters records")
|
stats.append("No counters records")
|
||||||
else:
|
else:
|
||||||
stats.append("Counters:")
|
stats.append("Counters:")
|
||||||
|
@ -43,7 +43,7 @@ class StatsCommand:
|
||||||
numNodes = 0
|
numNodes = 0
|
||||||
|
|
||||||
for i in main.IRCPool.keys():
|
for i in main.IRCPool.keys():
|
||||||
if "".join([x for x in i if not x in digits]) == spl[1]:
|
if "".join([x for x in i if x not in digits]) == spl[1]:
|
||||||
numChannels += len(main.IRCPool[i].channels)
|
numChannels += len(main.IRCPool[i].channels)
|
||||||
found = True
|
found = True
|
||||||
numNodes += 1
|
numNodes += 1
|
||||||
|
@ -54,7 +54,7 @@ class StatsCommand:
|
||||||
stats.append("User records: %s" % numWhoEntries)
|
stats.append("User records: %s" % numWhoEntries)
|
||||||
stats.append("Endpoints: %s" % numNodes)
|
stats.append("Endpoints: %s" % numNodes)
|
||||||
counterEvents = count.getEvents(spl[1])
|
counterEvents = count.getEvents(spl[1])
|
||||||
if counterEvents == None:
|
if counterEvents is None:
|
||||||
stats.append("No counters records")
|
stats.append("No counters records")
|
||||||
else:
|
else:
|
||||||
stats.append("Counters:")
|
stats.append("Counters:")
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import main
|
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import main
|
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,12 @@
|
||||||
},
|
},
|
||||||
"Key": "key.pem",
|
"Key": "key.pem",
|
||||||
"Certificate": "cert.pem",
|
"Certificate": "cert.pem",
|
||||||
"RedisSocket": "/var/run/redis/redis.sock",
|
"RedisSocket": "/tmp/redis.sock",
|
||||||
"RedisDBEphemeral": 2,
|
|
||||||
"RedisDBPersistent": 3,
|
|
||||||
"UsePassword": true,
|
"UsePassword": true,
|
||||||
"ConnectOnCreate": false,
|
"ConnectOnCreate": false,
|
||||||
"AutoReg": false,
|
"AutoReg": false,
|
||||||
"Debug": false,
|
"Debug": false,
|
||||||
"Trace": false,
|
"Trace", false,
|
||||||
"Relay": {
|
"Relay": {
|
||||||
"Host": "127.0.0.1",
|
"Host": "127.0.0.1",
|
||||||
"Port": "201x",
|
"Port": "201x",
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
"register": true,
|
"register": true,
|
||||||
"entity": "NickServ",
|
"entity": "NickServ",
|
||||||
"email": "{nickname}@domain.com",
|
"email": "{nickname}@domain.com",
|
||||||
"domains": [],
|
|
||||||
"registermsg": "REGISTER {password} {email}",
|
"registermsg": "REGISTER {password} {email}",
|
||||||
"confirm": "CONFIRM {token}",
|
"confirm": "CONFIRM {token}",
|
||||||
"check": true,
|
"check": true,
|
||||||
|
|
124
core/bot.py
124
core/bot.py
|
@ -2,16 +2,14 @@ from twisted.internet.protocol import ReconnectingClientFactory
|
||||||
from twisted.words.protocols.irc import IRCClient
|
from twisted.words.protocols.irc import IRCClient
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet.defer import Deferred
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
from twisted.internet import reactor, task
|
from twisted.internet import reactor
|
||||||
from twisted.words.protocols.irc import (
|
from twisted.words.protocols.irc import (
|
||||||
symbolic_to_numeric,
|
|
||||||
numeric_to_symbolic,
|
numeric_to_symbolic,
|
||||||
lowDequote,
|
lowDequote,
|
||||||
IRCBadMessage,
|
IRCBadMessage,
|
||||||
)
|
)
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from string import digits
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -24,19 +22,13 @@ from modules import regproc
|
||||||
|
|
||||||
from core.relay import sendRelayNotification
|
from core.relay import sendRelayNotification
|
||||||
from utils.dedup import dedup
|
from utils.dedup import dedup
|
||||||
from utils.get import getRelay
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log, warn, error
|
||||||
from utils.logging.debug import *
|
from utils.logging.debug import debug
|
||||||
from utils.logging.send import *
|
from utils.logging.send import sendAll
|
||||||
from utils.parsing import parsen
|
from utils.parsing import parsen
|
||||||
|
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
||||||
|
|
||||||
|
|
||||||
from utils.deliver_relay_commands import deliverRelayCommands
|
|
||||||
|
|
||||||
|
|
||||||
# Copied from the Twisted source so we can fix a bug
|
# Copied from the Twisted source so we can fix a bug
|
||||||
def parsemsg(s):
|
def parsemsg(s):
|
||||||
|
@ -64,69 +56,6 @@ def parsemsg(s):
|
||||||
return prefix, command, args
|
return prefix, command, args
|
||||||
|
|
||||||
|
|
||||||
class IRCRelay(IRCClient):
|
|
||||||
def __init__(self, num, relayCommands, user, stage2):
|
|
||||||
self.isconnected = False
|
|
||||||
self.buffer = ""
|
|
||||||
if user == None:
|
|
||||||
self.user = main.config["Relay"]["User"]
|
|
||||||
else:
|
|
||||||
self.user = user.lower()
|
|
||||||
password = main.config["Relay"]["Password"]
|
|
||||||
self.nickname = "relay"
|
|
||||||
self.realname = "relay"
|
|
||||||
self.username = self.user
|
|
||||||
self.password = self.user + ":" + password
|
|
||||||
|
|
||||||
self.relayCommands = relayCommands
|
|
||||||
self.num = num
|
|
||||||
self.stage2 = stage2
|
|
||||||
self.loop = None
|
|
||||||
|
|
||||||
def privmsg(self, user, channel, msg):
|
|
||||||
nick, ident, host = parsen(user)
|
|
||||||
for i in main.ZNCErrors:
|
|
||||||
if i in msg:
|
|
||||||
error("ZNC issue:", msg)
|
|
||||||
if nick[0] == main.config["Tweaks"]["ZNC"]["Prefix"]:
|
|
||||||
nick = nick[1:]
|
|
||||||
if nick in self.relayCommands.keys():
|
|
||||||
sendAll("[%s] %s -> %s" % (self.num, nick, msg))
|
|
||||||
|
|
||||||
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
|
||||||
log("%s: relay password mismatch" % self.num)
|
|
||||||
sendAll("%s: relay password mismatch" % self.num)
|
|
||||||
|
|
||||||
def sendStage2(self):
|
|
||||||
# [["user", {"sasl": ["message1", "message2"]}], []]
|
|
||||||
if not len(self.stage2) == 0:
|
|
||||||
user = self.stage2[0].pop(0)
|
|
||||||
commands = self.stage2[0].pop(0)
|
|
||||||
del self.stage2[0]
|
|
||||||
deliverRelayCommands(self.num, commands, user, self.stage2)
|
|
||||||
|
|
||||||
def signedOn(self):
|
|
||||||
if not self.isconnected:
|
|
||||||
self.isconnected = True
|
|
||||||
# log("signed on as a relay: %s" % self.num)
|
|
||||||
sleeptime = 0
|
|
||||||
increment = 0.8
|
|
||||||
for i in self.relayCommands.keys():
|
|
||||||
for x in self.relayCommands[i]:
|
|
||||||
reactor.callLater(
|
|
||||||
sleeptime,
|
|
||||||
self.msg,
|
|
||||||
main.config["Tweaks"]["ZNC"]["Prefix"] + i,
|
|
||||||
x,
|
|
||||||
)
|
|
||||||
sleeptime += increment
|
|
||||||
increment += 0.8
|
|
||||||
if not self.stage2 == None:
|
|
||||||
reactor.callLater(sleeptime, self.sendStage2)
|
|
||||||
reactor.callLater(sleeptime + 5, self.transport.loseConnection)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class IRCBot(IRCClient):
|
class IRCBot(IRCClient):
|
||||||
def __init__(self, net, num):
|
def __init__(self, net, num):
|
||||||
self.isconnected = False
|
self.isconnected = False
|
||||||
|
@ -188,7 +117,7 @@ class IRCBot(IRCClient):
|
||||||
sleeptime = 0.0
|
sleeptime = 0.0
|
||||||
increment = 0.8
|
increment = 0.8
|
||||||
for i in channels:
|
for i in channels:
|
||||||
if not i in self.channels:
|
if i not in self.channels:
|
||||||
if self.net in main.blacklist.keys():
|
if self.net in main.blacklist.keys():
|
||||||
if i in main.blacklist[self.net]:
|
if i in main.blacklist[self.net]:
|
||||||
debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num))
|
debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num))
|
||||||
|
@ -215,12 +144,12 @@ class IRCBot(IRCClient):
|
||||||
del main.TempChan[self.net]
|
del main.TempChan[self.net]
|
||||||
|
|
||||||
def event(self, **cast):
|
def event(self, **cast):
|
||||||
if not "ts" in cast.keys():
|
if "ts" not in cast.keys():
|
||||||
cast["ts"] = str(datetime.now().isoformat())
|
cast["ts"] = str(datetime.now().isoformat())
|
||||||
|
|
||||||
# remove odd stuff
|
# remove odd stuff
|
||||||
for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over
|
for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over
|
||||||
if cast[i] == "": # a dictionary that changes length with each iteration
|
if cast[i] == "": # a dictionary that changes length with each iteration
|
||||||
del cast[i]
|
del cast[i]
|
||||||
# remove server stuff
|
# remove server stuff
|
||||||
if "muser" in cast.keys():
|
if "muser" in cast.keys():
|
||||||
|
@ -302,16 +231,16 @@ class IRCBot(IRCClient):
|
||||||
|
|
||||||
# we have been mentioned in a msg/notice/action/part/quit/topic message
|
# we have been mentioned in a msg/notice/action/part/quit/topic message
|
||||||
if "msg" in cast.keys(): # Don't highlight queries
|
if "msg" in cast.keys(): # Don't highlight queries
|
||||||
if not cast["msg"] == None:
|
if cast["msg"] is not None:
|
||||||
if self.nickname.lower() in cast["msg"].lower():
|
if self.nickname.lower() in cast["msg"].lower():
|
||||||
castDup = deepcopy(cast)
|
castDup = deepcopy(cast)
|
||||||
castDup["mtype"] = cast["type"]
|
castDup["mtype"] = cast["type"]
|
||||||
castDup["type"] = "highlight"
|
castDup["type"] = "highlight"
|
||||||
self.event(**castDup)
|
self.event(**castDup)
|
||||||
|
|
||||||
if not "net" in cast.keys():
|
if "net" not in cast.keys():
|
||||||
cast["net"] = self.net
|
cast["net"] = self.net
|
||||||
if not "num" in cast.keys():
|
if "num" not in cast.keys():
|
||||||
cast["num"] = self.num
|
cast["num"] = self.num
|
||||||
if not self.authenticated:
|
if not self.authenticated:
|
||||||
regproc.registerTest(cast)
|
regproc.registerTest(cast)
|
||||||
|
@ -478,7 +407,7 @@ class IRCBot(IRCClient):
|
||||||
else:
|
else:
|
||||||
if nocheck:
|
if nocheck:
|
||||||
allRelays = True # override the system - if this is
|
allRelays = True # override the system - if this is
|
||||||
else: # specified, we already did this
|
else: # specified, we already did this
|
||||||
allRelays = chankeep.allRelaysActive(self.net)
|
allRelays = chankeep.allRelaysActive(self.net)
|
||||||
if not allRelays:
|
if not allRelays:
|
||||||
self.wantList = True
|
self.wantList = True
|
||||||
|
@ -535,7 +464,7 @@ class IRCBot(IRCClient):
|
||||||
allRelays = chankeep.allRelaysActive(self.net)
|
allRelays = chankeep.allRelaysActive(self.net)
|
||||||
if allRelays:
|
if allRelays:
|
||||||
name = self.net + "1"
|
name = self.net + "1"
|
||||||
if main.IRCPool[name].wantList == True:
|
if main.IRCPool[name].wantList is True:
|
||||||
main.IRCPool[name].list(nocheck=True)
|
main.IRCPool[name].list(nocheck=True)
|
||||||
debug("Asking for a list for %s after final relay %i connected" % (self.net, self.num))
|
debug("Asking for a list for %s after final relay %i connected" % (self.net, self.num))
|
||||||
if self.num == 1: # Only one instance should do a list
|
if self.num == 1: # Only one instance should do a list
|
||||||
|
@ -559,7 +488,7 @@ class IRCBot(IRCClient):
|
||||||
try:
|
try:
|
||||||
self.chanlimit = int(chanlimit)
|
self.chanlimit = int(chanlimit)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
warn("Invalid chanlimit: %s" % i)
|
warn("Invalid chanlimit: %s" % chanlimit)
|
||||||
if self.chanlimit == 0:
|
if self.chanlimit == 0:
|
||||||
self.chanlimit = 200 # don't take the piss if it's not limited
|
self.chanlimit = 200 # don't take the piss if it's not limited
|
||||||
if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation
|
if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation
|
||||||
|
@ -625,7 +554,7 @@ class IRCBot(IRCClient):
|
||||||
self.userLeft(prefix, channel, message)
|
self.userLeft(prefix, channel, message)
|
||||||
|
|
||||||
def irc_QUIT(self, prefix, params):
|
def irc_QUIT(self, prefix, params):
|
||||||
nick = prefix.split("!")[0]
|
# nick = prefix.split("!")[0]
|
||||||
self.userQuit(prefix, params[0])
|
self.userQuit(prefix, params[0])
|
||||||
|
|
||||||
def irc_NICK(self, prefix, params):
|
def irc_NICK(self, prefix, params):
|
||||||
|
@ -656,12 +585,12 @@ class IRCBot(IRCClient):
|
||||||
if not sinst:
|
if not sinst:
|
||||||
error(f"Registration ping failed for {self.net} - {self.num}")
|
error(f"Registration ping failed for {self.net} - {self.num}")
|
||||||
return
|
return
|
||||||
if not self._negativePass == True:
|
if self._negativePass is not True:
|
||||||
if negativepass == False:
|
if negativepass is False:
|
||||||
self._negativePass = False
|
self._negativePass = False
|
||||||
return
|
return
|
||||||
if negativepass == True:
|
if negativepass is True:
|
||||||
if self._negativePass == None:
|
if self._negativePass is None:
|
||||||
self._negativePass = True
|
self._negativePass = True
|
||||||
debug("Positive registration check - %s - %i" % (self.net, self.num))
|
debug("Positive registration check - %s - %i" % (self.net, self.num))
|
||||||
if sinst["ping"]:
|
if sinst["ping"]:
|
||||||
|
@ -701,7 +630,7 @@ class IRCBot(IRCClient):
|
||||||
reactor.callLater(10, self.regPing)
|
reactor.callLater(10, self.regPing)
|
||||||
|
|
||||||
def joined(self, channel):
|
def joined(self, channel):
|
||||||
if not channel in self.channels:
|
if channel not in self.channels:
|
||||||
self.channels.append(channel)
|
self.channels.append(channel)
|
||||||
self.names(channel).addCallback(self.got_names)
|
self.names(channel).addCallback(self.got_names)
|
||||||
if main.config["Toggles"]["Who"]:
|
if main.config["Toggles"]["Who"]:
|
||||||
|
@ -723,7 +652,7 @@ class IRCBot(IRCClient):
|
||||||
# log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
|
# log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
|
||||||
# other bots have different nicknames so
|
# other bots have different nicknames so
|
||||||
|
|
||||||
def left(self, user, channel, message): # even if they saw it, they wouldn't react
|
def left(self, user, channel, message): # even if they saw it, they wouldn't react
|
||||||
self.event(type="part", muser=user, channel=channel, msg=message)
|
self.event(type="part", muser=user, channel=channel, msg=message)
|
||||||
self.botLeft(channel)
|
self.botLeft(channel)
|
||||||
|
|
||||||
|
@ -749,7 +678,7 @@ class IRCBot(IRCClient):
|
||||||
# format
|
# format
|
||||||
return # stop right there sir!
|
return # stop right there sir!
|
||||||
chans = userinfo.getChanList(self.net, cast["nick"])
|
chans = userinfo.getChanList(self.net, cast["nick"])
|
||||||
if chans == None:
|
if chans is None:
|
||||||
error("No channels returned for chanless event: %s" % cast)
|
error("No channels returned for chanless event: %s" % cast)
|
||||||
# self.event(**cast) -- no, should NEVER happen
|
# self.event(**cast) -- no, should NEVER happen
|
||||||
return
|
return
|
||||||
|
@ -780,9 +709,10 @@ class IRCBot(IRCClient):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: strip out relay functionality
|
||||||
class IRCBotFactory(ReconnectingClientFactory):
|
class IRCBotFactory(ReconnectingClientFactory):
|
||||||
def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None):
|
def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None):
|
||||||
if net == None:
|
if net is None:
|
||||||
self.num = num
|
self.num = num
|
||||||
self.net = None
|
self.net = None
|
||||||
self.name = "relay - %i" % num
|
self.name = "relay - %i" % num
|
||||||
|
@ -801,11 +731,9 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
|
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
if self.relay == False:
|
if self.relay is False:
|
||||||
entry = IRCBot(self.net, self.num)
|
entry = IRCBot(self.net, self.num)
|
||||||
main.IRCPool[self.name] = entry
|
main.IRCPool[self.name] = entry
|
||||||
else:
|
|
||||||
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
|
|
||||||
|
|
||||||
self.client = entry
|
self.client = entry
|
||||||
return entry
|
return entry
|
||||||
|
@ -813,7 +741,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
if not self.relay:
|
if not self.relay:
|
||||||
userinfo.delChannels(self.net, self.client.channels)
|
userinfo.delChannels(self.net, self.client.channels)
|
||||||
if not self.client == None:
|
if self.client is not None:
|
||||||
self.client.isconnected = False
|
self.client.isconnected = False
|
||||||
self.client.authenticated = False
|
self.client.authenticated = False
|
||||||
self.client.channels = []
|
self.client.channels = []
|
||||||
|
@ -836,7 +764,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
# ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
# ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
if not self.client == None:
|
if self.client is not None:
|
||||||
self.client.isconnected = False
|
self.client.isconnected = False
|
||||||
self.client.authenticated = False
|
self.client.authenticated = False
|
||||||
self.client.channels = []
|
self.client.channels = []
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
class IRCBotFactory(ReconnectingClientFactory):
|
||||||
|
def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None):
|
||||||
|
if net is None:
|
||||||
|
self.num = num
|
||||||
|
self.net = None
|
||||||
|
self.name = "relay - %i" % num
|
||||||
|
self.relay = True
|
||||||
|
else:
|
||||||
|
self.name = net + str(num)
|
||||||
|
self.num = num
|
||||||
|
self.net = net
|
||||||
|
self.relay = False
|
||||||
|
self.client = None
|
||||||
|
self.maxDelay = main.config["Tweaks"]["Delays"]["MaxDelay"]
|
||||||
|
self.initialDelay = main.config["Tweaks"]["Delays"]["InitialDelay"]
|
||||||
|
self.factor = main.config["Tweaks"]["Delays"]["Factor"]
|
||||||
|
self.jitter = main.config["Tweaks"]["Delays"]["Jitter"]
|
||||||
|
|
||||||
|
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
|
||||||
|
|
||||||
|
def buildProtocol(self, addr):
|
||||||
|
if self.relay is False:
|
||||||
|
entry = IRCBot(self.net, self.num)
|
||||||
|
main.IRCPool[self.name] = entry
|
||||||
|
else:
|
||||||
|
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
|
||||||
|
|
||||||
|
self.client = entry
|
||||||
|
return entry
|
||||||
|
|
||||||
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
if not self.relay:
|
||||||
|
userinfo.delChannels(self.net, self.client.channels)
|
||||||
|
if self.client is not None:
|
||||||
|
self.client.isconnected = False
|
||||||
|
self.client.authenticated = False
|
||||||
|
self.client.channels = []
|
||||||
|
error = reason.getErrorMessage()
|
||||||
|
if not self.relay:
|
||||||
|
log("%s - %i: connection lost: %s" % (self.net, self.num, error))
|
||||||
|
sendAll("%s - %i: connection lost: %s" % (self.net, self.num, error))
|
||||||
|
ctime = str(datetime.now().isoformat())
|
||||||
|
sendRelayNotification(
|
||||||
|
{
|
||||||
|
"type": "conn",
|
||||||
|
"net": self.net,
|
||||||
|
"num": self.num,
|
||||||
|
"status": "lost",
|
||||||
|
"message": error,
|
||||||
|
"ts": ctime,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.retry(connector)
|
||||||
|
# ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
if self.client is not None:
|
||||||
|
self.client.isconnected = False
|
||||||
|
self.client.authenticated = False
|
||||||
|
self.client.channels = []
|
||||||
|
error = reason.getErrorMessage()
|
||||||
|
log("%s - %i: connection failed: %s" % (self.net, self.num, error))
|
||||||
|
if not self.relay:
|
||||||
|
sendAll("%s - %s: connection failed: %s" % (self.net, self.num, error))
|
||||||
|
ctime = str(datetime.now().isoformat())
|
||||||
|
sendRelayNotification(
|
||||||
|
{
|
||||||
|
"type": "conn",
|
||||||
|
"net": self.net,
|
||||||
|
"num": self.num,
|
||||||
|
"status": "failed",
|
||||||
|
"message": error,
|
||||||
|
"ts": ctime,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.retry(connector)
|
||||||
|
# ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
|
@ -1,9 +1,8 @@
|
||||||
import logstash
|
import logstash
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from json import dumps, loads
|
from json import dumps
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
|
||||||
|
|
||||||
logger = None
|
logger = None
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@ def init_logstash():
|
||||||
|
|
||||||
|
|
||||||
def sendLogstashNotification(text):
|
def sendLogstashNotification(text):
|
||||||
if not logger == None:
|
if logger is not None:
|
||||||
logger.info(dumps(text))
|
logger.info(dumps(text))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import warn
|
||||||
from utils.logging.send import *
|
from utils.logging.send import sendSuccess, sendFailure, sendInfo, incorrectUsage
|
||||||
|
|
||||||
|
|
||||||
def parseCommand(addr, authed, data):
|
def parseCommand(addr, authed, data):
|
||||||
|
@ -12,17 +12,12 @@ def parseCommand(addr, authed, data):
|
||||||
warn("Got connection object with no instance in the address pool")
|
warn("Got connection object with no instance in the address pool")
|
||||||
return
|
return
|
||||||
|
|
||||||
success = lambda data: sendSuccess(addr, data)
|
success = lambda data: sendSuccess(addr, data) # noqa: E731
|
||||||
failure = lambda data: sendFailure(addr, data)
|
failure = lambda data: sendFailure(addr, data) # noqa: E731
|
||||||
info = lambda data: sendInfo(addr, data)
|
info = lambda data: sendInfo(addr, data) # noqa: E731
|
||||||
|
|
||||||
incUsage = lambda mode: incorrectUsage(addr, mode)
|
incUsage = lambda mode: incorrectUsage(addr, mode) # noqa: E731
|
||||||
length = len(spl)
|
length = len(spl)
|
||||||
if len(spl) > 0:
|
|
||||||
cmd = spl[0]
|
|
||||||
else:
|
|
||||||
failure("No text was sent")
|
|
||||||
return
|
|
||||||
if spl[0] in main.CommandMap.keys():
|
if spl[0] in main.CommandMap.keys():
|
||||||
main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
|
main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
from twisted.internet.protocol import Protocol, Factory, ClientFactory
|
from twisted.internet.protocol import Protocol, Factory
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log, warn
|
||||||
|
|
||||||
validTypes = [
|
validTypes = [
|
||||||
"msg",
|
"msg",
|
||||||
|
@ -47,10 +45,10 @@ class Relay(Protocol):
|
||||||
data = data.decode("utf-8", "replace")
|
data = data.decode("utf-8", "replace")
|
||||||
try:
|
try:
|
||||||
parsed = loads(data)
|
parsed = loads(data)
|
||||||
except:
|
except: # noqa: E722
|
||||||
self.sendErr("MALFORMED")
|
self.sendErr("MALFORMED")
|
||||||
return
|
return
|
||||||
if not "type" in parsed.keys():
|
if "type" not in parsed.keys():
|
||||||
self.sendErr("NOTYPE")
|
self.sendErr("NOTYPE")
|
||||||
return
|
return
|
||||||
if parsed["type"] == "hello":
|
if parsed["type"] == "hello":
|
||||||
|
@ -87,7 +85,7 @@ class Relay(Protocol):
|
||||||
self.sendErr("NOTLIST")
|
self.sendErr("NOTLIST")
|
||||||
return
|
return
|
||||||
for i in lst:
|
for i in lst:
|
||||||
if not i in validTypes:
|
if i not in validTypes:
|
||||||
self.sendErr("NONEXISTANT")
|
self.sendErr("NONEXISTANT")
|
||||||
return
|
return
|
||||||
if i in self.subscriptions:
|
if i in self.subscriptions:
|
||||||
|
@ -102,10 +100,10 @@ class Relay(Protocol):
|
||||||
self.sendErr("NOTLIST")
|
self.sendErr("NOTLIST")
|
||||||
return
|
return
|
||||||
for i in lst:
|
for i in lst:
|
||||||
if not i in validTypes:
|
if i not in validTypes:
|
||||||
self.sendErr("NONEXISTANT")
|
self.sendErr("NONEXISTANT")
|
||||||
return
|
return
|
||||||
if not i in self.subscriptions:
|
if i not in self.subscriptions:
|
||||||
self.sendErr("NOTSUBSCRIBED")
|
self.sendErr("NOTSUBSCRIBED")
|
||||||
return
|
return
|
||||||
del self.subscriptions[i]
|
del self.subscriptions[i]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from twisted.internet.protocol import Protocol, Factory, ClientFactory
|
from twisted.internet.protocol import Protocol, Factory
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log, warn
|
||||||
|
|
||||||
from core.parser import parseCommand
|
from core.parser import parseCommand
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class Server(Protocol):
|
||||||
def __init__(self, addr):
|
def __init__(self, addr):
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
self.authed = False
|
self.authed = False
|
||||||
if main.config["UsePassword"] == False:
|
if main.config["UsePassword"] is False:
|
||||||
self.authed = True
|
self.authed = True
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
|
|
9
main.py
9
main.py
|
@ -4,8 +4,6 @@ from redis import StrictRedis
|
||||||
from string import digits
|
from string import digits
|
||||||
from os import urandom
|
from os import urandom
|
||||||
|
|
||||||
from utils.logging.log import *
|
|
||||||
|
|
||||||
# List of errors ZNC can give us
|
# List of errors ZNC can give us
|
||||||
ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"]
|
ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"]
|
||||||
|
|
||||||
|
@ -59,11 +57,12 @@ lastMinuteSample = 0
|
||||||
hashKey = urandom(16)
|
hashKey = urandom(16)
|
||||||
lastEvents = {}
|
lastEvents = {}
|
||||||
|
|
||||||
|
|
||||||
# Get networks that are currently online and dedupliate
|
# Get networks that are currently online and dedupliate
|
||||||
def liveNets():
|
def liveNets():
|
||||||
networks = set()
|
networks = set()
|
||||||
for i in IRCPool.keys():
|
for i in IRCPool.keys():
|
||||||
networks.add("".join([x for x in i if not x in digits]))
|
networks.add("".join([x for x in i if x not in digits]))
|
||||||
return networks
|
return networks
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,6 +106,6 @@ def initMain():
|
||||||
global r, g
|
global r, g
|
||||||
initConf()
|
initConf()
|
||||||
r = StrictRedis(
|
r = StrictRedis(
|
||||||
unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"]
|
unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"] # noqa
|
||||||
) # Ephemeral - flushed on quit
|
) # Ephemeral - flushed on quit
|
||||||
g = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]) # Persistent
|
g = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]) # noqa
|
||||||
|
|
|
@ -15,7 +15,7 @@ def generate_alias():
|
||||||
rand = random.randint(1, 4)
|
rand = random.randint(1, 4)
|
||||||
while rand == 1:
|
while rand == 1:
|
||||||
split = random.randint(0, len(nick) - 1)
|
split = random.randint(0, len(nick) - 1)
|
||||||
nick = nick[:split] + nick[split + 1 :]
|
nick = nick[:split] + nick[split + 1 :] # noqa: E203
|
||||||
rand = random.randint(1, 4)
|
rand = random.randint(1, 4)
|
||||||
rand = random.randint(1, 3)
|
rand = random.randint(1, 3)
|
||||||
if rand == 1 or rand == 4:
|
if rand == 1 or rand == 4:
|
||||||
|
@ -53,7 +53,7 @@ def generate_alias():
|
||||||
ident = namebase.split(" ")[0]
|
ident = namebase.split(" ")[0]
|
||||||
ident = ident[:10]
|
ident = ident[:10]
|
||||||
elif rand == 6:
|
elif rand == 6:
|
||||||
ident = re.sub("\s", "", namebase).lower()
|
ident = re.sub("\s", "", namebase).lower() # noqa: W605
|
||||||
ident = ident[:10]
|
ident = ident[:10]
|
||||||
|
|
||||||
realname = nick
|
realname = nick
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log, warn, error
|
||||||
from utils.logging.debug import *
|
from utils.logging.debug import debug
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from math import ceil
|
from math import ceil
|
||||||
import modules.provision
|
import modules.provision
|
||||||
|
@ -166,7 +166,7 @@ def _initialList(net, num, listinfo, chanlimit):
|
||||||
|
|
||||||
sigrelay = ceil(siglength / chanlimit)
|
sigrelay = ceil(siglength / chanlimit)
|
||||||
relay = ceil(listlength / chanlimit)
|
relay = ceil(listlength / chanlimit)
|
||||||
netbase = "list.%s" % net
|
# netbase = "list.%s" % net
|
||||||
abase = "analytics.list.%s" % net
|
abase = "analytics.list.%s" % net
|
||||||
p = main.g.pipeline()
|
p = main.g.pipeline()
|
||||||
p.hset(abase, "mean", mean)
|
p.hset(abase, "mean", mean)
|
||||||
|
|
|
@ -3,11 +3,11 @@ from twisted.internet.task import LoopingCall
|
||||||
|
|
||||||
|
|
||||||
def event(name, eventType):
|
def event(name, eventType):
|
||||||
if not "local" in main.counters.keys():
|
if "local" not in main.counters.keys():
|
||||||
main.counters["local"] = {}
|
main.counters["local"] = {}
|
||||||
if not "global" in main.counters.keys():
|
if "global" not in main.counters.keys():
|
||||||
main.counters["global"] = {}
|
main.counters["global"] = {}
|
||||||
if not name in main.counters["local"].keys():
|
if name not in main.counters["local"].keys():
|
||||||
main.counters["local"][name] = {}
|
main.counters["local"][name] = {}
|
||||||
if eventType not in main.counters["local"][name].keys():
|
if eventType not in main.counters["local"][name].keys():
|
||||||
main.counters["local"][name][eventType] = 0
|
main.counters["local"][name][eventType] = 0
|
||||||
|
@ -21,7 +21,7 @@ def event(name, eventType):
|
||||||
|
|
||||||
|
|
||||||
def getEvents(name=None):
|
def getEvents(name=None):
|
||||||
if name == None:
|
if name is None:
|
||||||
if "global" in main.counters.keys():
|
if "global" in main.counters.keys():
|
||||||
return main.counters["global"]
|
return main.counters["global"]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
from copy import deepcopy
|
|
||||||
from json import dumps
|
|
||||||
|
|
||||||
import main
|
|
||||||
from core.relay import sendRelayNotification
|
from core.relay import sendRelayNotification
|
||||||
from core.logstash import sendLogstashNotification
|
from core.logstash import sendLogstashNotification
|
||||||
from modules import userinfo
|
from modules import userinfo
|
||||||
from modules import regproc
|
|
||||||
from utils.dedup import dedup
|
from utils.dedup import dedup
|
||||||
|
|
||||||
order = [
|
order = [
|
||||||
|
@ -29,7 +24,7 @@ order = [
|
||||||
|
|
||||||
|
|
||||||
def parsemeta(numName, c):
|
def parsemeta(numName, c):
|
||||||
if not "channel" in c.keys():
|
if "channel" not in c.keys():
|
||||||
c["channel"] = None
|
c["channel"] = None
|
||||||
# metadata scraping
|
# metadata scraping
|
||||||
# need to check if this was received from a relay
|
# need to check if this was received from a relay
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
import json
|
|
||||||
|
|
||||||
from modules import alias
|
from modules import alias
|
||||||
from modules.chankeep import nukeNetwork
|
from modules.chankeep import nukeNetwork
|
||||||
from modules.regproc import needToRegister
|
from modules.regproc import needToRegister
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from core.bot import IRCBot, IRCBotFactory
|
from core.bot import IRCBotFactory
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log
|
||||||
from utils.get import getRelay
|
from utils.get import getRelay
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ class Network:
|
||||||
"registered": registered,
|
"registered": registered,
|
||||||
}
|
}
|
||||||
password = alias.generate_password()
|
password = alias.generate_password()
|
||||||
if not num in main.alias.keys():
|
if num not in main.alias.keys():
|
||||||
main.alias[num] = alias.generate_alias()
|
main.alias[num] = alias.generate_alias()
|
||||||
main.saveConf("alias")
|
main.saveConf("alias")
|
||||||
self.aliases[num] = {"password": password}
|
self.aliases[num] = {"password": password}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import main
|
import main
|
||||||
from utils.deliver_relay_commands import deliverRelayCommands
|
from utils.deliver_relay_commands import deliverRelayCommands
|
||||||
from utils.logging.log import *
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
import modules.regproc
|
import modules.regproc
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ def provisionAuthenticationData(num, nick, network, security, auth, password):
|
||||||
def provisionRelay(num, network): # provision user and network data
|
def provisionRelay(num, network): # provision user and network data
|
||||||
aliasObj = main.alias[num]
|
aliasObj = main.alias[num]
|
||||||
print("ALIASOBJ FALUES", aliasObj.values())
|
print("ALIASOBJ FALUES", aliasObj.values())
|
||||||
alias = aliasObj["nick"]
|
# alias = aliasObj["nick"]
|
||||||
provisionUserNetworkData(
|
provisionUserNetworkData(
|
||||||
num,
|
num,
|
||||||
*aliasObj.values(),
|
*aliasObj.values(),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import main
|
import main
|
||||||
from modules import provision
|
from modules import provision
|
||||||
from utils.logging.log import *
|
from utils.logging.log import error
|
||||||
from utils.logging.debug import *
|
from utils.logging.debug import debug
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from random import choice
|
from random import choice
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ def selectInst(net):
|
||||||
if net in main.irc.keys():
|
if net in main.irc.keys():
|
||||||
inst = deepcopy(main.irc[net])
|
inst = deepcopy(main.irc[net])
|
||||||
for i in main.irc["_"].keys():
|
for i in main.irc["_"].keys():
|
||||||
if not i in inst:
|
if i not in inst:
|
||||||
inst[i] = main.irc["_"][i]
|
inst[i] = main.irc["_"][i]
|
||||||
else:
|
else:
|
||||||
inst = main.irc["_"]
|
inst = main.irc["_"]
|
||||||
|
@ -50,7 +50,7 @@ def substitute(net, num, token=None):
|
||||||
error(f"Could not get email for {net} - {num}")
|
error(f"Could not get email for {net} - {num}")
|
||||||
return False
|
return False
|
||||||
nickname = alias["nick"]
|
nickname = alias["nick"]
|
||||||
username = nickname + "/" + net
|
# username = nickname + "/" + net
|
||||||
password = main.network[net].aliases[num]["password"]
|
password = main.network[net].aliases[num]["password"]
|
||||||
# inst["email"] = inst["email"].replace("{nickname}", nickname)
|
# inst["email"] = inst["email"].replace("{nickname}", nickname)
|
||||||
for i in inst.keys():
|
for i in inst.keys():
|
||||||
|
@ -88,7 +88,7 @@ def confirmRegistration(net, num, negativepass=None):
|
||||||
obj = main.network[net]
|
obj = main.network[net]
|
||||||
name = net + str(num)
|
name = net + str(num)
|
||||||
if name in main.IRCPool.keys():
|
if name in main.IRCPool.keys():
|
||||||
if not negativepass == None:
|
if negativepass is not None:
|
||||||
main.IRCPool[name].regPing(negativepass=negativepass)
|
main.IRCPool[name].regPing(negativepass=negativepass)
|
||||||
return
|
return
|
||||||
debug("Relay authenticated: %s - %i" % (net, num))
|
debug("Relay authenticated: %s - %i" % (net, num))
|
||||||
|
@ -100,7 +100,7 @@ def confirmRegistration(net, num, negativepass=None):
|
||||||
if main.IRCPool[name]._regAttempt:
|
if main.IRCPool[name]._regAttempt:
|
||||||
try:
|
try:
|
||||||
main.IRCPool[name]._regAttempt.cancel()
|
main.IRCPool[name]._regAttempt.cancel()
|
||||||
except:
|
except: # noqa
|
||||||
pass
|
pass
|
||||||
obj.relays[num]["registered"] = True
|
obj.relays[num]["registered"] = True
|
||||||
main.saveConf("network")
|
main.saveConf("network")
|
||||||
|
@ -112,22 +112,22 @@ def enableAuthentication(net, num):
|
||||||
security = obj.security
|
security = obj.security
|
||||||
auth = obj.auth
|
auth = obj.auth
|
||||||
password = obj.aliases[num]["password"]
|
password = obj.aliases[num]["password"]
|
||||||
uname = main.alias[num]["nick"] + "/" + net
|
# uname = main.alias[num]["nick"] + "/" + net
|
||||||
provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth
|
provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth
|
||||||
main.IRCPool[net + str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
|
main.IRCPool[net + str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump")
|
||||||
if selectInst(net)["check"] == False:
|
if selectInst(net)["check"] is False:
|
||||||
confirmRegistration(net, num)
|
confirmRegistration(net, num)
|
||||||
|
|
||||||
|
|
||||||
def registerTest(c):
|
def registerTest(c):
|
||||||
sinst = substitute(c["net"], c["num"])
|
sinst = substitute(c["net"], c["num"])
|
||||||
name = c["net"] + str(c["num"])
|
name = c["net"] + str(c["num"])
|
||||||
if sinst["check"] == False:
|
if sinst["check"] is False:
|
||||||
return
|
return
|
||||||
if "msg" in c.keys() and not c["msg"] == None:
|
if "msg" in c.keys() and not c["msg"] is None:
|
||||||
if sinst["negative"]:
|
if sinst["negative"]:
|
||||||
if name in main.IRCPool.keys():
|
if name in main.IRCPool.keys():
|
||||||
if not main.IRCPool[name]._negativePass == True:
|
if main.IRCPool[name]._negativePass is not True:
|
||||||
if c["type"] == "query" and c["nick"] == sinst["entity"]:
|
if c["type"] == "query" and c["nick"] == sinst["entity"]:
|
||||||
if sinst["checknegativemsg"] in c["msg"]:
|
if sinst["checknegativemsg"] in c["msg"]:
|
||||||
confirmRegistration(
|
confirmRegistration(
|
||||||
|
@ -150,6 +150,6 @@ def registerTest(c):
|
||||||
elif sinst["checktype"] == "mode":
|
elif sinst["checktype"] == "mode":
|
||||||
if c["type"] == "self":
|
if c["type"] == "self":
|
||||||
if c["mtype"] == "mode":
|
if c["mtype"] == "mode":
|
||||||
if sinst["checkmode"] in c["mode"] and c["status"] == True:
|
if sinst["checkmode"] in c["mode"] and c["status"] is True:
|
||||||
confirmRegistration(c["net"], c["num"])
|
confirmRegistration(c["net"], c["num"])
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from twisted.internet.threads import deferToThread
|
from twisted.internet.threads import deferToThread
|
||||||
from string import digits
|
|
||||||
|
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import warn
|
||||||
from utils.logging.debug import debug, trace
|
from utils.logging.debug import trace
|
||||||
from utils.parsing import parsen
|
from utils.parsing import parsen
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +96,7 @@ def _initialUsers(name, channel, users):
|
||||||
|
|
||||||
def initialUsers(name, channel, users):
|
def initialUsers(name, channel, users):
|
||||||
trace("Initialising WHO records for %s on %s" % (channel, name))
|
trace("Initialising WHO records for %s on %s" % (channel, name))
|
||||||
d = deferToThread(_initialUsers, name, channel, users)
|
deferToThread(_initialUsers, name, channel, users)
|
||||||
# d.addCallback(testCallback)
|
# d.addCallback(testCallback)
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ def _initialNames(name, channel, names):
|
||||||
|
|
||||||
def initialNames(name, channel, names):
|
def initialNames(name, channel, names):
|
||||||
trace("Initialising NAMES records for %s on %s" % (channel, name))
|
trace("Initialising NAMES records for %s on %s" % (channel, name))
|
||||||
d = deferToThread(_initialNames, name, channel, names)
|
deferToThread(_initialNames, name, channel, names)
|
||||||
# d.addCallback(testCallback)
|
# d.addCallback(testCallback)
|
||||||
|
|
||||||
|
|
||||||
|
@ -260,5 +259,5 @@ def _delChannels(net, channels):
|
||||||
|
|
||||||
def delChannels(net, channels): # we have left a channel
|
def delChannels(net, channels): # we have left a channel
|
||||||
trace("Purging channel %s for %s" % (", ".join(channels), net))
|
trace("Purging channel %s for %s" % (", ".join(channels), net))
|
||||||
d = deferToThread(_delChannels, net, channels)
|
deferToThread(_delChannels, net, channels)
|
||||||
# d.addCallback(testCallback)
|
# d.addCallback(testCallback)
|
||||||
|
|
31
threshold
31
threshold
|
@ -10,33 +10,38 @@ from signal import signal, SIGINT
|
||||||
from sys import stdout, stderr # Import again because we want to override
|
from sys import stdout, stderr # Import again because we want to override
|
||||||
from codecs import getwriter # fix printing odd shit to the terminal
|
from codecs import getwriter # fix printing odd shit to the terminal
|
||||||
|
|
||||||
stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know
|
|
||||||
stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using
|
|
||||||
# unicode quit messages for no reason
|
|
||||||
import main
|
import main
|
||||||
|
|
||||||
main.initMain()
|
|
||||||
from utils.cleanup import handler
|
from utils.cleanup import handler
|
||||||
|
|
||||||
signal(SIGINT, handler) # Handle Ctrl-C and run the cleanup routine
|
|
||||||
|
from utils.logging.log import log
|
||||||
|
from utils.loaders.command_loader import loadCommands
|
||||||
|
from core.server import ServerFactory
|
||||||
|
from core.relay import RelayFactory
|
||||||
|
import modules.counters
|
||||||
|
import core.logstash
|
||||||
|
|
||||||
|
main.initMain()
|
||||||
|
|
||||||
if "--debug" in sys.argv: # yes really
|
if "--debug" in sys.argv: # yes really
|
||||||
main.config["Debug"] = True
|
main.config["Debug"] = True
|
||||||
if "--trace" in sys.argv:
|
if "--trace" in sys.argv:
|
||||||
main.config["Trace"] = True
|
main.config["Trace"] = True
|
||||||
from utils.logging.log import *
|
|
||||||
from utils.loaders.command_loader import loadCommands
|
|
||||||
from core.server import Server, ServerFactory
|
|
||||||
from core.relay import Relay, RelayFactory
|
|
||||||
import modules.counters
|
|
||||||
|
|
||||||
loadCommands()
|
loadCommands()
|
||||||
import core.logstash
|
|
||||||
|
|
||||||
core.logstash.init_logstash()
|
core.logstash.init_logstash()
|
||||||
|
signal(SIGINT, handler) # Handle Ctrl-C and run the cleanup routine
|
||||||
|
stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know
|
||||||
|
stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using
|
||||||
|
# unicode quit messages for no reason
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
listener = ServerFactory()
|
listener = ServerFactory()
|
||||||
if main.config["Listener"]["UseSSL"] == True:
|
if main.config["Listener"]["UseSSL"] is True:
|
||||||
reactor.listenSSL(
|
reactor.listenSSL(
|
||||||
main.config["Listener"]["Port"],
|
main.config["Listener"]["Port"],
|
||||||
listener,
|
listener,
|
||||||
|
@ -59,7 +64,7 @@ if __name__ == "__main__":
|
||||||
log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
|
log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]))
|
||||||
if main.config["RelayAPI"]["Enabled"]:
|
if main.config["RelayAPI"]["Enabled"]:
|
||||||
relay = RelayFactory()
|
relay = RelayFactory()
|
||||||
if main.config["RelayAPI"]["UseSSL"] == True:
|
if main.config["RelayAPI"]["UseSSL"] is True:
|
||||||
reactor.listenSSL(
|
reactor.listenSSL(
|
||||||
main.config["RelayAPI"]["Port"],
|
main.config["RelayAPI"]["Port"],
|
||||||
relay,
|
relay,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import main
|
import main
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from utils.logging.debug import debug
|
from utils.logging.debug import debug
|
||||||
from utils.logging.log import *
|
from utils.logging.log import log
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def handler(sig, frame):
|
def handler(sig, frame):
|
||||||
|
|
|
@ -19,7 +19,7 @@ def dedup(numName, b):
|
||||||
return True
|
return True
|
||||||
if numName in main.lastEvents.keys():
|
if numName in main.lastEvents.keys():
|
||||||
main.lastEvents[numName].insert(0, castHash)
|
main.lastEvents[numName].insert(0, castHash)
|
||||||
main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]]
|
main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]] # noqa
|
||||||
else:
|
else:
|
||||||
main.lastEvents[numName] = [castHash]
|
main.lastEvents[numName] = [castHash]
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,7 +1,162 @@
|
||||||
|
import main
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
|
from twisted.internet import reactor
|
||||||
|
from twisted.words.protocols.irc import IRCClient
|
||||||
|
|
||||||
|
from twisted.internet.protocol import ReconnectingClientFactory
|
||||||
|
from utils.parsing import parsen
|
||||||
|
from utils.logging.log import log, error
|
||||||
|
from utils.logging.send import sendAll
|
||||||
|
from modules import userinfo
|
||||||
|
from datetime import datetime
|
||||||
|
from core.relay import sendRelayNotification
|
||||||
|
from utils.get import getRelay
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: strip out non-relay functionality
|
||||||
|
class IRCRelay(IRCClient):
|
||||||
|
def __init__(self, num, relayCommands, user, stage2):
|
||||||
|
self.isconnected = False
|
||||||
|
self.buffer = ""
|
||||||
|
if user is None:
|
||||||
|
self.user = main.config["Relay"]["User"]
|
||||||
|
else:
|
||||||
|
self.user = user.lower()
|
||||||
|
password = main.config["Relay"]["Password"]
|
||||||
|
self.nickname = "relay"
|
||||||
|
self.realname = "relay"
|
||||||
|
self.username = self.user
|
||||||
|
self.password = self.user + ":" + password
|
||||||
|
|
||||||
|
self.relayCommands = relayCommands
|
||||||
|
self.num = num
|
||||||
|
self.stage2 = stage2
|
||||||
|
self.loop = None
|
||||||
|
|
||||||
|
def privmsg(self, user, channel, msg):
|
||||||
|
nick, ident, host = parsen(user)
|
||||||
|
for i in main.ZNCErrors:
|
||||||
|
if i in msg:
|
||||||
|
error("ZNC issue:", msg)
|
||||||
|
if nick[0] == main.config["Tweaks"]["ZNC"]["Prefix"]:
|
||||||
|
nick = nick[1:]
|
||||||
|
if nick in self.relayCommands.keys():
|
||||||
|
sendAll("[%s] %s -> %s" % (self.num, nick, msg))
|
||||||
|
|
||||||
|
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
||||||
|
log("%s: relay password mismatch" % self.num)
|
||||||
|
sendAll("%s: relay password mismatch" % self.num)
|
||||||
|
|
||||||
|
def sendStage2(self):
|
||||||
|
# [["user", {"sasl": ["message1", "message2"]}], []]
|
||||||
|
if not len(self.stage2) == 0:
|
||||||
|
user = self.stage2[0].pop(0)
|
||||||
|
commands = self.stage2[0].pop(0)
|
||||||
|
del self.stage2[0]
|
||||||
|
deliverRelayCommands(self.num, commands, user, self.stage2)
|
||||||
|
|
||||||
|
def signedOn(self):
|
||||||
|
if not self.isconnected:
|
||||||
|
self.isconnected = True
|
||||||
|
# log("signed on as a relay: %s" % self.num)
|
||||||
|
sleeptime = 0
|
||||||
|
increment = 0.8
|
||||||
|
for i in self.relayCommands.keys():
|
||||||
|
for x in self.relayCommands[i]:
|
||||||
|
reactor.callLater(
|
||||||
|
sleeptime,
|
||||||
|
self.msg,
|
||||||
|
main.config["Tweaks"]["ZNC"]["Prefix"] + i,
|
||||||
|
x,
|
||||||
|
)
|
||||||
|
sleeptime += increment
|
||||||
|
increment += 0.8
|
||||||
|
if self.stage2 is not None:
|
||||||
|
reactor.callLater(sleeptime, self.sendStage2)
|
||||||
|
reactor.callLater(sleeptime + 5, self.transport.loseConnection)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class IRCRelayFactory(ReconnectingClientFactory):
|
||||||
|
def __init__(self, net, num=None, relayCommands=None, user=None, stage2=None):
|
||||||
|
if net is None:
|
||||||
|
self.num = num
|
||||||
|
self.net = None
|
||||||
|
self.name = "relay - %i" % num
|
||||||
|
self.relay = True
|
||||||
|
else:
|
||||||
|
self.name = net + str(num)
|
||||||
|
self.num = num
|
||||||
|
self.net = net
|
||||||
|
self.relay = False
|
||||||
|
self.client = None
|
||||||
|
self.maxDelay = main.config["Tweaks"]["Delays"]["MaxDelay"]
|
||||||
|
self.initialDelay = main.config["Tweaks"]["Delays"]["InitialDelay"]
|
||||||
|
self.factor = main.config["Tweaks"]["Delays"]["Factor"]
|
||||||
|
self.jitter = main.config["Tweaks"]["Delays"]["Jitter"]
|
||||||
|
|
||||||
|
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
|
||||||
|
|
||||||
|
def buildProtocol(self, addr):
|
||||||
|
|
||||||
|
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
|
||||||
|
|
||||||
|
self.client = entry
|
||||||
|
return entry
|
||||||
|
|
||||||
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
if not self.relay:
|
||||||
|
userinfo.delChannels(self.net, self.client.channels)
|
||||||
|
if self.client is not None:
|
||||||
|
self.client.isconnected = False
|
||||||
|
self.client.authenticated = False
|
||||||
|
self.client.channels = []
|
||||||
|
error = reason.getErrorMessage()
|
||||||
|
if not self.relay:
|
||||||
|
log("%s - %i: connection lost: %s" % (self.net, self.num, error))
|
||||||
|
sendAll("%s - %i: connection lost: %s" % (self.net, self.num, error))
|
||||||
|
ctime = str(datetime.now().isoformat())
|
||||||
|
sendRelayNotification(
|
||||||
|
{
|
||||||
|
"type": "conn",
|
||||||
|
"net": self.net,
|
||||||
|
"num": self.num,
|
||||||
|
"status": "lost",
|
||||||
|
"message": error,
|
||||||
|
"ts": ctime,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.retry(connector)
|
||||||
|
# ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
if self.client is not None:
|
||||||
|
self.client.isconnected = False
|
||||||
|
self.client.authenticated = False
|
||||||
|
self.client.channels = []
|
||||||
|
error = reason.getErrorMessage()
|
||||||
|
log("%s - %i: connection failed: %s" % (self.net, self.num, error))
|
||||||
|
if not self.relay:
|
||||||
|
sendAll("%s - %s: connection failed: %s" % (self.net, self.num, error))
|
||||||
|
ctime = str(datetime.now().isoformat())
|
||||||
|
sendRelayNotification(
|
||||||
|
{
|
||||||
|
"type": "conn",
|
||||||
|
"net": self.net,
|
||||||
|
"num": self.num,
|
||||||
|
"status": "failed",
|
||||||
|
"message": error,
|
||||||
|
"ts": ctime,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.retry(connector)
|
||||||
|
# ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
||||||
|
|
||||||
|
|
||||||
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
|
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
|
||||||
keyFN = main.certPath + main.config["Key"]
|
keyFN = main.certPath + main.config["Key"]
|
||||||
certFN = main.certPath + main.config["Certificate"]
|
certFN = main.certPath + main.config["Certificate"]
|
||||||
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
|
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
|
||||||
bot = IRCBotFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
|
bot = IRCRelayFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
|
||||||
host, port = getRelay(num)
|
host, port = getRelay(num)
|
||||||
rct = reactor.connectSSL(host, port, bot, contextFactory)
|
reactor.connectSSL(host, port, bot, contextFactory)
|
||||||
|
|
|
@ -4,8 +4,8 @@ import main
|
||||||
def getRelay(num):
|
def getRelay(num):
|
||||||
host = main.config["Relay"]["Host"].replace("x", str(num))
|
host = main.config["Relay"]["Host"].replace("x", str(num))
|
||||||
port = int(str(main.config["Relay"]["Port"]).replace("x", str(num).zfill(2)))
|
port = int(str(main.config["Relay"]["Port"]).replace("x", str(num).zfill(2)))
|
||||||
user = main.config["Relay"]["User"]
|
# user = main.config["Relay"]["User"]
|
||||||
password = main.config["Relay"]["Password"]
|
# password = main.config["Relay"]["Password"]
|
||||||
try:
|
try:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
|
||||||
from utils.logging.debug import debug
|
from utils.logging.debug import debug
|
||||||
from utils.logging.log import *
|
from utils.logging.log import error
|
||||||
import commands
|
|
||||||
|
|
||||||
from main import CommandMap
|
from main import CommandMap
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ def loadCommands(allowDup=False):
|
||||||
className = commandName.capitalize() + "Command"
|
className = commandName.capitalize() + "Command"
|
||||||
# try:
|
# try:
|
||||||
module = __import__("commands.%s" % commandName)
|
module = __import__("commands.%s" % commandName)
|
||||||
if not commandName in CommandMap:
|
if commandName not in CommandMap:
|
||||||
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||||||
debug("Registered command: %s" % commandName)
|
debug("Registered command: %s" % commandName)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,8 +3,6 @@ from importlib import reload
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from utils.logging.debug import debug
|
from utils.logging.debug import debug
|
||||||
from utils.logging.log import *
|
|
||||||
import commands
|
|
||||||
|
|
||||||
from main import CommandMap
|
from main import CommandMap
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
|
|
||||||
# we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main
|
# we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main
|
||||||
# to read the setting
|
# to read the setting
|
||||||
def debug(*data):
|
def debug(*data):
|
||||||
|
|
|
@ -32,7 +32,7 @@ def sendAll(data):
|
||||||
|
|
||||||
|
|
||||||
def incorrectUsage(addr, mode):
|
def incorrectUsage(addr, mode):
|
||||||
if mode == None:
|
if mode is None:
|
||||||
sendFailure(addr, "Incorrect usage")
|
sendFailure(addr, "Incorrect usage")
|
||||||
return
|
return
|
||||||
if mode in main.help.keys():
|
if mode in main.help.keys():
|
||||||
|
|
Loading…
Reference in New Issue