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.
multi-ogserver
Jose M. Guisado 2020-10-29 14:59:13 +01:00 committed by Roberto Hueso Gómez
parent a8d7494ab9
commit c08aca9219
4 changed files with 58 additions and 1 deletions

View File

@ -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=[])

View File

@ -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 %}

View File

@ -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') }}"

View File

@ -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)