summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-01-20 11:21:59 +0100
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-01-20 12:54:57 +0100
commitddd46295717bd63bd31eadb506a93a66c45c0b02 (patch)
tree4c73a973fee008ef7eeb3859b508d4e59d309933 /ogcp/views.py
parent20a89ce96535508974a4c9315c062928bea17a85 (diff)
Adds confirmation page to power off clients
This commit adds an extra view to ensure users do not power off clients accidentally. ogcp GET /poweroff returns the confirmation page and POST /poweroff builds and sends the request to ogServer. It also includes Spanish translation of the new strings.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index de92430..93c95e1 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -254,15 +254,34 @@ def scopes():
scopes, clients = get_scopes()
return render_template('scopes.html', scopes=scopes, clients=clients)
-@app.route('/action/poweroff', methods=['POST'])
+@app.route('/action/poweroff', methods=['GET', 'POST'])
@login_required
def action_poweroff():
- ips = parse_elements(request.form.to_dict())
- if not validate_elements(ips):
+ form = GenericForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ if not validate_elements(ips):
+ return redirect(url_for('commands'))
+
+ payload = {'clients': ips}
+ r = g.server.post('/poweroff', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error powering off client'),
+ category='error')
+ else:
+ flash(_('Client powered off successfully'),
+ category='info')
return redirect(url_for('commands'))
- payload = {'clients': list(ips)}
- g.server.post('/poweroff', payload)
- return redirect(url_for('commands'))
+ else:
+ ips = parse_elements(request.args.to_dict())
+ form.ips.data = " ".join(ips)
+ if validate_elements(ips):
+ scopes, clients = get_scopes(set(ips))
+ return render_template('actions/poweroff.html', form=form,
+ scopes=scopes)
+ else:
+ return redirect(url_for('commands'))
+
@app.route('/action/wol', methods=['GET', 'POST'])
@login_required