From 179381fa8cfd0d14a1b70a2496faf62992b7a9d6 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Tue, 18 Apr 2017 11:08:09 +0200 Subject: [PATCH] configuration added --- __init__.py | 31 ++++++++++++++++++++----------- config.cfg | 1 + templates/index.html | 13 ++++++++----- 3 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 config.cfg diff --git a/__init__.py b/__init__.py index c750dba..2bd6a29 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,9 @@ # -*- 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): @@ -8,19 +11,25 @@ def run_cmd(cmd): stderr=subprocess.PIPE, stdin=subprocess.PIPE) out,err = p.communicate() - return render_template("index.html",out=out) + 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(): - cmd = ["ls","-l"] - return run_cmd(cmd) + return render_template("index.html",out="Hello",keys=keys, title=cfg.title.decode("utf8")) -@app.route("/syslog") -def syslog(): - cmd = ["tail","-n 200", "/var/log/syslog"] - return run_cmd(cmd) +@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")) - -#if __name__ == "__main__" : -# app.run() +@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 diff --git a/config.cfg b/config.cfg new file mode 100644 index 0000000..ac3b786 --- /dev/null +++ b/config.cfg @@ -0,0 +1 @@ +title: 'Management für lokalen Server' \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index dd71d1c..c245fa1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,16 +1,19 @@ - Management + {{title}} -

My Management

+

{{title}}

+ {% endfor %} +
{{out.decode('utf-8')}}