configuration added
This commit is contained in:
31
__init__.py
31
__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("/<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
|
||||
|
||||
Reference in New Issue
Block a user