feat: enhance SQL migration handling and add Docker installation instructions for remote servers
This commit is contained in:
@@ -1149,7 +1149,7 @@ class InstallProtocolManager
|
||||
|
||||
if ($isAwg) {
|
||||
$detection = self::detectBuiltinAwg($server, $protocol);
|
||||
if (in_array($detection['status'] ?? '', ['existing', 'partial'], true)) {
|
||||
if (($detection['status'] ?? '') === 'existing') {
|
||||
Logger::appendInstall($serverId, 'Existing AWG installation detected, restoring instead of reinstalling');
|
||||
$restoreResult = self::restoreBuiltinAwg($server, $protocol, $detection, $options);
|
||||
// Import existing clients into DB
|
||||
@@ -1177,7 +1177,7 @@ class InstallProtocolManager
|
||||
|
||||
if ($isXray) {
|
||||
$xrayDetection = self::detectBuiltinXray($server, $protocol);
|
||||
if (in_array($xrayDetection['status'] ?? '', ['existing', 'partial'], true)) {
|
||||
if (($xrayDetection['status'] ?? '') === 'existing') {
|
||||
Logger::appendInstall($serverId, 'Existing X-Ray installation detected, restoring instead of reinstalling');
|
||||
$restoreResult = self::restoreBuiltinXray($server, $protocol, $xrayDetection, $options);
|
||||
return array_merge($restoreResult, ['mode' => 'restore_existing']);
|
||||
@@ -1189,12 +1189,41 @@ class InstallProtocolManager
|
||||
if ($engine === 'builtin_awg') {
|
||||
$res = $server->runAwgInstall($options);
|
||||
Logger::appendInstall($serverId, 'Builtin AWG install finished');
|
||||
|
||||
$resolvedPort = null;
|
||||
if (isset($res['vpn_port']) && (int) $res['vpn_port'] > 0) {
|
||||
$resolvedPort = (int) $res['vpn_port'];
|
||||
} elseif (isset($res['server_port']) && (int) $res['server_port'] > 0) {
|
||||
$resolvedPort = (int) $res['server_port'];
|
||||
}
|
||||
|
||||
$resolvedAwgParams = $res['awg_params'] ?? null;
|
||||
if (!is_array($resolvedAwgParams)) {
|
||||
$candidate = [];
|
||||
foreach (['Jc', 'Jmin', 'Jmax', 'S1', 'S2', 'H1', 'H2', 'H3', 'H4'] as $k) {
|
||||
if (array_key_exists($k, $res)) {
|
||||
$candidate[$k] = $res[$k];
|
||||
}
|
||||
}
|
||||
if ($candidate) {
|
||||
$resolvedAwgParams = $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
self::markServerActive($serverId, null, [
|
||||
'vpn_port' => $resolvedPort,
|
||||
'server_public_key' => $res['server_public_key'] ?? null,
|
||||
'preshared_key' => $res['preshared_key'] ?? null,
|
||||
'container_name' => $res['container_name'] ?? null,
|
||||
'awg_params' => $resolvedAwgParams,
|
||||
]);
|
||||
|
||||
$pdo = DB::conn();
|
||||
$pid = self::resolveProtocolId($protocol);
|
||||
if ($pid) {
|
||||
$config = [
|
||||
'server_host' => $server->getData()['host'] ?? null,
|
||||
'server_port' => $res['vpn_port'] ?? null,
|
||||
'server_port' => $resolvedPort,
|
||||
'extras' => $res
|
||||
];
|
||||
$stmt2 = $pdo->prepare('INSERT INTO server_protocols (server_id, protocol_id, config_data, applied_at, created_at) VALUES (?, ?, ?, NOW(), NOW()) ON DUPLICATE KEY UPDATE config_data = VALUES(config_data), applied_at = NOW()');
|
||||
|
||||
+17
-1
@@ -1459,10 +1459,19 @@ class VpnClient
|
||||
$awgParams = [];
|
||||
}
|
||||
|
||||
// Accept mixed-case keys from installer outputs (e.g. Jc/Jmin/Jmax)
|
||||
// by duplicating them into canonical uppercase AWG keys.
|
||||
foreach ($awgParams as $k => $v) {
|
||||
$uk = strtoupper((string) $k);
|
||||
if (in_array($uk, ['JC', 'JMIN', 'JMAX', 'S1', 'S2', 'S3', 'S4', 'H1', 'H2', 'H3', 'H4'], true) && !isset($awgParams[$uk])) {
|
||||
$awgParams[$uk] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
// If AWG params are missing (common after reinstall), fetch them directly from wg0.conf
|
||||
// to avoid falling back to template defaults that will not match the server.
|
||||
if (in_array($slug, ['amnezia-wg-advanced', 'awg2'], true)) {
|
||||
$needKeys = ['JC', 'JMIN', 'JMAX', 'S1', 'S2', 'S3', 'S4', 'H1', 'H2', 'H3', 'H4'];
|
||||
$needKeys = ['JC', 'JMIN', 'JMAX', 'S1', 'S2', 'H1', 'H2', 'H3', 'H4'];
|
||||
$missing = false;
|
||||
foreach ($needKeys as $k) {
|
||||
if (!isset($awgParams[$k])) {
|
||||
@@ -1494,6 +1503,13 @@ class VpnClient
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($awgParams['S3'])) {
|
||||
$awgParams['S3'] = 0;
|
||||
}
|
||||
if (!isset($awgParams['S4'])) {
|
||||
$awgParams['S4'] = 0;
|
||||
}
|
||||
|
||||
// Still missing? Refuse to overwrite config with template defaults.
|
||||
foreach ($needKeys as $k) {
|
||||
if (!isset($awgParams[$k])) {
|
||||
|
||||
Reference in New Issue
Block a user