mdserver-web/plugins/php/index.py

1129 lines
35 KiB
Python
Raw Normal View History

2018-11-26 00:57:06 -05:00
# coding:utf-8
import sys
import io
import os
import time
2018-12-18 02:13:33 -05:00
import re
2018-12-18 06:37:46 -05:00
import json
import shutil
2018-12-18 02:13:33 -05:00
2021-05-09 12:15:29 -04:00
# reload(sys)
# sys.setdefaultencoding('utf8')
2018-11-26 00:57:06 -05:00
2024-11-23 16:41:55 -05:00
web_dir = os.getcwd() + "/web"
if os.path.exists(web_dir):
sys.path.append(web_dir)
os.chdir(web_dir)
2018-11-26 00:57:06 -05:00
2024-11-23 16:41:55 -05:00
import core.mw as mw
2021-11-12 04:50:44 -05:00
2018-12-08 04:09:36 -05:00
app_debug = False
2020-07-10 03:57:25 -04:00
if mw.isAppleSystem():
2018-12-08 04:09:36 -05:00
app_debug = True
def getPluginName():
2018-12-09 07:31:39 -05:00
return 'php'
2018-12-08 04:09:36 -05:00
def getPluginDir():
2020-07-10 03:57:25 -04:00
return mw.getPluginDir() + '/' + getPluginName()
2018-12-08 04:09:36 -05:00
def getServerDir():
2020-07-10 03:57:25 -04:00
return mw.getServerDir() + '/' + getPluginName()
2018-12-08 04:09:36 -05:00
2019-03-15 03:23:54 -04:00
def getInitDFile(version):
2023-08-24 06:54:09 -04:00
current_os = mw.getOs()
2023-08-24 06:58:35 -04:00
if current_os == 'darwin':
2018-12-08 04:09:36 -05:00
return '/tmp/' + getPluginName()
2023-08-24 06:54:09 -04:00
if current_os.startswith('freebsd'):
return '/etc/rc.d/' + getPluginName()
2019-07-31 11:45:28 -04:00
return '/etc/init.d/' + getPluginName() + version
2018-12-08 04:09:36 -05:00
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
def getArgs():
2018-12-18 02:13:33 -05:00
args = sys.argv[3:]
2018-12-09 10:30:54 -05:00
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
2023-08-24 06:48:07 -04:00
if t.strip() == '':
tmp = []
else:
t = t.split(':', 1)
tmp[t[0]] = t[1]
2018-12-09 10:30:54 -05:00
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
2019-01-13 10:51:09 -05:00
def checkArgs(data, ck=[]):
for i in range(len(ck)):
if not ck[i] in data:
2020-07-10 03:57:25 -04:00
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
return (True, mw.returnJson(True, 'ok'))
2019-01-13 10:51:09 -05:00
2018-12-09 10:30:54 -05:00
def getConf(version):
2018-12-18 00:43:24 -05:00
path = getServerDir() + '/' + version + '/etc/php.ini'
2018-12-09 10:30:54 -05:00
return path
2024-01-10 01:52:19 -05:00
def getFpmConfFile(version, pool='www'):
2024-01-16 13:44:17 -05:00
args = getArgs()
if 'pool' in args:
pool = args['pool']
2024-01-10 09:23:44 -05:00
return getServerDir() + '/' + version + '/etc/php-fpm.d/'+pool+'.conf'
2022-07-07 22:14:27 -04:00
2024-01-06 15:12:33 -05:00
def getFpmFile(version):
return getServerDir() + '/' + version + '/etc/php-fpm.conf'
2022-07-07 22:14:27 -04:00
2022-07-11 12:01:17 -04:00
def status_progress(version):
2022-06-18 02:53:10 -04:00
# ps -ef|grep 'php/81' |grep -v grep | grep -v python | awk '{print $2}
2026-05-07 06:47:45 -04:00
cmd = "ps -ef|grep 'php/" + version + \
2018-12-10 02:32:31 -05:00
"' |grep -v grep | grep -v python | awk '{print $2}'"
2020-07-10 03:57:25 -04:00
data = mw.execShell(cmd)
2018-11-26 00:57:06 -05:00
if data[0] == '':
return 'stop'
return 'start'
2022-07-11 12:01:17 -04:00
def getPhpSocket(version):
path = getFpmConfFile(version)
content = mw.readFile(path)
2024-07-24 01:16:21 -04:00
rep = r'listen\s*=\s*(.*)'
2022-07-11 12:01:17 -04:00
tmp = re.search(rep, content)
return tmp.groups()[0].strip()
def status(version):
'''
sock文件判断是否启动
'''
sock = getPhpSocket(version)
2026-05-01 07:17:05 -04:00
if sock.find(':')>-1:
2022-07-11 12:01:17 -04:00
return status_progress(version)
if not os.path.exists(sock):
return 'stop'
return 'start'
2018-12-10 03:18:35 -05:00
def contentReplace(content, version):
2020-07-10 03:57:25 -04:00
service_path = mw.getServerDir()
2024-11-24 12:13:47 -05:00
content = content.replace('{$ROOT_PATH}', mw.getFatherDir())
2018-12-10 03:18:35 -05:00
content = content.replace('{$SERVER_PATH}', service_path)
content = content.replace('{$PHP_VERSION}', version)
2020-07-14 20:49:30 -04:00
content = content.replace('{$LOCAL_IP}', mw.getLocalIp())
2022-11-20 21:42:36 -05:00
content = content.replace('{$SSL_CRT}', mw.getSslCrt())
2018-12-18 06:43:41 -05:00
2020-07-10 03:57:25 -04:00
if mw.isAppleSystem():
# user = mw.execShell(
2018-12-18 21:34:18 -05:00
# "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
content = content.replace('{$PHP_USER}', 'nobody')
content = content.replace('{$PHP_GROUP}', 'nobody')
2024-07-24 01:16:21 -04:00
rep = r'listen.owner\s*=\s*(.+)\r?\n'
2018-12-27 06:00:15 -05:00
val = ';listen.owner = nobody\n'
content = re.sub(rep, val, content)
2024-07-24 01:16:21 -04:00
rep = r'listen.group\s*=\s*(.+)\r?\n'
2018-12-27 06:00:15 -05:00
val = ';listen.group = nobody\n'
content = re.sub(rep, val, content)
2024-07-24 01:16:21 -04:00
rep = r'user\s*=\s*(.+)\r?\n'
2018-12-18 21:34:18 -05:00
val = ';user = nobody\n'
content = re.sub(rep, val, content)
2018-12-27 06:11:08 -05:00
rep = r'[^\.]group\s*=\s*(.+)\r?\n'
2018-12-18 21:34:18 -05:00
val = ';group = nobody\n'
content = re.sub(rep, val, content)
2018-12-27 06:00:15 -05:00
2018-12-18 06:43:41 -05:00
else:
content = content.replace('{$PHP_USER}', 'www')
content = content.replace('{$PHP_GROUP}', 'www')
2018-12-10 03:18:35 -05:00
return content
2018-12-18 06:37:46 -05:00
def makeOpenrestyConf():
2020-09-26 07:43:04 -04:00
phpversions = ['00', '52', '53', '54', '55', '56',
2025-10-01 10:46:50 -04:00
'70', '71', '72', '73', '74', '80', '81', '82', '83','84','85']
2022-06-28 12:39:10 -04:00
sdir = mw.getServerDir()
dst_dir = sdir + '/web_conf/php'
if not os.path.exists(dst_dir):
mw.execShell('mkdir -p ' + dst_dir)
2024-01-19 08:21:36 -05:00
dst_dir_conf = sdir + '/web_conf/php/conf'
2022-06-28 12:39:10 -04:00
if not os.path.exists(dst_dir_conf):
mw.execShell('mkdir -p ' + dst_dir_conf)
2024-01-19 08:21:36 -05:00
dst_dir_upstream = sdir + '/web_conf/php/upstream'
if not os.path.exists(dst_dir_upstream):
mw.execShell('mkdir -p ' + dst_dir_upstream)
dst_pathinfo = sdir + '/web_conf/php/pathinfo.conf'
if not os.path.exists(dst_pathinfo):
src_pathinfo = getPluginDir() + '/conf/pathinfo.conf'
shutil.copyfile(src_pathinfo, dst_pathinfo)
2022-06-28 12:39:10 -04:00
info = getPluginDir() + '/info.json'
content = mw.readFile(info)
content = json.loads(content)
versions = content['versions']
tpl = getPluginDir() + '/conf/enable-php.conf'
tpl_content = mw.readFile(tpl)
for x in phpversions:
dfile = sdir + '/web_conf/php/conf/enable-php-' + x + '.conf'
if not os.path.exists(dfile):
if x == '00':
2024-01-19 08:21:36 -05:00
mw.writeFile(dfile, '')
2022-06-28 12:39:10 -04:00
else:
2024-01-19 08:21:36 -05:00
content = contentReplace(tpl_content, x)
mw.writeFile(dfile, content)
upstream_tpl = getPluginDir() + '/conf/enable-php-upstream.conf'
upstream_tpl_content = mw.readFile(upstream_tpl)
for x in phpversions:
dfile = sdir + '/web_conf/php/upstream/enable-php-' + x + '.conf'
if not os.path.exists(dfile):
if x == '00':
mw.writeFile(dfile, '')
else:
content = contentReplace(upstream_tpl_content, x)
mw.writeFile(dfile, content)
vhost_dir = mw.getServerDir() + '/web_conf/nginx/vhost'
write_php_upstream_conf = mw.getServerDir()+'/web_conf/php/upstream/*.conf;'
if not os.path.exists(vhost_dir):
mw.execShell('mkdir -p ' + vhost_dir)
vhost_php_upstream = vhost_dir+'/0.php_upstream.conf'
if not os.path.exists(vhost_php_upstream):
mw.writeFile(vhost_php_upstream,'include '+write_php_upstream_conf)
2018-12-18 06:37:46 -05:00
2019-07-31 11:45:28 -04:00
2020-07-12 06:14:56 -04:00
def phpPrependFile(version):
app_start = getServerDir() + '/app_start.php'
if not os.path.exists(app_start):
tpl = getPluginDir() + '/conf/app_start.php'
content = mw.readFile(tpl)
content = contentReplace(content, version)
mw.writeFile(app_start, content)
2018-12-10 03:18:35 -05:00
def phpFpmReplace(version):
2018-12-18 06:50:57 -05:00
desc_php_fpm = getServerDir() + '/' + version + '/etc/php-fpm.conf'
if not os.path.exists(desc_php_fpm):
tpl_php_fpm = getPluginDir() + '/conf/php-fpm.conf'
2020-07-10 03:57:25 -04:00
content = mw.readFile(tpl_php_fpm)
2018-12-18 06:50:57 -05:00
content = contentReplace(content, version)
2020-07-10 03:57:25 -04:00
mw.writeFile(desc_php_fpm, content)
2020-09-26 07:50:40 -04:00
else:
if version == '52':
2020-09-26 08:01:27 -04:00
tpl_php_fpm = tpl_php_fpm = getPluginDir() + '/conf/php-fpm-52.conf'
content = mw.readFile(tpl_php_fpm)
2020-09-26 07:50:40 -04:00
mw.writeFile(desc_php_fpm, content)
2018-12-10 02:32:31 -05:00
2024-01-16 13:44:17 -05:00
def phpFpmPoolReplace(version, pool = 'www'):
2018-12-10 02:53:06 -05:00
service_php_fpm_dir = getServerDir() + '/' + version + '/etc/php-fpm.d/'
2018-12-18 06:50:57 -05:00
2018-12-10 02:53:06 -05:00
if not os.path.exists(service_php_fpm_dir):
os.mkdir(service_php_fpm_dir)
2018-12-18 21:34:18 -05:00
2024-01-16 13:44:17 -05:00
service_php_fpmwww = service_php_fpm_dir + '/'+pool+'.conf'
2018-12-18 21:34:18 -05:00
if not os.path.exists(service_php_fpmwww):
2024-01-16 13:44:17 -05:00
tpl_php_fpmwww = getPluginDir() + '/conf/'+pool+'.conf'
2020-07-10 03:57:25 -04:00
content = mw.readFile(tpl_php_fpmwww)
2018-12-18 06:50:57 -05:00
content = contentReplace(content, version)
2020-07-10 03:57:25 -04:00
mw.writeFile(service_php_fpmwww, content)
2018-12-10 02:32:31 -05:00
2018-12-18 10:22:08 -05:00
def makePhpIni(version):
2022-07-07 22:14:27 -04:00
dst_ini = getConf(version)
2022-06-18 02:40:06 -04:00
if not os.path.exists(dst_ini):
src_ini = getPluginDir() + '/conf/php' + version[0:1] + '.ini'
2020-09-29 14:48:16 -04:00
# shutil.copyfile(s_ini, d_ini)
2022-06-18 02:40:06 -04:00
content = mw.readFile(src_ini)
2020-09-29 14:48:16 -04:00
if version == '52':
2020-09-29 15:11:10 -04:00
content = content + "auto_prepend_file=/www/server/php/app_start.php"
2022-06-19 02:05:07 -04:00
content = contentReplace(content, version)
2022-06-18 02:40:06 -04:00
mw.writeFile(dst_ini, content)
2018-12-18 10:22:08 -05:00
2018-12-18 06:37:46 -05:00
def initReplace(version):
makeOpenrestyConf()
2018-12-18 10:22:08 -05:00
makePhpIni(version)
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
2018-12-19 10:37:31 -05:00
file_bin = initD_path + '/php' + version
if not os.path.exists(file_bin):
2018-12-18 06:50:57 -05:00
file_tpl = getPluginDir() + '/init.d/php.tpl'
if version == '52':
file_tpl = getPluginDir() + '/init.d/php52.tpl'
2020-07-10 03:57:25 -04:00
content = mw.readFile(file_tpl)
2018-12-18 06:50:57 -05:00
content = contentReplace(content, version)
2018-12-09 10:30:54 -05:00
2020-07-10 03:57:25 -04:00
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
2018-12-10 02:32:31 -05:00
2020-07-12 06:14:56 -04:00
phpPrependFile(version)
2024-01-16 13:44:17 -05:00
phpFpmPoolReplace(version, 'www')
phpFpmPoolReplace(version, 'backup')
2018-12-10 02:32:31 -05:00
phpFpmReplace(version)
2018-12-10 02:53:06 -05:00
2022-06-19 01:17:50 -04:00
session_path = getServerDir() + '/tmp/session'
2019-01-07 10:31:13 -05:00
if not os.path.exists(session_path):
2022-06-19 02:03:04 -04:00
mw.execShell('mkdir -p ' + session_path)
mw.execShell('chown -R www:www ' + session_path)
2020-07-16 04:30:00 -04:00
2022-06-19 01:17:50 -04:00
upload_path = getServerDir() + '/tmp/upload'
2020-07-16 04:30:00 -04:00
if not os.path.exists(upload_path):
2022-06-19 02:03:04 -04:00
mw.execShell('mkdir -p ' + upload_path)
mw.execShell('chown -R www:www ' + upload_path)
2022-06-18 02:40:06 -04:00
# systemd
2022-07-11 01:49:25 -04:00
systemDir = mw.systemdCfgDir()
2022-06-18 02:40:06 -04:00
systemService = systemDir + '/php' + version + '.service'
2022-07-05 22:27:24 -04:00
2022-06-18 02:40:06 -04:00
if os.path.exists(systemDir) and not os.path.exists(systemService):
2023-08-24 06:54:09 -04:00
systemServiceTpl = getPluginDir() + '/init.d/php.service.tpl'
if version == '52':
systemServiceTpl = getPluginDir() + '/init.d/php.service.52.tpl'
2022-06-18 02:40:06 -04:00
service_path = mw.getServerDir()
se_content = mw.readFile(systemServiceTpl)
se_content = se_content.replace('{$VERSION}', version)
se_content = se_content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(systemService, se_content)
mw.execShell('systemctl daemon-reload')
2018-12-09 10:30:54 -05:00
return file_bin
def phpOp(version, method):
2018-12-18 06:37:46 -05:00
file = initReplace(version)
2022-06-18 02:40:06 -04:00
2023-08-24 06:54:09 -04:00
current_os = mw.getOs()
if current_os == "darwin":
data = mw.execShell(file + ' ' + method)
if data[1] == '':
return 'ok'
return data[1]
2022-07-05 21:14:30 -04:00
2023-08-24 06:54:09 -04:00
if current_os.startswith("freebsd"):
data = mw.execShell('service php' + version + ' ' + method)
2022-06-18 02:40:06 -04:00
if data[1] == '':
return 'ok'
2022-07-03 00:11:09 -04:00
return data[1]
2022-06-18 02:40:06 -04:00
2024-01-25 02:11:18 -05:00
if method == 'stop' or method == 'restart':
mw.execShell(file + ' ' + 'stop')
2023-08-24 06:54:09 -04:00
data = mw.execShell('systemctl ' + method + ' php' + version)
2018-12-09 10:30:54 -05:00
if data[1] == '':
2018-11-26 00:57:06 -05:00
return 'ok'
2018-12-18 06:37:46 -05:00
return data[1]
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
def start(version):
2025-02-15 09:41:49 -05:00
cmd = 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/www/server/lib/icu/lib:/usr/lib/x86_64-linux-gnu/:/opt/homebrew/lib'
2024-11-28 15:05:33 -05:00
mw.execShell(cmd)
2018-12-09 10:30:54 -05:00
return phpOp(version, 'start')
def stop(version):
2022-07-03 06:54:19 -04:00
status = phpOp(version, 'stop')
if version == '52':
file = initReplace(version)
data = mw.execShell(file + ' ' + 'stop')
2022-07-03 06:55:52 -04:00
if data[1] == '':
return 'ok'
2022-07-03 06:54:19 -04:00
return status
2018-12-09 10:30:54 -05:00
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
def restart(version):
return phpOp(version, 'restart')
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
def reload(version):
2022-07-05 22:28:15 -04:00
if version == '52':
return phpOp(version, 'restart')
return phpOp(version, 'reload')
2018-11-26 00:57:06 -05:00
2018-12-09 10:30:54 -05:00
2019-03-15 03:23:54 -04:00
def initdStatus(version):
2023-08-24 06:56:19 -04:00
current_os = mw.getOs()
2023-08-24 06:58:16 -04:00
if current_os == 'darwin':
2022-06-18 02:40:06 -04:00
return "Apple Computer does not support"
2023-08-24 06:56:19 -04:00
if current_os.startswith('freebsd'):
2023-08-24 07:05:11 -04:00
initd_bin = getInitDFile(version)
2023-08-24 06:56:19 -04:00
if os.path.exists(initd_bin):
return 'ok'
2022-06-18 09:46:52 -04:00
shell_cmd = 'systemctl status php' + version + ' | grep loaded | grep "enabled;"'
2022-06-18 02:40:06 -04:00
data = mw.execShell(shell_cmd)
if data[0] == '':
return 'fail'
return 'ok'
2019-03-15 03:23:54 -04:00
def initdInstall(version):
2023-08-24 06:56:19 -04:00
current_os = mw.getOs()
2023-08-24 06:58:16 -04:00
if current_os == 'darwin':
2022-06-18 02:40:06 -04:00
return "Apple Computer does not support"
2023-08-24 06:56:19 -04:00
if current_os.startswith('freebsd'):
import shutil
2023-08-24 08:47:49 -04:00
source_bin = initReplace(version)
2023-08-24 07:05:11 -04:00
initd_bin = getInitDFile(version)
2023-08-24 06:56:19 -04:00
shutil.copyfile(source_bin, initd_bin)
mw.execShell('chmod +x ' + initd_bin)
return 'ok'
2022-06-18 12:08:24 -04:00
mw.execShell('systemctl enable php' + version)
2019-03-15 03:23:54 -04:00
return 'ok'
def initdUinstall(version):
2023-08-24 06:56:19 -04:00
current_os = mw.getOs()
2023-08-24 06:58:59 -04:00
if current_os == 'darwin':
2022-06-18 02:40:06 -04:00
return "Apple Computer does not support"
2019-07-31 11:45:28 -04:00
2023-08-24 06:56:19 -04:00
if current_os.startswith('freebsd'):
2023-08-24 07:05:11 -04:00
initd_bin = getInitDFile(version)
2023-08-24 06:56:19 -04:00
os.remove(initd_bin)
return 'ok'
2022-06-18 12:08:24 -04:00
mw.execShell('systemctl disable php' + version)
2019-03-15 03:23:54 -04:00
return 'ok'
2018-12-18 02:23:48 -05:00
def fpmLog(version):
return getServerDir() + '/' + version + '/var/log/php-fpm.log'
def fpmSlowLog(version):
2018-12-19 02:50:07 -05:00
return getServerDir() + '/' + version + '/var/log/www-slow.log'
2018-12-18 02:23:48 -05:00
2018-12-18 02:13:33 -05:00
def getPhpConf(version):
gets = [
{'name': 'short_open_tag', 'type': 1, 'ps': '短标签支持'},
{'name': 'asp_tags', 'type': 1, 'ps': 'ASP标签支持'},
{'name': 'max_execution_time', 'type': 2, 'ps': '最大脚本运行时间'},
{'name': 'max_input_time', 'type': 2, 'ps': '最大输入时间'},
2022-07-05 12:36:33 -04:00
{'name': 'max_input_vars', 'type': 2, 'ps': '最大输入数量'},
2018-12-18 02:13:33 -05:00
{'name': 'memory_limit', 'type': 2, 'ps': '脚本内存限制'},
{'name': 'post_max_size', 'type': 2, 'ps': 'POST数据最大尺寸'},
{'name': 'file_uploads', 'type': 1, 'ps': '是否允许上传文件'},
{'name': 'upload_max_filesize', 'type': 2, 'ps': '允许上传文件的最大尺寸'},
{'name': 'max_file_uploads', 'type': 2, 'ps': '允许同时上传文件的最大数量'},
{'name': 'default_socket_timeout', 'type': 2, 'ps': 'Socket超时时间'},
{'name': 'error_reporting', 'type': 3, 'ps': '错误级别'},
{'name': 'display_errors', 'type': 1, 'ps': '是否输出详细错误信息'},
{'name': 'cgi.fix_pathinfo', 'type': 0, 'ps': '是否开启pathinfo'},
{'name': 'date.timezone', 'type': 3, 'ps': '时区'}
2018-11-26 00:57:06 -05:00
]
2022-07-07 22:14:27 -04:00
phpini = mw.readFile(getConf(version))
2018-12-18 02:13:33 -05:00
result = []
for g in gets:
2024-07-24 01:16:21 -04:00
rep = g['name'] + r'\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)'
2018-12-18 02:13:33 -05:00
tmp = re.search(rep, phpini)
if not tmp:
2018-11-26 00:57:06 -05:00
continue
2018-12-18 02:13:33 -05:00
g['value'] = tmp.groups()[0]
result.append(g)
2020-07-10 03:57:25 -04:00
return mw.getJson(result)
2018-11-26 00:57:06 -05:00
2018-12-18 02:13:33 -05:00
def submitPhpConf(version):
gets = ['display_errors', 'cgi.fix_pathinfo', 'date.timezone', 'short_open_tag',
2022-07-05 12:36:33 -04:00
'asp_tags', 'max_execution_time', 'max_input_time', 'max_input_vars', 'memory_limit',
2018-12-18 02:13:33 -05:00
'post_max_size', 'file_uploads', 'upload_max_filesize', 'max_file_uploads',
'default_socket_timeout', 'error_reporting']
args = getArgs()
filename = getServerDir() + '/' + version + '/etc/php.ini'
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(filename)
2018-12-18 02:13:33 -05:00
for g in gets:
if g in args:
2024-07-24 01:16:21 -04:00
rep = g + r'\s*=\s*(.+)\r?\n'
2018-12-18 02:13:33 -05:00
val = g + ' = ' + args[g] + '\n'
phpini = re.sub(rep, val, phpini)
2020-07-10 03:57:25 -04:00
mw.writeFile(filename, phpini)
2022-07-05 12:36:33 -04:00
# mw.execShell(getServerDir() + '/init.d/php' + version + ' reload')
reload(version)
2020-07-10 03:57:25 -04:00
return mw.returnJson(True, '设置成功')
2018-12-18 02:13:33 -05:00
2018-12-18 05:09:54 -05:00
def getLimitConf(version):
2022-07-07 22:14:27 -04:00
fileini = getConf(version)
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(fileini)
2022-07-07 22:14:27 -04:00
filefpm = getFpmConfFile(version)
2020-07-10 03:57:25 -04:00
phpfpm = mw.readFile(filefpm)
2018-12-18 05:09:54 -05:00
# print fileini, filefpm
data = {}
try:
2024-07-24 01:16:21 -04:00
rep = r"upload_max_filesize\s*=\s*([0-9]+)M"
2018-12-18 05:09:54 -05:00
tmp = re.search(rep, phpini).groups()
data['max'] = tmp[0]
except:
data['max'] = '50'
try:
2024-07-24 01:16:21 -04:00
rep = r"request_terminate_timeout\s*=\s*([0-9]+)\n"
2018-12-18 05:09:54 -05:00
tmp = re.search(rep, phpfpm).groups()
data['maxTime'] = tmp[0]
except:
data['maxTime'] = 0
try:
rep = r"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"
tmp = re.search(rep, phpini).groups()
if tmp[0] == '1':
data['pathinfo'] = True
else:
data['pathinfo'] = False
except:
data['pathinfo'] = False
2020-07-10 03:57:25 -04:00
return mw.getJson(data)
2018-12-18 05:09:54 -05:00
def setMaxTime(version):
args = getArgs()
2019-01-13 10:51:09 -05:00
data = checkArgs(args, ['time'])
if not data[0]:
return data[1]
2018-12-18 05:09:54 -05:00
time = args['time']
if int(time) < 30 or int(time) > 86400:
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '请填写30-86400间的值!')
2018-12-18 05:09:54 -05:00
2022-07-07 22:14:27 -04:00
filefpm = getFpmConfFile(version)
2020-07-10 03:57:25 -04:00
conf = mw.readFile(filefpm)
2024-07-24 01:16:21 -04:00
rep = r"request_terminate_timeout\s*=\s*([0-9]+)\n"
2018-12-18 05:09:54 -05:00
conf = re.sub(rep, "request_terminate_timeout = " + time + "\n", conf)
2020-07-10 03:57:25 -04:00
mw.writeFile(filefpm, conf)
2018-12-18 05:09:54 -05:00
fileini = getServerDir() + "/" + version + "/etc/php.ini"
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(fileini)
2024-07-24 01:16:21 -04:00
rep = r"max_execution_time\s*=\s*([0-9]+)\r?\n"
2018-12-18 05:09:54 -05:00
phpini = re.sub(rep, "max_execution_time = " + time + "\n", phpini)
2024-07-24 01:16:21 -04:00
rep = r"max_input_time\s*=\s*([0-9]+)\r?\n"
2018-12-18 05:09:54 -05:00
phpini = re.sub(rep, "max_input_time = " + time + "\n", phpini)
2020-07-10 03:57:25 -04:00
mw.writeFile(fileini, phpini)
return mw.returnJson(True, '设置成功!')
2018-12-18 05:09:54 -05:00
def setMaxSize(version):
args = getArgs()
2022-07-03 00:16:43 -04:00
data = checkArgs(args, ['max'])
if not data[0]:
return data[1]
maxVal = args['max']
if int(maxVal) < 2:
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '上传大小限制不能小于2MB!')
2018-12-18 05:09:54 -05:00
2022-07-07 22:14:27 -04:00
path = getConf(version)
2020-07-10 03:57:25 -04:00
conf = mw.readFile(path)
2024-07-24 01:16:21 -04:00
rep = r"\nupload_max_filesize\s*=\s*[0-9]+M"
2022-07-03 00:16:43 -04:00
conf = re.sub(rep, u'\nupload_max_filesize = ' + maxVal + 'M', conf)
2024-07-24 01:16:21 -04:00
rep = r"\npost_max_size\s*=\s*[0-9]+M"
2022-07-03 00:16:43 -04:00
conf = re.sub(rep, u'\npost_max_size = ' + maxVal + 'M', conf)
2020-07-10 03:57:25 -04:00
mw.writeFile(path, conf)
2018-12-18 05:09:54 -05:00
2022-07-03 00:16:43 -04:00
msg = mw.getInfo('设置PHP-{1}最大上传大小为[{2}MB]!', (version, maxVal,))
2020-07-10 03:57:25 -04:00
mw.writeLog('插件管理[PHP]', msg)
return mw.returnJson(True, '设置成功!')
2018-12-18 05:09:54 -05:00
2024-01-16 13:44:17 -05:00
def getFpmConfig(version, pool = 'www'):
args = getArgs()
pool = 'www'
if 'pool' in args:
pool = args['pool']
2018-12-19 00:54:19 -05:00
2024-01-16 13:44:17 -05:00
filefpm = getServerDir() + '/' + version + '/etc/php-fpm.d/'+pool+'.conf'
2020-07-10 03:57:25 -04:00
conf = mw.readFile(filefpm)
2018-12-19 00:54:19 -05:00
data = {}
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.max_children\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
tmp = re.search(rep, conf).groups()
data['max_children'] = tmp[0]
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.start_servers\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
tmp = re.search(rep, conf).groups()
data['start_servers'] = tmp[0]
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
tmp = re.search(rep, conf).groups()
data['min_spare_servers'] = tmp[0]
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
tmp = re.search(rep, conf).groups()
data['max_spare_servers'] = tmp[0]
2024-07-24 01:16:21 -04:00
rep = r"\s*pm\s*=\s*(\w+)\s*"
2018-12-19 00:54:19 -05:00
tmp = re.search(rep, conf).groups()
data['pm'] = tmp[0]
2020-07-10 03:57:25 -04:00
return mw.getJson(data)
2018-12-19 00:54:19 -05:00
def setFpmConfig(version):
args = getArgs()
# if not 'max' in args:
# return 'missing time args!'
version = args['version']
max_children = args['max_children']
start_servers = args['start_servers']
min_spare_servers = args['min_spare_servers']
max_spare_servers = args['max_spare_servers']
pm = args['pm']
2024-01-16 13:44:17 -05:00
pool = args['pool']
2018-12-19 00:54:19 -05:00
2024-01-16 13:44:17 -05:00
file = getServerDir() + '/' + version + '/etc/php-fpm.d/'+pool+'.conf'
2020-07-10 03:57:25 -04:00
conf = mw.readFile(file)
2018-12-19 00:54:19 -05:00
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.max_children\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
conf = re.sub(rep, "\npm.max_children = " + max_children, conf)
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.start_servers\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
conf = re.sub(rep, "\npm.start_servers = " + start_servers, conf)
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
conf = re.sub(rep, "\npm.min_spare_servers = " +
min_spare_servers, conf)
2024-07-24 01:16:21 -04:00
rep = r"\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*"
2018-12-19 00:54:19 -05:00
conf = re.sub(rep, "\npm.max_spare_servers = " +
max_spare_servers + "\n", conf)
2024-07-24 01:16:21 -04:00
rep = r"\s*pm\s*=\s*(\w+)\s*"
2018-12-19 00:54:19 -05:00
conf = re.sub(rep, "\npm = " + pm + "\n", conf)
2020-07-10 03:57:25 -04:00
mw.writeFile(file, conf)
2018-12-19 03:50:15 -05:00
reload(version)
2020-07-10 03:57:25 -04:00
msg = mw.getInfo('设置PHP-{1}并发设置,max_children={2},start_servers={3},min_spare_servers={4},max_spare_servers={5}', (version, max_children,
start_servers, min_spare_servers, max_spare_servers,))
mw.writeLog('插件管理[PHP]', msg)
return mw.returnJson(True, '设置成功!')
2018-12-19 00:54:19 -05:00
# def checkFpmStatusFile(version):
# if not mw.isInstalledWeb():
# return False
2022-06-22 15:14:35 -04:00
# dfile = getServerDir() + '/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
# if not os.path.exists(dfile):
# tpl = getPluginDir() + '/conf/phpfpm_status.conf'
# content = mw.readFile(tpl)
# content = contentReplace(content, version)
# mw.writeFile(dfile, content)
# mw.restartWeb()
# return True
2024-01-16 13:44:17 -05:00
def getFpmAddress(version, pool='www'):
fpm_address = '/tmp/php-cgi-{}.sock'.format(version)
2024-01-16 13:44:17 -05:00
if pool != 'www':
fpm_address = '/tmp/php-cgi-{}.{}.sock'.format(version,pool)
php_fpm_file = getFpmConfFile(version)
try:
content = readFile(php_fpm_file)
tmp = re.findall(r"listen\s*=\s*(.+)", content)
if not tmp:
return fpm_address
if tmp[0].find('sock') != -1:
return fpm_address
if tmp[0].find(':') != -1:
listen_tmp = tmp[0].split(':')
if bind:
fpm_address = (listen_tmp[0], int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(listen_tmp[1]))
else:
fpm_address = ('127.0.0.1', int(tmp[0]))
return fpm_address
except:
return fpm_address
2018-12-19 02:41:00 -05:00
2018-12-19 02:21:31 -05:00
def getFpmStatus(version):
2022-07-04 21:56:36 -04:00
if version == '52':
return mw.returnJson(False, 'PHP[' + version + ']不支持!!!')
2022-06-22 14:49:49 -04:00
2022-06-28 06:24:59 -04:00
stat = status(version)
if stat == 'stop':
return mw.returnJson(False, 'PHP[' + version + ']未启动!!!')
2024-01-16 13:44:17 -05:00
args = getArgs()
pool = 'www'
if 'pool' in args:
pool = args['pool']
sock_file = getFpmAddress(version, pool)
uri = '/phpfpm_status_' + version + '?json'
if pool != 'www':
uri = '/phpfpm_status_' + version + '_'+pool+'?json'
2022-06-22 14:49:49 -04:00
try:
2024-01-16 13:44:17 -05:00
sock_data = mw.requestFcgiPHP(sock_file, uri)
2022-06-22 15:20:45 -04:00
except Exception as e:
return mw.returnJson(False, str(e))
2022-06-22 14:49:49 -04:00
2024-01-16 13:44:17 -05:00
result = str(sock_data, encoding='utf-8')
data = json.loads(result)
fTime = time.localtime(int(data['start time']))
data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
2022-06-28 06:24:59 -04:00
return mw.returnJson(True, "OK", data)
2018-12-19 02:21:31 -05:00
2018-12-19 03:50:15 -05:00
2022-10-10 07:54:23 -04:00
def getSessionConf(version):
filename = getConf(version)
if not os.path.exists(filename):
return mw.returnJson(False, '指定PHP版本不存在!')
phpini = mw.readFile(filename)
rep = r'session.save_handler\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)'
save_handler = re.search(rep, phpini)
if save_handler:
save_handler = save_handler.group(1)
else:
save_handler = "files"
reppath = r'\nsession.save_path\s*=\s*"tcp\:\/\/([\d\.]+):(\d+).*\r?\n'
passrep = r'\nsession.save_path\s*=\s*"tcp://[\w\.\?\:]+=(.*)"\r?\n'
memcached = r'\nsession.save_path\s*=\s*"([\d\.]+):(\d+)"'
save_path = re.search(reppath, phpini)
if not save_path:
save_path = re.search(memcached, phpini)
passwd = re.search(passrep, phpini)
port = ""
if passwd:
passwd = passwd.group(1)
else:
passwd = ""
if save_path:
port = save_path.group(2)
save_path = save_path.group(1)
else:
save_path = ""
data = {"save_handler": save_handler, "save_path": save_path,
"passwd": passwd, "port": port}
return mw.returnJson(True, 'ok', data)
def setSessionConf(version):
args = getArgs()
ip = args['ip']
port = args['port']
passwd = args['passwd']
save_handler = args['save_handler']
2022-10-24 08:18:34 -04:00
if save_handler != "files":
2022-10-10 07:54:23 -04:00
iprep = r"(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})\.(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})\.(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})\.(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})"
if not re.search(iprep, ip):
return mw.returnJson(False, '请输入正确的IP地址')
try:
port = int(port)
if port >= 65535 or port < 1:
return mw.returnJson(False, '请输入正确的端口号')
except:
return mw.returnJson(False, '请输入正确的端口号')
prep = r"[\~\`\/\=]"
if re.search(prep, passwd):
return mw.returnJson(False, '请不要输入以下特殊字符 " ~ ` / = "')
filename = getConf(version)
if not os.path.exists(filename):
return mw.returnJson(False, '指定PHP版本不存在!')
phpini = mw.readFile(filename)
session_tmp = getServerDir() + "/tmp/session"
rep = r'session.save_handler\s*=\s*(.+)\r?\n'
val = r'session.save_handler = ' + save_handler + '\n'
phpini = re.sub(rep, val, phpini)
if save_handler == "memcached":
if not re.search("memcached.so", phpini):
return mw.returnJson(False, '请先安装%s扩展' % save_handler)
rep = r'\nsession.save_path\s*=\s*(.+)\r?\n'
val = r'\nsession.save_path = "%s:%s" \n' % (ip, port)
if re.search(rep, phpini):
phpini = re.sub(rep, val, phpini)
else:
phpini = re.sub('\n;session.save_path = "' + session_tmp + '"',
'\n;session.save_path = "' + session_tmp + '"' + val, phpini)
if save_handler == "memcache":
if not re.search("memcache.so", phpini):
return mw.returnJson(False, '请先安装%s扩展' % save_handler)
rep = r'\nsession.save_path\s*=\s*(.+)\r?\n'
val = r'\nsession.save_path = "%s:%s" \n' % (ip, port)
if re.search(rep, phpini):
phpini = re.sub(rep, val, phpini)
else:
phpini = re.sub('\n;session.save_path = "' + session_tmp + '"',
'\n;session.save_path = "' + session_tmp + '"' + val, phpini)
if save_handler == "redis":
if not re.search("redis.so", phpini):
return mw.returnJson(False, '请先安装%s扩展' % save_handler)
if passwd:
passwd = "?auth=" + passwd
else:
passwd = ""
rep = r'\nsession.save_path\s*=\s*(.+)\r?\n'
val = r'\nsession.save_path = "tcp://%s:%s%s"\n' % (ip, port, passwd)
res = re.search(rep, phpini)
if res:
phpini = re.sub(rep, val, phpini)
else:
phpini = re.sub('\n;session.save_path = "' + session_tmp + '"',
'\n;session.save_path = "' + session_tmp + '"' + val, phpini)
2022-10-24 08:06:38 -04:00
if save_handler == "files":
2022-10-10 07:54:23 -04:00
rep = r'\nsession.save_path\s*=\s*(.+)\r?\n'
val = r'\nsession.save_path = "' + session_tmp + '"\n'
if re.search(rep, phpini):
phpini = re.sub(rep, val, phpini)
else:
phpini = re.sub('\n;session.save_path = "' + session_tmp + '"',
'\n;session.save_path = "' + session_tmp + '"' + val, phpini)
mw.writeFile(filename, phpini)
reload(version)
return mw.returnJson(True, '设置成功!')
def getSessionCount_Origin(version):
session_tmp = getServerDir() + "/tmp/session"
d = [session_tmp]
count = 0
for i in d:
if not os.path.exists(i):
mw.execShell('mkdir -p %s' % i)
list = os.listdir(i)
for l in list:
if os.path.isdir(i + "/" + l):
l1 = os.listdir(i + "/" + l)
for ll in l1:
if "sess_" in ll:
count += 1
continue
if "sess_" in l:
count += 1
s = "find /tmp -mtime +1 |grep 'sess_' | wc -l"
old_file = int(mw.execShell(s)[0].split("\n")[0])
s = "find " + session_tmp + " -mtime +1 |grep 'sess_'|wc -l"
old_file += int(mw.execShell(s)[0].split("\n")[0])
return {"total": count, "oldfile": old_file}
def getSessionCount(version):
data = getSessionCount_Origin(version)
return mw.returnJson(True, 'ok!', data)
def cleanSessionOld(version):
s = "find /tmp -mtime +1 |grep 'sess_'|xargs rm -f"
mw.execShell(s)
session_tmp = getServerDir() + "/tmp/session"
s = "find " + session_tmp + " -mtime +1 |grep 'sess_' |xargs rm -f"
mw.execShell(s)
old_file_conf = getSessionCount_Origin(version)["oldfile"]
if old_file_conf == 0:
return mw.returnJson(True, '清理成功')
else:
return mw.returnJson(True, '清理失败')
2018-12-19 03:50:15 -05:00
def getDisableFunc(version):
2022-07-07 22:14:27 -04:00
filename = getConf(version)
2018-12-19 03:50:15 -05:00
if not os.path.exists(filename):
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '指定PHP版本不存在!')
2018-12-19 03:50:15 -05:00
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(filename)
2018-12-19 03:50:15 -05:00
data = {}
2024-07-24 01:16:21 -04:00
rep = r"disable_functions\s*=\s{0,1}(.*)\n"
2018-12-19 03:50:15 -05:00
tmp = re.search(rep, phpini).groups()
data['disable_functions'] = tmp[0]
2020-07-10 03:57:25 -04:00
return mw.getJson(data)
2018-12-19 03:50:15 -05:00
def setDisableFunc(version):
2022-07-07 22:14:27 -04:00
filename = getConf(version)
2018-12-19 03:50:15 -05:00
if not os.path.exists(filename):
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '指定PHP版本不存在!')
2018-12-19 03:50:15 -05:00
args = getArgs()
disable_functions = args['disable_functions']
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(filename)
2024-07-24 01:16:21 -04:00
rep = r"disable_functions\s*=\s*.*\n"
2019-07-31 11:45:28 -04:00
phpini = re.sub(rep, 'disable_functions = ' +
disable_functions + "\n", phpini)
2019-03-19 04:06:20 -04:00
2020-07-10 03:57:25 -04:00
msg = mw.getInfo('修改PHP-{1}的禁用函数为[{2}]', (version, disable_functions,))
mw.writeLog('插件管理[PHP]', msg)
mw.writeFile(filename, phpini)
2018-12-19 03:50:15 -05:00
reload(version)
2020-07-10 03:57:25 -04:00
return mw.returnJson(True, '设置成功!')
2018-12-19 03:50:15 -05:00
def getPhpinfo(version):
stat = status(version)
if stat == 'stop':
2022-07-08 07:28:28 -04:00
return 'PHP[' + version + ']未启动,不可访问!!!'
2018-12-19 04:17:07 -05:00
sock_file = getFpmAddress(version)
2024-11-24 12:13:47 -05:00
root_dir = mw.getFatherDir() + '/phpinfo'
2022-06-30 11:20:41 -04:00
mw.execShell("rm -rf " + root_dir)
mw.execShell("mkdir -p " + root_dir)
mw.writeFile(root_dir + '/phpinfo.php', '<?php phpinfo(); ?>')
sock_data = mw.requestFcgiPHP(sock_file, '/phpinfo.php', root_dir)
2022-07-08 07:40:49 -04:00
os.system("rm -rf " + root_dir)
phpinfo = str(sock_data, encoding='utf-8')
2019-03-04 10:22:29 -05:00
return phpinfo
2018-12-19 04:17:07 -05:00
def get_php_info(args):
return getPhpinfo(args['version'])
2023-08-24 08:45:25 -04:00
def libConfCommon(version):
2022-07-07 22:14:27 -04:00
fname = getConf(version)
2019-01-12 08:29:07 -05:00
if not os.path.exists(fname):
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '指定PHP版本不存在!')
2018-12-19 03:50:15 -05:00
2020-07-10 03:57:25 -04:00
phpini = mw.readFile(fname)
2019-01-12 08:29:07 -05:00
libpath = getPluginDir() + '/versions/phplib.conf'
2020-07-10 03:57:25 -04:00
phplib = json.loads(mw.readFile(libpath))
2019-01-12 08:29:07 -05:00
libs = []
2024-12-10 05:05:43 -05:00
tasks = mw.M('tasks').where("status!=?", ('1',)).field('status,name').select()
2019-01-12 08:29:07 -05:00
for lib in phplib:
lib['task'] = '1'
for task in tasks:
2020-07-10 03:57:25 -04:00
tmp = mw.getStrBetween('[', ']', task['name'])
2019-01-12 08:29:07 -05:00
if not tmp:
continue
tmp1 = tmp.split('-')
if tmp1[0].lower() == lib['name'].lower():
lib['task'] = task['status']
lib['phpversions'] = []
lib['phpversions'].append(tmp1[1])
if phpini.find(lib['check']) == -1:
lib['status'] = False
else:
lib['status'] = True
libs.append(lib)
2023-08-24 08:45:25 -04:00
return libs
def get_lib_conf(data):
libs = libConfCommon(data['version'])
# print(libs)
return mw.returnData(True, 'OK!', libs)
def getLibConf(version):
libs = libConfCommon(version)
2020-07-10 03:57:25 -04:00
return mw.returnJson(True, 'OK!', libs)
2018-12-19 03:50:15 -05:00
2019-01-12 10:49:41 -05:00
def installLib(version):
2019-01-13 10:51:09 -05:00
args = getArgs()
2019-01-14 02:28:27 -05:00
data = checkArgs(args, ['name'])
2019-01-13 10:51:09 -05:00
if not data[0]:
return data[1]
name = args['name']
2024-11-25 14:49:36 -05:00
cmd = "cd " + getPluginDir() + "/versions && /bin/bash common.sh " + version + ' install ' + name
install_name = '安装[' + name + '-' + version + ']'
import thisdb
thisdb.addTask(name=install_name,cmd=cmd)
2024-11-25 14:50:08 -05:00
2022-06-30 01:23:08 -04:00
mw.triggerTask()
2020-07-10 03:57:25 -04:00
return mw.returnJson(True, '已将下载任务添加到队列!')
2019-01-12 10:49:41 -05:00
2019-01-14 00:13:24 -05:00
def uninstallLib(version):
2019-01-14 02:28:27 -05:00
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
name = args['name']
2024-11-25 14:50:08 -05:00
execstr = "cd " + getPluginDir() + "/versions && /bin/bash common.sh " + version + ' uninstall ' + name
2019-01-14 02:28:27 -05:00
2020-07-10 03:57:25 -04:00
data = mw.execShell(execstr)
2022-07-05 00:43:46 -04:00
# data[0] == '' and
if data[1] == '':
2020-07-10 03:57:25 -04:00
return mw.returnJson(True, '已经卸载成功!')
2019-03-07 05:59:15 -05:00
else:
2020-07-10 03:57:25 -04:00
return mw.returnJson(False, '卸载信息![通道0]:' + data[0] + "[通道0]:" + data[1])
2019-03-07 05:59:15 -05:00
2019-01-14 00:13:24 -05:00
2020-07-12 06:14:56 -04:00
def getConfAppStart():
pstart = mw.getServerDir() + '/php/app_start.php'
return pstart
2024-01-21 03:01:10 -05:00
def opcacheBlacklistFile():
op_bl = mw.getServerDir() + '/php/opcache-blacklist.txt'
return op_bl
2022-07-11 10:19:00 -04:00
def installPreInspection(version):
2022-07-11 10:31:53 -04:00
# 仅对PHP52检查
if version != '52':
return 'ok'
sys = mw.execShell(
"cat /etc/*-release | grep PRETTY_NAME |awk -F = '{print $2}' | awk -F '\"' '{print $2}'| awk '{print $1}'")
if sys[1] != '':
return '不支持改系统'
sys_id = mw.execShell(
"cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F '\"' '{print $2}'")
sysName = sys[0].strip().lower()
sysId = sys_id[0].strip()
if sysName == 'ubuntu':
2022-07-11 10:36:51 -04:00
return 'ubuntu已经安装不了'
2022-07-11 10:31:53 -04:00
2022-07-16 03:42:57 -04:00
if sysName == 'debian' and int(sysId) > 10:
2022-07-11 10:31:53 -04:00
return 'debian10可以安装'
2022-07-13 06:25:37 -04:00
2022-07-16 03:42:57 -04:00
if sysName == 'centos' and int(sysId) > 8:
2022-07-16 03:07:13 -04:00
return 'centos[{}]不可以安装'.format(sysId)
2022-07-13 06:48:27 -04:00
if sysName == 'fedora':
sys_id = mw.execShell(
"cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}'")
sysId = sys_id[0].strip()
if int(sysId) > 31:
return 'fedora[{}]不可安装'.format(sysId)
2022-07-11 10:31:53 -04:00
return 'ok'
2022-07-11 10:19:00 -04:00
2022-10-10 07:54:23 -04:00
2018-11-26 00:57:06 -05:00
if __name__ == "__main__":
2018-12-18 02:13:33 -05:00
if len(sys.argv) < 3:
2021-05-09 12:12:36 -04:00
print('missing parameters')
2018-12-18 02:13:33 -05:00
exit(0)
2018-11-26 00:57:06 -05:00
func = sys.argv[1]
2018-12-09 07:31:39 -05:00
version = sys.argv[2]
if func == 'status':
2021-05-08 13:11:18 -04:00
print(status(version))
2018-11-26 00:57:06 -05:00
elif func == 'start':
2021-05-08 13:11:18 -04:00
print(start(version))
2018-11-26 00:57:06 -05:00
elif func == 'stop':
2021-05-08 13:11:18 -04:00
print(stop(version))
2018-11-26 00:57:06 -05:00
elif func == 'restart':
2021-05-08 13:11:18 -04:00
print(restart(version))
2018-11-26 00:57:06 -05:00
elif func == 'reload':
2021-05-08 13:11:18 -04:00
print(reload(version))
2022-07-11 10:19:00 -04:00
elif func == 'install_pre_inspection':
print(installPreInspection(version))
2019-03-15 03:23:54 -04:00
elif func == 'initd_status':
2021-05-08 13:11:18 -04:00
print(initdStatus(version))
2019-03-15 03:23:54 -04:00
elif func == 'initd_install':
2021-05-08 13:11:18 -04:00
print(initdInstall(version))
2019-03-15 03:23:54 -04:00
elif func == 'initd_uninstall':
2021-05-08 13:11:18 -04:00
print(initdUinstall(version))
2018-12-18 02:23:48 -05:00
elif func == 'fpm_log':
2021-05-08 13:11:18 -04:00
print(fpmLog(version))
2018-12-18 02:23:48 -05:00
elif func == 'fpm_slow_log':
2021-05-08 13:11:18 -04:00
print(fpmSlowLog(version))
2018-12-09 07:31:39 -05:00
elif func == 'conf':
2021-05-08 13:11:18 -04:00
print(getConf(version))
2020-07-12 06:14:56 -04:00
elif func == 'app_start':
2021-05-08 13:11:18 -04:00
print(getConfAppStart())
2024-01-21 03:01:10 -05:00
elif func == 'opcache_blacklist_file':
print(opcacheBlacklistFile())
2018-12-18 02:13:33 -05:00
elif func == 'get_php_conf':
2021-05-08 13:11:18 -04:00
print(getPhpConf(version))
2022-07-07 03:49:44 -04:00
elif func == 'get_fpm_conf_file':
print(getFpmConfFile(version))
2024-01-06 15:12:33 -05:00
elif func == 'get_fpm_file':
print(getFpmFile(version))
2018-12-18 02:13:33 -05:00
elif func == 'submit_php_conf':
2021-05-08 13:11:18 -04:00
print(submitPhpConf(version))
2018-12-18 05:09:54 -05:00
elif func == 'get_limit_conf':
2021-05-08 13:11:18 -04:00
print(getLimitConf(version))
2018-12-18 05:09:54 -05:00
elif func == 'set_max_time':
2021-05-08 13:11:18 -04:00
print(setMaxTime(version))
2018-12-18 05:09:54 -05:00
elif func == 'set_max_size':
2021-05-08 13:11:18 -04:00
print(setMaxSize(version))
2018-12-19 00:54:19 -05:00
elif func == 'get_fpm_conf':
2021-05-08 13:11:18 -04:00
print(getFpmConfig(version))
2018-12-19 00:54:19 -05:00
elif func == 'set_fpm_conf':
2021-05-08 13:11:18 -04:00
print(setFpmConfig(version))
2018-12-19 02:21:31 -05:00
elif func == 'get_fpm_status':
2021-05-08 13:11:18 -04:00
print(getFpmStatus(version))
2022-10-10 07:54:23 -04:00
elif func == 'get_session_conf':
print(getSessionConf(version))
elif func == 'set_session_conf':
print(setSessionConf(version))
elif func == 'get_session_count':
print(getSessionCount(version))
elif func == 'clean_session_old':
print(cleanSessionOld(version))
2018-12-19 03:50:15 -05:00
elif func == 'get_disable_func':
2021-05-08 13:11:18 -04:00
print(getDisableFunc(version))
2018-12-19 03:50:15 -05:00
elif func == 'set_disable_func':
2021-05-08 13:11:18 -04:00
print(setDisableFunc(version))
2018-12-19 04:17:07 -05:00
elif func == 'get_phpinfo':
2021-05-08 13:11:18 -04:00
print(getPhpinfo(version))
2018-12-19 03:50:15 -05:00
elif func == 'get_lib_conf':
2021-05-08 13:11:18 -04:00
print(getLibConf(version))
2019-01-12 10:49:41 -05:00
elif func == 'install_lib':
2021-05-08 13:11:18 -04:00
print(installLib(version))
2019-01-14 00:13:24 -05:00
elif func == 'uninstall_lib':
2021-05-08 13:11:18 -04:00
print(uninstallLib(version))
2018-12-09 07:31:39 -05:00
else:
2021-05-08 13:11:18 -04:00
print("fail")