configuration added
This commit is contained in:
31
__init__.py
31
__init__.py
@@ -1,6 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from flask import Flask,jsonify,send_from_directory, render_template
|
from flask import Flask,jsonify,send_from_directory, render_template
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import os
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||||
def run_cmd(cmd):
|
def run_cmd(cmd):
|
||||||
@@ -8,19 +11,25 @@ def run_cmd(cmd):
|
|||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE)
|
stdin=subprocess.PIPE)
|
||||||
out,err = p.communicate()
|
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("/")
|
@app.route("/")
|
||||||
def hello():
|
def hello():
|
||||||
cmd = ["ls","-l"]
|
return render_template("index.html",out="Hello",keys=keys, title=cfg.title.decode("utf8"))
|
||||||
return run_cmd(cmd)
|
|
||||||
|
|
||||||
@app.route("/syslog")
|
@app.route("/reload")
|
||||||
def syslog():
|
def reload():
|
||||||
cmd = ["tail","-n 200", "/var/log/syslog"]
|
cmds = Config(file(os.path.join(package_directory, 'cmds.cfg')))
|
||||||
return run_cmd(cmd)
|
return render_template("index.html",out="",keys=keys, title=cfg.title.decode("utf8"))
|
||||||
|
|
||||||
|
@app.route("/<string:cmd>")
|
||||||
#if __name__ == "__main__" :
|
def cm(cmd):
|
||||||
# app.run()
|
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
1
config.cfg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
title: 'Management für lokalen Server'
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Management</title>
|
<title>{{title}}</title>
|
||||||
<script src="static/jquery-3.2.0.min.js" ></script>
|
<script src="static/jquery-3.2.0.min.js" ></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>My Management</h1>
|
<h1>{{title}}</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
{% for k in keys %}
|
||||||
<li>
|
<li>
|
||||||
<a href="syslog"> syslog</a>
|
|
||||||
<a href="/"> root</a>
|
<a href="{{k}}">{{k}}</a>
|
||||||
|
|
||||||
</li>
|
</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>
|
<div style="white-space: pre-wrap;font:Courier, monospace; font-size:small; width:80em;background:#DDF">{{out.decode('utf-8')}}</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user