Reformat project

This commit is contained in:
2022-07-21 13:39:59 +01:00
parent 9d4d31fdc2
commit 760e43b59a
57 changed files with 523 additions and 218 deletions

View File

@@ -1,7 +1,8 @@
import main
import random
import re
import main
def generate_password():
return "".join([chr(random.randint(0, 74) + 48) for i in range(32)])

View File

@@ -1,11 +1,13 @@
import main
from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
from math import ceil
import modules.provision
from twisted.internet.threads import deferToThread
import main
import modules.provision
from utils.logging.debug import *
from utils.logging.log import *
def allRelaysActive(net):
relayNum = len(main.network[net].relays.keys())
@@ -46,7 +48,10 @@ def emptyChanAllocate(net, flist, relay, new):
if toalloc > sum(chanfree[0].values()):
correction = round(toalloc - sum(chanfree[0].values()) / chanfree[1])
# print("correction", correction)
warn("Ran out of channel spaces, provisioning additional %i relays for %s" % (correction, net))
warn(
"Ran out of channel spaces, provisioning additional %i relays for %s"
% (correction, net)
)
# newNums = modules.provision.provisionMultipleRelays(net, correction)
return False
for i in chanfree[0].keys():
@@ -99,12 +104,18 @@ def keepChannels(net, listinfo, mean, sigrelay, relay):
listinfo = minifyChans(net, listinfo)
if not listinfo:
return
if relay <= main.config["ChanKeep"]["SigSwitch"]: # we can cover all of the channels
if (
relay <= main.config["ChanKeep"]["SigSwitch"]
): # we can cover all of the channels
coverAll = True
elif relay > main.config["ChanKeep"]["SigSwitch"]: # we cannot cover all of the channels
elif (
relay > main.config["ChanKeep"]["SigSwitch"]
): # we cannot cover all of the channels
coverAll = False
if not sigrelay <= main.config["ChanKeep"]["MaxRelay"]:
error("Network %s is too big to cover: %i relays required" % (net, sigrelay))
error(
"Network %s is too big to cover: %i relays required" % (net, sigrelay)
)
return
if coverAll:
needed = relay - len(main.network[net].relays.keys())

View File

@@ -1,6 +1,7 @@
import main
from twisted.internet.task import LoopingCall
import main
def event(name, eventType):
if not "local" in main.counters.keys():

View File

@@ -2,10 +2,9 @@ from copy import deepcopy
from json import dumps
import main
from core.relay import sendRelayNotification
from core.logstash import sendLogstashNotification
from modules import userinfo
from modules import regproc
from core.relay import sendRelayNotification
from modules import regproc, userinfo
from utils.dedup import dedup
order = [
@@ -68,7 +67,9 @@ def parsemeta(numName, c):
)
def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen
def event(
numName, c
): # yes I'm using a short variable because otherwise it goes off the screen
if dedup(numName, c):
return

View File

@@ -1,14 +1,15 @@
from twisted.internet.ssl import DefaultOpenSSLContextFactory
import json
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
import main
from core.bot import IRCBot, IRCBotFactory
from modules import alias
from modules.chankeep import nukeNetwork
from modules.regproc import needToRegister
from twisted.internet import reactor
from core.bot import IRCBot, IRCBotFactory
import main
from utils.logging.log import *
from utils.get import getRelay
from utils.logging.log import *
class Network:
@@ -77,7 +78,9 @@ class Network:
# e.g. freenode1 for the first relay on freenode network
keyFN = main.certPath + main.config["Key"]
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(self.net, num)
# host, port = self.relays[num]["host"], self.relays[num]["port"]
host, port = getRelay(num)

View File

@@ -1,11 +1,25 @@
from twisted.internet import reactor
import main
import modules.regproc
from core.bot import deliverRelayCommands
from utils.logging.log import *
from twisted.internet import reactor
import modules.regproc
def provisionUserNetworkData(num, nick, altnick, ident, realname, emails, network, host, port, security, auth, password):
def provisionUserNetworkData(
num,
nick,
altnick,
ident,
realname,
emails,
network,
host,
port,
security,
auth,
password,
):
print("nick", nick)
print("altnick", altnick)
print("emails", emails)
@@ -16,17 +30,25 @@ def provisionUserNetworkData(num, nick, altnick, ident, realname, emails, networ
stage2commands["status"] = []
commands["controlpanel"] = []
user = nick.lower()
commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"]))
commands["controlpanel"].append(
"AddUser %s %s" % (user, main.config["Relay"]["Password"])
)
commands["controlpanel"].append("AddNetwork %s %s" % (user, network))
commands["controlpanel"].append("Set Nick %s %s" % (user, nick))
commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick))
commands["controlpanel"].append("Set Ident %s %s" % (user, ident))
commands["controlpanel"].append("Set RealName %s %s" % (user, realname))
if security == "ssl":
commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me
commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port))
commands["controlpanel"].append(
"SetNetwork TrustAllCerts %s %s true" % (user, network)
) # Don't judge me
commands["controlpanel"].append(
"AddServer %s %s %s +%s" % (user, network, host, port)
)
elif security == "plain":
commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port))
commands["controlpanel"].append(
"AddServer %s %s %s %s" % (user, network, host, port)
)
if not main.config["ConnectOnCreate"]:
stage2commands["status"].append("Disconnect")
if main.config["Toggles"]["CycleChans"]:

View File

@@ -1,10 +1,12 @@
import main
from modules import provision
from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
from random import choice
import main
from modules import provision
from utils.logging.debug import *
from utils.logging.log import *
def needToRegister(net):
# Check if the network does not support authentication
networkObj = main.network[net]
@@ -51,7 +53,7 @@ def substitute(net, num, token=None):
nickname = alias["nick"]
username = nickname + "/" + net
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():
if not isinstance(inst[i], str):
continue
@@ -112,8 +114,12 @@ def enableAuthentication(net, num):
auth = obj.auth
password = obj.aliases[num]["password"]
uname = main.alias[num]["nick"] + "/" + net
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")
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"
)
if selectInst(net)["check"] == False:
confirmRegistration(net, num)
@@ -129,10 +135,14 @@ def registerTest(c):
if not main.IRCPool[name]._negativePass == True:
if c["type"] == "query" and c["nick"] == sinst["entity"]:
if sinst["checknegativemsg"] in c["msg"]:
confirmRegistration(c["net"], c["num"], negativepass=False) # Not passed negative check, report back
confirmRegistration(
c["net"], c["num"], negativepass=False
) # Not passed negative check, report back
return
if sinst["checkendnegative"] in c["msg"]:
confirmRegistration(c["net"], c["num"], negativepass=True) # Passed the negative check, report back
confirmRegistration(
c["net"], c["num"], negativepass=True
) # Passed the negative check, report back
return
if sinst["ping"]:
if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]:

View File

@@ -1,9 +1,10 @@
from twisted.internet.threads import deferToThread
from string import digits
from twisted.internet.threads import deferToThread
import main
from utils.logging.log import *
from utils.logging.debug import debug, trace
from utils.logging.log import *
from utils.parsing import parsen
@@ -145,7 +146,9 @@ def delUser(name, channel, nick, user):
p.srem(namespace, nick)
if channels == {channel.encode()}: # can we only see them on this channel?
p.delete(chanspace) # remove channel tracking entry
p.hdel("live.prefix." + name + "." + channel, nick) # remove prefix tracking entry
p.hdel(
"live.prefix." + name + "." + channel, nick
) # remove prefix tracking entry
p.hdel(mapspace, nick) # remove nick mapping entry
if user:
p.srem(gnamespace, user) # remove global userinfo entry
@@ -170,7 +173,10 @@ def getUserByNick(name, nick):
if main.r.hexists(mapspace, nick):
return main.r.hget(mapspace, nick)
else:
warn("Entry doesn't exist: %s on %s - attempting auxiliary lookup" % (nick, mapspace))
warn(
"Entry doesn't exist: %s on %s - attempting auxiliary lookup"
% (nick, mapspace)
)
# return False
# legacy code below - remove when map is reliable
usermatch = main.r.sscan(gnamespace, match=escape(nick) + "!*", count=999999999)
@@ -200,10 +206,18 @@ def renameUser(name, oldnick, olduser, newnick, newuser):
p.sadd("live.who." + name + "." + i, newnick)
p.hdel(mapspace, oldnick)
p.hset(mapspace, newnick, newuser)
if main.r.exists("live.prefix." + name + "." + i): # if there's a prefix entry for the channel
if main.r.hexists("live.prefix." + name + "." + i, oldnick): # if the old nick is in it
mode = main.r.hget("live.prefix." + name + "." + i, oldnick) # retrieve old modes
p.hset("live.prefix." + name + "." + i, newnick, mode) # set old modes to new nickname
if main.r.exists(
"live.prefix." + name + "." + i
): # if there's a prefix entry for the channel
if main.r.hexists(
"live.prefix." + name + "." + i, oldnick
): # if the old nick is in it
mode = main.r.hget(
"live.prefix." + name + "." + i, oldnick
) # retrieve old modes
p.hset(
"live.prefix." + name + "." + i, newnick, mode
) # set old modes to new nickname
if main.r.exists(chanspace):
p.rename(chanspace, newchanspace)
else: