仰望星辰工作室

refactor: 将节点PHP版本管理移至系统底层,脱离插件依赖

Y yang1145 提交于 2026-07-19 21:29 · b6bcbb0 ·父提交 07b12d0
refactor: 将节点PHP版本管理移至系统底层,脱离插件依赖

- 新增 MPHX/bt_php.function.php 提供核心函数
- 新增 admin/bt_php.php + templates/default/admin/bt_php.php 管理页面
- admin/api/bt.php 添加 list_node_php / auto_detect_node_php / set_node_php 接口
- 添加宝塔时自动检测并保存默认 PHP 版本
- 侧边栏「节点与宝塔」新增「节点PHP版本」入口
- install.sql 的 MN_bt 表新增 mrbts_php 列
- 从 hosting_shop 插件剥离所有节点 PHP 版本相关代码
9 个文件变更 +216 -179 13172193298@163.com
•MPHX/bt_php.function.php +108 -0
•admin/api/bt.php +53 -1
•admin/bt_php.php +6 -0
•app_plugins/hosting_shop/bootstrap.php +2 -46
•app_plugins/hosting_shop/install.sql +0 -2
•app_plugins/hosting_shop/lib/hosting.php +22 -88
•install/install.sql +3 -0
•app_plugins/hosting_shop/views/admin/node_php.php => templates/default/admin/bt_php.php +21 -42
•templates/default/admin/index.php +1 -0
变更内容
diff --git a/MPHX/bt_php.function.php b/MPHX/bt_php.function.php
new file mode 100644
index 0000000..a209caa
--- /dev/null
+++ b/MPHX/bt_php.function.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * BT节点 PHP 版本管理函数
+ *
+ * 系统底层函数,独立于任何插件,提供宝塔节点的 PHP 版本管理能力。
+ * 在 admin/api/bt.php、admin/api/zj.php、api/api.php 中均直接使用。
+ */
+
+if (!defined('IN_CRONLITE')) {
+    exit;
+}
+
+/**
+ * 获取指定节点的 PHP 版本列表(从宝塔 API 实时拉取)。
+ * @return array ['ok'=>bool, 'versions'=>array, 'latest'=>string, 'msg'=>string]
+ */
+function mnbt_node_php_list($btdh)
+{
+    global $DB;
+    $node = $DB->get_row_prepare("SELECT * FROM MN_bt WHERE btdh=? LIMIT 1", [$btdh]);
+    if (!$node) {
+        return ['ok' => false, 'msg' => '节点不存在'];
+    }
+    $bt_api_file = defined('SYSTEM_ROOT') ? SYSTEM_ROOT . 'bt_api.php' : ROOT . 'MPHX/bt_api.php';
+    if (!is_file($bt_api_file)) {
+        return ['ok' => false, 'msg' => 'bt_api 类文件缺失'];
+    }
+    require_once $bt_api_file;
+
+    $btipe = ($node['ptl'] == 'true' ? 'https' : 'http') . '://' . $node['btip'] . ':' . $node['btdk'];
+    $api = new bt_api($btipe, $node['btmy']);
+    $result = $api->btapi_listphp();
+    if (!is_array($result)) {
+        return ['ok' => false, 'msg' => '无法获取 PHP 版本列表'];
+    }
+    $versions = [];
+    foreach ($result as $v) {
+        if (($v['status'] ?? false) && ($v['version'] ?? '') !== '00') {
+            $versions[] = ['version' => $v['version'], 'name' => $v['name'] ?? ('PHP-' . $v['version'])];
+        }
+    }
+    if (empty($versions)) {
+        return ['ok' => false, 'msg' => '该节点未安装任何 PHP 版本'];
+    }
+    usort($versions, function ($a, $b) {
+        return strcmp($b['version'], $a['version']);
+    });
+    return ['ok' => true, 'versions' => $versions, 'latest' => $versions[0]['version']];
+}
+
+/**
+ * 获取节点的当前默认 PHP 版本。
+ * 优先读取 mrbts_php,为空时自动检测并保存最新版本。
+ * @return string 版本号(空字符串表示无法获取)
+ */
+function mnbt_node_get_php($btdh)
+{
+    global $DB;
+    $node = $DB->get_row_prepare("SELECT mrbts_php FROM MN_bt WHERE btdh=? LIMIT 1", [$btdh]);
+    $php = $node['mrbts_php'] ?? '';
+    if ($php !== '' && $php !== '00') {
+        return $php;
+    }
+    $result = mnbt_node_auto_detect_php($btdh);
+    return $result['ok'] ? $result['version'] : '';
+}
+
+/**
+ * 设置节点的默认 PHP 版本。
+ */
+function mnbt_node_set_php($btdh, $version)
+{
+    global $DB;
+    $version = trim((string)$version);
+    if ($version === '') {
+        return false;
+    }
+    return (bool)$DB->query_prepare(
+        "UPDATE MN_bt SET mrbts_php=? WHERE btdh=? LIMIT 1",
+        [$version, $btdh]
+    );
+}
+
+/**
+ * 自动检测节点最新的 PHP 版本并保存为默认版本。
+ * @return array ['ok'=>bool, 'version'=>string, 'msg'=>string]
+ */
+function mnbt_node_auto_detect_php($btdh)
+{
+    $result = mnbt_node_php_list($btdh);
+    if (!$result['ok']) {
+        return $result;
+    }
+    $latest = $result['latest'];
+    if (!mnbt_node_set_php($btdh, $latest)) {
+        return ['ok' => false, 'msg' => '保存默认 PHP 版本失败'];
+    }
+    return ['ok' => true, 'version' => $latest, 'msg' => '已设置默认 PHP 版本为 ' . $latest];
+}
+
+/**
+ * 获取所有节点列表(含 mrbts_php 信息)。
+ */
+function mnbt_node_list_all()
+{
+    global $DB;
+    return $DB->get_all_prepare("SELECT * FROM MN_bt ORDER BY id ASC") ?: [];
+}
diff --git a/admin/api/bt.php b/admin/api/bt.php
index 0e335b2..ecc387a 100644
--- a/admin/api/bt.php
+++ b/admin/api/bt.php
@@ -16,7 +16,16 @@ if($egn=='addbt') {
 	$ktmy=md5($dati);
 	$qmk=md5($kiterw);
 	logjl($user,'添加宝塔','添加了一个编号为'.$bh.'的宝塔','添加成功',$DB);
-	if($DB->query_prepare("INSERT INTO `MN_bt` (`id`, `btip`, `btdk`, `btmy`, `date`, `ktmy`, `qmk`, `btdh`, `qk`, `btos`, `als`, `ptl`, `ftpdz`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", [$id, $ip, $dk, $key, $date, $ktmy, $qmk, $bh, $kg, $btos, $urlla, $xieyi, $ftpdz]))json_exit('添加成功'); else json_exit('添加失败'.$DB->error());
+	if($DB->query_prepare("INSERT INTO `MN_bt` (`id`, `btip`, `btdk`, `btmy`, `date`, `ktmy`, `qmk`, `btdh`, `qk`, `btos`, `als`, `ptl`, `ftpdz`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", [$id, $ip, $dk, $key, $date, $ktmy, $qmk, $bh, $kg, $btos, $urlla, $xieyi, $ftpdz])) {
+		// 添加成功后自动检测并设置默认 PHP 版本(非阻塞)
+		if (is_file(SYSTEM_ROOT . 'bt_php.function.php')) {
+			require_once SYSTEM_ROOT . 'bt_php.function.php';
+			mnbt_node_auto_detect_php($bh);
+		}
+		json_exit('添加成功');
+	} else {
+		json_exit('添加失败'.$DB->error());
+	}
 	return;
 }
 if($egn=='btsc') {
@@ -113,4 +122,47 @@ if($egn=='btztjc') {
 		exit(json_encode(['qk'=>0,'code'=>'连接失败:'.$e->getMessage(),'titco'=>'text-danger']));
 	}
 }
+
+// ====== 节点 PHP 版本管理(系统底层,独立于插件) ======
+
+if ($egn === 'list_node_php') {
+	$btdh = trim((string)($_POST['btdh'] ?? ''));
+	if ($btdh === '') {
+		exit(json_encode(['qk' => 0, 'msg' => '请指定节点']));
+	}
+	require_once SYSTEM_ROOT . 'bt_php.function.php';
+	$result = mnbt_node_php_list($btdh);
+	if (!$result['ok']) {
+		exit(json_encode(['qk' => 0, 'msg' => $result['msg']]));
+	}
+	$currentDefault = mnbt_node_get_php($btdh);
+	exit(json_encode(['qk' => 1, 'versions' => $result['versions'], 'latest' => $result['latest'], 'current_default' => $currentDefault]));
+}
+
+if ($egn === 'auto_detect_node_php') {
+	$btdh = trim((string)($_POST['btdh'] ?? ''));
+	if ($btdh === '') {
+		exit(json_encode(['qk' => 0, 'msg' => '请指定节点']));
+	}
+	require_once SYSTEM_ROOT . 'bt_php.function.php';
+	$result = mnbt_node_auto_detect_php($btdh);
+	if (!$result['ok']) {
+		exit(json_encode(['qk' => 0, 'msg' => $result['msg']]));
+	}
+	exit(json_encode(['qk' => 1, 'version' => $result['version'], 'msg' => $result['msg']]));
+}
+
+if ($egn === 'set_node_php') {
+	$btdh = trim((string)($_POST['btdh'] ?? ''));
+	$version = trim((string)($_POST['version'] ?? ''));
+	if ($btdh === '' || $version === '') {
+		exit(json_encode(['qk' => 0, 'msg' => '参数不完整']));
+	}
+	require_once SYSTEM_ROOT . 'bt_php.function.php';
+	if (!mnbt_node_set_php($btdh, $version)) {
+		exit(json_encode(['qk' => 0, 'msg' => '保存失败']));
+	}
+	exit(json_encode(['qk' => 1, 'msg' => '已设置节点 ' . htmlspecialchars($btdh) . ' 的默认 PHP 版本为 ' . $version]));
+}
+
 return;
diff --git a/admin/bt_php.php b/admin/bt_php.php
new file mode 100644
index 0000000..c9ddc0e
--- /dev/null
+++ b/admin/bt_php.php
@@ -0,0 +1,6 @@
+<?php
+include("../MPHX/common.php");
+require_once ROOT . 'MPHX/bt_php.function.php';
+$title = '节点PHP版本管理';
+mnbt_admin_require_login();
+mnbt_admin_render('bt_php');
diff --git a/app_plugins/hosting_shop/bootstrap.php b/app_plugins/hosting_shop/bootstrap.php
index 9707bc5..34d0566 100644
--- a/app_plugins/hosting_shop/bootstrap.php
+++ b/app_plugins/hosting_shop/bootstrap.php
@@ -242,7 +242,6 @@ mnbt_register_page('admin', 'plans', 'views/admin/plans.php', '套餐管理');
 mnbt_register_page('admin', 'plan_edit', 'views/admin/plan_edit.php', '套餐编辑');
 mnbt_register_page('admin', 'orders', 'views/admin/orders.php', '订单管理');
 mnbt_register_page('admin', 'assets', 'views/admin/assets.php', '资产管理');
-mnbt_register_page('admin', 'node_php', 'views/admin/node_php.php', '节点PHP管理');
 
 // 侧边栏菜单(三级结构)
 mnbt_register_menu('admin', [
@@ -253,53 +252,10 @@ mnbt_register_menu('admin', [
 		['title' => '套餐管理', 'page' => 'plans', 'icon' => 'mdi-package-variant', 'multitabs' => true],
 		['title' => '订单管理', 'page' => 'orders', 'icon' => 'mdi-receipt', 'multitabs' => true],
 		['title' => '资产管理', 'page' => 'assets', 'icon' => 'mdi-server', 'multitabs' => true],
-		['title' => '节点PHP管理', 'page' => 'node_php', 'icon' => 'mdi-language-php', 'multitabs' => true],
 	],
 ]);
 
 /* ============================================================
- *  管理员端 AJAX:节点 PHP 版本管理
+ *  节点 PHP 版本管理已移至系统底层
+ *  请访问管理后台 → 节点与宝塔 → 节点PHP版本
  * ============================================================ */
-
-// 获取指定节点的 PHP 版本列表(从宝塔 API 实时拉取)
-mnbt_register_ajax('admin', 'p_hosting_node_php_list', function () {
-	mnbt_plugin_require_admin();
-	$btdh = trim((string)($_POST['btdh'] ?? ''));
-	if ($btdh === '') {
-		json_exit_error('请指定节点');
-	}
-	$result = hosting_node_php_list($btdh);
-	if (!$result['ok']) {
-		json_exit_error($result['msg']);
-	}
-	$currentDefault = hosting_node_get_default_php($btdh);
-	json_exit_success('ok', ['versions' => $result['versions'], 'latest' => $result['latest'], 'current_default' => $currentDefault]);
-});
-
-// 自动检测并设置节点的默认 PHP 版本
-mnbt_register_ajax('admin', 'p_hosting_node_php_auto_detect', function () {
-	mnbt_plugin_require_admin();
-	$btdh = trim((string)($_POST['btdh'] ?? ''));
-	if ($btdh === '') {
-		json_exit_error('请指定节点');
-	}
-	$result = hosting_node_auto_detect_php($btdh);
-	if (!$result['ok']) {
-		json_exit_error($result['msg']);
-	}
-	json_exit_success($result['msg'], ['version' => $result['version']]);
-});
-
-// 手动设置节点的默认 PHP 版本
-mnbt_register_ajax('admin', 'p_hosting_node_php_set', function () {
-	mnbt_plugin_require_admin();
-	$btdh = trim((string)($_POST['btdh'] ?? ''));
-	$version = trim((string)($_POST['version'] ?? ''));
-	if ($btdh === '' || $version === '') {
-		json_exit_error('参数不完整');
-	}
-	if (!hosting_node_set_default_php($btdh, $version)) {
-		json_exit_error('保存失败');
-	}
-	json_exit_success('已设置节点 ' . htmlspecialchars($btdh) . ' 的默认 PHP 版本为 ' . $version);
-});
diff --git a/app_plugins/hosting_shop/install.sql b/app_plugins/hosting_shop/install.sql
index 82a352a..5f2b0b5 100644
--- a/app_plugins/hosting_shop/install.sql
+++ b/app_plugins/hosting_shop/install.sql
@@ -63,5 +63,3 @@ CREATE TABLE `MN_plugin_hosting_asset` (
   KEY `idx_host` (`host_id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
--- 为 MN_bt 表追加节点默认 PHP 版本列(V1.82 起每个宝塔节点独立管理 PHP 版本)
-ALTER TABLE `MN_bt` ADD COLUMN `mrbts_php` varchar(10) NOT NULL DEFAULT '' AFTER `qk`;
diff --git a/app_plugins/hosting_shop/lib/hosting.php b/app_plugins/hosting_shop/lib/hosting.php
index aa4f80b..23faa52 100644
--- a/app_plugins/hosting_shop/lib/hosting.php
+++ b/app_plugins/hosting_shop/lib/hosting.php
@@ -325,93 +325,10 @@ function hosting_node_list_all()
 	return $DB->get_all_prepare("SELECT * FROM MN_bt ORDER BY id ASC") ?: [];
 }
 
-/**
- * 获取节点的默认 PHP 版本。
- * 优先使用节点自定义的 mrbts_php,为空时自动检测最新版本。
- */
-function hosting_node_get_default_php($btdh)
-{
-	global $DB;
-	$node = $DB->get_row_prepare("SELECT mrbts_php FROM MN_bt WHERE btdh=? LIMIT 1", [$btdh]);
-	$php = $node['mrbts_php'] ?? '';
-	if ($php !== '' && $php !== '00') {
-		return $php;
-	}
-	// 自动检测最新版本
-	$detected = hosting_node_auto_detect_php($btdh);
-	return $detected['ok'] ? $detected['version'] : '';
-}
-
-/**
- * 设置节点的默认 PHP 版本。
- */
-function hosting_node_set_default_php($btdh, $version)
-{
-	global $DB;
-	$version = trim((string)$version);
-	if ($version === '') {
-		return false;
-	}
-	return (bool)$DB->query_prepare(
-		"UPDATE MN_bt SET mrbts_php=? WHERE btdh=? LIMIT 1",
-		[$version, $btdh]
-	);
-}
-
-/**
- * 从宝塔 API 获取节点可用 PHP 版本列表。
- * @return array ['ok'=>bool, 'versions'=>array, 'msg'=>string]
- */
-function hosting_node_php_list($btdh)
-{
-	$node = hosting_node_get($btdh);
-	if (!$node) {
-		return ['ok' => false, 'msg' => '节点不存在'];
-	}
-	$bt_api_file = ROOT . 'MPHX/bt_api.php';
-	if (!is_file($bt_api_file)) {
-		return ['ok' => false, 'msg' => 'bt_api 类文件缺失'];
-	}
-	require_once $bt_api_file;
-
-	$btipe = ($node['ptl'] == 'true' ? 'https' : 'http') . '://' . $node['btip'] . ':' . $node['btdk'];
-	$api = new bt_api($btipe, $node['btmy']);
-	$result = $api->btapi_listphp();
-	if (!is_array($result)) {
-		return ['ok' => false, 'msg' => '无法获取 PHP 版本列表'];
-	}
-	$versions = [];
-	foreach ($result as $v) {
-		if (($v['status'] ?? false) && ($v['version'] ?? '') !== '00') {
-			$versions[] = ['version' => $v['version'], 'name' => $v['name'] ?? ('PHP-' . $v['version'])];
-		}
-	}
-	if (empty($versions)) {
-		return ['ok' => false, 'msg' => '该节点未安装任何 PHP 版本'];
-	}
-	// 按版本号降序排列(最新在前)
-	usort($versions, function ($a, $b) {
-		return strcmp($b['version'], $a['version']);
-	});
-	return ['ok' => true, 'versions' => $versions, 'latest' => $versions[0]['version']];
-}
-
-/**
- * 自动检测节点最新的 PHP 版本并保存为默认版本。
- * @return array ['ok'=>bool, 'version'=>string, 'msg'=>string]
- */
-function hosting_node_auto_detect_php($btdh)
-{
-	$result = hosting_node_php_list($btdh);
-	if (!$result['ok']) {
-		return $result;
-	}
-	$latest = $result['latest'];
-	if (!hosting_node_set_default_php($btdh, $latest)) {
-		return ['ok' => false, 'msg' => '保存默认 PHP 版本失败'];
-	}
-	return ['ok' => true, 'version' => $latest, 'msg' => '已设置默认 PHP 版本为 ' . $latest];
-}
+/* ============================================================
+ *  节点 PHP 版本管理已移至系统底层 MPHX/bt_php.function.php
+ *  请使用 mnbt_node_get_php() / mnbt_node_set_php() 等函数
+ * ============================================================ */
 
 /* ============================================================
  *  订单管理
@@ -656,7 +573,24 @@ function hosting_open_host($order_id)
 		$cp_eh_ftp = 'true';
 		$cp_eh_sql = 'true';
 	}
-	$phpVersion = hosting_node_get_default_php($order['node']);
+	// 确定 PHP 版本:优先使用节点已保存的,否则自动检测最新版本
+	$phpVersion = $node['mrbts_php'] ?? '';
+	if ($phpVersion === '' || $phpVersion === '00') {
+		$phpList = $api->btapi_listphp();
+		if (is_array($phpList)) {
+			$versions = [];
+			foreach ($phpList as $v) {
+				if (($v['status'] ?? false) && ($v['version'] ?? '') !== '00') {
+					$versions[] = $v['version'];
+				}
+			}
+			if (!empty($versions)) {
+				usort($versions, function($a, $b) { return strcmp($b, $a); });
+				$phpVersion = $versions[0];
+				$DB->query_prepare("UPDATE MN_bt SET mrbts_php=? WHERE btdh=? LIMIT 1", [$phpVersion, $order['node']]);
+			}
+		}
+	}
 	if ($phpVersion === '' || $phpVersion === '00') {
 		hosting_order_set_status($order_id, 'failed', '无法获取节点 PHP 版本');
 		return ['ok' => false, 'msg' => '无法获取该节点的 PHP 版本,请先在宝塔面板安装 PHP 或在节点管理中设置默认 PHP 版本'];
diff --git a/install/install.sql b/install/install.sql
index 563a89f..7c49a4b 100644
--- a/install/install.sql
+++ b/install/install.sql
@@ -61,6 +61,7 @@ CREATE TABLE `MN_bt` (
   `ftpdz` varchar(50) NOT NULL,					-- 自定义FTP地址
   `ptl` varchar(50) NOT NULL,					-- 是否开启安全访问(true和false)
   `qk` varchar(50) NOT NULL,					-- 目前宝塔情况
+  `mrbts_php` varchar(10) NOT NULL DEFAULT '',	-- 节点默认 PHP 版本
   PRIMARY KEY (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
@@ -339,3 +340,5 @@ CREATE TABLE `MN_plugin_option` (
   PRIMARY KEY (`id`),
   UNIQUE KEY `uk_plugin_k` (`plugin_slug`,`k`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+ALTER TABLE `MN_bt` ADD COLUMN `mrbts_php` varchar(10) NOT NULL DEFAULT '' AFTER `qk`;
diff --git a/app_plugins/hosting_shop/views/admin/node_php.php b/templates/default/admin/bt_php.php
similarity index 72%
rename from app_plugins/hosting_shop/views/admin/node_php.php
rename to templates/default/admin/bt_php.php
index 3f8fb2d..94c6325 100644
--- a/app_plugins/hosting_shop/views/admin/node_php.php
+++ b/templates/default/admin/bt_php.php
@@ -1,15 +1,4 @@
-<?php
-/**
- * 管理员端 - 节点 PHP 版本管理
- */
-if (!defined('IN_CRONLITE')) {
-	exit;
-}
-
-$nodes = hosting_node_list_all();
-$title = $title ?? '节点PHP管理';
-mnbt_admin_include('head');
-?>
+<?php mnbt_admin_include('head'); ?>
 <div class="container-fluid p-t-15">
 	<div class="card">
 		<div class="card-header">
@@ -17,9 +6,10 @@ mnbt_admin_include('head');
 		</div>
 		<div class="card-body">
 			<div class="alert alert-info">
-				<i class="mdi mdi-information"></i> 每个宝塔节点可独立设置默认 PHP 版本。节点未设置时,系统会自动从宝塔 API 检测最新版本。
+				<i class="mdi mdi-information"></i> 每个宝塔节点可独立设置默认 PHP 版本。节点未设置时,系统自动从宝塔 API 检测最新版本。
 			</div>
 
+			<?php $nodes = mnbt_node_list_all(); ?>
 			<?php if (empty($nodes)): ?>
 				<div class="alert alert-warning">尚未添加任何宝塔节点。</div>
 			<?php else: ?>
@@ -29,8 +19,8 @@ mnbt_admin_include('head');
 							<tr>
 								<th style="width:60px">#</th>
 								<th>节点代号</th>
-								<th style="width:130px">当前默认 PHP</th>
-								<th style="width:130px">操作</th>
+								<th style="width:140px">当前默认 PHP</th>
+								<th style="width:280px">操作</th>
 							</tr>
 						</thead>
 						<tbody>
@@ -68,7 +58,6 @@ mnbt_admin_include('head');
 		</div>
 	</div>
 
-	<!-- 版本选择弹窗 -->
 	<div class="modal fade" id="versionModal" tabindex="-1">
 		<div class="modal-dialog">
 			<div class="modal-content">
@@ -88,13 +77,6 @@ mnbt_admin_include('head');
 </div>
 
 <script>
-function ajax(gn, data, cb) {
-	$.post('./ajax.php', $.extend({gn: gn}, data), function(res) {
-		try { res = typeof res === 'string' ? JSON.parse(res) : res; } catch(e) {}
-		cb(res);
-	});
-}
-
 function fetchVersions(btdh) {
 	var btn = $('#btn_fetch_' + btdh);
 	btn.prop('disabled', true).html('<i class="mdi mdi-loading mdi-spin"></i> 获取中...');
@@ -102,27 +84,22 @@ function fetchVersions(btdh) {
 	$('#versionList').html('<div class="text-center text-muted p-4">加载中...</div>');
 	$('#versionModal').modal('show');
 
-	ajax('p_hosting_node_php_list', {btdh: btdh}, function(res) {
+	$.post('./ajax.php', {gn: 'list_node_php', btdh: btdh}, function(res) {
+		try { res = typeof res === 'string' ? JSON.parse(res) : res; } catch(e) {}
 		btn.prop('disabled', false).html('<i class="mdi mdi-cloud-download"></i> 获取版本');
-		if (res.qk !== 1) {
-			$('#versionList').html('<div class="alert alert-danger">' + (res.msg || res.code || '获取失败') + '</div>');
+		if (!res.versions || res.versions.length === 0) {
+			$('#versionList').html('<div class="alert alert-warning">' + (res.msg || '该节点未安装任何 PHP 版本或无法获取') + '</div>');
 			return;
 		}
-		var versions = res.versions || [];
 		var current = res.current_default || '';
-		var html = '';
-		if (versions.length === 0) {
-			html = '<div class="alert alert-warning">该节点未安装任何 PHP 版本</div>';
-		} else {
-			html += '<div class="list-group list-group-flush">';
-			versions.forEach(function(v) {
-				var active = v.version === current ? ' active' : '';
-				var badge = v.version === current ? ' <span class="badge badge-success float-right">当前默认</span>' : '';
-				html += '<a href="javascript:;" class="list-group-item list-group-item-action' + active + '" onclick="setVersion(\'' + btdh + '\', \'' + v.version + '\')">' +
-					'<strong>' + v.version + '</strong> - ' + v.name + badge + '</a>';
-			});
-			html += '</div>';
-		}
+		var html = '<div class="list-group list-group-flush">';
+		res.versions.forEach(function(v) {
+			var active = v.version === current ? ' active' : '';
+			var badge = v.version === current ? ' <span class="badge badge-success float-right">当前默认</span>' : '';
+			html += '<a href="javascript:;" class="list-group-item list-group-item-action' + active + '" onclick="setVersion(\'' + btdh + '\', \'' + v.version + '\')">' +
+				'<strong>' + v.version + '</strong> - ' + v.name + badge + '</a>';
+		});
+		html += '</div>';
 		$('#versionList').html(html);
 	});
 }
@@ -130,7 +107,8 @@ function fetchVersions(btdh) {
 function autoDetect(btdh) {
 	var btn = $('#btn_detect_' + btdh);
 	btn.prop('disabled', true).html('<i class="mdi mdi-loading mdi-spin"></i> 检测中...');
-	ajax('p_hosting_node_php_auto_detect', {btdh: btdh}, function(res) {
+	$.post('./ajax.php', {gn: 'auto_detect_node_php', btdh: btdh}, function(res) {
+		try { res = typeof res === 'string' ? JSON.parse(res) : res; } catch(e) {}
 		btn.prop('disabled', false).html('<i class="mdi mdi-magic"></i> 自动设置最新');
 		if (res.qk === 1) {
 			$('#php_label_' + btdh).html('<span class="badge badge-success">' + (res.version || '') + '</span>');
@@ -142,7 +120,8 @@ function autoDetect(btdh) {
 }
 
 function setVersion(btdh, version) {
-	ajax('p_hosting_node_php_set', {btdh: btdh, version: version}, function(res) {
+	$.post('./ajax.php', {gn: 'set_node_php', btdh: btdh, version: version}, function(res) {
+		try { res = typeof res === 'string' ? JSON.parse(res) : res; } catch(e) {}
 		if (res.qk === 1) {
 			$('#php_label_' + btdh).html('<span class="badge badge-success">' + version + '</span>');
 			$('#versionModal').modal('hide');
diff --git a/templates/default/admin/index.php b/templates/default/admin/index.php
index de0f8d0..d91c26d 100644
--- a/templates/default/admin/index.php
+++ b/templates/default/admin/index.php
@@ -97,6 +97,7 @@
                 <li><a class="multitabs" href="add.php?gn=bt">添加宝塔</a></li>
                 <li><a class="multitabs" href="node.php">节点列表</a></li>
                 <li><a class="multitabs" href="node.php?tab=scan">违禁词扫描</a></li>
+                <li><a class="multitabs" href="bt_php.php">节点PHP版本</a></li>
               </ul>
             </li>