2022-07-21 12:40:09 +00:00
|
|
|
from string import digits
|
|
|
|
|
2022-07-21 12:40:01 +00:00
|
|
|
from yaml import dump
|
2022-07-21 12:40:09 +00:00
|
|
|
|
|
|
|
import main
|
2019-08-11 20:58:14 +00:00
|
|
|
from modules.network import Network
|
2019-01-26 01:57:24 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class NetworkCommand:
|
2019-01-26 18:58:21 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.network(*args)
|
2019-01-26 01:57:24 +00:00
|
|
|
|
2022-07-21 12:40:01 +00:00
|
|
|
def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
2019-01-26 01:57:24 +00:00
|
|
|
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
|
2019-09-29 13:57:36 +00:00
|
|
|
if set(spl[2]).intersection(set(digits)):
|
|
|
|
failure("Network name cannot contain numbers")
|
|
|
|
return
|
2019-01-26 01:57:24 +00:00
|
|
|
if not spl[6].lower() in ["sasl", "ns", "none"]:
|
|
|
|
failure("Auth must be sasl, ns or none, not %s" % spl[5])
|
|
|
|
return
|
|
|
|
else:
|
2022-07-21 12:40:01 +00:00
|
|
|
main.network[spl[2]] = Network(spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower())
|
2019-01-26 01:57:24 +00:00
|
|
|
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():
|
2022-07-21 12:39:41 +00:00
|
|
|
main.network[spl[2]].seppuku() # ;(
|
2019-01-26 01:57:24 +00:00
|
|
|
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)
|