|
|
@ -76,7 +76,7 @@ socketio.init_app(app) |
|
|
|
# http_server.serve_forever() |
|
|
|
# http_server.serve_forever() |
|
|
|
|
|
|
|
|
|
|
|
# debug macosx dev |
|
|
|
# debug macosx dev |
|
|
|
if mw.isAppleSystem(): |
|
|
|
if mw.isDebugMode(): |
|
|
|
app.debug = True |
|
|
|
app.debug = True |
|
|
|
app.config.version = app.config.version + str(time.time()) |
|
|
|
app.config.version = app.config.version + str(time.time()) |
|
|
|
|
|
|
|
|
|
|
@ -84,6 +84,33 @@ import common |
|
|
|
common.init() |
|
|
|
common.init() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- error function start ----------------- |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
# ---------- error function end ----------------- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def funConvert(fun): |
|
|
|
def funConvert(fun): |
|
|
|
block = fun.split('_') |
|
|
|
block = fun.split('_') |
|
|
|
func = block[0] |
|
|
|
func = block[0] |
|
|
@ -98,6 +125,7 @@ def isLogined(): |
|
|
|
if 'login' in session and 'username' in session and session['login'] == True: |
|
|
|
if 'login' in session and 'username' in session and session['login'] == True: |
|
|
|
userInfo = mw.M('users').where( |
|
|
|
userInfo = mw.M('users').where( |
|
|
|
"id=?", (1,)).field('id,username,password').find() |
|
|
|
"id=?", (1,)).field('id,username,password').find() |
|
|
|
|
|
|
|
# print(userInfo) |
|
|
|
if userInfo['username'] != session['username']: |
|
|
|
if userInfo['username'] != session['username']: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
@ -291,6 +319,46 @@ def admin_safe_path(path, req, data, pageFile): |
|
|
|
return render_template(req + '.html', data=data) |
|
|
|
return render_template(req + '.html', data=data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def login_temp_user(token): |
|
|
|
|
|
|
|
print(token) |
|
|
|
|
|
|
|
if len(token) != 48: |
|
|
|
|
|
|
|
return '错误的参数!' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skey = mw.getClientIp() + '_temp_login' |
|
|
|
|
|
|
|
if not getErrorNum(skey, 10): |
|
|
|
|
|
|
|
return '连续10次验证失败,禁止1小时' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stime = int(time.time()) |
|
|
|
|
|
|
|
data = mw.M('temp_login').where('state=? and expire>?', |
|
|
|
|
|
|
|
(0, stime)).field('id,token,salt,expire').find() |
|
|
|
|
|
|
|
if not data: |
|
|
|
|
|
|
|
setErrorNum(skey) |
|
|
|
|
|
|
|
return '验证失败!' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r_token = mw.md5(token + data['salt']) |
|
|
|
|
|
|
|
if r_token != data['token']: |
|
|
|
|
|
|
|
setErrorNum(skey) |
|
|
|
|
|
|
|
return '验证失败!' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userInfo = mw.M('users').where( |
|
|
|
|
|
|
|
"id=?", (1,)).field('id,username').find() |
|
|
|
|
|
|
|
session['login'] = True |
|
|
|
|
|
|
|
session['username'] = userInfo['username'] |
|
|
|
|
|
|
|
session['tmp_login'] = True |
|
|
|
|
|
|
|
session['tmp_login_id'] = str(data['id']) |
|
|
|
|
|
|
|
session['tmp_login_expire'] = time.time() + 3600 |
|
|
|
|
|
|
|
session['uid'] = data['id'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
login_addr = mw.getClientIp() + ":" + str(request.environ.get('REMOTE_PORT')) |
|
|
|
|
|
|
|
mw.writeLog('用户登录', "登录成功,帐号:{1},登录IP:{2}", |
|
|
|
|
|
|
|
(userInfo['username'], login_addr)) |
|
|
|
|
|
|
|
mw.M('temp_login').where('id=?', (data['id'],)).update( |
|
|
|
|
|
|
|
{"login_time": stime, 'state': 1, 'login_addr': login_addr}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(session) |
|
|
|
|
|
|
|
return redirect('/') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/<reqClass>/<reqAction>', methods=['POST', 'GET']) |
|
|
|
@app.route('/<reqClass>/<reqAction>', methods=['POST', 'GET']) |
|
|
|
@app.route('/<reqClass>/', methods=['POST', 'GET']) |
|
|
|
@app.route('/<reqClass>/', methods=['POST', 'GET']) |
|
|
|
@app.route('/<reqClass>', methods=['POST', 'GET']) |
|
|
|
@app.route('/<reqClass>', methods=['POST', 'GET']) |
|
|
@ -312,11 +380,18 @@ def index(reqClass=None, reqAction=None, reqData=None): |
|
|
|
pageFile = ('config', 'control', 'crontab', 'files', 'firewall', |
|
|
|
pageFile = ('config', 'control', 'crontab', 'files', 'firewall', |
|
|
|
'index', 'plugins', 'login', 'system', 'site', 'ssl', 'task', 'soft') |
|
|
|
'index', 'plugins', 'login', 'system', 'site', 'ssl', 'task', 'soft') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if reqClass == 'login': |
|
|
|
|
|
|
|
token = request.args.get('tmp_token', '').strip() |
|
|
|
|
|
|
|
print(token) |
|
|
|
|
|
|
|
if token != '': |
|
|
|
|
|
|
|
return login_temp_user(token) |
|
|
|
|
|
|
|
|
|
|
|
# 设置了安全路径 |
|
|
|
# 设置了安全路径 |
|
|
|
ainfo = get_admin_safe() |
|
|
|
ainfo = get_admin_safe() |
|
|
|
|
|
|
|
|
|
|
|
# 登录页 |
|
|
|
# 登录页 |
|
|
|
if reqClass == 'login': |
|
|
|
if reqClass == 'login': |
|
|
|
|
|
|
|
|
|
|
|
dologin = request.args.get('dologin', '') |
|
|
|
dologin = request.args.get('dologin', '') |
|
|
|
if dologin == 'True': |
|
|
|
if dologin == 'True': |
|
|
|
session.clear() |
|
|
|
session.clear() |
|
|
|