Implement the backend for automatically provisioning relays
This commit is contained in:
@@ -7,15 +7,17 @@ class Alias:
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 6:
|
||||
if length == 8:
|
||||
if spl[1] == "add":
|
||||
if spl[2] in main.alias.keys():
|
||||
failure("Alias already exists: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
main.alias[spl[2]] = {"nick": spl[3],
|
||||
"ident": spl[4],
|
||||
"realname": spl[5]}
|
||||
"altnick": spl[4],
|
||||
"ident": spl[5],
|
||||
"realname": spl[6],
|
||||
"password": spl[7]}
|
||||
success("Successfully created alias: %s" % spl[2])
|
||||
main.saveConf("alias")
|
||||
return
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import main
|
||||
|
||||
class Default:
|
||||
def __init__(self, register):
|
||||
register("default", self.default)
|
||||
|
||||
def default(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
toUnset = False
|
||||
if length == 1:
|
||||
optionMap = ["Viewing defaults"]
|
||||
for i in main.config["Default"].keys():
|
||||
optionMap.append("%s: %s" % (i, main.config["Default"][i]))
|
||||
info("\n".join(optionMap))
|
||||
return
|
||||
elif length == 2:
|
||||
if not spl[1] in main.config["Default"].keys():
|
||||
failure("No such key: %s" % spl[1])
|
||||
return
|
||||
info("%s: %s" % (spl[1], main.config["Default"][spl[1]]))
|
||||
return
|
||||
elif length == 3:
|
||||
if not spl[1] in main.config["Default"].keys():
|
||||
failure("No such key: %s" % spl[1])
|
||||
return
|
||||
|
||||
if spl[2].lower() in ["none", "nil"]:
|
||||
spl[2] = None
|
||||
toUnset = True
|
||||
|
||||
if spl[1] in ["port", "timeout", "maxdelay"]:
|
||||
try:
|
||||
spl[2] = int(spl[2])
|
||||
except:
|
||||
failure("Value must be an integer, not %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[2] in ["initialdelay", "factor", "jitter"]:
|
||||
try:
|
||||
spl[3] = float(spl[3])
|
||||
except:
|
||||
failure("Value must be a floating point integer, not %s" % spl[3])
|
||||
return
|
||||
|
||||
if spl[1] == "protocol":
|
||||
if not toUnset:
|
||||
if not spl[2] in ["ssl", "plain"]:
|
||||
failure("Protocol must be ssl or plain, not %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[2] == main.config["Default"][spl[1]]:
|
||||
failure("Value already exists: %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[1] == "authtype":
|
||||
if not toUnset:
|
||||
if not spl[2] in ["sp", "ns"]:
|
||||
failure("Authtype must be sp or ns, not %s" % spl[2])
|
||||
return
|
||||
if spl[1] == "enabled":
|
||||
failure("Use the ConnectOnCreate main.config parameter to set this")
|
||||
return
|
||||
if spl[1] == "autojoin":
|
||||
if not toUnset:
|
||||
spl[2] = spl[2].split(",")
|
||||
else:
|
||||
spl[2] = []
|
||||
|
||||
main.config["Default"][spl[1]] = spl[2]
|
||||
main.saveConf("config")
|
||||
if toUnset:
|
||||
success("Successfully unset key %s" % spl[1])
|
||||
else:
|
||||
success("Successfully set key %s to %s" % (spl[1], spl[2]))
|
||||
return
|
||||
else:
|
||||
incUsage("default")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
60
commands/network.py
Normal file
60
commands/network.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
|
||||
class Network:
|
||||
def __init__(self, register):
|
||||
register("network", self.network)
|
||||
|
||||
def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 7:
|
||||
if spl[1] == "add":
|
||||
if spl[2] in main.network.keys():
|
||||
failure("Network already exists: %s" % spl[2])
|
||||
return
|
||||
if not spl[4].isdigit():
|
||||
failure("Port must be an integer, not %s" % spl[4])
|
||||
return
|
||||
if not spl[5].lower() in ["ssl", "plain"]:
|
||||
failure("Security must be ssl or plain, not %s" % spl[5])
|
||||
return
|
||||
if not spl[6].lower() in ["sasl", "ns", "none"]:
|
||||
failure("Auth must be sasl, ns or none, not %s" % spl[5])
|
||||
return
|
||||
else:
|
||||
main.network[spl[2]] = {"host": spl[3],
|
||||
"port": spl[4],
|
||||
"security": spl[5].lower(),
|
||||
"auth": spl[6].lower()}
|
||||
success("Successfully created network: %s" % spl[2])
|
||||
main.saveConf("network")
|
||||
return
|
||||
else:
|
||||
incUsage("network")
|
||||
return
|
||||
|
||||
elif length == 3:
|
||||
if spl[1] == "del":
|
||||
if spl[2] in main.network.keys():
|
||||
del main.network[spl[2]]
|
||||
success("Successfully removed network: %s" % spl[2])
|
||||
main.saveConf("network")
|
||||
return
|
||||
else:
|
||||
failure("No such network: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
incUsage("network")
|
||||
return
|
||||
elif length == 2:
|
||||
if spl[1] == "list":
|
||||
info(dump(main.network))
|
||||
return
|
||||
else:
|
||||
incUsage("network")
|
||||
return
|
||||
else:
|
||||
incUsage("network")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
59
commands/provision.py
Normal file
59
commands/provision.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import main
|
||||
from modules import provision
|
||||
|
||||
class Provision:
|
||||
def __init__(self, register):
|
||||
register("provision", self.provision)
|
||||
|
||||
def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 4 or length == 3:
|
||||
if not spl[1] in main.relay.keys():
|
||||
failure("No such relay: %s" % spl[1])
|
||||
return
|
||||
if not spl[2] in main.alias.keys():
|
||||
failure("No such alias: %s" % spl[2])
|
||||
return
|
||||
if length == 4: # provision for relay, alias and network
|
||||
if not spl[3] in main.network.keys():
|
||||
failure("No such network: %s" % spl[3])
|
||||
return
|
||||
|
||||
if "users" in main.relay[spl[1]]:
|
||||
if not spl[2] in main.relay[spl[1]]["users"]:
|
||||
failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
||||
return
|
||||
else:
|
||||
failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
||||
return
|
||||
|
||||
rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3])
|
||||
if rtrn == "PROVISIONED":
|
||||
failure("Relay %s already provisioned for network %s" % (spl[1], spl[3]))
|
||||
return
|
||||
elif rtrn == "DUPLICATE":
|
||||
failure("Instance with relay %s and alias %s already exists for network %s" % (spl[1], spl[2], spl[3]))
|
||||
elif rtrn:
|
||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[3], spl[1], spl[2]))
|
||||
info("Instance name is %s" % rtrn)
|
||||
return
|
||||
else:
|
||||
failure("Failure while provisioning relay %s" % spl[1])
|
||||
return
|
||||
if length == 3: # provision for relay and alias only
|
||||
rtrn = provision.provisionRelayForAlias(spl[1], spl[2])
|
||||
if rtrn == "PROVISIONED":
|
||||
failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2]))
|
||||
return
|
||||
elif rtrn:
|
||||
success("Started provisioning relay %s for alias %s" % (spl[1], spl[2]))
|
||||
return
|
||||
else:
|
||||
failure("Failure while provisioning relay %s" % spl[1])
|
||||
return
|
||||
|
||||
else:
|
||||
incUsage("provision")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -12,10 +12,10 @@ class Relay:
|
||||
if spl[2] in main.relay.keys():
|
||||
failure("Relay already exists: %s" % spl[2])
|
||||
return
|
||||
if not spl[4].isdigit():
|
||||
failure("Port must be an integer, not %s" % spl[4])
|
||||
return
|
||||
else:
|
||||
if not spl[4].isdigit():
|
||||
failure("Port must be an integer, not %s" % spl[4])
|
||||
return
|
||||
main.relay[spl[2]] = {"host": spl[3],
|
||||
"port": spl[4],
|
||||
"user": spl[5],
|
||||
|
||||
Reference in New Issue
Block a user