mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright [midoks] [midoks of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -97,7 +97,7 @@ curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/up
|
||||
```
|
||||
|
||||
### 微信赞助
|
||||
- [](/route/static/img/weixin_zz.jpg)
|
||||
[](/route/static/img/weixin_zz.jpg)
|
||||
|
||||
### 无图不真相
|
||||
|
||||
|
||||
+15
-2
@@ -111,9 +111,22 @@ def isInstalledWeb():
|
||||
|
||||
|
||||
def restartWeb():
|
||||
if isInstalledWeb():
|
||||
initd = getServerDir() + '/openresty/init.d/openresty'
|
||||
if not isInstalledWeb():
|
||||
return False
|
||||
|
||||
# systemd
|
||||
systemd = '/lib/systemd/system/openresty.service'
|
||||
if os.path.exists(systemd):
|
||||
execShell('systemctl restart openresty')
|
||||
return True
|
||||
|
||||
# initd
|
||||
initd = getServerDir() + '/openresty/init.d/openresty'
|
||||
if os.path.exists(initd):
|
||||
execShell(initd + ' ' + 'restart')
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def restartMw():
|
||||
|
||||
@@ -599,7 +599,11 @@ class site_api:
|
||||
if not os.path.exists(acem):
|
||||
return mw.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装<p>安装命令: curl https://get.acme.sh | sh</p>' + acem)
|
||||
|
||||
force_bool = False
|
||||
# 避免频繁执行
|
||||
checkAcmeRun = mw.execShell('ps -ef|grep acme.sh |grep -v grep')
|
||||
if checkAcmeRun[0] != '':
|
||||
return mw.returnJson(False, '正在申请或更新SSL中...')
|
||||
|
||||
if force == 'true':
|
||||
force_bool = True
|
||||
|
||||
@@ -973,7 +977,7 @@ class site_api:
|
||||
"-START(.|\n)+BINDING-" + domain + "-END"
|
||||
tmp = re.search(rep, conf).group()
|
||||
dirConf = tmp.replace('rewrite/' + site['name'] + '.conf;', 'rewrite/' + site[
|
||||
'name'] + '_' + find['path'] + '.conf;')
|
||||
'name'] + '_' + find['path'] + '.conf;')
|
||||
conf = conf.replace(tmp, dirConf)
|
||||
mw.writeFile(file, conf)
|
||||
data = {}
|
||||
|
||||
@@ -131,11 +131,16 @@ def confReplace():
|
||||
content = content.replace('{$OS_USER}', user)
|
||||
content = content.replace('{$OS_USER_GROUP}', user_group)
|
||||
|
||||
# 主配置文件
|
||||
nconf = getServerDir() + '/nginx/conf/nginx.conf'
|
||||
|
||||
__content = mw.readFile(nconf)
|
||||
if __content.find('#user'):
|
||||
mw.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)
|
||||
mw.writeFile(nconf, content)
|
||||
|
||||
# 静态配置
|
||||
static_conf = getServerDir() + '/nginx/conf/enable-php-00.conf'
|
||||
if not os.path.exists(static_conf):
|
||||
mw.writeFile(static_conf, '')
|
||||
|
||||
# give nginx root permission
|
||||
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#! /bin/bash
|
||||
#禁止弱口令登录改良版
|
||||
|
||||
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > black.txt #尝试登录的次数和ip
|
||||
|
||||
DEFINE="5" #单个ip尝试登录最大值
|
||||
|
||||
for i in `cat /root/black.txt`
|
||||
do
|
||||
|
||||
IP=`echo $i |awk -F= '{print $1}'`
|
||||
NUM=`echo $i|awk -F= '{print $2}'`
|
||||
|
||||
if [ $NUM -gt $DEFINE ]; then
|
||||
grep $IP /etc/hosts.deny > /dev/null
|
||||
|
||||
if [ $? -gt 0 ]; then
|
||||
echo "sshd:$IP" >> /etc/hosts.deny #扔到hosts文件中
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -46,7 +46,7 @@ fi
|
||||
|
||||
wget -O /tmp/master.zip https://gitee.com/midoks/mdserver-web/repository/archive/master.zip
|
||||
cd /tmp && unzip /tmp/master.zip
|
||||
mv /tmp/mdserver-web-master /www/server/mdserver-web
|
||||
cp -rf /tmp/mdserver-web-master/* /www/server/mdserver-web
|
||||
rm -rf /tmp/master.zip
|
||||
rm -rf /tmp/mdserver-web-master
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ fi
|
||||
|
||||
wget -O /tmp/dev.zip https://github.com/midoks/mdserver-web/archive/refs/heads/dev.zip
|
||||
cd /tmp && unzip /tmp/dev.zip
|
||||
mv /tmp/mdserver-web-dev /www/server/mdserver-web
|
||||
cp -rf /tmp/mdserver-web-dev/* /www/server/mdserver-web
|
||||
rm -rf /tmp/dev.zip
|
||||
rm -rf /tmp/mdserver-web-dev
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ def execShell(cmdstring, cwd=None, timeout=None, shell=True):
|
||||
import shlex
|
||||
import datetime
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
if timeout:
|
||||
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
|
||||
@@ -226,7 +225,6 @@ def systemTask():
|
||||
try:
|
||||
import system_api
|
||||
import psutil
|
||||
import time
|
||||
sm = system_api.system_api()
|
||||
filename = 'data/control.conf'
|
||||
|
||||
@@ -368,7 +366,7 @@ def systemTask():
|
||||
mw.writeFile('logs/sys_interrupt.pl', str(ex))
|
||||
|
||||
restartMw()
|
||||
import time
|
||||
|
||||
time.sleep(30)
|
||||
systemTask()
|
||||
|
||||
@@ -388,17 +386,18 @@ def check502Task():
|
||||
|
||||
def check502():
|
||||
try:
|
||||
phpversions = ['53', '54', '55', '56', '70', '71', '72', '73', '74']
|
||||
for version in phpversions:
|
||||
verlist = ['52', '53', '54', '55', '56', '70',
|
||||
'71', '72', '73', '74', '80', '81']
|
||||
for ver in verlist:
|
||||
sdir = mw.getServerDir()
|
||||
php_path = sdir + '/php/' + version + '/sbin/php-fpm'
|
||||
php_path = sdir + '/php/' + ver + '/sbin/php-fpm'
|
||||
if not os.path.exists(php_path):
|
||||
continue
|
||||
if checkPHPVersion(version):
|
||||
if checkPHPVersion(ver):
|
||||
continue
|
||||
if startPHPVersion(version):
|
||||
print('检测到PHP-' + version + '处理异常,已自动修复!')
|
||||
mw.writeLog('PHP守护程序', '检测到PHP-' + version + '处理异常,已自动修复!')
|
||||
if startPHPVersion(ver):
|
||||
print('检测到PHP-' + ver + '处理异常,已自动修复!')
|
||||
mw.writeLog('PHP守护程序', '检测到PHP-' + ver + '处理异常,已自动修复!')
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
@@ -452,8 +451,8 @@ def checkPHPVersion(version):
|
||||
try:
|
||||
url = 'http://127.0.0.1/phpfpm_status_' + version
|
||||
result = mw.httpGet(url)
|
||||
# print version,result
|
||||
# 检查nginx
|
||||
# print(version,result)
|
||||
# 检查openresty
|
||||
if result.find('Bad Gateway') != -1:
|
||||
return False
|
||||
if result.find('HTTP Error 404: Not Found') != -1:
|
||||
@@ -466,17 +465,52 @@ def checkPHPVersion(version):
|
||||
isStatus = mw.readFile(isTask)
|
||||
if isStatus == 'True':
|
||||
return True
|
||||
filename = '/etc/init.d/openresty'
|
||||
if os.path.exists(filename):
|
||||
os.system(filename + ' start')
|
||||
|
||||
# systemd
|
||||
systemd = '/lib/systemd/system/openresty.service'
|
||||
if os.path.exists(systemd):
|
||||
execShell('systemctl reload openresty')
|
||||
return True
|
||||
# initd
|
||||
initd = '/etc/init.d/openresty'
|
||||
if os.path.exists(initd):
|
||||
os.system(initd + ' reload')
|
||||
return True
|
||||
except:
|
||||
return True
|
||||
|
||||
# --------------------------------------PHP监控 end--------------------------------------------- #
|
||||
|
||||
|
||||
# --------------------------------------OpenResty Auto Restart Start --------------------------------------------- #
|
||||
# 解决acme.sh续签后,未起效。
|
||||
def openrestyAutoRestart():
|
||||
try:
|
||||
while True:
|
||||
# 检查是否安装
|
||||
odir = mw.getServerDir() + '/openresty'
|
||||
if not os.path.exists(odir):
|
||||
time.sleep(86400)
|
||||
continue
|
||||
|
||||
# systemd
|
||||
systemd = '/lib/systemd/system/openresty.service'
|
||||
initd = '/etc/init.d/openresty'
|
||||
if os.path.exists(systemd):
|
||||
execShell('systemctl reload openresty')
|
||||
elif os.path.exists(initd):
|
||||
os.system(initd + ' reload')
|
||||
time.sleep(86400)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
time.sleep(86400)
|
||||
|
||||
# --------------------------------------OpenResty Auto Restart End --------------------------------------------- #
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# 系统监控
|
||||
t = threading.Thread(target=systemTask)
|
||||
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
|
||||
t.daemon = True
|
||||
@@ -484,12 +518,20 @@ if __name__ == "__main__":
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
|
||||
# PHP 502错误检查线程
|
||||
p = threading.Thread(target=check502Task)
|
||||
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
|
||||
p.daemon = True
|
||||
else:
|
||||
p.setDaemon(True)
|
||||
|
||||
p.start()
|
||||
|
||||
# OpenResty Auto Restart Start
|
||||
oar = threading.Thread(target=openrestyAutoRestart)
|
||||
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
|
||||
oar.daemon = True
|
||||
else:
|
||||
oar.setDaemon(True)
|
||||
oar.start()
|
||||
|
||||
startTask()
|
||||
|
||||
Reference in New Issue
Block a user