mirror of
https://github.com/unraid/webgui.git
synced 2026-04-27 21:40:20 -05:00
+1
-1
@@ -15,7 +15,7 @@
|
||||
. /etc/rc.d/rc.runlog
|
||||
|
||||
# import CA proxy
|
||||
UnProxy=/boot/config/proxy.cfg
|
||||
UnProxy=/boot/config/plugins/dynamix/outgoingproxy.cfg
|
||||
CAProxy=/boot/config/plugins/community.applications/proxy.cfg
|
||||
if [[ -f "${CAProxy}" && ! -f "${UnProxy}" ]]; then
|
||||
proxy=
|
||||
|
||||
+13
-142
@@ -66,31 +66,31 @@ function unset_proxy_sh() {
|
||||
|
||||
/* Write proxy information to /usr/local/emhttp/state/proxy.ini. */
|
||||
function set_proxy_ini() {
|
||||
global $proxy_ini, $proxy_url, $no_proxy;
|
||||
global $proxy_ini, $proxy_url, $no_proxy;
|
||||
|
||||
$content = "http_proxy=".$proxy_url."\n";
|
||||
$content = "http_proxy=".$proxy_url."\n";
|
||||
$content .= "https_proxy=".$proxy_url."\n";
|
||||
$content .= "no_proxy=".$no_proxy."\n";
|
||||
|
||||
write_file($proxy_ini, $content);
|
||||
write_file($proxy_ini, $content);
|
||||
}
|
||||
|
||||
/* Clear /usr/local/emhttp/state/proxy.ini. */
|
||||
function unset_proxy_ini() {
|
||||
/* Vars are empty now, call set_proxy_ini to add empty vars to proxy.ini. */
|
||||
set_proxy_ini();
|
||||
/* Vars are empty now, call set_proxy_ini to add empty vars to proxy.ini. */
|
||||
set_proxy_ini();
|
||||
}
|
||||
|
||||
/* Generate proxy files. */
|
||||
function add_proxy_to_generated_files() {
|
||||
global $verbose;
|
||||
global $verbose;
|
||||
|
||||
echo("generating proxy files\n");
|
||||
set_proxy_sh();
|
||||
set_proxy_ini();
|
||||
if ($verbose) {
|
||||
display_generated_files();
|
||||
}
|
||||
echo("generating proxy files\n");
|
||||
set_proxy_sh();
|
||||
set_proxy_ini();
|
||||
if ($verbose) {
|
||||
display_generated_files();
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove proxy info from all generated files. */
|
||||
@@ -129,7 +129,7 @@ function display_generated_file($file) {
|
||||
$config = parse_plugin_config();
|
||||
|
||||
/* Get the current active proxy. */
|
||||
$proxy_active = $config['proxy_active'];
|
||||
$proxy_active = array_key_exists('proxy_active', $config) ? $config['proxy_active'] : 0;
|
||||
$proxy_url = "";
|
||||
|
||||
/* Only build full url for an active proxy. */
|
||||
@@ -154,132 +154,3 @@ if ($proxy_active != "0") {
|
||||
remove_proxy_from_generated_files();
|
||||
}
|
||||
?>
|
||||
=======
|
||||
#!/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
|
||||
PROXY_INI=/usr/local/emhttp/state/proxy.ini
|
||||
|
||||
# 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 <<EOF >"${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 <<EOF >"${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}"
|
||||
}
|
||||
|
||||
set_proxy_ini() {
|
||||
local FILE
|
||||
FILE="${PROXY_INI}"
|
||||
cat <<EOF >"${FILE}.${RND}"
|
||||
http_proxy="${proxy_url}"
|
||||
https_proxy="${proxy_url}"
|
||||
no_proxy="${no_proxy}"
|
||||
EOF
|
||||
chmod 644 "${FILE}.${RND}"
|
||||
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
|
||||
}
|
||||
|
||||
# generate proxy files
|
||||
add_proxy_to_generated_files_and_exit() {
|
||||
echo "generating proxy files"
|
||||
set_proxy_sh
|
||||
set_proxy_ini
|
||||
[[ -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
|
||||
unset_proxy_ini
|
||||
[[ -n "${VERBOSE}" ]] && display_generated_files
|
||||
exit 0
|
||||
}
|
||||
|
||||
# when verbose mode enabled
|
||||
display_generated_files() {
|
||||
echo
|
||||
display_generated_file "${PROXY_SH}"
|
||||
display_generated_file "${PROXY_INI}"
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user