Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Nov 10, 2024
1 parent e6af36a commit c2a8b95
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 97 deletions.
2 changes: 1 addition & 1 deletion panel_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
os.chdir(web_dir)
sys.path.append(web_dir)

from utils.firewall import firewall as MwFirewall
from utils.firewall import Firewall as MwFirewall
import core.mw as mw
import thisdb

Expand Down
31 changes: 29 additions & 2 deletions web/admin/setting/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from flask import Blueprint, render_template
from flask import request

from admin import model

from admin import session
from admin.user_login_check import panel_login_required


Expand Down Expand Up @@ -203,6 +202,34 @@ def set_ipv6_status():
mw.restartMw()
return mw.returnData(True, '设置成功!')

# 设置面板用户
@blueprint.route('/set_name', endpoint='set_name', methods=['POST'])
@panel_login_required
def set_name():
name1 = request.form.get('name1', '')
name2 = request.form.get('name2', '')
if name1 != name2:
return mw.returnData(False, '两次输入的用户名不一致,请重新输入!')
if len(name1) < 3:
return mw.returnData(False, '用户名长度不能少于3位')
thisdb.setUserByName(session['username'], name1)
session['username'] = name1
return mw.returnData(True, '用户修改成功!')

@blueprint.route('/set_password', endpoint='set_password', methods=['POST'])
@panel_login_required
def set_password():
password1 = request.form.get('password1', '')
password2 = request.form.get('password2', '')
if password1 != password2:
return mw.returnData(False, '两次输入的密码不一致,请重新输入!')
if len(password1) < 5:
return mw.returnData(False, '用户密码不能小于5位!')

thisdb.setUserPwdByName(session['username'], password1)
return mw.returnData(True, '密码修改成功!')


# 设置站点状态
@blueprint.route('/set_port', endpoint='set_port', methods=['POST'])
@panel_login_required
Expand Down
187 changes: 93 additions & 94 deletions web/static/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,126 +310,125 @@ function modifyAuthPath() {
});
}

function setPassword(a) {
if(a == 1) {
p1 = $("#p1").val();
p2 = $("#p2").val();
if(p1 == "" || p1.length < 8) {
layer.msg('面板密码不能少于8位!', {icon: 2});
return
}

//准备弱口令匹配元素
var checks = ['admin888','123123123','12345678','45678910','87654321','asdfghjkl','password','qwerqwer'];
pchecks = 'abcdefghijklmnopqrstuvwxyz1234567890';
for(var i=0;i<pchecks.length;i++){
checks.push(pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]);
}

//检查弱口令
cps = p1.toLowerCase();
var isError = "";
for(var i=0;i<checks.length;i++){
if(cps == checks[i]){
isError += '['+checks[i]+'] ';
}
}

if(isError != ""){
layer.msg('面板密码不能为弱口令'+isError,{icon:5});
return;
}

if(p1 != p2) {
layer.msg('两次输入的密码不一致', {icon: 2});
return;
}
$.post("/setting/set_password", "password1=" + encodeURIComponent(p1) + "&password2=" + encodeURIComponent(p2), function(b) {
if(b.status) {
layer.closeAll();
layer.msg(b.msg, {icon: 1});
} else {
layer.msg(b.msg, {icon: 2});
}
},'json');
return;
}
function setPassword() {
layer.open({
type: 1,
area: "290px",
area: ["350px",'auto'],
title: '修改密码',
closeBtn: 1,
shift: 5,
shadeClose: false,
content: "<div class='bt-form pd20 pb70'>\
btn:["修改","关闭","随机"],
content: "<div class='bt-form'>\
<div class='line'>\
<span class='tname'>密码</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='password1' id='p1' value='' placeholder='新的密码' style='width:100%'/></div>\
<div class='info-r'><input class='bt-input-text' type='text' name='password1' id='p1' value='' placeholder='新的密码' style='width:70%'/></div>\
</div>\
<div class='line'>\
<span class='tname'>重复</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='password2' id='p2' value='' placeholder='再输一次' style='width:100%' /></div>\
</div>\
<div class='bt-form-submit-btn'>\
<span style='float: left;' title='随机密码' class='btn btn-default btn-sm' onclick='randPwd(10)'>随机</span>\
<button type='button' class='btn btn-danger btn-sm' onclick=\"layer.closeAll()\">关闭</button>\
<button type='button' class='btn btn-success btn-sm' onclick=\"setPassword(1)\">修改</button>\
<div class='info-r'><input class='bt-input-text' type='text' name='password2' id='p2' value='' placeholder='再输一次' style='width:70%' /></div>\
</div>\
</div>"
</div>",
yes:function(){
var p1 = $("#p1").val();
var p2 = $("#p2").val();
if(p1 == "" || p1.length < 8) {
layer.msg('面板密码不能少于8位!', {icon: 2});
return
}

//准备弱口令匹配元素
var checks = ['admin888','123123123','12345678','45678910','87654321','asdfghjkl','password','qwerqwer'];
pchecks = 'abcdefghijklmnopqrstuvwxyz1234567890';
for(var i=0;i<pchecks.length;i++){
checks.push(pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]+pchecks[i]);
}

//检查弱口令
cps = p1.toLowerCase();
var isError = "";
for(var i=0;i<checks.length;i++){
if(cps == checks[i]){
isError += '['+checks[i]+'] ';
}
}

if(isError != ""){
layer.msg('面板密码不能为弱口令'+isError,{icon:5});
return;
}

if(p1 != p2) {
layer.msg('两次输入的密码不一致', {icon: 2});
return;
}
$.post("/setting/set_password", "password1=" + encodeURIComponent(p1) + "&password2=" + encodeURIComponent(p2), function(b) {
if(b.status) {
layer.closeAll();
layer.msg(b.msg, {icon: 1});
} else {
layer.msg(b.msg, {icon: 2});
}
},'json');
return;
},
btn3: function(){
var pwd = randomStrPwd(12);
$("#p1").val(pwd);
$("#p2").val(pwd);
layer.msg('请在修改前记录好您的新密码!',{time:2000});
return false;
}
});
}


function randPwd(){
var pwd = randomStrPwd(12);
$("#p1").val(pwd);
$("#p2").val(pwd);
layer.msg(lan.bt.pass_rep_ps,{time:2000})
}

function setUserName(a) {
if(a == 1) {
p1 = $("#p1").val();
p2 = $("#p2").val();
if(p1 == "" || p1.length < 3) {
layer.msg('用户名长度不能少于3位', {icon: 2});
return;
}
if(p1 != p2) {
layer.msg('两次输入的用户名不一致', {icon: 2});
return;
}
$.post("/setting/set_name", "name1=" + encodeURIComponent(p1) + "&name2=" + encodeURIComponent(p2), function(b) {
if(b.status) {
layer.closeAll();
layer.msg(b.msg, {icon: 1});
$("input[name='username_']").val(p1)
} else {
layer.msg(b.msg, {icon: 2});
}
},'json');
return
}
function setUserName() {
layer.open({
type: 1,
area: "290px",
area: ["350px",'auto'],
title: '修改面板用户名',
closeBtn: 1,
shift: 5,
shadeClose: false,
content: "<div class='bt-form pd20 pb70'>\
btn:["确定","取消","随机"],
content: "<div class='bt-form pd20'>\
<div class='line'><span class='tname'>用户名</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='password1' id='p1' value='' placeholder='新的用户名' style='width:100%'/></div>\
<div class='info-r'><input class='bt-input-text' type='text' name='password1' id='p1' value='' placeholder='新的用户名' style='width:70%'/></div>\
</div>\
<div class='line'>\
<span class='tname'>重复</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='password2' id='p2' value='' placeholder='再输一次' style='width:100%'/></div>\
<div class='info-r'><input class='bt-input-text' type='text' name='password2' id='p2' value='' placeholder='再输一次' style='width:70%'/></div>\
</div>\
<div class='bt-form-submit-btn'>\
<button type='button' class='btn btn-danger btn-sm' onclick=\"layer.closeAll()\">关闭</button>\
<button type='button' class='btn btn-success btn-sm' onclick=\"setUserName(1)\">修改</button>\
</div>\
</div>"
</div>",
yes: function(){
p1 = $("#p1").val();
p2 = $("#p2").val();
if(p1 == "" || p1.length < 3) {
layer.msg('用户名长度不能少于3位', {icon: 2});
return;
}
if(p1 != p2) {
layer.msg('两次输入的用户名不一致', {icon: 2});
return;
}
$.post("/setting/set_name", "name1=" + encodeURIComponent(p1) + "&name2=" + encodeURIComponent(p2), function(b) {
if(b.status) {
layer.closeAll();
layer.msg(b.msg, {icon: 1});
$("input[name='username_']").val(p1)
} else {
layer.msg(b.msg, {icon: 2});
}
},'json');
return
},
btn3:function(){
var pwd = randomStrPwd(12);
$("#p1").val(pwd);
$("#p2").val(pwd);
layer.msg('请在修改前记录好您的用户名!',{time:2000});
return false;
}
})
}

Expand Down
7 changes: 7 additions & 0 deletions web/thisdb/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def updateUserLoginTime():
mw.M('users').field(__field).where('id=?', (1,)).update({'login_time':now_time})
return True

def setUserByName(name, new_name):
return mw.M('users').where("name=?", (name,)).setField('name', new_name.strip())

def setUserPwdByName(name, password):
pwd = mw.md5(password)
return mw.M('users').where("name=?", (name,)).setField('password', pwd)

def setUserByRoot(
name: str | None = None,
password: str | None = None,
Expand Down

0 comments on commit c2a8b95

Please sign in to comment.