提交 e262ce6b 编写于 作者: H hjdhnx

新增登录功能

上级 d483fec1
......@@ -54,9 +54,17 @@ def getParmas(key=None,value=''):
:param key:
:return:
"""
content_type = request.headers.get('Content-Type')
args = {}
if request.method == 'POST':
args = request.json
if 'application/x-www-form-urlencoded' in content_type or 'multipart/form-data' in content_type:
args = request.form
elif 'application/json' in content_type:
args = request.json
elif 'text/plain' in content_type:
args = request.data
else:
args = request.args
elif request.method == 'GET':
args = request.args
if key:
......@@ -79,6 +87,36 @@ def index(): # put application's code here
# print(manager2)
return render_template('index.html',getHost=getHost,manager0=manager0,manager1=manager1,manager2=manager2,is_linux=is_linux())
@app.route('/admin')
def admin_home(): # 管理员界面
# headers = request.headers
# print(headers)
cookies = request.cookies
# print(cookies)
token = cookies.get('token','')
# print(f'mytoken:{token}')
if not verfy_token(token):
return render_template('login.html')
# return jsonify(error.success('登录成功'))
return render_template('admin.html')
@app.route('/api/login',methods=['GET','POST'])
def login_api():
username = getParmas('username')
password = getParmas('password')
autologin = getParmas('autologin')
if not all([username,password]):
return jsonify(error.failed('账号密码字段必填'))
token = md5(f'{username};{password}')
check = verfy_token(token)
if check:
# response = make_response(redirect('/admin'))
response = make_response(jsonify(error.success('登录成功')))
response.set_cookie('token', token)
return response
else:
return jsonify(error.failed('登录失败,用户名或密码错误'))
@app.route('/vod')
def vod():
t0 = time()
......
......@@ -9,7 +9,7 @@ import re
import math
from utils.web import *
from models import *
from utils.config import config
from utils.config import playerConfig
from utils.log import logger
from utils.encode import base64Encode,baseDecode,fetch,post,request,getCryptoJS,getPreJs,buildUrl,getHome
from utils.encode import verifyCode
......@@ -382,7 +382,7 @@ class CMS:
result['class'] = classes
if self.filter:
result['filters'] = config['filter']
result['filters'] = playerConfig['filter']
result.update(video_result)
logger.info(f'{self.getName()}获取首页总耗时(包含读取缓存):{get_interval(t1)}毫秒')
return result
......
......@@ -27,4 +27,6 @@ SUP_PORT = 9001 # supervisord 服务端口
RETRY_CNT = 3 # 验证码重试次数
# OCR_API = 'http://192.168.3.224:9000/api/ocr_img' # 验证码识别接口,传参数data
OCR_API = 'http://dm.mudery.com:10000' # 验证码识别接口,传参数data
UNAME = 'admin' # 管理员账号
PWD = 'drpy' # 管理员密码
# {% if config.WALL_PAPER %}"wallpaper":"{{ config.WALL_PAPER }}",{% endif %}
\ No newline at end of file
......@@ -2,6 +2,8 @@
##### python3.6-3.8完美运行(3.9以上不支持linux进程启动)
###### 更新日志
###### 2022/08/30
- [X] 1.增加管理员登录功能(用户上传和删除规则)
###### 2022/08/30
- [X] 1.增加动态局域网ip获取
- [X] 2.增加js规则热加载(增删改不用重启)
- [X] 3.增加视界的加密库
......
.btn{
margin-bottom: 1rem;
border: 1px solid #615e5e;
width: 240px;
height: 30px;
text-align: center;
background-color: #1379cb;
color: #ffffff;
border-radius: 20px;
line-height: 30px;
}
.btn a{
color: #ffffff;
}
a {
text-decoration: none;
text-align: center;
line-height: 30px;
}
.jyw{
margin-bottom: 5rem;
}
\ No newline at end of file
/* =============================================================================
HTML5 CSS Reset Minified - Eric Meyer
========================================================================== */
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}
body{line-height:1}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}
nav ul{list-style:none}
blockquote,q{quotes:none}
blockquote:before,blockquote:after,q:before,q:after{content:none}
a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:transparent;text-decoration:none}
mark{background-color:#ff9;color:#000;font-style:italic;font-weight:bold}
del{text-decoration:line-through}
abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help}
table{border-collapse:collapse;border-spacing:0}
hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0;padding:0}
input,select{vertical-align:middle}
li{list-style:none}
/* =============================================================================
My CSS
========================================================================== */
/* ---- base ---- */
html,body{
width:100%;
height:100%;
background:#111;
}
html{
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body{
font:normal 75% Arial, Helvetica, sans-serif;
}
canvas{
display:block;
vertical-align:bottom;
}
/* ---- stats.js ---- */
.count-particles{
background: #000022;
position: absolute;
top: 48px;
left: 0;
width: 80px;
color: #13E8E9;
font-size: .8em;
text-align: left;
text-indent: 4px;
line-height: 14px;
padding-bottom: 2px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
}
.js-count-particles{
font-size: 1.1em;
}
#stats,
.count-particles{
-webkit-user-select: none;
margin-top: 5px;
margin-left: 5px;
}
#stats{
border-radius: 3px 3px 0 0;
overflow: hidden;
}
.count-particles{
border-radius: 0 0 3px 3px;
}
/* ---- particles.js container ---- */
#particles-js{
width: 100%;
height: 100%;
background-image: url('../img/login_background.png');
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.login-content{
width: 400px;
height: 280px;
margin: 0 auto;
position: relative;
top: 300px;
border: 1px solid #2890fa;
background: rgba(40, 144, 250, 0.2);
border-radius: 5px;
}
.login-tit{
background: rgba(0, 0, 0, 0.8);
border: 1px solid #2890fa;
color: #fff;
padding: 15px 20px;
font-size: 18px
}
.login-input {
width: 90%;
margin: 30px auto 0 auto;
}
.login-input input{
background: rgba(0, 0, 0, 0);
border: 0;
height: 30px;
width: 100%;
line-height: 30px;
color: #fff;
border-bottom: 1px solid rgba(40, 144, 250, 0.4);
}
.login-input input:focus{
outline:none;
}
.login-btn{
width: 90%;
display: flex;
color: #ffffff;
margin: 40px auto 0 auto;
}
.login-btn-left span{
background: #2890fa;
padding: 10px 30px;
border-radius: 5px;
cursor: pointer;
}
.login-btn-right{
display: flex;
align-items: center;
margin-left: 20px
}
.login-btn-right img{
margin-right: 10px
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>管理员界面</title>
</head>
<body>
<h1>欢迎使用py_dr管理员界面</h1>
<p>你可以在此页面在线上传规则文件到js目录或者删除js目录的文件</p>
</body>
</html>
\ No newline at end of file
......@@ -9,31 +9,11 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>dr_py首页</title>
<script src="/static/js/jquery.min.js"></script>
<link rel="stylesheet" media="screen" href="/static/css/index.css"/>
</head>
<style>
.btn{
margin-bottom: 2rem;
border: 1px solid #615e5e;
width: 240px;
height: 30px;
text-align: center;
background-color: #1379cb;
color: #ffffff;
border-radius: 20px;
line-height: 30px;
}
.btn a{
color: #ffffff;
}
a {
text-decoration: none;
text-align: center;
line-height: 30px;
}
.jyw{
margin-bottom: 5rem;
.title {
font-size: 18px;
}
</style>
<body style="background: #FFFFFF url(https://cdn.seovx.com/d/?mom=302) no-repeat fixed center;max-hright;">
......@@ -59,6 +39,10 @@ a {
<div class="btn">
<a href="/vod?rule=">猫CMS接口</a>
</div>
<div class="btn">
<!-- <a href="/admin" target="_blank">CMS后台管理</a>-->
<a href="/admin">CMS后台管理</a>
</div>
<div class="btn">
<a href="/rules">缓存文件列表-清除</a>
</div>
......
此差异已折叠。
......@@ -5,6 +5,7 @@
# Date : 2022/8/25
import socket
import hashlib
from werkzeug.utils import import_string
from netifaces import interfaces, ifaddresses, AF_INET
from flask import request
......@@ -70,4 +71,19 @@ def get_conf(obj):
def get_interval(t):
interval = time() - t
interval = round(interval*1000,2)
return interval
\ No newline at end of file
return interval
def md5(str):
return hashlib.md5(str.encode(encoding='UTF-8')).hexdigest()
def verfy_token(token=''):
if not token or len(str(token))!=32:
return False
cfg = get_conf(settings)
username = cfg.get('UNAME','')
pwd = cfg.get('PWD','')
ctoken = md5(f'{username};{pwd}')
# print(f'username:{username},pwd:{pwd},current_token:{ctoken},input_token:{ctoken}')
if token != ctoken:
return False
return True
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册