Skip to content

Commit 31571a6

Browse files
committed
update
1 parent 8803d3e commit 31571a6

File tree

23 files changed

+894
-532
lines changed

23 files changed

+894
-532
lines changed

new_cli.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/hom
33
DIR=$(cd "$(dirname "$0")"; pwd)
44
MDIR=$(dirname "$DIR")
55

6+
export LC_ALL="en_US.UTF-8"
7+
68
# echo $DIR
79

810
PATH=$PATH:$DIR/bin
@@ -14,9 +16,6 @@ if [ -f ${DIR}/bin/activate ];then
1416
fi
1517
fi
1618

17-
export LC_ALL="en_US.UTF-8"
18-
19-
2019
mw_start_task()
2120
{
2221
isStart=$(ps aux |grep 'panel_task.py'|grep -v grep|awk '{print $2}')

panel_task.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
import core.db as db
3232

3333

34-
# print(mw.getPanelDir())
35-
36-
# print sys.path
37-
38-
# cmd = 'ls /usr/local/lib/ | grep python | cut -d \\ -f 1 | awk \'END {print}\''
39-
# info = mw.execShell(cmd)
40-
# p = "/usr/local/lib/" + info[0].strip() + "/site-packages"
41-
# sys.path.append(p)
42-
43-
4434
global pre, timeoutCount, logPath, isTask, oldEdate, isCheck
4535
pre = 0
4636
timeoutCount = 0
@@ -85,9 +75,12 @@ def service_cmd(method):
8575
execShell(cmd + ' ' + method)
8676
return
8777

88-
cmd = mw.getRunDir() + '/scripts/init.d/mw'
78+
cmd = mw.getPanelDir() + '/scripts/init.d/mw'
79+
print(cmd)
8980
if os.path.exists(cmd):
90-
execShell(cmd + ' ' + method)
81+
print(cmd + ' ' + method)
82+
data = execShell(cmd + ' ' + method)
83+
print(data)
9184
return
9285

9386

@@ -573,7 +566,7 @@ def openrestyRestartAtOnce():
573566

574567
# --------------------------------------Panel Restart Start --------------------------------------------- #
575568
def restartPanelService():
576-
restartTip = 'data/restart.pl'
569+
restartTip = mw.getPanelDir()+'/data/restart.pl'
577570
while True:
578571
if os.path.exists(restartTip):
579572
os.remove(restartTip)
@@ -612,10 +605,10 @@ def run():
612605
# oar.start()
613606

614607

615-
# # Panel Restart Start
616-
# rps = threading.Thread(target=restartPanelService)
617-
# rps = setDaemon(rps)
618-
# rps.start()
608+
# Panel Restart Start
609+
rps = threading.Thread(target=restartPanelService)
610+
rps = setDaemon(rps)
611+
rps.start()
619612

620613
# 面板后台任务
621614
startPanelTask()

panel_tools.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,15 @@ def set_panel_pwd(password, ncli=False):
228228

229229

230230
def show_panel_pwd():
231-
# 设置面板密码
232-
sql = db.Sql()
233-
password = sql.table('users').where('id=?', (1,)).getField('password')
234-
235-
file_pwd = ''
236-
if os.path.exists('data/default.pl'):
237-
file_pwd = mw.readFile('data/default.pl').strip()
231+
# 面板密码展示
232+
info = model.getUserByRoot()
233+
defailt_pwd_file = mw.getPanelDir()+'/data/default.pl'
234+
pwd = ''
235+
if os.path.exists(defailt_pwd_file):
236+
pwd = mw.readFile(defailt_pwd_file).strip()
238237

239-
if mw.md5(file_pwd) == password:
240-
print('password: ' + file_pwd)
238+
if mw.md5(pwd) == info['password']:
239+
print('password: ' + pwd)
241240
return
242241
print("password has been changed!")
243242

scripts/init.d/mw.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mw_start()
104104
# /www/server/mdserver-web/tmp/panelTask.pl && service mw restart_task
105105
mw_stop_task()
106106
{
107-
if [ -f $mw_path/tmp/panelTask.pl ];then
107+
if [ -f ${PANEL_DIR}/tmp/panelTask.pl ];then
108108
echo -e "\033[32mthe task is running and cannot be stopped\033[0m"
109109
exit 0
110110
fi
@@ -123,7 +123,7 @@ mw_stop_panel()
123123
{
124124
echo -e "stopping mw-panel... \c";
125125

126-
pidfile=${mw_path}/logs/mw.pid
126+
pidfile=${PANEL_DIR}/logs/mw.pid
127127
if [ -f $pidfile ];then
128128
pid=`cat $pidfile`
129129
kill -9 $pid > /dev/null 2>&1

web/admin/crontab/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def list():
2727
page = request.args.get('p', 1)
2828
size = 10
2929
count = Crontab.query.count()
30-
print(count)
30+
# print(count)
3131
clist = Crontab.query.paginate(page=int(page), per_page=size)
32-
print(clist)
32+
# print(clist)
3333

3434
return []

web/admin/dashboard/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
def index():
3333
return render_template('default/index.html')
3434

35+
# 安全路径
36+
@blueprint.route('/<path>',endpoint='admin_safe_path',methods=['GET'])
37+
def admin_safe_path(path):
38+
db_path = model.getOption('admin_path')
39+
if db_path == path:
40+
return render_template('default/login.html')
41+
42+
unauthorized_status = model.getOption('unauthorized_status')
43+
if unauthorized_status == '0':
44+
return render_template('default/path.html')
45+
return Response(status=int(unauthorized_status))
46+
3547
# 仅针对webhook插件
3648
@blueprint.route("/hook", methods=['POST', 'GET'])
3749
def webhook():
@@ -63,19 +75,6 @@ def webhook():
6375
except Exception as e:
6476
return str(e)
6577

66-
# 安全路径
67-
@blueprint.route('/<path>',endpoint='admin_safe_path',methods=['GET'])
68-
def admin_safe_path(path):
69-
db_path = model.getOption('admin_path')
70-
if db_path == path:
71-
return render_template('default/login.html')
72-
73-
unauthorized_status = model.getOption('unauthorized_status')
74-
if unauthorized_status == '0':
75-
return render_template('default/path.html')
76-
return Response(status=int(unauthorized_status))
77-
78-
7978
# ---------------------------------------------------------------------------------
8079
# 定义登录入口相关方法
8180
# ---------------------------------------------------------------------------------

web/admin/firewall/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,21 @@ def set_ping():
7575
mf = MwFirewall.instance()
7676
return mf.setPing()
7777

78+
# 添加放行端口
79+
@blueprint.route('/add_accept_port', endpoint='add_accept_port', methods=['POST'])
80+
@panel_login_required
81+
def add_accept_port():
82+
mf = MwFirewall.instance()
83+
if not mf.getFwStatus():
84+
return mw.returnData(False, '防火墙启动时,才能添加规则!')
7885

86+
port = request.form.get('port', '').strip()
87+
ps = request.form.get('ps', '').strip()
88+
protocol = request.form.get('protocol', '').strip()
89+
stype = request.form.get('type', '').strip()
7990

91+
data = mf.addAcceptPort(port, ps, stype, protocol=protocol)
92+
return mw.getJson(data)
8093

8194

8295

web/admin/model/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Author: midoks <[email protected]>
99
# ---------------------------------------------------------------------------------
1010

11+
1112
from .initdb import *
1213

1314
from .logs import addLog,clearLog
@@ -25,5 +26,11 @@
2526
from .user import getUserByName,getUserById,getUserByRoot
2627
from .user import setUserByRoot
2728

29+
from .firewall import addFirewall
30+
2831
from .temp_login import getTempLoginByToken,clearTempLogin
2932

33+
34+
35+
36+

web/admin/model/firewall.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# coding:utf-8
2+
3+
# ---------------------------------------------------------------------------------
4+
# MW-Linux面板
5+
# ---------------------------------------------------------------------------------
6+
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
7+
# ---------------------------------------------------------------------------------
8+
# Author: midoks <[email protected]>
9+
# ---------------------------------------------------------------------------------
10+
11+
from admin.model import db, Firewall
12+
13+
import core.mw as mw
14+
15+
16+
17+
def addFirewall(port,
18+
protocol: str | None = 'tcp',
19+
ps: str | None = '备注'
20+
) -> bool:
21+
'''
22+
设置配置的值
23+
:port -> str 端口 (必填)
24+
:protocol -> str 协议 (可选|tcp,udp,tcp/udp)
25+
:ps -> str 备注 (可选)
26+
'''
27+
now_time = mw.formatDate()
28+
add_data = Firewall(
29+
port=port,
30+
protocol=protocol,
31+
add_time=now_time,
32+
update_time=now_time)
33+
db.session.add(add_data)
34+
db.session.commit()
35+
return True
36+
37+
38+
def getFirewallCountByPort(port):
39+
return Firewall.query.filter(Tasks.port==port).count()
40+
41+

web/admin/model/logs.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
import time
1414

1515
from admin.model import db, Logs
16-
17-
def formatDate(format="%Y-%m-%d %H:%M:%S", times=None):
18-
# 格式化指定时间戳
19-
if not times:
20-
times = int(time.time())
21-
time_local = time.localtime(times)
22-
return time.strftime(format, time_local)
16+
import core.mw as mw
2317

2418
def clearLog():
2519
try:
@@ -42,12 +36,12 @@ def addLog(type, log,
4236
:log -> str 日志内容 (必填)
4337
:uid -> int 用户ID
4438
'''
45-
add_time = formatDate()
39+
now_time = mw.formatDate()
4640
add_logs = Logs(
4741
uid=uid,
4842
log=log,
4943
type=type,
50-
add_time=add_time)
44+
add_time=now_time)
5145
db.session.add(add_logs)
5246
db.session.commit()
5347
db.session.close()

0 commit comments

Comments
 (0)