cmd/tailscale/cli: [web] update JS in web.html for Unraid support

Signed-off-by: Shayne Sweeney <shayne@tailscale.com>
This commit is contained in:
Shayne Sweeney 2023-05-16 20:34:30 -04:00
parent b15d8525d0
commit 1dc9edde90
No known key found for this signature in database
GPG Key ID: 69DA13E86BF403B0

View File

@ -116,12 +116,12 @@
<a class="text-xs text-gray-500 hover:text-gray-600" href="{{ .LicensesURL }}">Open Source Licenses</a>
</footer>
<script>(function () {
const advertiseExitNode = {{.AdvertiseExitNode}};
const isUnraid = {{.IsUnraid}};
const unraidCsrfToken = "{{.UnraidToken}}";
const advertiseExitNode = {{ .AdvertiseExitNode }};
const isUnraid = {{ .IsUnraid }};
const unraidCsrfToken = "{{ .UnraidToken }}";
let fetchingUrl = false;
var data = {
AdvertiseRoutes: "{{.AdvertiseRoutes}}",
AdvertiseRoutes: "{{ .AdvertiseRoutes }}",
AdvertiseExitNode: advertiseExitNode,
Reauthenticate: false,
ForceLogout: false
@ -143,20 +143,18 @@ function postData(e) {
}
const nextUrl = new URL(window.location);
nextUrl.search = nextParams.toString()
const url = nextUrl.toString();
let contentType = "application/json";
let body = JSON.stringify(data);
if (isUnraid) {
var formBody = [];
formBody.push(encodeURIComponent("csrf_token") + "=" + encodeURIComponent(unraidCsrfToken));
formBody.push(encodeURIComponent("ts_data") + "=" + encodeURIComponent(JSON.stringify(data)));
var body = formBody.join("&");
var contentType = "application/x-www-form-urlencoded;charset=UTF-8";
} else {
var body = JSON.stringify(data);
var contentType = "application/json";
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, {
method: "POST",
headers: {