You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.0 KiB
Python

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("main.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)