summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-01-20 13:26:43 +0100
committersoleta <soleta@soleta.eu>2022-01-20 15:20:38 +0100
commitb566528012aabfc435f82525d84471ab7bbcff74 (patch)
tree969b335ac7e1a3d958819cabdec511f3abbbc1c6 /ogcp/views.py
parentddd46295717bd63bd31eadb506a93a66c45c0b02 (diff)
Adds confirmation page to reboot clients
This commit adds an extra view to ensure users do not reboot clients accidentally. ogcp GET /reboot returns the confirmation page and POST /reboot 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.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 93c95e1..3c587d2 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -793,20 +793,34 @@ def action_image_create():
form.os.choices.append((choice_value, choice_name))
return render_template('actions/image_create.html', form=form)
-@app.route('/action/reboot', methods=['POST'])
+@app.route('/action/reboot', methods=['GET', 'POST'])
@login_required
def action_reboot():
- ips = parse_elements(request.form.to_dict())
- if not validate_elements(ips):
- return redirect(url_for('commands'))
+ 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': list(ips)}
- r = g.server.post('/reboot', payload)
- if r.status_code != requests.codes.ok:
- flash(_('OgServer replied with a non ok status code'), category='error')
+ payload = {'clients': ips}
+ r = g.server.post('/reboot', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error rebooting client'),
+ category='error')
+ else:
+ flash(_('Client rebooted successfully'),
+ category='info')
+ return redirect(url_for('commands'))
else:
- flash(_('Refresh request processed successfully'), category='info')
- return redirect(url_for('commands'))
+ 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/reboot.html', form=form,
+ scopes=scopes)
+ else:
+ return redirect(url_for('commands'))
+
@app.route('/action/refresh', methods=['POST'])
@login_required