|
|
|
@ -5,7 +5,7 @@ from klein import Klein
|
|
|
|
|
from twisted.web.server import Request
|
|
|
|
|
|
|
|
|
|
import main
|
|
|
|
|
from modules import userinfo
|
|
|
|
|
from modules import chankeep, userinfo
|
|
|
|
|
from utils.logging.log import warn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,7 +195,7 @@ class API(object):
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network(self, request, net):
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps(False)
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
inst = main.network[net]
|
|
|
|
|
network = {}
|
|
|
|
|
network["net"] = inst.net
|
|
|
|
@ -217,7 +217,7 @@ class API(object):
|
|
|
|
|
except JSONDecodeError:
|
|
|
|
|
return "Invalid JSON"
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps(False)
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
inst = main.network[net]
|
|
|
|
|
for item in data:
|
|
|
|
|
if item == "auth":
|
|
|
|
@ -252,7 +252,7 @@ class API(object):
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network_relays(self, request, net):
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps(False)
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
relays_inst = main.network[net].relays
|
|
|
|
|
relays = []
|
|
|
|
|
for num in relays_inst.keys():
|
|
|
|
@ -268,11 +268,37 @@ class API(object):
|
|
|
|
|
|
|
|
|
|
return dumps({"relays": relays})
|
|
|
|
|
|
|
|
|
|
@app.route("/irc/network/<net>/<num>/", methods=["POST"])
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network_relay(self, request, net, num):
|
|
|
|
|
try:
|
|
|
|
|
data = loads(request.content.read())
|
|
|
|
|
except JSONDecodeError:
|
|
|
|
|
return "Invalid JSON"
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
if not num.isdigit():
|
|
|
|
|
return dumps({"success": False, "reason": "invalid num: not a number."})
|
|
|
|
|
num = int(num)
|
|
|
|
|
net_inst = main.network[net]
|
|
|
|
|
if num not in net_inst.relays:
|
|
|
|
|
return dumps({"success": False, "reason": "network has no such relay."})
|
|
|
|
|
if "status" in data:
|
|
|
|
|
if not type(data["status"]) == int:
|
|
|
|
|
return dumps({"success": False, "reason": "invalid type for enabled."})
|
|
|
|
|
enabled = data["status"]
|
|
|
|
|
if enabled:
|
|
|
|
|
net_inst.enable_relay(num)
|
|
|
|
|
else:
|
|
|
|
|
net_inst.disable_relay(num)
|
|
|
|
|
main.saveConf("network")
|
|
|
|
|
return dumps({"success": True})
|
|
|
|
|
|
|
|
|
|
@app.route("/irc/network/<net>/channels/", methods=["POST"])
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network_channels(self, request, net):
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps(False)
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
relays_inst = main.network[net].relays
|
|
|
|
|
channels = {}
|
|
|
|
|
for num in relays_inst.keys():
|
|
|
|
@ -284,3 +310,34 @@ class API(object):
|
|
|
|
|
channels[channel] = channels_annotated[channel]
|
|
|
|
|
|
|
|
|
|
return dumps({"channels": channels})
|
|
|
|
|
|
|
|
|
|
@app.route("/irc/network/<net>/channel/<channel>/", methods=["DELETE"])
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network_channel_part(self, request, net, channel):
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
parted = chankeep.partSingle(net, channel)
|
|
|
|
|
if not parted:
|
|
|
|
|
dumps({"success": False, "reason": "no channels matched."})
|
|
|
|
|
return dumps({"success": True, "relays": parted})
|
|
|
|
|
|
|
|
|
|
@app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"])
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_network_channel_join(self, request, net, channel):
|
|
|
|
|
if net not in main.network.keys():
|
|
|
|
|
return dumps({"success": False, "reason": "no such net."})
|
|
|
|
|
joined = chankeep.joinSingle(net, channel)
|
|
|
|
|
if not joined:
|
|
|
|
|
dumps({"success": False, "reason": "no channels joined."})
|
|
|
|
|
return dumps({"success": True, "relays": joined})
|
|
|
|
|
|
|
|
|
|
@app.route("/aliases/", methods=["GET"])
|
|
|
|
|
@login_required
|
|
|
|
|
def aliases(self, request):
|
|
|
|
|
alias_list = []
|
|
|
|
|
for num, alias in main.alias.items():
|
|
|
|
|
alias_dup = dict(alias)
|
|
|
|
|
alias_dup["num"] = num
|
|
|
|
|
alias_list.append(alias_dup)
|
|
|
|
|
|
|
|
|
|
return dumps({"aliases": alias_list})
|
|
|
|
|