Merge pull request #15359 from uberbrady/improve_windows_upgrade

Fixed #15190 - Improvements to upgrade.php script to improve Windows experience
This commit is contained in:
snipe 2024-08-21 12:12:23 +01:00 committed by GitHub
commit 01c4fe6113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,9 +1,14 @@
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
// We define this because we can't reliable use file_get_contents because some
// We define this because we can't reliably use file_get_contents because some
// machines don't allow URL access via allow_url_fopen being set to off
function url_get_contents ($Url) {
$results = file_get_contents($Url);
if ($results) {
return $results;
}
print("file_get_contents() failed, trying curl instead.\n");
if (!function_exists('curl_init')){
die("cURL is not installed!\nThis is required for Snipe-IT as well as the upgrade script, so you will need to fix this before continuing.\nAborting upgrade...\n");
}
@ -13,11 +18,18 @@ function url_get_contents ($Url) {
// If we're on windows, make sure we can load intermediate certificates in
// weird corporate environments.
// See: https://github.com/curl/curl/commit/2d6333101a71129a6a802eb93f84a5ac89e34479
if (PHP_OS == "WINNT"){
// this will _probably_ only work if your libcurl has been linked to Schannel, the native Windows SSL implementation
if (PHP_OS == "WINNT" && defined("CURLOPT_SSL_OPTIONS") && defined("CURLSSLOPT_NATIVE_CA")) {
curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
}
$output = curl_exec($ch);
curl_close($ch);
if ($output === false) {
print("Error retrieving PHP requirements!\n");
print("Error was: " . curl_error($ch) . "\n");
print("Try enabling allow_url_fopen in php.ini, or fixing your curl/OpenSSL setup, or try rerunning with --skip-php-compatibility-checks");
return '{}';
}
return $output;
}
@ -72,7 +84,7 @@ if (! $upgrade_requirements) {
echo "\nERROR: Failed to retrieve remote requirements from $remote_requirements_file\n\n";
if ($branch_override){
echo "NOTE: You passed a custom branch: $branch\n";
echo " If the above URL doesn't work, that may be why. Please check you branch spelling/extistance\n\n";
echo " If the above URL doesn't work, that may be why. Please check you branch spelling/existence\n\n";
}
if (json_last_error()) {
@ -149,7 +161,11 @@ foreach ($env as $line_num => $line) {
if ((strlen($line) > 1) && (strpos($line, "#") !== 0)) {
list ($env_key, $env_value) = $env_line = explode('=', $line);
$env_line = explode('=', $line, 2);
if (count($env_line) != 2) {
continue;
}
list ($env_key, $env_value) = $env_line;
// The array starts at 0
$show_line_num = $line_num+1;