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":
|
|
|
|
if spl[2] in main.relay.keys():
|
|
|
|
failure("Relay already exists: %s" % spl[2])
|
|
|
|
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:
|
|
|
|
main.relay[spl[2]] = {"host": spl[3],
|
|
|
|
"port": spl[4],
|
|
|
|
"user": spl[5],
|
|
|
|
"password": spl[6]}
|
|
|
|
success("Successfully created relay: %s" % spl[2])
|
|
|
|
main.saveConf("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
|
|
|
|
elif length == 3:
|
|
|
|
if spl[1] == "del":
|
|
|
|
if spl[2] in main.relay.keys():
|
|
|
|
del main.relay[spl[2]]
|
|
|
|
success("Successfully removed relay: %s" % spl[2])
|
|
|
|
main.saveConf("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
failure("No such relay: %s" % spl[2])
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
elif length == 2:
|
|
|
|
if spl[1] == "list":
|
|
|
|
info(dump(main.relay))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("relay")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|