mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
update
This commit is contained in:
+14
-12
@@ -31,8 +31,9 @@ from flask_migrate import Migrate
|
||||
from flask_caching import Cache
|
||||
from werkzeug.local import LocalProxy
|
||||
|
||||
from admin import model
|
||||
# from admin import model
|
||||
from admin import setup
|
||||
import thisdb
|
||||
|
||||
from admin.model import db as sys_db
|
||||
|
||||
@@ -68,12 +69,13 @@ app.config['SESSION_COOKIE_NAME'] = "MW_VER_1"
|
||||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=31)
|
||||
|
||||
# db的配置
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = mw.getSqitePrefix()+config.SQLITE_PATH+"?timeout=20" # 使用 SQLite 数据库
|
||||
# app.config['SQLALCHEMY_DATABASE_URI'] = mw.getSqitePrefix()+config.SQLITE_PATH+"?timeout=20" # 使用 SQLite 数据库
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
|
||||
|
||||
# 初始化db
|
||||
sys_db.init_app(app)
|
||||
Migrate(app, sys_db)
|
||||
# sys_db.init_app(app)
|
||||
# Migrate(app, sys_db)
|
||||
|
||||
|
||||
# 检查数据库是否存在。如果没有就创建它。
|
||||
@@ -84,15 +86,15 @@ if not os.path.isfile(config.SQLITE_PATH):
|
||||
# with app.app_context():
|
||||
# sys_db.create_all()
|
||||
|
||||
with app.app_context():
|
||||
if setup_db_required:
|
||||
sys_db.create_all()
|
||||
# with app.app_context():
|
||||
# if setup_db_required:
|
||||
# sys_db.create_all()
|
||||
|
||||
# 初始化用户信息
|
||||
with app.app_context():
|
||||
if setup_db_required:
|
||||
setup.init_admin_user()
|
||||
setup.init_option()
|
||||
if setup_db_required:
|
||||
# 初始化用户信息
|
||||
thisdb.initPanelData()
|
||||
setup.init_admin_user()
|
||||
setup.init_option()
|
||||
setup.init_cmd()
|
||||
setup.init_db_system()
|
||||
|
||||
|
||||
+3
-2
@@ -10,13 +10,14 @@
|
||||
|
||||
import time
|
||||
|
||||
from admin import model
|
||||
# from admin import model
|
||||
from admin import session
|
||||
import thisdb
|
||||
|
||||
def isLogined():
|
||||
if 'login' in session and session['login'] == True and 'username' in session:
|
||||
username = session['username']
|
||||
info = model.getUserByName(username)
|
||||
info = thisdb.getUserByName(username)
|
||||
if info is None:
|
||||
return False
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ from flask import Blueprint, render_template
|
||||
from flask import request
|
||||
|
||||
from admin.user_login_check import panel_login_required
|
||||
from admin.model import Crontab
|
||||
|
||||
from utils.crontab import crontab as MwCrontab
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
blueprint = Blueprint('crontab', __name__, url_prefix='/crontab', template_folder='../../templates/default')
|
||||
@blueprint.route('/index', endpoint='index')
|
||||
@@ -24,26 +27,51 @@ def index():
|
||||
@blueprint.route('/list', endpoint='list', methods=['GET','POST'])
|
||||
@panel_login_required
|
||||
def list():
|
||||
page = request.args.get('p', 1)
|
||||
size = 10
|
||||
count = Crontab.query.count()
|
||||
# print(count)
|
||||
clist = Crontab.query.paginate(page=int(page), per_page=size)
|
||||
# print(clist)
|
||||
page = request.args.get('p', '1').strip()
|
||||
limit = request.args.get('limit', '10').strip()
|
||||
return MwCrontab.instance().getCrontabList(page=int(page),size=int(limit))
|
||||
|
||||
return []
|
||||
# 插件列表
|
||||
@blueprint.route('/logs', endpoint='logs', methods=['GET','POST'])
|
||||
def logs(self):
|
||||
sid = request.form.get('id', '')
|
||||
echo = mw.M('crontab').where("id=?", (sid,)).field('echo').find()
|
||||
logFile = mw.getServerDir() + '/cron/' + echo['echo'] + '.log'
|
||||
if not os.path.exists(logFile):
|
||||
return mw.returnData(False, '当前日志为空!')
|
||||
log = mw.getLastLine(logFile, 500)
|
||||
return mw.returnData(True, log)
|
||||
|
||||
# 获取计划任务
|
||||
@blueprint.route('/del', endpoint='del', methods=['GET','POST'])
|
||||
def crontab_del():
|
||||
task_id = request.form.get('id', '')
|
||||
return MwCrontab.instance().delete(task_id)
|
||||
|
||||
# 获取计划任务
|
||||
@blueprint.route('/get_crond_find', endpoint='get_crond_find', methods=['GET','POST'])
|
||||
def get_crond_find():
|
||||
sid = request.form.get('id', '')
|
||||
data = MwCrontab.instance().getCrondFind(sid)
|
||||
return data
|
||||
|
||||
# 添加计划任务
|
||||
@blueprint.route('/add', endpoint='add', methods=['GET','POST'])
|
||||
@panel_login_required
|
||||
def add():
|
||||
page = request.args.get('p', 1)
|
||||
size = 10
|
||||
count = Crontab.query.count()
|
||||
# print(count)
|
||||
clist = Crontab.query.paginate(page=int(page), per_page=size)
|
||||
# print(clist)
|
||||
|
||||
return []
|
||||
request_data = {}
|
||||
request_data['name'] = request.form.get('name', '')
|
||||
request_data['type'] = request.form.get('type', '')
|
||||
request_data['week'] = request.form.get('week', '')
|
||||
request_data['where1'] = request.form.get('where1', '')
|
||||
request_data['hour'] = request.form.get('hour', '')
|
||||
request_data['minute'] = request.form.get('minute', '')
|
||||
request_data['save'] = request.form.get('save', '')
|
||||
request_data['backup_to'] = request.form.get('backupTo', '')
|
||||
request_data['stype'] = request.form.get('sType', '')
|
||||
request_data['sname'] = request.form.get('sName', '')
|
||||
request_data['sbody'] = request.form.get('sBody', '')
|
||||
request_data['url_address'] = request.form.get('urladdress', '')
|
||||
return MwCrontab.instance().add(request_data)
|
||||
|
||||
|
||||
|
||||
@@ -8,236 +8,6 @@
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import io
|
||||
import time
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import make_response
|
||||
from flask import redirect
|
||||
from flask import Response
|
||||
from flask import request,g
|
||||
|
||||
from admin.common import isLogined
|
||||
from admin.user_login_check import panel_login_required
|
||||
from admin import cache,session
|
||||
from admin import model
|
||||
from admin.model import db,TempLogin,Users
|
||||
|
||||
import core.mw as mw
|
||||
|
||||
|
||||
blueprint = Blueprint('dashboard', __name__, url_prefix='/', template_folder='../../templates')
|
||||
@blueprint.route('/')
|
||||
@panel_login_required
|
||||
def index():
|
||||
return render_template('default/index.html')
|
||||
|
||||
# 安全路径
|
||||
@blueprint.route('/<path>',endpoint='admin_safe_path',methods=['GET'])
|
||||
def admin_safe_path(path):
|
||||
db_path = model.getOption('admin_path')
|
||||
|
||||
if isLogined():
|
||||
return redirect('/')
|
||||
|
||||
if db_path == path:
|
||||
return render_template('default/login.html')
|
||||
|
||||
unauthorized_status = model.getOption('unauthorized_status')
|
||||
if unauthorized_status == '0':
|
||||
return render_template('default/path.html')
|
||||
return Response(status=int(unauthorized_status))
|
||||
|
||||
# 仅针对webhook插件
|
||||
@blueprint.route("/hook", methods=['POST', 'GET'])
|
||||
def webhook():
|
||||
# 兼容获取关键数据
|
||||
access_key = request.args.get('access_key', '').strip()
|
||||
if access_key == '':
|
||||
access_key = request.form.get('access_key', '').strip()
|
||||
|
||||
params = request.args.get('params', '').strip()
|
||||
if params == '':
|
||||
params = request.form.get('params', '').strip()
|
||||
|
||||
input_args = {
|
||||
'access_key': access_key,
|
||||
'params': params,
|
||||
}
|
||||
|
||||
wh_install_path = mw.getServerDir() + '/webhook'
|
||||
if not os.path.exists(wh_install_path):
|
||||
return mw.returnData(False, '请先安装WebHook插件!')
|
||||
|
||||
package = mw.getPanelDir() + "/plugins/webhook"
|
||||
if not package in sys.path:
|
||||
sys.path.append(package)
|
||||
|
||||
try:
|
||||
import webhook_index
|
||||
return webhook_index.runShellArgs(input_args)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 定义登录入口相关方法
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
def getErrorNum(key, limit=None):
|
||||
key = mw.md5(key)
|
||||
num = cache.get(key)
|
||||
if not num:
|
||||
num = 0
|
||||
if not limit:
|
||||
return num
|
||||
if limit > num:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def setErrorNum(key, empty=False, expire=3600):
|
||||
key = mw.md5(key)
|
||||
num = cache.get(key)
|
||||
if not num:
|
||||
num = 0
|
||||
else:
|
||||
if empty:
|
||||
cache.delete(key)
|
||||
return True
|
||||
cache.set(key, num + 1, expire)
|
||||
return True
|
||||
|
||||
def login_temp_user(token):
|
||||
if len(token) != 32:
|
||||
return '错误的参数!'
|
||||
|
||||
skey = mw.getClientIp() + '_temp_login'
|
||||
if not getErrorNum(skey, 10):
|
||||
return '连续10次验证失败,禁止1小时'
|
||||
|
||||
stime = int(time.time())
|
||||
|
||||
tmp_data = model.getTempLoginByToken(token)
|
||||
if not tmp_data:
|
||||
setErrorNum(skey)
|
||||
return '验证失败!'
|
||||
|
||||
if stime > int(tmp_data['expire']):
|
||||
setErrorNum(skey)
|
||||
return "过期"
|
||||
|
||||
user_data = model.getUserById(1)
|
||||
|
||||
login_addr = mw.getClientIp() + ":" + str(request.environ.get('REMOTE_PORT'))
|
||||
mw.writeLog('用户临时登录', "登录成功,帐号:{1},登录IP:{2}",(user_data['name'], login_addr))
|
||||
|
||||
TempLogin.query.filter(TempLogin.id==tmp_data['id']).update({"login_time": stime, 'state': 1, 'login_addr': login_addr})
|
||||
db.session.commit()
|
||||
|
||||
session['login'] = True
|
||||
session['username'] = user_data['name']
|
||||
session['tmp_login'] = True
|
||||
session['tmp_login_id'] = str(tmp_data['id'])
|
||||
session['tmp_login_expire'] = int(tmp_data['expire'])
|
||||
session['uid'] = user_data['id']
|
||||
|
||||
return redirect('/')
|
||||
|
||||
# 登录页: 当设置了安全路径,本页失效。
|
||||
@blueprint.route('/login')
|
||||
def login():
|
||||
|
||||
# 临时登录功能
|
||||
token = request.args.get('tmp_token', '').strip()
|
||||
if token != '':
|
||||
return login_temp_user(token)
|
||||
|
||||
# 注销登录
|
||||
signout = request.args.get('signout', '')
|
||||
if signout == 'True':
|
||||
session.clear()
|
||||
session['login'] = False
|
||||
session['overdue'] = 0
|
||||
|
||||
db_path = model.getOption('admin_path')
|
||||
if db_path == '':
|
||||
return render_template('default/login.html')
|
||||
else:
|
||||
unauthorized_status = model.getOption('unauthorized_status')
|
||||
if unauthorized_status == '0':
|
||||
return render_template('default/path.html')
|
||||
return Response(status=int(unauthorized_status))
|
||||
|
||||
# 验证码
|
||||
@blueprint.route('/code')
|
||||
def code():
|
||||
import utils.vilidate as vilidate
|
||||
vie = vilidate.vieCode()
|
||||
codeImage = vie.GetCodeImage(80, 4)
|
||||
out = io.BytesIO()
|
||||
codeImage[0].save(out, "png")
|
||||
session['code'] = mw.md5(''.join(codeImage[1]).lower())
|
||||
|
||||
img = Response(out.getvalue(), headers={'Content-Type': 'image/png'})
|
||||
return make_response(img)
|
||||
|
||||
# 检查是否登录
|
||||
@blueprint.route('/check_login',methods=['GET','POST'])
|
||||
def check_login():
|
||||
if isLogined():
|
||||
return mw.returnData(True,'已登录')
|
||||
return mw.returnData(False,'未登录')
|
||||
|
||||
# 执行登录操作
|
||||
@blueprint.route('/do_login', endpoint='do_login', methods=['POST'])
|
||||
def do_login():
|
||||
username = request.form.get('username', '').strip()
|
||||
password = request.form.get('password', '').strip()
|
||||
code = request.form.get('code', '').strip()
|
||||
|
||||
login_cache_count = 5
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
|
||||
if 'code' in session:
|
||||
if session['code'] != mw.md5(code):
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnJson(False, '面板已经关闭!')
|
||||
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
login_err_msg = mw.getInfo("验证码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit)))
|
||||
mw.writeLog('用户登录', login_err_msg)
|
||||
return mw.returnData(False, login_err_msg)
|
||||
|
||||
info = model.getUserByName(username)
|
||||
password = mw.md5(password)
|
||||
|
||||
if info['name'] != username or info['password'] != password:
|
||||
msg = "<a style='color: red'>密码错误</a>,帐号:{1},密码:{2},登录IP:{3}", (('****', '******', request.remote_addr))
|
||||
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnData(False, '面板已经关闭!')
|
||||
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
mw.writeLog('用户登录', mw.getInfo(msg))
|
||||
return mw.returnData(-1, mw.getInfo("用户名或密码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit))))
|
||||
|
||||
|
||||
session['login'] = True
|
||||
session['username'] = info['name']
|
||||
session['overdue'] = int(time.time()) + 7 * 24 * 60 * 60
|
||||
|
||||
return mw.returnJson(1, '登录成功,正在跳转...')
|
||||
from .dashboard import *
|
||||
from .login import *
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# coding:utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import io
|
||||
import time
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import make_response
|
||||
from flask import redirect
|
||||
from flask import Response
|
||||
from flask import request,g
|
||||
|
||||
from admin.common import isLogined
|
||||
from admin.user_login_check import panel_login_required
|
||||
from admin import cache,session
|
||||
from admin import model
|
||||
from admin.model import db,TempLogin,Users
|
||||
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
|
||||
blueprint = Blueprint('dashboard', __name__, url_prefix='/', template_folder='../../templates')
|
||||
@blueprint.route('/')
|
||||
@panel_login_required
|
||||
def index():
|
||||
return render_template('default/index.html')
|
||||
|
||||
# 安全路径
|
||||
@blueprint.route('/<path>',endpoint='admin_safe_path',methods=['GET'])
|
||||
def admin_safe_path(path):
|
||||
db_path = thisdb.getOption('admin_path')
|
||||
if isLogined():
|
||||
return redirect('/')
|
||||
|
||||
print(db_path,path)
|
||||
if db_path == path:
|
||||
return render_template('default/login.html')
|
||||
|
||||
unauthorized_status = thisdb.getOption('unauthorized_status')
|
||||
if unauthorized_status == '0':
|
||||
return render_template('default/path.html')
|
||||
return Response(status=int(unauthorized_status))
|
||||
|
||||
# 仅针对webhook插件
|
||||
@blueprint.route("/hook", methods=['POST', 'GET'])
|
||||
def webhook():
|
||||
# 兼容获取关键数据
|
||||
access_key = request.args.get('access_key', '').strip()
|
||||
if access_key == '':
|
||||
access_key = request.form.get('access_key', '').strip()
|
||||
|
||||
params = request.args.get('params', '').strip()
|
||||
if params == '':
|
||||
params = request.form.get('params', '').strip()
|
||||
|
||||
input_args = {
|
||||
'access_key': access_key,
|
||||
'params': params,
|
||||
}
|
||||
|
||||
wh_install_path = mw.getServerDir() + '/webhook'
|
||||
if not os.path.exists(wh_install_path):
|
||||
return mw.returnData(False, '请先安装WebHook插件!')
|
||||
|
||||
package = mw.getPanelDir() + "/plugins/webhook"
|
||||
if not package in sys.path:
|
||||
sys.path.append(package)
|
||||
|
||||
try:
|
||||
import webhook_index
|
||||
return webhook_index.runShellArgs(input_args)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -0,0 +1,189 @@
|
||||
# coding:utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import io
|
||||
import time
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import make_response
|
||||
from flask import redirect
|
||||
from flask import Response
|
||||
from flask import request,g
|
||||
|
||||
from admin.common import isLogined
|
||||
from admin.user_login_check import panel_login_required
|
||||
from admin import cache,session
|
||||
from admin import model
|
||||
from admin.model import db,TempLogin,Users
|
||||
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
from .dashboard import blueprint
|
||||
|
||||
|
||||
def getErrorNum(key, limit=None):
|
||||
key = mw.md5(key)
|
||||
num = cache.get(key)
|
||||
if not num:
|
||||
num = 0
|
||||
if not limit:
|
||||
return num
|
||||
if limit > num:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def setErrorNum(key, empty=False, expire=3600):
|
||||
key = mw.md5(key)
|
||||
num = cache.get(key)
|
||||
if not num:
|
||||
num = 0
|
||||
else:
|
||||
if empty:
|
||||
cache.delete(key)
|
||||
return True
|
||||
cache.set(key, num + 1, expire)
|
||||
return True
|
||||
|
||||
def login_temp_user(token):
|
||||
if len(token) != 32:
|
||||
return '错误的参数!'
|
||||
|
||||
skey = mw.getClientIp() + '_temp_login'
|
||||
if not getErrorNum(skey, 10):
|
||||
return '连续10次验证失败,禁止1小时'
|
||||
|
||||
stime = int(time.time())
|
||||
|
||||
tmp_data = model.getTempLoginByToken(token)
|
||||
if not tmp_data:
|
||||
setErrorNum(skey)
|
||||
return '验证失败!'
|
||||
|
||||
if stime > int(tmp_data['expire']):
|
||||
setErrorNum(skey)
|
||||
return "过期"
|
||||
|
||||
user_data = thisdb.getUserById(1)
|
||||
|
||||
login_addr = mw.getClientIp() + ":" + str(request.environ.get('REMOTE_PORT'))
|
||||
mw.writeLog('用户临时登录', "登录成功,帐号:{1},登录IP:{2}",(user_data['name'], login_addr))
|
||||
|
||||
TempLogin.query.filter(TempLogin.id==tmp_data['id']).update({"login_time": stime, 'state': 1, 'login_addr': login_addr})
|
||||
db.session.commit()
|
||||
|
||||
session['login'] = True
|
||||
session['username'] = user_data['name']
|
||||
session['tmp_login'] = True
|
||||
session['tmp_login_id'] = str(tmp_data['id'])
|
||||
session['tmp_login_expire'] = int(tmp_data['expire'])
|
||||
session['uid'] = user_data['id']
|
||||
|
||||
return redirect('/')
|
||||
|
||||
# 登录页: 当设置了安全路径,本页失效。
|
||||
@blueprint.route('/login')
|
||||
def login():
|
||||
|
||||
# 临时登录功能
|
||||
token = request.args.get('tmp_token', '').strip()
|
||||
if token != '':
|
||||
return login_temp_user(token)
|
||||
|
||||
# 注销登录
|
||||
signout = request.args.get('signout', '')
|
||||
if signout == 'True':
|
||||
session.clear()
|
||||
session['login'] = False
|
||||
session['overdue'] = 0
|
||||
|
||||
db_path = model.getOption('admin_path')
|
||||
if db_path == '':
|
||||
return render_template('default/login.html')
|
||||
else:
|
||||
unauthorized_status = model.getOption('unauthorized_status')
|
||||
if unauthorized_status == '0':
|
||||
return render_template('default/path.html')
|
||||
return Response(status=int(unauthorized_status))
|
||||
|
||||
# 验证码
|
||||
@blueprint.route('/code')
|
||||
def code():
|
||||
import utils.vilidate as vilidate
|
||||
vie = vilidate.vieCode()
|
||||
codeImage = vie.GetCodeImage(80, 4)
|
||||
out = io.BytesIO()
|
||||
codeImage[0].save(out, "png")
|
||||
session['code'] = mw.md5(''.join(codeImage[1]).lower())
|
||||
|
||||
img = Response(out.getvalue(), headers={'Content-Type': 'image/png'})
|
||||
return make_response(img)
|
||||
|
||||
# 检查是否登录
|
||||
@blueprint.route('/check_login',methods=['GET','POST'])
|
||||
def check_login():
|
||||
if isLogined():
|
||||
return mw.returnData(True,'已登录')
|
||||
return mw.returnData(False,'未登录')
|
||||
|
||||
# 执行登录操作
|
||||
@blueprint.route('/do_login', endpoint='do_login', methods=['POST'])
|
||||
def do_login():
|
||||
username = request.form.get('username', '').strip()
|
||||
password = request.form.get('password', '').strip()
|
||||
code = request.form.get('code', '').strip()
|
||||
|
||||
login_cache_count = 5
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
|
||||
if 'code' in session:
|
||||
if session['code'] != mw.md5(code):
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnJson(False, '面板已经关闭!')
|
||||
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
login_err_msg = mw.getInfo("验证码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit)))
|
||||
mw.writeLog('用户登录', login_err_msg)
|
||||
return mw.returnData(False, login_err_msg)
|
||||
|
||||
info = thisdb.getUserByName(username)
|
||||
password = mw.md5(password)
|
||||
|
||||
if info['name'] != username or info['password'] != password:
|
||||
msg = "<a style='color: red'>密码错误</a>,帐号:{1},密码:{2},登录IP:{3}", (('****', '******', request.remote_addr))
|
||||
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnData(False, '面板已经关闭!')
|
||||
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
mw.writeLog('用户登录', mw.getInfo(msg))
|
||||
return mw.returnData(-1, mw.getInfo("用户名或密码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit))))
|
||||
|
||||
|
||||
session['login'] = True
|
||||
session['username'] = info['name']
|
||||
session['overdue'] = int(time.time()) + 7 * 24 * 60 * 60
|
||||
|
||||
return mw.returnJson(1, '登录成功,正在跳转...')
|
||||
@@ -14,11 +14,9 @@ from flask import request
|
||||
|
||||
from admin.user_login_check import panel_login_required
|
||||
|
||||
from admin import model
|
||||
from admin.model import db, Logs
|
||||
|
||||
import core.mw as mw
|
||||
import utils.adult_log as adult_log
|
||||
import thisdb
|
||||
|
||||
# 日志页面
|
||||
blueprint = Blueprint('logs', __name__, url_prefix='/logs', template_folder='../../templates')
|
||||
@@ -36,33 +34,18 @@ def get_log_list():
|
||||
size = request.form.get('limit', '10').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
|
||||
count = Logs.query.filter_by().count()
|
||||
if search != '':
|
||||
pagination = Logs.query.filter_by(Logs.type.like(search) or Logs.log.like(search)).paginate(page=int(p), per_page=int(size))
|
||||
else:
|
||||
pagination = Logs.query.filter_by().order_by(Logs.id.desc()).paginate(page=int(p), per_page=int(size))
|
||||
|
||||
rows = []
|
||||
for item in pagination.items:
|
||||
t = {}
|
||||
t['id'] = item.id
|
||||
t['type'] = item.type
|
||||
t['log'] = item.log
|
||||
t['uid'] = item.uid
|
||||
t['add_time'] = item.add_time
|
||||
rows.append(t)
|
||||
info = thisdb.getLogsList(page=int(p),size=int(size), search=search)
|
||||
|
||||
data = {}
|
||||
data['data'] = rows
|
||||
data['page'] = mw.getPage({'count':count,'tojs':'getLogs','p':p})
|
||||
data['data'] = info['list']
|
||||
data['page'] = mw.getPage({'count':info['count'],'tojs':'getLogs','p':p,'row':size})
|
||||
return data
|
||||
|
||||
# 日志清空
|
||||
@blueprint.route('/del_panel_logs', endpoint='del_panel_logs', methods=['POST'])
|
||||
@panel_login_required
|
||||
def del_panel_logs():
|
||||
model.clearLog()
|
||||
# mw.M('logs').dbPos(mw.getPanelDataDir(),'panel').where('id>?', (0,)).delete()
|
||||
thisdb.clearLog()
|
||||
mw.writeLog('面板设置', '面板操作日志已清空!')
|
||||
return mw.returnData(True, '面板操作日志已清空!')
|
||||
|
||||
|
||||
@@ -16,10 +16,12 @@ from flask import Blueprint, render_template
|
||||
from flask import request
|
||||
|
||||
from admin import model
|
||||
|
||||
from admin.user_login_check import panel_login_required
|
||||
|
||||
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
import utils.config as utils_config
|
||||
|
||||
|
||||
@@ -41,9 +43,9 @@ def get_panel_list():
|
||||
@panel_login_required
|
||||
def set_webname():
|
||||
webname = request.form.get('webname', '')
|
||||
src_webname = model.getOption('title')
|
||||
src_webname = thisdb.getOption('title')
|
||||
if webname != src_webname:
|
||||
model.setOption('title', webname)
|
||||
thisdb.setOption('title', webname)
|
||||
return mw.returnData(True, '面板别名保存成功!')
|
||||
|
||||
# 设置服务器IP
|
||||
@@ -51,9 +53,9 @@ def set_webname():
|
||||
@panel_login_required
|
||||
def set_ip():
|
||||
host_ip = request.form.get('host_ip', '')
|
||||
src_host_ip = model.getOption('server_ip')
|
||||
src_host_ip = thisdb.getOption('server_ip')
|
||||
if host_ip != src_host_ip:
|
||||
model.setOption('server_ip', host_ip)
|
||||
thisdb.setOption('server_ip', host_ip)
|
||||
return mw.returnData(True, 'IP保存成功!')
|
||||
|
||||
# 默认备份目录
|
||||
@@ -61,9 +63,9 @@ def set_ip():
|
||||
@panel_login_required
|
||||
def set_backup_dir():
|
||||
backup_path = request.form.get('backup_path', '')
|
||||
src_backup_path = model.getOption('backup_path')
|
||||
src_backup_path = thisdb.getOption('backup_path')
|
||||
if backup_path != src_backup_path:
|
||||
model.setOption('backup_path', backup_path)
|
||||
thisdb.setOption('backup_path', backup_path)
|
||||
return mw.returnData(True, '修改默认备份目录成功!')
|
||||
|
||||
# 默认站点目录
|
||||
@@ -71,9 +73,9 @@ def set_backup_dir():
|
||||
@panel_login_required
|
||||
def set_www_dir():
|
||||
sites_path = request.form.get('sites_path', '')
|
||||
src_sites_path = model.getOption('sites_path')
|
||||
src_sites_path = thisdb.getOption('sites_path')
|
||||
if sites_path != src_sites_path:
|
||||
model.setOption('sites_path', sites_path)
|
||||
thisdb.setOption('sites_path', sites_path)
|
||||
return mw.returnData(True, '修改默认建站目录成功!')
|
||||
|
||||
|
||||
@@ -102,9 +104,9 @@ def set_admin_path():
|
||||
if not re.match(r"^/[\w]+$", admin_path):
|
||||
return mw.returnData(False, '入口地址格式不正确,示例: /mw_rand')
|
||||
|
||||
src_admin_path = model.getOption('admin_path')
|
||||
src_admin_path = thisdb.getOption('admin_path')
|
||||
if admin_path != src_admin_path:
|
||||
model.setOption('admin_path', admin_path[1:])
|
||||
thisdb.setOption('admin_path', admin_path[1:])
|
||||
return mw.returnData(True, '修改成功!')
|
||||
|
||||
|
||||
@@ -125,7 +127,7 @@ def set_basic_auth():
|
||||
is_open = False
|
||||
|
||||
if basic_open == 'false':
|
||||
model.setOption('basic_auth', json.dumps({'open':False}))
|
||||
thisdb.setOption('basic_auth', json.dumps({'open':False}))
|
||||
mw.writeLog('面板设置', '设置BasicAuth状态为: %s' % is_open)
|
||||
return mw.returnData(True, '删除BasicAuth成功!')
|
||||
|
||||
@@ -139,7 +141,7 @@ def set_basic_auth():
|
||||
data['basic_pwd'] = mw.md5(basic_pwd + salt)
|
||||
data['open'] = is_open
|
||||
|
||||
model.setOption('basic_auth', json.dumps(data))
|
||||
thisdb.setOption('basic_auth', json.dumps(data))
|
||||
mw.writeLog('面板设置', '设置BasicAuth状态为: %s' % is_open)
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
@@ -158,7 +160,7 @@ def set_status_code():
|
||||
return mw.returnData(False, '状态码范围错误!')
|
||||
|
||||
info = utils_config.getUnauthStatus(code=str(status_code))
|
||||
model.setOption('unauthorized_status', str(status_code))
|
||||
thisdb.setOption('unauthorized_status', str(status_code))
|
||||
mw.writeLog('面板设置', '将未授权响应状态码设置为:{0}:{1}'.format(status_code,info['text']))
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
@@ -166,11 +168,11 @@ def set_status_code():
|
||||
@blueprint.route('/open_debug', endpoint='open_debug', methods=['POST'])
|
||||
@panel_login_required
|
||||
def open_debug():
|
||||
debug = model.getOption('debug',default='close')
|
||||
debug = thisdb.getOption('debug',default='close')
|
||||
if debug == 'open':
|
||||
model.setOption('debug','close')
|
||||
thisdb.setOption('debug','close')
|
||||
return mw.returnData(True, '开发模式关闭!')
|
||||
model.setOption('debug','open')
|
||||
thisdb.setOption('debug','open')
|
||||
return mw.returnData(True, '开发模式开启!')
|
||||
|
||||
|
||||
@@ -178,11 +180,11 @@ def open_debug():
|
||||
@blueprint.route('/close_panel', endpoint='close_panel', methods=['POST'])
|
||||
@panel_login_required
|
||||
def close_panel():
|
||||
admin_close = model.getOption('admin_close',default='no')
|
||||
admin_close = thisdb.getOption('admin_close',default='no')
|
||||
if admin_close == 'no':
|
||||
model.setOption('admin_close','yes')
|
||||
thisdb.setOption('admin_close','yes')
|
||||
return mw.returnData(True, '开启面板成功!')
|
||||
model.setOption('admin_close','no')
|
||||
thisdb.setOption('admin_close','no')
|
||||
return mw.returnData(True, '关闭面板成功!')
|
||||
|
||||
# 设置IPV6状态
|
||||
|
||||
+16
-19
@@ -12,50 +12,47 @@ import json
|
||||
|
||||
from flask import request
|
||||
|
||||
from admin import model
|
||||
from admin.model import db, Users
|
||||
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
def init_option():
|
||||
model.setOption('title', '后羿面板')
|
||||
model.setOption('recycle_bin', 'open')
|
||||
model.setOption('template', 'default')
|
||||
thisdb.setOption('title', '后羿面板')
|
||||
thisdb.setOption('recycle_bin', 'open')
|
||||
thisdb.setOption('template', 'default')
|
||||
|
||||
# 后台面板是否关闭
|
||||
model.setOption('admin_close', 'no')
|
||||
thisdb.setOption('admin_close', 'no')
|
||||
|
||||
# 未认证状态码
|
||||
model.setOption('unauthorized_status', '0')
|
||||
thisdb.setOption('unauthorized_status', '0')
|
||||
|
||||
# 调式模式,默认关闭
|
||||
model.setOption('debug', 'close')
|
||||
thisdb.setOption('debug', 'close')
|
||||
|
||||
# basic auth 配置
|
||||
model.setOption('basic_auth', json.dumps({'open':False}))
|
||||
thisdb.setOption('basic_auth', json.dumps({'open':False}))
|
||||
|
||||
# 开启后台任务
|
||||
# model.setOption('run_bg_task', 'close')
|
||||
|
||||
# 首页展示初始化
|
||||
model.setOption('display_index', '[]')
|
||||
thisdb.setOption('display_index', '[]')
|
||||
|
||||
# 监控默认配置
|
||||
model.setOption('monitor_status', 'open', type='monitor')
|
||||
model.setOption('monitor_day', '30', type='monitor')
|
||||
model.setOption('monitor_only_netio', 'open', type='monitor')
|
||||
thisdb.setOption('monitor_status', 'open', type='monitor')
|
||||
thisdb.setOption('monitor_day', '30', type='monitor')
|
||||
thisdb.setOption('monitor_only_netio', 'open', type='monitor')
|
||||
|
||||
# 初始化安全路径
|
||||
model.setOption('admin_path', mw.getRandomString(8))
|
||||
thisdb.setOption('admin_path', mw.getRandomString(8))
|
||||
|
||||
|
||||
ip = mw.getLocalIp()
|
||||
model.setOption('server_ip', ip)
|
||||
thisdb.setOption('server_ip', ip)
|
||||
|
||||
# 默认备份目录
|
||||
model.setOption('backup_path', mw.getFatherDir()+'/backup')
|
||||
thisdb.setOption('backup_path', mw.getFatherDir()+'/backup')
|
||||
# 默认站点目录
|
||||
model.setOption('site_path', mw.getFatherDir()+'/wwwroot')
|
||||
thisdb.setOption('site_path', mw.getFatherDir()+'/wwwroot')
|
||||
|
||||
|
||||
return True
|
||||
+2
-20
@@ -14,28 +14,10 @@ from admin import model
|
||||
from admin.model import db, Users
|
||||
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
# 初始化用户信息
|
||||
def init_admin_user():
|
||||
data = Users.query.filter_by(id=1).first()
|
||||
if not data:
|
||||
name = mw.getRandomString(8).lower()
|
||||
password = mw.getRandomString(8).lower()
|
||||
file_pass_pl = mw.getPanelDataDir() + '/default.pl'
|
||||
mw.writeFile(file_pass_pl, password)
|
||||
insert_time = mw.formatDate()
|
||||
login_ip = '127.0.0.1'
|
||||
add_user = Users(
|
||||
name=name,
|
||||
password=mw.md5(password),
|
||||
login_ip=login_ip,
|
||||
login_time=insert_time,
|
||||
phone='',
|
||||
email='',
|
||||
add_time=insert_time,
|
||||
update_time=insert_time)
|
||||
db.session.add(add_user)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
thisdb.initAdminUser()
|
||||
return True
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from admin.user_login_check import panel_login_required
|
||||
from utils.plugin import plugin as MwPlugin
|
||||
import utils.site as site
|
||||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
blueprint = Blueprint('site', __name__, url_prefix='/site', template_folder='../../templates/default')
|
||||
@blueprint.route('/index', endpoint='index')
|
||||
@@ -34,28 +35,11 @@ def list():
|
||||
type_id = request.form.get('type_id', '0').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
|
||||
count = Sites.query.count()
|
||||
pagination = Sites.query.paginate(page=int(p), per_page=int(limit))
|
||||
|
||||
site_list = []
|
||||
for item in pagination.items:
|
||||
t = {}
|
||||
t['id'] = item.id
|
||||
t['name'] = item.name
|
||||
t['path'] = item.path
|
||||
t['index'] = item.index
|
||||
t['ps'] = item.ps
|
||||
t['edate'] = item.edate
|
||||
t['type_id'] = item.type_id
|
||||
t['status'] = item.status
|
||||
t['add_time'] = item.add_time
|
||||
t['update_time'] = item.update_time
|
||||
site_list.append(t)
|
||||
info = thisdb.getSitesList(page=int(p),size=int(limit),type_id=int(type_id), search=search)
|
||||
|
||||
data = {}
|
||||
data['data'] = site_list
|
||||
data['page'] = mw.getPage({'count':count,'tojs':'getWeb','p':p, 'row':limit})
|
||||
|
||||
data['data'] = info['list']
|
||||
data['page'] = mw.getPage({'count':info['count'],'tojs':'getWeb','p':p, 'row':limit})
|
||||
return data
|
||||
|
||||
@blueprint.route('/get_site_types', endpoint='get_site_types',methods=['POST'])
|
||||
|
||||
@@ -16,9 +16,9 @@ from flask import request
|
||||
from admin.user_login_check import panel_login_required
|
||||
from utils.system import monitor
|
||||
|
||||
import admin.model.option as option
|
||||
import core.mw as mw
|
||||
import utils.system as sys
|
||||
import thisdb
|
||||
|
||||
|
||||
|
||||
@@ -112,19 +112,19 @@ def set_control():
|
||||
day = request.form.get('day', '')
|
||||
|
||||
if stype == '0':
|
||||
option.setOption('monitor_status', 'close', type='monitor')
|
||||
thisdb.setOption('monitor_status', 'close', type='monitor')
|
||||
return mw.returnData(True, "设置成功!")
|
||||
elif stype == '1':
|
||||
_day = int(day)
|
||||
if _day < 1:
|
||||
return mw.returnData(False, "设置失败!")
|
||||
option.setOption('monitor_day', day, type='monitor')
|
||||
thisdb.setOption('monitor_day', day, type='monitor')
|
||||
return mw.returnData(True, "设置成功!")
|
||||
elif stype == '2':
|
||||
option.setOption('monitor_only_netio', 'close', type='monitor')
|
||||
thisdb.setOption('monitor_only_netio', 'close', type='monitor')
|
||||
return mw.returnData(True, "设置成功!")
|
||||
elif stype == '3':
|
||||
option.setOption('monitor_only_netio', 'open', type='monitor')
|
||||
thisdb.setOption('monitor_only_netio', 'open', type='monitor')
|
||||
return mw.returnData(True, "设置成功!")
|
||||
elif stype == 'del':
|
||||
if not mw.isRestart():
|
||||
@@ -132,9 +132,9 @@ def set_control():
|
||||
monitor.instance().clearDbFile()
|
||||
return mw.returnData(True, "清空监控记录成功!")
|
||||
else:
|
||||
monitor_status = option.getOption('monitor_status', default='open', type='monitor')
|
||||
monitor_day = option.getOption('monitor_day', default='30', type='monitor')
|
||||
monitor_only_netio = option.getOption('monitor_only_netio', default='open', type='monitor')
|
||||
monitor_status = thisdb.getOption('monitor_status', default='open', type='monitor')
|
||||
monitor_day = thisdb.getOption('monitor_day', default='30', type='monitor')
|
||||
monitor_only_netio = thisdb.getOption('monitor_only_netio', default='open', type='monitor')
|
||||
data = {}
|
||||
data['day'] = monitor_day
|
||||
if monitor_status == 'open':
|
||||
|
||||
@@ -18,6 +18,7 @@ from admin.user_login_check import panel_login_required
|
||||
|
||||
import core.mw as mw
|
||||
import utils.task as MwTasks
|
||||
import thisdb
|
||||
|
||||
blueprint = Blueprint('task', __name__, url_prefix='/task', template_folder='../../templates/default')
|
||||
|
||||
@@ -25,7 +26,7 @@ blueprint = Blueprint('task', __name__, url_prefix='/task', template_folder='../
|
||||
@blueprint.route('/count', endpoint='task_count')
|
||||
@panel_login_required
|
||||
def task_count():
|
||||
return str(model.getTaskUnexecutedCount())
|
||||
return str(thisdb.getTaskUnexecutedCount())
|
||||
|
||||
|
||||
@blueprint.route('/list', endpoint='list', methods=['POST'])
|
||||
|
||||
@@ -14,17 +14,17 @@ from flask import Response
|
||||
|
||||
from functools import wraps
|
||||
|
||||
from admin import model
|
||||
from admin import session
|
||||
from admin.common import isLogined
|
||||
|
||||
import thisdb
|
||||
|
||||
def panel_login_required(func):
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not isLogined():
|
||||
unauthorized_status = model.getOption('unauthorized_status')
|
||||
unauthorized_status = thisdb.getOption('unauthorized_status')
|
||||
if unauthorized_status == '0':
|
||||
return render_template('default/path.html')
|
||||
return Response(status=int(unauthorized_status))
|
||||
|
||||
Reference in New Issue
Block a user