2019-01-20 19:56:54 +00:00
|
|
|
import main
|
|
|
|
from yaml import dump
|
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class RelayCommand:
|
2019-01-26 18:58:21 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.relay(*args)
|
2019-01-20 19:56:54 +00:00
|
|
|
|
|
|
|
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
|
|
if authed:
|
|
|
|
if length == 7:
|
|
|
|
if spl[1] == "add":
|
2019-08-11 20:58:14 +00:00
|
|
|
if spl[2] not in main.network.keys():
|
|
|
|
failure("No such network: %s" % spl[2])
|
2019-01-20 19:56:54 +00:00
|
|
|
return
|
2019-01-26 01:57:24 +00:00
|
|
|
if not spl[4].isdigit():
|
|
|
|
failure("Port must be an integer, not %s" % spl[4])
|
|
|
|
return
|
2019-01-20 19:56:54 +00:00
|
|
|
else:
|
2019-08-11 20:58:14 +00:00
|
|
|
id, alias = main.network[spl[2]].add_relay(spl[3], spl[4], spl[5], spl[6])
|
|
|
|
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
|
|
|
|
main.saveConf("network")
|
2019-01-20 19:56:54 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
|
2019-08-11 20:58:14 +00:00
|
|
|
elif length == 4:
|
2019-01-20 19:56:54 +00:00
|
|
|
if spl[1] == "del":
|
2019-08-11 20:58:14 +00:00
|
|
|
if spl[2] not in main.network.keys():
|
|
|
|
failure("No such network: %s" % spl[2])
|
2019-01-20 19:56:54 +00:00
|
|
|
return
|
2019-08-11 20:58:14 +00:00
|
|
|
if int(spl[3]) not in main.network[spl[2]].relays.keys():
|
|
|
|
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
|
2019-01-20 19:56:54 +00:00
|
|
|
return
|
2019-08-11 20:58:14 +00:00
|
|
|
main.network[spl[2]].delete_relay(int(spl[3]))
|
|
|
|
success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
|
|
|
|
main.saveConf("network")
|
|
|
|
return
|
2019-01-20 19:56:54 +00:00
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
2019-08-11 20:58:14 +00:00
|
|
|
elif length == 3:
|
2019-01-20 19:56:54 +00:00
|
|
|
if spl[1] == "list":
|
2019-08-11 20:58:14 +00:00
|
|
|
if spl[2] not in main.network.keys():
|
|
|
|
failure("No such network: %s" % spl[2])
|
|
|
|
return
|
|
|
|
info(dump(main.network[spl[2]].relays))
|
2019-01-20 19:56:54 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|