From d57f3e689cda6e93a2eb9d96b843993d5ba0a5f5 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 7 Dec 2024 22:13:38 +0100 Subject: [PATCH 1/3] TS Mullvad VPN changes - Prioritize searching for Exit Nodes through the container before using the Tailscale plugin if installed. This is necessary to display Exit Nodes from Mullvad for specific containers. --- .../include/CreateDocker.php | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php b/emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php index b2fa890d1..d08e80c4c 100644 --- a/emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php +++ b/emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php @@ -331,30 +331,6 @@ if (isset($xml["Config"]) && is_array($xml["Config"])) { } } -# Look for Exit Nodes if Tailscale plugin is installed -$ts_exit_nodes = []; -$ts_en_check = false; -if (file_exists('/usr/local/sbin/tailscale') && exec('pgrep --ns $$ -f "/usr/local/sbin/tailscaled"')) { - exec('tailscale exit-node list', $ts_exit_node_list, $retval); - if ($retval === 0) { - foreach ($ts_exit_node_list as $line) { - if (!empty(trim($line))) { - if (preg_match('/^(\d+\.\d+\.\d+\.\d+)\s+(.+)$/', trim($line), $matches)) { - $parts = preg_split('/\s+/', $matches[2]); - $ts_exit_nodes[] = [ - 'ip' => $matches[1], - 'hostname' => $parts[0], - 'country' => $parts[1], - 'city' => $parts[2], - 'status' => $parts[3] - ]; - $ts_en_check = true; - } - } - } - } -} - # Try to detect port from WebUI and set webui_url $TSwebuiport = ''; $webui_url = ''; @@ -376,11 +352,36 @@ $TS_DirectMachineLink = $TS_MachinesLink; $TS_HostNameActual = ""; $TS_not_approved = ""; $TS_https_enabled = false; +$ts_exit_nodes = []; +$ts_en_check = false; // Get Tailscale information and create arrays/variables !empty($xml) && exec("docker exec -i " . escapeshellarg($xml['Name']) . " /bin/sh -c \"tailscale status --peers=false --json\"", $TS_raw); $TS_no_peers = json_decode(implode('', $TS_raw),true); $TS_container = json_decode(implode('', $TS_raw),true); $TS_container = $TS_container['Self']??''; + +# Look for Exit Nodes through Tailscale plugin (if installed) when container is not running +if (empty($TS_container) && file_exists('/usr/local/sbin/tailscale') && exec('pgrep --ns $$ -f "/usr/local/sbin/tailscaled"')) { + exec('tailscale exit-node list', $ts_exit_node_list, $retval); + if ($retval === 0) { + foreach ($ts_exit_node_list as $line) { + if (!empty(trim($line))) { + if (preg_match('/^(\d+\.\d+\.\d+\.\d+)\s+(.+)$/', trim($line), $matches)) { + $parts = preg_split('/\s+/', $matches[2]); + $ts_exit_nodes[] = [ + 'ip' => $matches[1], + 'hostname' => $parts[0], + 'country' => $parts[1], + 'city' => $parts[2], + 'status' => $parts[3] + ]; + $ts_en_check = true; + } + } + } + } +} + if (!empty($TS_no_peers) && !empty($TS_container)) { // define the direct link to this machine on the Tailscale website if (!empty($TS_container['TailscaleIPs']) && !empty($TS_container['TailscaleIPs'][0])) { From daacabf32e5d2acb2d24abc6b666b928fff4f6a0 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 10 Dec 2024 08:38:38 +0100 Subject: [PATCH 2/3] Update tailscale_container_hook - minor improvements to the message in container logs when state dir can't be found --- share/docker/tailscale_container_hook | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/docker/tailscale_container_hook b/share/docker/tailscale_container_hook index d93b662b7..f34f04152 100755 --- a/share/docker/tailscale_container_hook +++ b/share/docker/tailscale_container_hook @@ -145,7 +145,8 @@ elif [ -d "/config" ]; then else if [ -z "${TAILSCALE_STATE_DIR}" ]; then TAILSCALE_STATE_DIR="/config/.tailscale_state" - echo "ERROR: Couldn't detect persistent Docker directory for .tailscale_state! Enable Tailscale Advanced Settings in the Docker template and set the Tailscale State Directory!" + echo "ERROR: Couldn't detect persistent Docker directory for .tailscale_state!" + echo " Please enable Tailscale Advanced Settings in the Docker template and set the Tailscale State Directory manually!" sleep infinity fi TSD_STATE_DIR="${TAILSCALE_STATE_DIR}" From 50e95fefa3125f7968b8059c0638303e49c26cc8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 10 Dec 2024 21:44:44 +0100 Subject: [PATCH 3/3] Improvements to TS State Dir check - make sure override actually overrides state dir - display error message when override is not set and detection failed --- share/docker/tailscale_container_hook | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/share/docker/tailscale_container_hook b/share/docker/tailscale_container_hook index f34f04152..3b78cd438 100755 --- a/share/docker/tailscale_container_hook +++ b/share/docker/tailscale_container_hook @@ -134,7 +134,9 @@ fi unset TSD_PARAMS unset TS_PARAMS -if [ ! -z "${SERVER_DIR}" ]; then +if [ ! -z "${TAILSCALE_STATE_DIR}" ]; then + TSD_STATE_DIR="${TAILSCALE_STATE_DIR}" +elif [ ! -z "${SERVER_DIR}" ]; then TSD_STATE_DIR="${SERVER_DIR}/.tailscale_state" elif [ ! -z "${DATA_DIR}" ]; then TSD_STATE_DIR="${DATA_DIR}/.tailscale_state" @@ -142,14 +144,12 @@ elif [ ! -z "${USER_HOME}" ]; then TSD_STATE_DIR="${USER_HOME}/.tailscale_state" elif [ -d "/config" ]; then TSD_STATE_DIR="/config/.tailscale_state" +elif [ -d "/data" ]; then + TSD_STATE_DIR="/data/.tailscale_state" else - if [ -z "${TAILSCALE_STATE_DIR}" ]; then - TAILSCALE_STATE_DIR="/config/.tailscale_state" - echo "ERROR: Couldn't detect persistent Docker directory for .tailscale_state!" - echo " Please enable Tailscale Advanced Settings in the Docker template and set the Tailscale State Directory manually!" - sleep infinity - fi - TSD_STATE_DIR="${TAILSCALE_STATE_DIR}" + echo "ERROR: Couldn't detect persistent Docker directory for .tailscale_state!" + echo " Please enable Tailscale Advanced Settings in the Docker template and set the Tailscale State Directory manually!" + sleep infinity fi echo "Settings Tailscale state dir to: ${TSD_STATE_DIR}"