Skip to content

Commit c56c1c7

Browse files
committed
Update __init__.py
1 parent 580235b commit c56c1c7

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

web/admin/site/__init__.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,42 @@ def get_cli_php_version():
8383
if link_re.find(v['version']) != -1:
8484
return mw.returnData({"select": v, "versions": php_versions})
8585

86-
return mw.getJson({"select": php_versions[0],"versions": php_versions})
86+
return mw.getJson({"select": php_versions[0],"versions": php_versions})
87+
88+
@blueprint.route('/get_cli_php_version', endpoint='get_cli_php_version',methods=['POST'])
89+
@panel_login_required
90+
def get_cli_php_version():
91+
if mw.isAppleSystem():
92+
return mw.returnData(False, "开发机不可设置!")
93+
94+
version = request.form.get('version', '')
95+
96+
php_bin = '/usr/bin/php'
97+
php_bin_src = "/www/server/php/%s/bin/php" % version
98+
php_ize = '/usr/bin/phpize'
99+
php_ize_src = "/www/server/php/%s/bin/phpize" % version
100+
php_fpm = '/usr/bin/php-fpm'
101+
php_fpm_src = "/www/server/php/%s/sbin/php-fpm" % version
102+
php_pecl = '/usr/bin/pecl'
103+
php_pecl_src = "/www/server/php/%s/bin/pecl" % version
104+
php_pear = '/usr/bin/pear'
105+
php_pear_src = "/www/server/php/%s/bin/pear" % version
106+
if not os.path.exists(php_bin_src):
107+
return mw.returnData(False, '指定PHP版本未安装!')
108+
109+
is_chattr = mw.execShell('lsattr /usr|grep /usr/bin')[0].find('-i-')
110+
if is_chattr != -1:
111+
mw.execShell('chattr -i /usr/bin')
112+
mw.execShell("rm -f " + php_bin + ' ' + php_ize + ' ' +
113+
php_fpm + ' ' + php_pecl + ' ' + php_pear)
114+
mw.execShell("ln -sf %s %s" % (php_bin_src, php_bin))
115+
mw.execShell("ln -sf %s %s" % (php_ize_src, php_ize))
116+
mw.execShell("ln -sf %s %s" % (php_fpm_src, php_fpm))
117+
mw.execShell("ln -sf %s %s" % (php_pecl_src, php_pecl))
118+
mw.execShell("ln -sf %s %s" % (php_pear_src, php_pear))
119+
if is_chattr != -1:
120+
mw.execShell('chattr +i /usr/bin')
121+
mw.writeLog('面板设置', '设置PHP-CLI版本为: %s' % version)
122+
return mw.returnData(True, '设置成功!')
123+
124+

0 commit comments

Comments
 (0)