From e425da26566e7d2edbb2bfd5ec1c69243a26742f Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 12:01:42 +0800 Subject: [PATCH 01/14] Delete check-ssh.sh --- plugins/ssh-no-login/check-ssh.sh | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100755 plugins/ssh-no-login/check-ssh.sh diff --git a/plugins/ssh-no-login/check-ssh.sh b/plugins/ssh-no-login/check-ssh.sh deleted file mode 100755 index 8a648ef10..000000000 --- a/plugins/ssh-no-login/check-ssh.sh +++ /dev/null @@ -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 \ No newline at end of file From f4cc17cf3ae316e3f390c0f0d935e9d15bcc134b Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 12:03:11 +0800 Subject: [PATCH 02/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12b58fae4..2c908a929 100644 --- a/README.md +++ b/README.md @@ -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) +[![截图](/route/static/img/weixin_zz.jpg)](/route/static/img/weixin_zz.jpg) ### 无图不真相 From 5227e66531235c5b570cbf1c3d56d1a63000b93f Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 13:19:00 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BC=98=E5=8C=96openresty=E9=87=8D?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/mw.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 745d1c5d1..5629d57ac 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -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(): From d42a34be483b55bd98451edc9537dc83463e18d5 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 13:41:04 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E4=BC=98=E5=8C=96openresty=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E9=85=8D=E7=BD=AE-=E9=9D=99=E6=80=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=8D=E5=AD=98=E5=9C=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/openresty/index.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index 397917aab..d686f78d3 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -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 os.path.exists(static_conf): + mw.writeFile(static_conf, '') # give nginx root permission ng_exe_bin = getServerDir() + "/nginx/sbin/nginx" From 5c851db77775854684f5533b6cfb51dd9571a8f6 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 13:44:35 +0800 Subject: [PATCH 05/14] Update index.py --- plugins/openresty/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index d686f78d3..8875bb4e7 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -139,7 +139,7 @@ def confReplace(): # 静态配置 static_conf = getServerDir() + '/nginx/conf/enable-php-00.conf' - if os.path.exists(static_conf): + if not os.path.exists(static_conf): mw.writeFile(static_conf, '') # give nginx root permission From e766ffd55f907c74163a63772841182f40fabcd9 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 13:50:51 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/update_cn.sh | 2 +- scripts/update_dev.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/update_cn.sh b/scripts/update_cn.sh index 095210cbc..a5353fb1b 100755 --- a/scripts/update_cn.sh +++ b/scripts/update_cn.sh @@ -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 diff --git a/scripts/update_dev.sh b/scripts/update_dev.sh index 5852e81c6..c3942ae88 100755 --- a/scripts/update_dev.sh +++ b/scripts/update_dev.sh @@ -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 From 3f69f06cea85318acd14ff29aa34a82c02c0276e Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:09:59 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0author?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 261eeb9e9..f37a89ca4 100644 --- a/LICENSE +++ b/LICENSE @@ -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. From 798e51a1c175a7be484b2bca06ba9be310983536 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:33:05 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=A2=91=E7=B9=81?= =?UTF-8?q?=E6=89=A7=E8=A1=8Cacme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/site_api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/class/core/site_api.py b/class/core/site_api.py index 9ab00f1dc..6978c96e1 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -599,7 +599,11 @@ class site_api: if not os.path.exists(acem): return mw.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装

安装命令: curl https://get.acme.sh | sh

' + 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 = {} From eb740d7d1b1d3872d6acb40a453c5b8bf5175947 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:36:12 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/task.py b/task.py index 62ba5f4ef..ad284595b 100755 --- a/task.py +++ b/task.py @@ -452,8 +452,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,9 +466,16 @@ 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 From 701bdbbe84e54e89ae4c03e6d01969fda41cb54a Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:37:10 +0800 Subject: [PATCH 10/14] Update task.py --- task.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task.py b/task.py index ad284595b..4d54a4331 100755 --- a/task.py +++ b/task.py @@ -388,7 +388,8 @@ def check502Task(): def check502(): try: - phpversions = ['53', '54', '55', '56', '70', '71', '72', '73', '74'] + phpversions = ['52', '53', '54', '55', '56', '70', + '71', '72', '73', '74', '80', '81'] for version in phpversions: sdir = mw.getServerDir() php_path = sdir + '/php/' + version + '/sbin/php-fpm' From 110a59466c318aa22a1add1d926a9953391aed35 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:37:32 +0800 Subject: [PATCH 11/14] Update task.py --- task.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/task.py b/task.py index 4d54a4331..3ec03afbf 100755 --- a/task.py +++ b/task.py @@ -388,9 +388,9 @@ def check502Task(): def check502(): try: - phpversions = ['52', '53', '54', '55', '56', '70', - '71', '72', '73', '74', '80', '81'] - for version in phpversions: + verlist = ['52', '53', '54', '55', '56', '70', + '71', '72', '73', '74', '80', '81'] + for version in verlist: sdir = mw.getServerDir() php_path = sdir + '/php/' + version + '/sbin/php-fpm' if not os.path.exists(php_path): From e47545edf6f971ea967b07d056515c9339e48fbf Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:37:56 +0800 Subject: [PATCH 12/14] Update task.py --- task.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/task.py b/task.py index 3ec03afbf..4130ff396 100755 --- a/task.py +++ b/task.py @@ -390,16 +390,16 @@ def check502(): try: verlist = ['52', '53', '54', '55', '56', '70', '71', '72', '73', '74', '80', '81'] - for version in verlist: + 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)) From c8cadbda2eddab2bfe014c4dc6f7df0c5638cc49 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 16:57:58 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E4=BC=98=E5=8C=96task=EF=BC=8C=E6=AF=8F?= =?UTF-8?q?=E5=A4=A9=E9=87=8D=E5=90=AF=E4=B8=80=E6=AC=A1openresty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task.py | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/task.py b/task.py index 4130ff396..c1dcb1590 100755 --- a/task.py +++ b/task.py @@ -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() @@ -483,8 +481,35 @@ def checkPHPVersion(version): # --------------------------------------PHP监控 end--------------------------------------------- # + +# --------------------------------------OpenResty Auto Restart Start --------------------------------------------- # +# 解决acme.sh续签后,未起效。 +def openrestyAutoRestart(): + try: + while True: + # 检查是否安装 + odir = mw.getServerDir() + '/openresty' + if os.path.exists(odir): + 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 @@ -492,12 +517,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() From 9acf8edd8b35535a8d78a297794fed8a59625796 Mon Sep 17 00:00:00 2001 From: midoks Date: Wed, 22 Jun 2022 17:20:09 +0800 Subject: [PATCH 14/14] Update task.py --- task.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/task.py b/task.py index c1dcb1590..5cee97a14 100755 --- a/task.py +++ b/task.py @@ -489,7 +489,8 @@ def openrestyAutoRestart(): while True: # 检查是否安装 odir = mw.getServerDir() + '/openresty' - if os.path.exists(odir): + if not os.path.exists(odir): + time.sleep(86400) continue # systemd @@ -499,7 +500,7 @@ def openrestyAutoRestart(): execShell('systemctl reload openresty') elif os.path.exists(initd): os.system(initd + ' reload') - time.sleep(86400) + time.sleep(86400) except Exception as e: print(str(e)) time.sleep(86400)