diff options
Diffstat (limited to 'ogcp')
-rw-r--r-- | ogcp/forms/action_forms.py | 7 | ||||
-rw-r--r-- | ogcp/templates/scopes.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 25 |
3 files changed, 32 insertions, 2 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 39dae81..4dfaa21 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -1,6 +1,6 @@ from wtforms import ( Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, - StringField + StringField, RadioField ) from flask_wtf import FlaskForm from flask_babel import _ @@ -33,6 +33,11 @@ class HardwareForm(FlaskForm): ips = HiddenField() refresh = SubmitField(label=_('Refresh')) +class SessionForm(FlaskForm): + ips = HiddenField() + os = RadioField(label=_('Session'), choices=[]) + run = SubmitField(label=_('Run')) + class ClientDetailsForm(FlaskForm): name = StringField(label=_('Name')) ip = StringField(label=_('IP')) diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index 460fc3e..27524e9 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -42,6 +42,8 @@ formaction="{{ url_for('action_refresh') }}" formmethod="post"> <input class="dropdown-item" type="submit" value="{{ _('Hardware') }}" formaction="{{ url_for('action_hardware') }}" formmethod="get"> + <input class="dropdown-item" type="submit" value="{{ _('Sessions') }}" + formaction="{{ url_for('action_session') }}" formmethod="get"> <input class="dropdown-item" type="submit" value="{{ _('Setup') }}" formaction="{{ url_for('action_setup_show') }}" formmethod="get"> <input class="dropdown-item" type="submit" value="{{ _('Details') }}" diff --git a/ogcp/views.py b/ogcp/views.py index a8add41..e3f559d 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,6 +1,6 @@ from flask import g, render_template, url_for, request, jsonify, make_response from ogcp.forms.action_forms import ( - WOLForm, PartitionForm, ClientDetailsForm, HardwareForm + WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm ) from ogcp.og_server import OGServer from flask_babel import _ @@ -214,6 +214,29 @@ def action_hardware(): return render_template('actions/hardware.html', form=form, hardware=hardware) +@app.route('/action/session', methods=['GET', 'POST']) +def action_session(): + form = SessionForm(request.form) + if request.method == 'POST': + ips = form.ips.data.split(' ') + disk, partition = form.os.data.split(' ') + r = g.server.post('/session', payload={'clients': ips, + 'disk': str(disk), + 'partition': str(partition)}) + if r.status_code == requests.codes.ok: + return make_response("200 OK", 200) + return make_response("400 Bad Request", 400) + else: + ips = parse_ips(request.args.to_dict()) + form.ips.data = ' '.join(ips) + r = g.server.get('/session', payload={'client': list(ips)}) + sessions = r.json()['sessions'] + for os in sessions: + choice = (f"{os['disk']} {os['partition']}", + f"{os['name']} ({os['disk']},{os['partition']})") + form.os.choices.append(choice) + return render_template('actions/session.html', form=form) + @app.route('/action/client/info', methods=['GET']) def action_client_info(): form = ClientDetailsForm() |