diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-06-21 13:14:51 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-06-25 13:53:04 +0200 |
commit | 0ed9ecdae9a7e4c7fbb30af30ef4310cd45f2143 (patch) | |
tree | 0abf1330b55891c18ba62c39a39977cfc0566ab3 /ogcp/views.py | |
parent | af8236b18948b083c408df39306fc36bc26b51b7 (diff) |
ogcp: add support to view script output
Add view at /action/script/output to visualize the result of
/shell/run for multiple clients.
Use shell/output to request the execution data of the selected clients.
Each client element has execution timestamip (UTC), client ip, cmd,
return code and stdout of the executed command.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 109957a..45a0f73 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1881,6 +1881,48 @@ def action_run_script(): selected_clients=selected_clients, scopes=scopes) +@app.route('/action/script/output', methods=['GET']) +@login_required +def action_script_display_output(): + ips = parse_elements(request.args.to_dict()) + + if not validate_elements(ips): + return redirect(url_for('commands')) + + server = get_server_from_clients(ips) + + r = server.get('/shell/output', payload={'clients': list(ips)}) + if not r: + return ogserver_down('commands') + if r.status_code != requests.codes.ok: + return ogserver_error('commands') + + client_data = r.json()['clients'] + + for client in client_data: + if not 'output' in client: + client['output'] = _('No output') + + if not 'retcode' in client: + client['retcode'] = 0 + + if not 'cmd' in client: + client['cmd'] = ['Null'] + + if not 'tstamp' in client: + client['tstamp'] = _('No time available') + else: + timestamp_utc = datetime.datetime.utcfromtimestamp(client['tstamp']) + client['tstamp'] = timestamp_utc.strftime('%Y-%m-%d %H:%M:%S') + + client_data.sort(key=lambda x:x['tstamp'], reverse=True) + + scopes, clients = get_scopes(set(ips)) + selected_clients = list(get_selected_clients(scopes['scope']).items()) + return render_template('actions/script_output.html', + selected_clients=selected_clients, + scopes=scopes, client_data=client_data) + def get_clients_modes(ips, server): modes = {} for ip in ips: |