mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
cmd/tailscale: allow Tailscale to work with Unraid web interface (#8062)
Updates tailscale/tailscale#8026 Signed-off-by: Derek Kaser <derek.kaser@gmail.com>
This commit is contained in:
parent
f0ee03dfaf
commit
7c88eeba86
@ -61,6 +61,8 @@ type tmplData struct {
|
|||||||
TUNMode bool
|
TUNMode bool
|
||||||
IsSynology bool
|
IsSynology bool
|
||||||
DSMVersion int // 6 or 7, if IsSynology=true
|
DSMVersion int // 6 or 7, if IsSynology=true
|
||||||
|
IsUnraid bool
|
||||||
|
UnraidToken string
|
||||||
IPNVersion string
|
IPNVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,6 +443,8 @@ func webHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
TUNMode: st.TUN,
|
TUNMode: st.TUN,
|
||||||
IsSynology: distro.Get() == distro.Synology || envknob.Bool("TS_FAKE_SYNOLOGY"),
|
IsSynology: distro.Get() == distro.Synology || envknob.Bool("TS_FAKE_SYNOLOGY"),
|
||||||
DSMVersion: distro.DSMVersion(),
|
DSMVersion: distro.DSMVersion(),
|
||||||
|
IsUnraid: distro.Get() == distro.Unraid,
|
||||||
|
UnraidToken: os.Getenv("UNRAID_CSRF_TOKEN"),
|
||||||
IPNVersion: versionShort,
|
IPNVersion: versionShort,
|
||||||
}
|
}
|
||||||
exitNodeRouteV4 := netip.MustParsePrefix("0.0.0.0/0")
|
exitNodeRouteV4 := netip.MustParsePrefix("0.0.0.0/0")
|
||||||
|
@ -116,10 +116,12 @@
|
|||||||
<a class="text-xs text-gray-500 hover:text-gray-600" href="{{ .LicensesURL }}">Open Source Licenses</a>
|
<a class="text-xs text-gray-500 hover:text-gray-600" href="{{ .LicensesURL }}">Open Source Licenses</a>
|
||||||
</footer>
|
</footer>
|
||||||
<script>(function () {
|
<script>(function () {
|
||||||
const advertiseExitNode = {{.AdvertiseExitNode}};
|
const advertiseExitNode = {{ .AdvertiseExitNode }};
|
||||||
|
const isUnraid = {{ .IsUnraid }};
|
||||||
|
const unraidCsrfToken = "{{ .UnraidToken }}";
|
||||||
let fetchingUrl = false;
|
let fetchingUrl = false;
|
||||||
var data = {
|
var data = {
|
||||||
AdvertiseRoutes: "{{.AdvertiseRoutes}}",
|
AdvertiseRoutes: "{{ .AdvertiseRoutes }}",
|
||||||
AdvertiseExitNode: advertiseExitNode,
|
AdvertiseExitNode: advertiseExitNode,
|
||||||
Reauthenticate: false,
|
Reauthenticate: false,
|
||||||
ForceLogout: false
|
ForceLogout: false
|
||||||
@ -141,15 +143,27 @@ function postData(e) {
|
|||||||
}
|
}
|
||||||
const nextUrl = new URL(window.location);
|
const nextUrl = new URL(window.location);
|
||||||
nextUrl.search = nextParams.toString()
|
nextUrl.search = nextParams.toString()
|
||||||
const url = nextUrl.toString();
|
|
||||||
|
|
||||||
|
let body = JSON.stringify(data);
|
||||||
|
let contentType = "application/json";
|
||||||
|
|
||||||
|
if (isUnraid) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.append("csrf_token", unraidCsrfToken);
|
||||||
|
params.append("ts_data", JSON.stringify(data));
|
||||||
|
|
||||||
|
body = params.toString();
|
||||||
|
contentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = nextUrl.toString();
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": contentType,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data)
|
body: body
|
||||||
}).then(res => res.json()).then(res => {
|
}).then(res => res.json()).then(res => {
|
||||||
fetchingUrl = false;
|
fetchingUrl = false;
|
||||||
const err = res["error"];
|
const err = res["error"];
|
||||||
@ -158,7 +172,11 @@ function postData(e) {
|
|||||||
}
|
}
|
||||||
const url = res["url"];
|
const url = res["url"];
|
||||||
if (url) {
|
if (url) {
|
||||||
document.location.href = url;
|
if(isUnraid) {
|
||||||
|
window.open(url, "_blank");
|
||||||
|
} else {
|
||||||
|
document.location.href = url;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user