remove proxy.ini, use environment variables instead

This commit is contained in:
ljm42
2024-03-18 14:22:57 -07:00
parent 6d379a4dd6
commit 77bd950c6d
2 changed files with 18 additions and 35 deletions
+7 -9
View File
@@ -292,14 +292,13 @@ function my_mkdir($dirname,$permissions = 0777,$recursive = false) {
}
}
// use when calling file_get_contents, fopen, or similar on a url
// reads proxy.ini and determines whether to proxy the request
// reads environment variables and determines whether to proxy the request
// example usage: file_get_contents($url, false, getProxyStreamContext($url));
function getProxyStreamContext($url, $streamContextOptions = [], $http_proxy_override = null, $no_proxy_override = null) {
$url_host=parse_url($url, PHP_URL_HOST);
$proxy = (array)@parse_ini_file("/var/local/emhttp/proxy.ini",true);
$http_proxy = $http_proxy_override ?? _var($proxy,'http_proxy');
$no_proxy = $no_proxy_override ?? _var($proxy,'no_proxy');
$http_proxy = $http_proxy_override ?? getenv('http_proxy');
$no_proxy = $no_proxy_override ?? getenv('no_proxy');
$no_proxy_arr = ($no_proxy) ? explode (",", $no_proxy) : [];
// php does not support sock5 proxies in HTTP context options, only http proxies
@@ -326,14 +325,13 @@ function getProxyStreamContext($url, $streamContextOptions = [], $http_proxy_ove
}
}
// use after calling curl_init();
// reads proxy.ini and determines whether to proxy the request
// reads environment variables and determines whether to proxy the request
// example usage: $ch = getProxyCurlOpt($url, $ch);
function getProxyCurlOpt($url, $ch, $http_proxy_override = null, $no_proxy_override = null) {
$url_host=parse_url($url, PHP_URL_HOST);
$proxy = (array)@parse_ini_file("/var/local/emhttp/proxy.ini",true);
$http_proxy = $http_proxy_override ?? _var($proxy,'http_proxy');
$no_proxy = $no_proxy_override ?? _var($proxy,'no_proxy');
$http_proxy = $http_proxy_override ?? getenv('http_proxy');
$no_proxy = $no_proxy_override ?? getenv('no_proxy');
$no_proxy_arr = ($no_proxy) ? explode (",", $no_proxy) : [];
// do not proxy hosts listed in the no_proxy environment variable
+11 -26
View File
@@ -11,7 +11,6 @@ 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
PROXY_INI=/usr/local/emhttp/state/proxy.ini
WGET=/root/.wgetrc
# random file extension for atomic writes
@@ -55,11 +54,13 @@ EOF
mv "${FILE}.${RND}" "${FILE}"
}
# write /usr/local/emhttp/state/proxy.ini
set_proxy_ini() {
# write /root/.wgetrc
set_wget() {
local FILE
FILE="${PROXY_INI}"
FILE="${WGET}"
cat <<EOF >"${FILE}.${RND}"
# Do not edit. This file is autogenerated by /usr/local/sbin/set_proxy
use_proxy=yes
http_proxy="${proxy_url}"
https_proxy="${proxy_url}"
no_proxy="${no_proxy}"
@@ -68,25 +69,8 @@ EOF
mv "${FILE}.${RND}" "${FILE}"
}
# clear /usr/local/emhttp/state/proxy.ini
unset_proxy_ini() {
# vars are empty now, call set_proxy_ini to add empty vars to proxy.ini
set_proxy_ini
}
# write /root/.wgetrc
set_wget() {
local FILE
FILE="${WGET}"
cat <<EOF >"${FILE}.${RND}"
# Do not edit. This file is autogenerated by /usr/local/sbin/set_proxy
use_proxy=yes
http_proxy=${proxy_url}
https_proxy=${proxy_url}
no_proxy="${no_proxy}"
EOF
chmod 644 "${FILE}.${RND}"
mv "${FILE}.${RND}" "${FILE}"
restart_phpfpm () {
/etc/rc.d/rc.php-fpm restart > /dev/null
}
# clear /root/.wgetrc
@@ -100,8 +84,9 @@ unset_wget() {
add_proxy_to_generated_files_and_exit() {
echo "generating proxy files"
set_proxy_sh
set_proxy_ini
set_wget
. "${PROXY_SH}"
restart_phpfpm
[[ -n "${VERBOSE}" ]] && display_generated_files
exit 0
}
@@ -110,8 +95,9 @@ add_proxy_to_generated_files_and_exit() {
remove_proxy_from_generated_files_and_exit() {
echo "removing proxy info from generated files"
unset_proxy_sh
unset_proxy_ini
unset_wget
. "${PROXY_SH}"
restart_phpfpm
[[ -n "${VERBOSE}" ]] && display_generated_files
exit 0
}
@@ -119,7 +105,6 @@ remove_proxy_from_generated_files_and_exit() {
display_generated_files() {
echo
display_generated_file "${PROXY_SH}"
display_generated_file "${PROXY_INI}"
display_generated_file "${WGET}"
}