summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2020-10-29 14:59:13 +0100
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-29 15:03:35 +0100
commitc08aca92196cdd8df4c8d81da71e248b407f5bb2 (patch)
treeaa61c3524b58a0b50886a92cf4fe6eca36ba822b
parenta8d7494ab9601d2ea4fb2065018580fb2a1c95b3 (diff)
Add software action
This action lists every piece of software installed in an OS from a client. This action can handle listing the software from the DB as well as updating that DB with the latest client information.
-rw-r--r--ogcp/forms/action_forms.py6
-rw-r--r--ogcp/templates/actions/software.html11
-rw-r--r--ogcp/templates/scopes.html2
-rw-r--r--ogcp/views.py40
4 files changed, 58 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 154e9f0..bc0915a 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -33,6 +33,12 @@ class HardwareForm(FlaskForm):
ips = HiddenField()
refresh = SubmitField(label=_('Refresh'))
+class SoftwareForm(FlaskForm):
+ ips = HiddenField()
+ os = SelectField(label=_('Partition'), choices=[])
+ view = SubmitField(label=_('View'))
+ update = SubmitField(label=_('Update'))
+
class SessionForm(FlaskForm):
ips = HiddenField()
os = RadioField(label=_('Session'), choices=[])
diff --git a/ogcp/templates/actions/software.html b/ogcp/templates/actions/software.html
new file mode 100644
index 0000000..713f89b
--- /dev/null
+++ b/ogcp/templates/actions/software.html
@@ -0,0 +1,11 @@
+{% extends 'base.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% block content %}
+
+{{ wtf.quick_form(form,
+ action=url_for('action_software'),
+ method='post',
+ button_map={'view': 'primary', 'update': 'primary'}) }}
+
+{% endblock %}
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 19ce9d8..d810b2a 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="{{ _('Software') }}"
+ formaction="{{ url_for('action_software') }}" formmethod="get">
<input class="dropdown-item" type="submit" value="{{ _('Sessions') }}"
formaction="{{ url_for('action_session') }}" formmethod="get">
<input class="dropdown-item" type="submit" value="{{ _('Restore Image') }}"
diff --git a/ogcp/views.py b/ogcp/views.py
index 7aaf60d..09486d5 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1,7 +1,7 @@
from flask import g, render_template, url_for, request, jsonify, make_response
from ogcp.forms.action_forms import (
WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm,
- ImageRestoreForm, ImageCreateForm
+ ImageRestoreForm, ImageCreateForm, SoftwareForm
)
from ogcp.og_server import OGServer
from flask_babel import _
@@ -269,6 +269,44 @@ def action_hardware():
return render_template('actions/hardware.html', form=form,
hardware=hardware)
+@app.route('/action/software', methods=['GET', 'POST'])
+def action_software():
+ form = SoftwareForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ disk, partition = form.os.data.split(' ')
+ if form.view.data:
+ r = g.server.get('/software', payload={'client': ips,
+ 'disk': int(disk),
+ 'partition': int(partition)})
+ if r.status_code == requests.codes.ok:
+ return r.json()
+
+ elif form.update.data:
+ r = g.server.post('/software', payload={'clients': ips,
+ 'disk': disk,
+ 'partition': partition})
+ if r.status_code == requests.codes.ok:
+ return make_response(f"Se generó correctamente el perfil "
+ f"software de {ips[0]} D:{disk} "
+ f"P:{partition}",
+ 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('/client/setup', payload={'client': list(ips)})
+
+ for part in r.json()['partitions'][1:]:
+ form.os.choices.append(
+ (f"{part.get('disk')} {part.get('partition')}",
+ f"Disco {part.get('disk')} | Partición {part.get('partition')} "
+ f"| {PART_TYPE_CODES[part.get('code')]} "
+ f"{FS_CODES[part.get('filesystem')]}")
+ )
+ return render_template('actions/software.html', form=form)
+
@app.route('/action/session', methods=['GET', 'POST'])
def action_session():
form = SessionForm(request.form)