Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/views/plugins.py

90 lines
1.9 KiB

7 years ago
# coding:utf-8
from flask import Blueprint, render_template
7 years ago
from flask import jsonify
7 years ago
from flask import request
7 years ago
7 years ago
import psutil
import time
import sys
import os
sys.path.append("class/")
import public
import json
7 years ago
plugins = Blueprint('plugins', __name__, template_folder='templates')
7 years ago
__plugin_name = "plugins"
7 years ago
@plugins.route("/")
def index():
7 years ago
return render_template('default/ftp.html')
@plugins.route("/file", methods=['GET'])
def file():
7 years ago
name = request.args.get('name', '')
if name.strip() == '':
return ''
f = request.args.get('f', '')
if f.strip() == '':
return ''
file = "plugins/" + name + "/" + f
if not os.path.exists(file):
return ""
c = public.readFile(file)
return c
7 years ago
@plugins.route("/list", methods=['GET', 'POST'])
7 years ago
def list():
7 years ago
data = json.loads(public.readFile("data/type.json"))
ret = {}
ret["type"] = data
7 years ago
plugins_info = []
7 years ago
typeVal = request.args.get('type', '')
if typeVal == "":
typeVal = "0"
7 years ago
7 years ago
for dirinfo in os.listdir(__plugin_name):
path = __plugin_name + "/" + dirinfo
if os.path.isdir(path):
jsonFile = path + "/info.json"
if os.path.exists(jsonFile):
try:
tmp = json.loads(public.readFile(jsonFile))
7 years ago
if typeVal == "0":
plugins_info.append(tmp)
else:
if tmp['pid'] == typeVal:
plugins_info.append(tmp)
except ValueError, Argument:
7 years ago
pass
7 years ago
7 years ago
ret['data'] = plugins_info
7 years ago
return jsonify(ret)
7 years ago
@plugins.route("/install", methods=['POST'])
def install():
7 years ago
7 years ago
name = request.form['name']
if name.strip() == '':
return ''
install = "plugins/" + name + "/install.sh"
print install
os.system('/bin/bash ' + install + ' install')
print request.args
return ''