diff --git a/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php b/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php index 6845cf7cf..2c1dd964f 100644 --- a/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php +++ b/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php @@ -124,24 +124,12 @@ class UnraidOsCheck if ($parsedAltUrl) $params['altUrl'] = $parsedAltUrl; $urlbase = $parsedAltUrl ?? $defaultUrl; - $url = $urlbase.'?'.http_build_query($params); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); - curl_setopt($ch, CURLOPT_TIMEOUT, 45); - curl_setopt($ch, CURLOPT_ENCODING, ""); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_REFERER, ""); - curl_setopt($ch, CURLOPT_FAILONERROR, true); - $response = curl_exec($ch); - if (curl_errno($ch)) { - $response = json_encode(array('error' => curl_error($ch)), JSON_PRETTY_PRINT); + $url = $urlbase.'?'.http_build_query($params); + $curlinfo = []; + $response = http_get_contents($url,[],$curlinfo); + if (array_key_exists('error', $curlinfo)) { + $response = json_encode(array('error' => $curlinfo['error']), JSON_PRETTY_PRINT); } - curl_close($ch); - $responseMutated = json_decode($response, true); if (!$responseMutated) { $response = json_encode(array('error' => 'Invalid response from '.$urlbase), JSON_PRETTY_PRINT); diff --git a/emhttp/plugins/dynamix/include/Wrappers.php b/emhttp/plugins/dynamix/include/Wrappers.php index 7e3f293c8..e362ae679 100644 --- a/emhttp/plugins/dynamix/include/Wrappers.php +++ b/emhttp/plugins/dynamix/include/Wrappers.php @@ -149,4 +149,47 @@ function my_date($fmt, $time) { function my_logger($message, $logger='webgui') { exec('logger -t '.escapeshellarg($logger).' -- '.escapeshellarg($message)); } +// Original PHP code by Chirp Internet: www.chirpinternet.eu +// Please acknowledge use of this code by including this header. +// https://www.the-art-of-web.com/php/http-get-contents/ +// Modified for Unraid +/** + * Fetches URL and returns content + * @param string $url The URL to fetch + * @param array $opts Array of options to pass to curl_setopt() + * @param array $getinfo Empty array passed by reference, will contain results of curl_getinfo and curl_error + * @return string|false $out The fetched content + */ +function http_get_contents(string $url, array $opts = [], array &$getinfo = NULL) { + $ch = curl_init(); + if(isset($getinfo)) { + curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); + } + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); + curl_setopt($ch, CURLOPT_TIMEOUT, 45); + curl_setopt($ch, CURLOPT_ENCODING, ""); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_REFERER, ""); + curl_setopt($ch, CURLOPT_FAILONERROR, true); + if(is_array($opts) && $opts) { + foreach($opts as $key => $val) { + curl_setopt($ch, $key, $val); + } + } + $out = curl_exec($ch); + if(isset($getinfo)) { + $getinfo = curl_getinfo($ch); + } + if (curl_errno($ch)) { + $msg = curl_error($ch) . " {$url}"; + if(isset($getinfo)) { + $getinfo['error'] = $msg; + } + my_logger($msg, "http_get_contents"); + } + return $out; +} ?> diff --git a/emhttp/plugins/dynamix/include/update.wireguard.php b/emhttp/plugins/dynamix/include/update.wireguard.php index 4c292b059..d394630e2 100644 --- a/emhttp/plugins/dynamix/include/update.wireguard.php +++ b/emhttp/plugins/dynamix/include/update.wireguard.php @@ -13,6 +13,7 @@