# -*- coding: utf-8 -*- from flask import Flask,jsonify,send_from_directory, render_template import subprocess import os from config import Config app = Flask(__name__, template_folder="templates", static_folder="static") def run_cmd(cmd): p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out,err = p.communicate() return render_template("index.html",out=out,keys=keys, title=cfg.title.decode("utf8")) package_directory = os.path.dirname(os.path.abspath(__file__)) cfg = Config(file(os.path.join(package_directory, 'config.cfg'))) cmds = Config(file(os.path.join(package_directory, 'cmds.cfg'))) keys=cmds.keys() @app.route("/") def hello(): return render_template("index.html",out="Hello",keys=keys, title=cfg.title.decode("utf8")) @app.route("/reload") def reload(): cmds = Config(file(os.path.join(package_directory, 'cmds.cfg'))) return render_template("index.html",out="",keys=keys, title=cfg.title.decode("utf8")) @app.route("/") def cm(cmd): if cmd in cmds.keys(): c=cmds[cmd] return run_cmd(c) else: return render_template("index.html", out="Command not found"), 404