From 664d032884dcd6366ca1068aa2c2f35fffc2a285 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Mon, 28 Sep 2020 15:02:16 +0200 Subject: Add client details action This action is used to visualize the specific details of a client, such as its IP, Name, MAC, etc. --- ogcp/forms/action_forms.py | 25 ++++++++++++++++++++++++- ogcp/templates/scopes.html | 2 ++ ogcp/views.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) (limited to 'ogcp') diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 6479b48..ac761f5 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -1,5 +1,6 @@ from wtforms import ( - Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField + Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, + StringField ) from flask_wtf import FlaskForm from flask_babel import _ @@ -27,3 +28,25 @@ class PartitionForm(FlaskForm): format_partition = BooleanField(label=_('Format')) modify = SubmitField(label=_('Modify')) delete = SubmitField(label=_('Delete')) + +class ClientDetailsForm(FlaskForm): + name = StringField(label=_('Name')) + ip = StringField(label=_('IP')) + mac = StringField(label=_('MAC')) + serial_number = StringField(label=_('Serial Number')) + netmask = StringField(label=_('Netmask')) + livedir = SelectField(label=_('ogLive'), + choices=[('ogLive', 'Default'),]) + remote = BooleanField(label=_('Remote')) + maintenance = BooleanField(label=_('Maintenance')) + netiface = SelectField(label=_('Interface'), + choices=[('eth0', 'eth0'), + ('eth1', 'eth1'), + ('eth2', 'eth2')]) + netdriver = SelectField(label=_('Driver'), + choices=[('generic', 'generic')]) + repo = SelectField(label=_('Repository'), + choices=[(1, 'Default')]) + room = SelectField(label=_('Room')) + boot = SelectField(label=_('Boot Mode')) + create = SubmitField(label=_('Create')) diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html index 376df67..18775b2 100644 --- a/ogcp/templates/scopes.html +++ b/ogcp/templates/scopes.html @@ -42,6 +42,8 @@ formaction="{{ url_for('action_refresh') }}" formmethod="post"> + diff --git a/ogcp/views.py b/ogcp/views.py index 8c14675..3a03078 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1,5 +1,5 @@ from flask import g, render_template, url_for, request, jsonify, make_response -from ogcp.forms.action_forms import WOLForm, PartitionForm +from ogcp.forms.action_forms import WOLForm, PartitionForm, ClientDetailsForm from ogcp.og_server import OGServer from flask_babel import _ from ogcp import app @@ -37,6 +37,15 @@ def get_client_setup(ip): partition['filesystem'] = FS_CODES[partition['filesystem']] return db_partitions +def parse_scopes_from_tree(tree, scope_type): + scopes = [] + for scope in tree['scope']: + if scope['type'] == scope_type: + scopes.append(scope) + else: + scopes += parse_scopes_from_tree(scope, scope_type) + return scopes + @app.before_request def load_config(): g.server = OGServer() @@ -186,6 +195,40 @@ def action_setup_delete(): return make_response("200 OK", 200) return make_response("400 Bad Request", 400) +@app.route('/action/client/info', methods=['GET']) +def action_client_info(): + form = ClientDetailsForm() + ips = parse_ips(request.args.to_dict()) + payload = {'client': list(ips)} + r = g.server.get('/client/info', payload) + db_client = r.json() + + form.name.data = db_client['name'] + form.ip.data = db_client['ip'] + form.mac.data = db_client['mac'] + form.serial_number.data = db_client['serial_number'] + form.netmask.data = db_client['netmask'] + form.livedir.data = db_client['livedir'] + form.remote.data = db_client['remote'] + form.maintenance.data = db_client['maintenance'] + form.netiface.data = db_client['netiface'] + form.netdriver.data = db_client['netdriver'] + form.repo.data = db_client['repo_id'] + form.room.data = db_client['room'] + form.boot.data = db_client['boot'] + + r = g.server.get('/mode') + available_modes = [(mode, mode) for mode in r.json()['modes']] + form.boot.choices = list(available_modes) + + r = g.server.get('/scopes') + rooms = parse_scopes_from_tree(r.json(), 'room') + rooms = [(room['id'], room['name']) for room in rooms] + form.room.choices = list(rooms) + + form.create.render_kw = {"style": "visibility:hidden;"} + return render_template('actions/client_details.html', form=form) + @app.route('/action/reboot', methods=['POST']) def action_reboot(): ips = parse_ips(request.form.to_dict()) -- cgit v1.2.3-18-g5258