Implement the backend for automatically provisioning relays
This commit is contained in:
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)
|
||||
Reference in New Issue
Block a user