diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-02 14:46:20 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-09-02 14:46:20 +0200 |
commit | c12ff832c7b46e7af9fa89f4c2f944e047e4c281 (patch) | |
tree | a283a8a3f26d3d6e5779f659e6921d20e4d6c607 /ogcp/views.py | |
parent | 30c5173aeaf700c7b03ad252541a353c47352d29 (diff) |
Add action_poweroff() view function
This function handles a poweroff request to one or multiple scopes.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 15 |
1 files changed, 14 insertions, 1 deletions
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) |