Merge pull request #1926 from ich777/ich777-TS-query-fix

Properly replace `[IP]` and `[PORT:.....]` in query part from URL, if they exist
This commit is contained in:
tom mortensen
2024-11-20 10:18:02 -08:00
committed by GitHub
2 changed files with 8 additions and 0 deletions
@@ -450,6 +450,8 @@ if (!empty($TS_no_peers) && !empty($TS_container)) {
// Check if serve or funnel are enabled by checking for [hostname] and replace string with TS_DNSName
if (!empty($xml['TailscaleWebUI']) && strpos($xml['TailscaleWebUI'], '[hostname]') !== false && isset($TS_DNSName)) {
$TS_webui_url = str_replace("[hostname][magicdns]", rtrim($TS_DNSName, '.'), $xml['TailscaleWebUI']);
$TS_webui_url = preg_replace('/\[IP\]/', rtrim($TS_DNSName, '.'), $TS_webui_url);
$TS_webui_url = preg_replace('/\[PORT:(\d{1,5})\]/', '443', $TS_webui_url);
// Check if serve is disabled, construct url with port, path and query if present and replace [noserve] with url
} elseif (strpos($xml['TailscaleWebUI'], '[noserve]') !== false && isset($TS_container['TailscaleIPs'])) {
$ipv4 = '';
@@ -464,6 +466,8 @@ if (!empty($TS_no_peers) && !empty($TS_container)) {
$webui_port = (preg_match('/\[PORT:(\d+)\]/', $xml['WebUI'], $matches)) ? ':' . $matches[1] : '';
$webui_path = $webui_url['path'] ?? '';
$webui_query = isset($webui_url['query']) ? '?' . $webui_url['query'] : '';
$webui_query = preg_replace('/\[IP\]/', $ipv4, $webui_query);
$webui_query = preg_replace('/\[PORT:(\d{1,5})\]/', ltrim($webui_port, ':'), $webui_query);
$TS_webui_url = 'http://' . $ipv4 . $webui_port . $webui_path . $webui_query;
}
// Check if TailscaleWebUI in the xml is custom and display instead
@@ -355,6 +355,8 @@ class DockerTemplates {
// Check if serve or funnel are enabled by checking for [hostname] and replace string with TS_DNSName
if (strpos($ct['TSUrl'], '[hostname]') !== false && isset($TS_DNSName)) {
$tmp['TSurl'] = str_replace("[hostname][magicdns]", rtrim($TS_DNSName, '.'), $ct['TSUrl']);
$tmp['TSurl'] = preg_replace('/\[IP\]/', rtrim($TS_DNSName, '.'), $tmp['TSurl']);
$tmp['TSurl'] = preg_replace('/\[PORT:(\d{1,5})\]/', '443', $tmp['TSurl']);
// Check if serve is disabled, construct url with port, path and query if present and replace [noserve] with url
} elseif (strpos($ct['TSUrl'], '[noserve]') !== false && isset($TS_container['TailscaleIPs'])) {
$ipv4 = '';
@@ -369,6 +371,8 @@ class DockerTemplates {
$webui_port = (preg_match('/\[PORT:(\d+)\]/', $webui, $matches)) ? ':' . $matches[1] : '';
$webui_path = $webui_url['path'] ?? '';
$webui_query = isset($webui_url['query']) ? '?' . $webui_url['query'] : '';
$webui_query = preg_replace('/\[IP\]/', $ipv4, $webui_query);
$webui_query = preg_replace('/\[PORT:(\d{1,5})\]/', ltrim($webui_port, ':'), $webui_query);
$tmp['TSurl'] = 'http://' . $ipv4 . $webui_port . $webui_path . $webui_query;
}
// Check if TailscaleWebUI in the xml is custom and display instead