#!/usr/bin/python3 import paramiko from config import * from flask import Flask, redirect, render_template, request, url_for, Response app = Flask(__name__) def get_remote(hostname, port, username, password, local_script_path, remote_script_path): ssh = paramiko.SSHClient() try: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname, port, username, password) sftp = ssh.open_sftp() sftp.put(local_script_path, remote_script_path) sftp.close() stdin, stdout, stderr = ssh.exec_command(f"python3 {remote_script_path}") output = stdout.read().decode() return(output) finally: ssh.close() def get_full(node): remote_info = get_remote(node, ssh_conf.port, ssh_conf.username, ssh_conf.password, paths.agent_path, paths.remote_path) full = eval(remote_info) return full @app.route("/", methods = ['GET']) def get_info(): node = 'localhost' full = get_full(node) return render_template('index.html', full = full, client = client, titre = flask_conf.title) @app.route("/n/", methods = ['POST', 'GET']) def get_node_info(node): full = get_full(node) return render_template('index.html', full = full, client = client, titre = flask_conf.title) if __name__ == "__main__": app.run(host=flask_conf.host, port=flask_conf.port, use_reloader=flask_conf.reloader, threaded=flask_conf.thread, debug=flask_conf.debug, ssl_context=flask_conf.ssl)