configuration added

This commit is contained in:
Andreas Stephanides
2017-04-18 11:08:09 +02:00
parent 67df39f401
commit 179381fa8c
3 changed files with 29 additions and 16 deletions

View File

@@ -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("/<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"), 404

1
config.cfg Normal file
View File

@@ -0,0 +1 @@
title: 'Management für lokalen Server'

View File

@@ -1,16 +1,19 @@
<html>
<head>
<title>Management</title>
<title>{{title}}</title>
<script src="static/jquery-3.2.0.min.js" ></script>
</head>
<body>
<h1>My Management</h1>
<h1>{{title}}</h1>
<ul>
{% for k in keys %}
<li>
<a href="syslog"> syslog</a>
<a href="/"> root</a>
<a href="{{k}}">{{k}}</a>
</li>
</ul>
{% endfor %}
</ul>
<div style="white-space: pre-wrap;font:Courier, monospace; font-size:small; width:80em;background:#DDF">{{out.decode('utf-8')}}</div>
</body>