Revert "Reformat project"

This reverts commit 64e3e1160aa76d191740342ab3edc68807f890fb.
This commit is contained in:
2022-07-21 13:40:01 +01:00
parent da678617d8
commit 27cafa1def
57 changed files with 214 additions and 519 deletions

View File

@@ -1,8 +1,7 @@
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,12 +1,10 @@
import main
from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
from math import ceil
from twisted.internet.threads import deferToThread
import main
import modules.provision
from utils.logging.debug import *
from utils.logging.log import *
from twisted.internet.threads import deferToThread
def allRelaysActive(net):
@@ -48,10 +46,7 @@ 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():
@@ -104,18 +99,12 @@ 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,5 @@
from twisted.internet.task import LoopingCall
import main
from twisted.internet.task import LoopingCall
def event(name, eventType):

View File

@@ -2,9 +2,10 @@ from copy import deepcopy
from json import dumps
import main
from core.logstash import sendLogstashNotification
from core.relay import sendRelayNotification
from modules import regproc, userinfo
from core.logstash import sendLogstashNotification
from modules import userinfo
from modules import regproc
from utils.dedup import dedup
order = [
@@ -67,9 +68,7 @@ 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,15 +1,14 @@
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 utils.get import getRelay
from twisted.internet import reactor
from core.bot import IRCBot, IRCBotFactory
import main
from utils.logging.log import *
from utils.get import getRelay
class Network:
@@ -78,9 +77,7 @@ 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,25 +1,11 @@
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)
@@ -30,25 +16,17 @@ def provisionUserNetworkData(
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,11 +1,9 @@
from copy import deepcopy
from random import choice
import main
from modules import provision
from utils.logging.debug import *
from utils.logging.log import *
from utils.logging.debug import *
from copy import deepcopy
from random import choice
def needToRegister(net):
# Check if the network does not support authentication
@@ -53,7 +51,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
@@ -114,12 +112,8 @@ 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)
@@ -135,14 +129,10 @@ 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,10 +1,9 @@
from twisted.internet.threads import deferToThread
from string import digits
from twisted.internet.threads import deferToThread
import main
from utils.logging.debug import debug, trace
from utils.logging.log import *
from utils.logging.debug import debug, trace
from utils.parsing import parsen
@@ -146,9 +145,7 @@ 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
@@ -173,10 +170,7 @@ 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)
@@ -206,18 +200,10 @@ 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: