From 689f0bb697646d42f2e8f8d740f8d0732c8eca92 Mon Sep 17 00:00:00 2001 From: dlandon Date: Wed, 3 Apr 2024 10:38:52 -0500 Subject: [PATCH] Add Outgoing Proxy Manager. --- emhttp/plugins/dynamix/OutgoingProxy.page | 314 ++++++++++++++++++ emhttp/plugins/dynamix/OutgoingProxy.php | 50 +++ .../plugins/dynamix/OutgoingProxyManager.page | 6 + .../dynamix/include/OutgoingProxyLib.php | 108 ++++++ .../plugins/dynamix/scripts/outgoingproxy.sh | 117 +++++++ 5 files changed, 595 insertions(+) create mode 100644 emhttp/plugins/dynamix/OutgoingProxy.page create mode 100644 emhttp/plugins/dynamix/OutgoingProxy.php create mode 100644 emhttp/plugins/dynamix/OutgoingProxyManager.page create mode 100644 emhttp/plugins/dynamix/include/OutgoingProxyLib.php create mode 100644 emhttp/plugins/dynamix/scripts/outgoingproxy.sh diff --git a/emhttp/plugins/dynamix/OutgoingProxy.page b/emhttp/plugins/dynamix/OutgoingProxy.page new file mode 100644 index 000000000..7b5474270 --- /dev/null +++ b/emhttp/plugins/dynamix/OutgoingProxy.page @@ -0,0 +1,314 @@ +Menu="OutgoingProxyManager" +Title="Outgoing Proxy Manager" +Tag="icon-network" +--- + + +
+ + + + +

_(Enable Outgoing Proxy)_

+_(Select Proxy)_: +: + +:outgoing_proxy_enable_plug: +> Select the Proxy to use. Only online Proxies will be selectable. +> +> If your network environment requires an outgoing http proxy, define that here. +> +> Outgoing connections from the webgui and some system processes will use the specified http proxy. Docker container installs and updates will use the proxy, but the container itself will not, neither will any VMs. +> +> For a more comprehensive solution you might consider setting up _(VPN tunnel access for System)_. +:end + +

_(Outgoing Proxy)_ 1

+_(Name)_: +: + +:outgoing_proxy_name_plug: +> Outgoing Proxy name for this Proxy. +:end + +_(URL)_: +: + +:outgoing_proxy_url_plug: +> Outgoing Proxy URL for this Proxy. The URL can be entered with or without credentials. The credentials will be parsed from the URL. +> +> If you enter a User and Password, they will be used as new credentials. +:end + +_(User)_: +: + +:outgoing_proxy_user_plug: +> Outgoing Proxy User Name for this Proxy. +:end + +_(Password)_: +: + +:outgoing_proxy_password_plug: +> Outgoing Proxy Password for this Proxy. +:end + +

_(Outgoing Proxy)_ 2

+_(Name)_: +: + +:outgoing_proxy_name_plug: +> Outgoing Proxy name for this Proxy. +:end + +_(URL)_: +: + +:outgoing_proxy_url_plug: +> Outgoing Proxy URL for this Proxy. The URL can be entered with or without credentials. The credentials will be parsed from the URL. +> +> If you enter a User and Password, they will be used as new credentials. +:end + +_(User)_: +: + +:outgoing_proxy_user_plug: +> Outgoing Proxy User Name for this Proxy. +:end + +_(Password)_: +: + +:outgoing_proxy_password_plug: +> Outgoing Proxy Password for this Proxy. +:end + +

_(Outgoing Proxy)_ 3

+_(Name)_: +: + +:outgoing_proxy_name_plug: +> Outgoing Proxy name for this Proxy. +:end + +_(URL)_: +: + +:outgoing_proxy_url_plug: +> Outgoing Proxy URL for this Proxy. The URL can be entered with or without credentials. The credentials will be parsed from the URL. +> +> If you enter a User and Password, they will be used as new credentials. +:end + +_(User)_: +: + +:outgoing_proxy_user_plug: +> Outgoing Proxy User Name for this Proxy. +:end + +_(Password)_: +: + +:outgoing_proxy_password_plug: +> Outgoing Proxy Password for this Proxy. +:end + +  +: +
+ + diff --git a/emhttp/plugins/dynamix/OutgoingProxy.php b/emhttp/plugins/dynamix/OutgoingProxy.php new file mode 100644 index 000000000..4ea3c6209 --- /dev/null +++ b/emhttp/plugins/dynamix/OutgoingProxy.php @@ -0,0 +1,50 @@ + $proxy_1_status, 'proxy_status_2' => $proxy_2_status, 'proxy_status_3' => $proxy_3_status )); + break; + + default: + outgoingproxy_log("Undefined POST action - ".$_POST['action']."."); + break; +} +?> diff --git a/emhttp/plugins/dynamix/OutgoingProxyManager.page b/emhttp/plugins/dynamix/OutgoingProxyManager.page new file mode 100644 index 000000000..91c1bf768 --- /dev/null +++ b/emhttp/plugins/dynamix/OutgoingProxyManager.page @@ -0,0 +1,6 @@ +Menu="NetworkServices" +Type="xmenu" +Title="Outgoing Proxy Manager" +Icon="icon-network" +Tag="icon-network" +--- diff --git a/emhttp/plugins/dynamix/include/OutgoingProxyLib.php b/emhttp/plugins/dynamix/include/OutgoingProxyLib.php new file mode 100644 index 000000000..0a3b07b23 --- /dev/null +++ b/emhttp/plugins/dynamix/include/OutgoingProxyLib.php @@ -0,0 +1,108 @@ + '', + 'user' => '', + 'pass' => '', + ]; + + if ($cfg_url) { + /* Parse the URL by removing the user and password. */ + $urlComponents = parse_url($cfg_url); + + /* Parse user, password, host, and port from stored URL. */ + $host = isset($urlComponents['host']) ? $urlComponents['host'] : ''; + $port = isset($urlComponents['port']) ? $urlComponents['port'] : ''; + $user = isset($urlComponents['user']) ? $urlComponents['user'] : ''; + $pass = isset($urlComponents['pass']) ? $urlComponents['pass'] : ''; + + /* Return array of url, user, and password. */ + $return['url'] = "http://".$host.':'.$port; + + /* Extract the credentials. */ + if (strpos($cfg_url, '%') !== false) { + /* The credentials are urlencoded. */ + $return['user'] = urldecode($user); + $return['pass'] = urldecode($pass); + } else { + /* The credentials are not urlencoded. */ + $return['user'] = $user; + $return['pass'] = $pass; + } + } + + return($return); +} +?> diff --git a/emhttp/plugins/dynamix/scripts/outgoingproxy.sh b/emhttp/plugins/dynamix/scripts/outgoingproxy.sh new file mode 100644 index 000000000..5858ac9a0 --- /dev/null +++ b/emhttp/plugins/dynamix/scripts/outgoingproxy.sh @@ -0,0 +1,117 @@ +#!/usr/bin/php + $value) { + $iniString .= "$key=\"$value\"\n"; + } + + /* Write the INI string to a file. */ + file_put_contents($proxy_config_file, $iniString); + + /* Let things settle. */ + sleep(1); + + /* Now run the proxy setup script. */ + if (is_executable("/usr/local/sbin/set_proxy")) { + exec("at -M -f /usr/local/sbin/set_proxy now 2>/dev/null"); + + outgoingproxy_log("'set_proxy' script executed"); + } else { + outgoingproxy_log("'set_proxy' script does not exist"); + } +} + +/* Main entry point, */ +switch ($argv[1]) { + case 'apply': + apply(); + break; + + default: + echo("Error: 'outgoingproxy.sh {$argv[1]}' not understood\n"); + echo("outgoingproxy.sh usage: 'apply'\n"); + exit(0); + break; +} +?>