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/route/__init__.py

67 lines
1.7 KiB

7 years ago
# coding:utf-8
6 years ago
import sys
import io
import os
import time
import shutil
6 years ago
from datetime import timedelta
6 years ago
from flask import Flask
from flask import render_template
sys.path.append(os.getcwd() + "/class/core")
6 years ago
import public
6 years ago
app = Flask(__name__, template_folder='templates/default')
6 years ago
app.config.version = '0.0.1'
app.config['SECRET_KEY'] = os.urandom(24)
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
def funConvert(fun):
block = fun.split('_')
func = block[0]
for x in range(len(block) - 1):
suf = block[x + 1].title()
func += suf
return func
6 years ago
6 years ago
def publicObject(toObject, func, action=None, get=None):
6 years ago
name = funConvert(func) + 'Api'
6 years ago
if hasattr(toObject, name):
efunc = 'toObject.' + name + '()'
6 years ago
data = eval(efunc)
6 years ago
return data
return public.retFail('访问异常!')
6 years ago
6 years ago
@app.route("/check_login", methods=['POST', 'GET'])
def checkLogin():
return "true"
6 years ago
6 years ago
@app.route('/<reqClass>/<reqAction>', methods=['POST', 'GET'])
@app.route('/<reqClass>/', methods=['POST', 'GET'])
@app.route('/<reqClass>', methods=['POST', 'GET'])
@app.route('/', methods=['POST', 'GET'])
def index(reqClass=None, reqAction=None, reqData=None):
if (reqClass == None):
reqClass = 'index'
6 years ago
classFile = ('config', 'control', 'crontab', 'files', 'firewall',
'index', 'plugins', 'login', 'system', 'site', 'task', 'soft')
6 years ago
if not reqClass in classFile:
return '403 no access!'
if reqAction == None:
return render_template(reqClass + '.html')
className = reqClass + '_api'
eval_str = "__import__('" + className + "')." + className + '()'
newInstance = eval(eval_str)
6 years ago
return publicObject(newInstance, reqAction)