提交 ff03d664 编写于 作者: H hjdhnx

完善了管理员操作界面

上级 62d0401b
......@@ -99,7 +99,7 @@ def admin_home(): # 管理员界面
if not verfy_token(token):
return render_template('login.html')
# return jsonify(error.success('登录成功'))
return render_template('admin.html')
return render_template('admin.html',rules=getRules('js'))
@app.route('/api/login',methods=['GET','POST'])
def login_api():
......@@ -118,6 +118,26 @@ def login_api():
else:
return jsonify(error.failed('登录失败,用户名或密码错误'))
@app.route("/admin/view/<name>",methods=['GET'])
def admin_view_rule(name):
if not name or not name.split('.')[-1] in ['js','txt','py','json']:
return jsonify(error.failed(f'非法猥亵,未指定文件名。必须包含js|txt|json|py'))
try:
return parser.toJs(name,'js')
except Exception as e:
return jsonify(error.failed(f'非法猥亵\n{e}'))
@app.route('/admin/clear/<name>')
def admin_clear_rule(name):
if not name or not name.split('.')[-1] in ['js','txt','py','json']:
return jsonify(error.failed(f'非法猥亵,未指定文件名。必须包含js|txt|json|py'))
file_path = os.path.abspath(f'js/{name}')
if not os.path.exists(file_path):
return jsonify(error.failed('服务端没有此文件!'+file_path))
os.remove(file_path)
return jsonify(error.success('成功删除文件:'+file_path))
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
cookies = request.cookies
......@@ -127,13 +147,18 @@ def upload_file():
if not verfy_token(token):
return render_template('login.html')
if request.method == 'POST':
f = request.files['file']
# print(request.files)
filename = secure_filename(f.filename)
savePath = f'js/{filename}'
# print(savePath)
f.save(savePath)
return jsonify(error.success('文件上传成功'))
try:
f = request.files['file']
# print(request.files)
filename = secure_filename(f.filename)
savePath = f'js/{filename}'
if os.path.exists(savePath):
return jsonify(error.failed(f'上传失败,文件已存在,请先查看删除再试'))
# print(savePath)
f.save(savePath)
return jsonify(error.success('文件上传成功'))
except Exception as e:
return jsonify(error.failed(f'文件上传失败!{e}'))
else:
# return render_template('upload.html')
return jsonify(error.failed('文件上传失败'))
......@@ -409,7 +434,7 @@ def config_gen():
def plugin(name):
# name=道长影视模板.js
if not name or not name.split('.')[-1] in ['js','txt','py','json']:
return jsonify(error.failed(f'非法威胁,未指定文件名。必须包含js|txt|json|py'))
return jsonify(error.failed(f'非法猥亵,未指定文件名。必须包含js|txt|json|py'))
try:
return parser.toJs(name)
except Exception as e:
......
......@@ -2,7 +2,8 @@
##### python3.6-3.8完美运行(3.9以上不支持linux进程启动)
###### 更新日志
###### 2022/08/30
- [X] 1.增加管理员登录功能(用户上传和删除规则)
- [X] 1.增加管理员登录功能
- [X] 2.增加管理员上传和删除内置规则功能
###### 2022/08/30
- [X] 1.增加动态局域网ip获取
- [X] 2.增加js规则热加载(增删改不用重启)
......@@ -121,4 +122,13 @@ var rule = {
// 搜索可以是*,集成一级,或者跟一级一样的写法 列表;标题;图片;描述;链接;详情
搜索:'*',
}
```
模板继承写法
```javascript
var rule = Object.assign(muban.mxpro,{
title:'鸭奈飞',
host:'https://yanetflix.com',
url:'/index.php/vod/show/id/fyclass/page/fypage.html',
class_parse:'.navbar-items li:gt(1):lt(6);a&&Text;a&&href;.*/(.*?).html',
});
```
\ No newline at end of file
......@@ -2,19 +2,157 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>管理员操作中心</title>
<title>管理员操作中心-{{rules.count}}条规则</title>
<meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
<meta name="author" content="道长"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="/static/css/admin.css">
<link rel="icon" href="/static/img/logo.png" type="image/x-icon">
<script src="/static/js/jquery.min.js"></script>
</head>
<style>
.red {
color:red;
font-weight: bold;
padding-left:10px;
/*padding-top:10px;*/
margin-left:10px;
width: 240px;
height: 30px;
}
.green {
color:forestgreen;
font-weight: bold;
padding-left:10px;
/*padding-top:10px;*/
margin-left:10px;
width: 240px;
height: 30px;
}
.btn{
color:#FFFFFF;
background-color: #1379cb;
}
.clear{
/*word-spacing:2px;*/
letter-spacing:5px;
margin-left:20px;
width: 120px;
height: 30px;
text-align: center;
border-style: solid;
/*border-color: #8CD4F5;*/
border-color: #1379cb;
text-decoration:none;
color:#FFFFFF;
background-color: #1379cb;
}
/*li a {*/
/* display: block !important;*/
/*}*/
</style>
<body>
<h2 class="title">欢迎使用py_dr管理员界面</h2>
<script>
$(document).ready(function(){
$(".view").click(function(){
// location.reload();
let rule = this.innerText.trim();
location.href = '/admin/view/'+rule+'.js';
});
$(".clear").click(function(){
// location.reload();
// let rule = this.innerText.trim();
let rule = this.getAttribute('value').trim();
if(confirm('确认删除内置规则:'+rule+'?')){
let code = $.ajax({url:'/admin/clear/'+rule+'.js',async:false}).responseText;
code = typeof(code) === "object"?code:JSON.parse(code);
if(code.code === 200){
alert('操作成功!\n'+code.msg);
location.reload()
}else{
alert('操作失败!\n'+code.msg);
}
}
// location.href = '/admin/clear/'+rule;
});
$('#upload').click(function(){
var file_data = $("input[name='file']").prop("files")[0];
console.log(file_data);
if(!file_data){
alert('文件必选');
return
}
var form_data = new FormData();
// 把所有表单信息
form_data.append("id", "001");
form_data.append("name", file_data.name);
form_data.append("file", file_data);
$.ajax({
type: "POST",
url: "/upload",
dataType : "json",
processData: false, // 注意:让jQuery不要处理数据
contentType: false, // 注意:让jQuery不要设置contentType
data: form_data
}).success(function(ret) {
console.log(ret);
alert(ret.msg);
location.reload();
}).fail(function(ret) {
console.log(ret);
alert(ret.msg);
});
});
});
function getFileSize(fileObj)
{
$('#file_size').text('文件大小为:'+fileObj.files[0].size/1024+'kb');
}
</script>
<h2 class="title">欢迎使用py_dr管理员界面</h2><h4><a href="/index">返回首页</a></h4>
<p>你可以在此页面在线上传规则文件到js目录或者删除js目录的文件</p>
<form action = "/upload" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit" value="提交"/>
<input type = "file" name = "file" class="btn" accept=".js" onchange="getFileSize(this)"/>
<!-- <input type = "submit" value="上传" class="btn"/>-->
<input type="button" id="upload" value="上传" class="btn"/>
</form>
<p id="file_size"></p>
<h1>内置规则列表</h1>
{% if rules.count < 1 %}
<h3>暂无内置的规则</h3>
{% endif %}
{% for rule in rules.list %}
{% if rule.name|length > 2 %}
<li class="red">
<a class="view" href="javascript:void(0);">{{ rule.name }}</a>
<a class="clear" href="javascript:void(0);" value="{{ rule.name }}">删除</a>
</li>
{% else %}
<li class="green">
<a class="view" href="javascript:void(0);">{{ rule.name }}</a>
<a class="clear" href="javascript:void(0);" value="{{ rule.name }}">删除</a>
</li>
{% endif %}
{% endfor %}
<!--{% if rules.count > 0 %}-->
<!--<h1>删除内置规则</h1>-->
<!--{% for rule in rules.list %}-->
<!--{% if rule|length > 2 %}-->
<!-- <li class="red">-->
<!-- <a class="clear" href="javascript:void(0);">{{ rule.name }}</a>-->
<!-- </li>-->
<!--{% else %}-->
<!-- <li class="yellow">-->
<!-- <a class="clear" href="javascript:void(0);">{{ rule.name }}</a>-->
<!-- </li>-->
<!--{% endif %}-->
<!-- {% endfor %}-->
<!--{% endif %}-->
</body>
</html>
\ No newline at end of file
......@@ -47,17 +47,17 @@
{% for rule in rules.list %}
{% if rule|length > 2 %}
{% if rule.name|length > 2 %}
<!-- | 为过滤条件 -->
<li class="red">
<!-- <a class="refresh" href="/clear?rule={{rule}}" target="_blank">{{ rule }}</a>-->
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
<a class="refresh" href="javascript:void(0);">{{ rule.name }}</a>
</li>
{% else %}
<!-- 如果是if条件,最后必须要有else,否则就会报错 -->
<li class="yellow">
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
<a class="refresh" href="javascript:void(0);">{{ rule.name }}</a>
</li>
{% endif %}
......
......@@ -65,13 +65,13 @@
<!-- | 为过滤条件 -->
<li class="red">
<!-- <a class="refresh" href="/clear?rule={{rule}}" target="_blank">{{ rule }}</a>-->
<a class="refresh" href="javascript:void(0);">{{ rule }}</a>
<a class="refresh" href="javascript:void(0);">{{ rule.name }}</a>
</li>
{% else %}
<!-- 如果是if条件,最后必须要有else,否则就会报错 -->
<li class="yellow">
<a class="refresh" href="javascript:void(0);" target="_blank">{{ rule }}</a>
<a class="refresh" href="javascript:void(0);" target="_blank">{{ rule.name }}</a>
</li>
{% endif %}
......
......@@ -68,9 +68,9 @@ def runJs(jsPath, before='', after='', ctx=None):
# loader.execute(jscode_to_run)
# return loader,js_code
def toJs(jsPath):
def toJs(jsPath,jsRoot='cache'):
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录
js_path = os.path.join(base_path, f'cache/{jsPath}')
js_path = os.path.join(base_path, f'{jsRoot}/{jsPath}')
print(js_path)
if not os.path.exists(js_path):
return jsonify({'code': -2, 'msg': f'非法猥亵,文件不存在'})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册