Files
web_management/__init__.py
Andreas Stephanides f683cc6661 cmds1
2017-04-18 18:54:09 +02:00

36 lines
1.3 KiB
Python

# -*- 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("/<string:cmd>")
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",keys=keys, title=cfg.title.decode("utf8")), 404