diff --git a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
index a56a8ffe8..772db2c2d 100644
--- a/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
+++ b/emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
@@ -176,7 +176,7 @@ class DockerTemplates {
}
// if after above we don't have a valid url, check for GitLab
if (empty($github_api['url'])) {
- $source = file_get_contents($url);
+ $source = $this->download_url($url);
// the following should always exist for GitLab Community Edition or GitLab Enterprise Edition
if (preg_match("//", $source) > 0) {
$parse = parse_url($url);
diff --git a/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php b/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php
index 2f2b091d6..6845cf7cf 100644
--- a/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php
+++ b/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheck.php
@@ -126,18 +126,21 @@ class UnraidOsCheck
$urlbase = $parsedAltUrl ?? $defaultUrl;
$url = $urlbase.'?'.http_build_query($params);
- $response = "";
- // use error handler to convert warnings from file_get_contents to errors so they can be captured
- function warning_as_error($severity, $message, $filename, $lineno) {
- throw new ErrorException($message, 0, $severity, $filename, $lineno);
+ $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);
}
- set_error_handler("warning_as_error");
- try {
- $response = file_get_contents($url);
- } catch (Exception $e) {
- $response = json_encode(array('error' => $e->getMessage()), JSON_PRETTY_PRINT);
- }
- restore_error_handler();
+ curl_close($ch);
$responseMutated = json_decode($response, true);
if (!$responseMutated) {
@@ -160,7 +163,7 @@ class UnraidOsCheck
// send notification if a newer version is available and not ignored
$isNewerVersion = array_key_exists('isNewer',$responseMutated) ? $responseMutated['isNewer'] : false;
- $isReleaseIgnored = in_array($responseMutated['version'], $this->getIgnoredReleases());
+ $isReleaseIgnored = array_key_exists('version',$responseMutated) ? in_array($responseMutated['version'], $this->getIgnoredReleases()) : false;
if ($responseMutated && $isNewerVersion && !$isReleaseIgnored) {
$output = _var($notify,'plugin');
diff --git a/emhttp/plugins/dynamix/include/update.wireguard.php b/emhttp/plugins/dynamix/include/update.wireguard.php
index 4892371e7..4c292b059 100644
--- a/emhttp/plugins/dynamix/include/update.wireguard.php
+++ b/emhttp/plugins/dynamix/include/update.wireguard.php
@@ -21,6 +21,22 @@ if (!isset($_SESSION['locale'])) $_SESSION['locale'] = _var($_POST,'#locale');
require_once "$docroot/webGui/include/Translations.php";
+function download_url($url) {
+ $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, 12);
+ 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);
+ $out = curl_exec($ch) ?: false;
+ curl_close($ch);
+ return $out;
+}
+
$dockerd = is_file('/var/run/dockerd.pid') && is_dir('/proc/'.file_get_contents('/var/run/dockerd.pid'));
$etc = '/etc/wireguard';
$validIP4 = "(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})";
@@ -425,11 +441,10 @@ case 'public':
$ip = _var($_POST,'#ip');
$v4 = _var($_POST,'#prot')!='6';
$v6 = _var($_POST,'#prot')!='';
- $context = stream_context_create(['https'=>['timeout'=>12]]);
$int_ipv4 = $v4 ? (preg_match("/^$validIP4$/",$ip) ? $ip : (@dns_get_record($ip,DNS_A)[0]['ip'] ?: '')) : '';
- $ext_ipv4 = $v4 ? (@file_get_contents('https://wanip4.unraid.net',false,$context) ?: '') : '';
+ $ext_ipv4 = $v4 ? (download_url('https://wanip4.unraid.net') ?: '') : '';
$int_ipv6 = $v6 ? (preg_match("/^$validIP6$/",$ip) ? $ip : (@dns_get_record($ip,DNS_AAAA)[0]['ipv6'] ?: '')) : '';
- $ext_ipv6 = $v6 ? (@file_get_contents('https://wanip6.unraid.net',false,$context) ?: '') : '';
+ $ext_ipv6 = $v6 ? (download_url('https://wanip6.unraid.net') ?: '') : '';
echo "$int_ipv4;$ext_ipv4;$int_ipv6;$ext_ipv6";
break;
case 'addtunnel':
diff --git a/emhttp/plugins/dynamix/scripts/diagnostics b/emhttp/plugins/dynamix/scripts/diagnostics
index 397fed3ad..32d3c24c3 100755
--- a/emhttp/plugins/dynamix/scripts/diagnostics
+++ b/emhttp/plugins/dynamix/scripts/diagnostics
@@ -25,6 +25,7 @@ $zip = $all ? ($argv[2]??'') : ($argv[1]??'');
$cli = empty($zip);
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
+require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/Wrappers.php";
$folders = ['/boot','/boot/config','/boot/config/plugins','/boot/syslinux','/var/log','/var/log/plugins','/boot/extra','/var/log/packages','/var/lib/pkgtools/packages','/tmp'];
@@ -115,16 +116,6 @@ function maskIP($file) {
// anonymize full IPv6 addresses
run("sed -ri 's/([\"\[ ]([0-9a-f]{1,4}:){4})(([0-9a-f]{1,4}:){3}|:)([0-9a-f]{1,4})([/\" .]|$)/\\1XXXX:XXXX:XXXX:\\5\\6/g' ".escapeshellarg($file)." 2>/dev/null");
}
-
-function cache_only($disk) {
- return _var($disk,'type')=='Cache';
-}
-function cache_filter($disks) {
- return array_filter($disks,'cache_only');
-}
-function pools_filter($disks) {
- return array_unique(array_map('prefix',array_keys(cache_filter($disks))));
-}
function download_url($url, $path="", $bg=false, $timeout=15) {
$ch = curl_init();
curl_setopt_array($ch,[
diff --git a/etc/rc.d/rc.local b/etc/rc.d/rc.local
index b73cd534f..f71112bf4 100755
--- a/etc/rc.d/rc.local
+++ b/etc/rc.d/rc.local
@@ -14,6 +14,10 @@
# run & log functions
. /etc/rc.d/rc.runlog
+# load proxy environment vars so it is used for plugin updates and the go script
+/usr/local/sbin/set_proxy
+[[ -x /etc/profile.d/proxy.sh ]] && . /etc/profile.d/proxy.sh
+
# irqbalance daemon distributes interrupts over processors and cores
# if [[ -x /usr/sbin/irqbalance ]]; then
# /usr/sbin/irqbalance
diff --git a/sbin/set_proxy b/sbin/set_proxy
new file mode 100755
index 000000000..10127f213
--- /dev/null
+++ b/sbin/set_proxy
@@ -0,0 +1,114 @@
+#!/bin/bash
+#
+# script: set_proxy
+#
+# Copyright 2005-2024, Lime Technology
+#
+# call this script (/usr/local/sbin/set_proxy) when /boot/config/proxy.cfg changes
+
+# proxy.cfg is the source of all proxy information
+CFG=/boot/config/proxy.cfg
+
+# these files are generated by this script based on the data in proxy.cfg
+PROXY_SH=/etc/profile.d/proxy.sh
+
+# random file extension for atomic writes
+RND=$RANDOM
+
+VERBOSE=
+[[ "$1" == "-v" ]] && VERBOSE=1
+
+# global vars defined later
+proxy_active=
+proxy_url=
+no_proxy=
+
+# write environment variables to /etc/profile.d/proxy.sh
+set_proxy_sh() {
+ local FILE
+ FILE="${PROXY_SH}"
+ cat <"${FILE}.${RND}"
+#!/bin/bash
+# Do not edit. This file is autogenerated by /usr/local/sbin/set_proxy
+export http_proxy="${proxy_url}"
+export https_proxy="${proxy_url}"
+export no_proxy="${no_proxy}"
+EOF
+ chmod 755 "${FILE}.${RND}"
+ mv "${FILE}.${RND}" "${FILE}"
+}
+
+# clear environment variables from /etc/profile.d/proxy.sh
+unset_proxy_sh() {
+ local FILE
+ FILE="${PROXY_SH}"
+ cat <"${FILE}.${RND}"
+#!/bin/bash
+# Do not edit. This file is autogenerated by /usr/local/sbin/set_proxy
+unset http_proxy
+unset https_proxy
+unset no_proxy
+EOF
+ chmod 755 "${FILE}.${RND}"
+ mv "${FILE}.${RND}" "${FILE}"
+}
+
+# restart_phpfpm whenever the environment variables change
+restart_phpfpm () {
+ /etc/rc.d/rc.php-fpm restart > /dev/null
+}
+
+# generate proxy files
+add_proxy_to_generated_files_and_exit() {
+ echo "generating proxy files"
+ set_proxy_sh
+ . "${PROXY_SH}"
+ restart_phpfpm
+ [[ -n "${VERBOSE}" ]] && display_generated_files
+ exit 0
+}
+
+# remove proxy info from all generated files and exit
+remove_proxy_from_generated_files_and_exit() {
+ echo "removing proxy info from generated files"
+ unset_proxy_sh
+ . "${PROXY_SH}"
+ restart_phpfpm
+ [[ -n "${VERBOSE}" ]] && display_generated_files
+ exit 0
+}
+
+# when verbose mode enabled
+display_generated_files() {
+ echo
+ display_generated_file "${PROXY_SH}"
+}
+
+# when verbose mode enabled
+display_generated_file() {
+ local FILE
+ FILE=$1
+ echo "${FILE}"
+ [[ -f "${FILE}" ]] && cat "${FILE}" || echo "file does not exist"
+ echo
+}
+
+# if no proxy config, remove proxy info from all generated files and exit
+[[ ! -f "${CFG}" ]] && remove_proxy_from_generated_files_and_exit
+
+# read current proxy information from /boot/config/proxy.cfg
+# shellcheck source=/dev/null
+. <(/usr/bin/fromdos <"${CFG}")
+
+# determine proxy information
+proxy_url_var="proxy_url_${proxy_active:=}"
+proxy_url="${!proxy_url_var}"
+
+# if no active proxies, remove proxy info from all generated files and exit
+if [[ "${proxy_active:=0}" == "0" || "${proxy_url}" == "" ]]; then
+ remove_proxy_from_generated_files_and_exit
+fi
+
+# proxies are defined, write generated files
+no_proxy="127.0.0.1,localhost"
+add_proxy_to_generated_files_and_exit