From b566528012aabfc435f82525d84471ab7bbcff74 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Thu, 20 Jan 2022 13:26:43 +0100 Subject: 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. --- ogcp/views.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'ogcp/views.py') 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 -- cgit v1.2.3-18-g5258