cmd/tailscale: allow Tailscale to work with Unraid web interface
Updates tailscale/tailscale#8026 Signed-off-by: Derek Kaser <derek.kaser@gmail.com>unraid-web
parent
0d7303b798
commit
b15d8525d0
|
@ -61,6 +61,8 @@ type tmplData struct {
|
|||
TUNMode bool
|
||||
IsSynology bool
|
||||
DSMVersion int // 6 or 7, if IsSynology=true
|
||||
IsUnraid bool
|
||||
UnraidToken string
|
||||
IPNVersion string
|
||||
}
|
||||
|
||||
|
@ -440,6 +442,8 @@ func webHandler(w http.ResponseWriter, r *http.Request) {
|
|||
LicensesURL: licensesURL(),
|
||||
TUNMode: st.TUN,
|
||||
IsSynology: distro.Get() == distro.Synology || envknob.Bool("TS_FAKE_SYNOLOGY"),
|
||||
IsUnraid: distro.Get() == distro.Unraid,
|
||||
UnraidToken: os.Getenv("UNRAID_CSRF_TOKEN"),
|
||||
DSMVersion: distro.DSMVersion(),
|
||||
IPNVersion: versionShort,
|
||||
}
|
||||
|
|
|
@ -117,6 +117,8 @@
|
|||
</footer>
|
||||
<script>(function () {
|
||||
const advertiseExitNode = {{.AdvertiseExitNode}};
|
||||
const isUnraid = {{.IsUnraid}};
|
||||
const unraidCsrfToken = "{{.UnraidToken}}";
|
||||
let fetchingUrl = false;
|
||||
var data = {
|
||||
AdvertiseRoutes: "{{.AdvertiseRoutes}}",
|
||||
|
@ -143,13 +145,25 @@ function postData(e) {
|
|||
nextUrl.search = nextParams.toString()
|
||||
const url = nextUrl.toString();
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Content-Type": contentType,
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
body: body
|
||||
}).then(res => res.json()).then(res => {
|
||||
fetchingUrl = false;
|
||||
const err = res["error"];
|
||||
|
@ -158,7 +172,11 @@ function postData(e) {
|
|||
}
|
||||
const url = res["url"];
|
||||
if (url) {
|
||||
document.location.href = url;
|
||||
if(isUnraid) {
|
||||
window.open(url, "_blank");
|
||||
} else {
|
||||
document.location.href = url;
|
||||
}
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue