diff --git a/Panel/modules/administration/panel_update.php b/Panel/modules/administration/panel_update.php index b3bae28e..bb6f0751 100644 --- a/Panel/modules/administration/panel_update.php +++ b/Panel/modules/administration/panel_update.php @@ -163,9 +163,17 @@ return [ function gsp_validate_update_settings(array $cfg) { $errors = []; -if (!preg_match('/^https?:\/\/[^ \t\r\n]+\.git$/i', (string)$cfg['repo_url']) -&& !preg_match('/^(?:ssh:\/\/|git@)[^ \t\r\n]+$/i', (string)$cfg['repo_url'])) { -$errors[] = 'Repository URL must be an http(s), ssh, or git@ URL.'; +$repo_source = trim((string)$cfg['repo_url']); +$is_git_url = preg_match('/^https?:\/\/[^ \t\r\n]+(?:\.git)?$/i', $repo_source) +|| preg_match('/^(?:ssh:\/\/|git@)[^ \t\r\n]+$/i', $repo_source); +$is_local_path = preg_match('/^\//', $repo_source) +&& strpos($repo_source, "\0") === false +&& strpos($repo_source, '..') === false; +if (!$is_git_url && !$is_local_path) { +$errors[] = 'Repository source must be an http(s), ssh, git@ URL, or a safe absolute local path.'; +} +if ($is_local_path && !is_dir($repo_source)) { +$errors[] = 'Repository local path does not exist or is not a directory: ' . $repo_source; } if (!preg_match('/^[A-Za-z0-9._\/-]{1,128}$/', (string)$cfg['branch'])) { $errors[] = 'Branch/channel contains invalid characters.'; @@ -1020,14 +1028,22 @@ $temp_dir = sys_get_temp_dir() . '/gsp_git_' . time() . '_' . mt_rand(1000, 9999 if (!@mkdir($temp_dir, 0750, true)) { return ['success' => false, 'error' => 'Cannot create temporary git checkout directory.']; } +if (!function_exists('exec')) { +gsp_rmdir_recursive($temp_dir); +return ['success' => false, 'error' => 'PHP exec() is disabled, so the updater cannot run git clone.']; +} $out = []; $ret = 0; $cmd = 'git clone --depth 1 --branch ' . escapeshellarg($branch) . ' ' . escapeshellarg($repo_url) . ' ' . escapeshellarg($temp_dir) . ' 2>&1'; +gsp_update_log('Starting configured git checkout from ' . $repo_url . ' branch ' . $branch); exec($cmd, $out, $ret); if ($ret !== 0) { gsp_rmdir_recursive($temp_dir); -return ['success' => false, 'error' => 'git clone failed: ' . implode(' | ', array_slice($out, -20))]; +$tail = implode(' | ', array_slice($out, -20)); +gsp_update_log('Configured git checkout failed from ' . $repo_url . ' branch ' . $branch . ': ' . $tail); +return ['success' => false, 'error' => 'git clone failed for repository source "' . $repo_url . '" branch "' . $branch . '": ' . $tail]; } +gsp_update_log('Configured git checkout completed from ' . $repo_url . ' branch ' . $branch); return ['success' => true, 'temp_dir' => $temp_dir, 'source_root' => $temp_dir, 'output' => implode("\n", $out)]; } @@ -2081,7 +2097,7 @@ echo "