From c12ff832c7b46e7af9fa89f4c2f944e047e4c281 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Wed, 2 Sep 2020 14:46:20 +0200 Subject: Add action_poweroff() view function This function handles a poweroff request to one or multiple scopes. --- ogcp/views.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ogcp/views.py b/ogcp/views.py index ad6bdaa..a458530 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,8 +1,14 @@ -from flask import g, render_template, url_for +from flask import g, render_template, url_for, request, jsonify, make_response from ogcp.og_server import OGServer from flask_babel import _ from ogcp import app +def parse_ips(checkboxes_dict): + ips = set() + for ips_list in checkboxes_dict.values(): + ips.update(ips_list.split(' ')) + return ips + @app.before_request def load_config(): g.server = OGServer() @@ -35,3 +41,10 @@ def scopes(): clients = r.json() add_state_to_scopes(scopes, clients['clients']) return render_template('scopes.html', scopes=scopes, clients=clients) + +@app.route('/action/poweroff', methods=['POST']) +def action_poweroff(): + ips = parse_ips(request.form.to_dict()) + payload = {'clients': list(ips)} + g.server.post('/poweroff', payload) + return make_response("200 OK", 200) -- cgit v1.2.3-18-g5258