Skip to content

Commit

Permalink
Merge pull request #15359 from uberbrady/improve_windows_upgrade
Browse files Browse the repository at this point in the history
Fixed #15190 - Improvements to upgrade.php script to improve Windows experience
  • Loading branch information
snipe authored Aug 21, 2024
2 parents 7e475a0 + 0fa9f57 commit 01c4fe6
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions upgrade.php
Original file line number Diff line number Diff line change
@@ -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");
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -72,7 +84,7 @@ function url_get_contents ($Url) {
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()) {
Expand Down Expand Up @@ -149,7 +161,11 @@ function url_get_contents ($Url) {

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;
Expand Down

0 comments on commit 01c4fe6

Please sign in to comment.