removed the apple.html and windows.html in templates and replaced with apple.html and windows.html

and their usage in other files
This commit is contained in:
amha-mersha 2024-09-12 17:55:46 +03:00
parent 7b03faee1e
commit f86c4d3446
4 changed files with 245 additions and 246 deletions

View file

@ -13,14 +13,14 @@ import (
"github.com/rs/zerolog/log"
)
//go:embed templates/apple.html
var appleTemplate string
// WindowsConfigMessage shows a simple message in the browser for how to configure the Windows Tailscale client.
func (h *Headscale) WindowsConfigMessage(
writer http.ResponseWriter,
req *http.Request,
) {
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
writer.WriteHeader(http.StatusOK)
if _, err := writer.Write([]byte(templates.HeadscaleWindows(h.cfg.ServerURL).Render())); err != nil {
log.Error().
Caller().
@ -34,36 +34,10 @@ func (h *Headscale) AppleConfigMessage(
writer http.ResponseWriter,
req *http.Request,
) {
appleTemplate := template.Must(template.New("apple").Parse(appleTemplate))
config := map[string]interface{}{
"URL": h.cfg.ServerURL,
}
var payload bytes.Buffer
if err := appleTemplate.Execute(&payload, config); err != nil {
log.Error().
Str("handler", "AppleMobileConfig").
Err(err).
Msg("Could not render Apple index template")
writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
writer.WriteHeader(http.StatusInternalServerError)
_, err := writer.Write([]byte("Could not render Apple index template"))
if err != nil {
log.Error().
Caller().
Err(err).
Msg("Failed to write response")
}
return
}
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
writer.WriteHeader(http.StatusOK)
_, err := writer.Write(payload.Bytes())
if err != nil {
if _, err := writer.Write([]byte(templates.HeadscaleApple(h.cfg.ServerURL).Render())); err != nil {
log.Error().
Caller().
Err(err).

View file

@ -0,0 +1,240 @@
package templates
import (
"fmt"
"github.com/chasefleming/elem-go"
"github.com/chasefleming/elem-go/attrs"
)
func HeadscaleApple(url string) *elem.Element {
return elem.Html(nil,
elem.Head(attrs.Props{
attrs.Lang: "en",
},
elem.Meta(attrs.Props{
attrs.Charset: "UTF-8",
}),
elem.Meta(attrs.Props{
attrs.HTTPequiv: "X-UA-Compatible",
attrs.Content: "IE=edge",
}),
elem.Meta(attrs.Props{
attrs.Name: "viewport",
attrs.Content: "width=device-width, initial-scale=1.0",
}),
elem.Title(nil,
elem.Text("headscale - Apple")),
elem.Style(nil,
elem.CSS(`
body {
margin: 40px auto;
max-width: 800px;
line-height: 1.5;
font-size: 16px;
color: #444;
padding: 0 10px;
font-family: Sans-serif;
}
h1,
h2,
h3 {
line-height: 1.2;
}
`),
),
),
elem.Body(nil,
elem.H1(nil,
elem.Text("headscale: macOS configuration")),
elem.H2(nil,
elem.Text("Recent Tailscale versions (1.34.0 and higher)"),
),
elem.P(nil,
elem.Text("Tailscale added Fast User Switching in version 1.34 and you can now use the new login command to connect to one or more headscale (and Tailscale) servers. The previously used profiles does not have an effect anymore."),
),
elem.H3(nil,
elem.Text("Command line"),
),
elem.P(nil,
elem.Text("Use Tailscale's login command to add your profile:"),
),
elem.Pre(nil,
elem.Code(nil,
elem.Text(
fmt.Sprintf("tailscale login --login-server %s", url)),
),
),
elem.H3(nil,
elem.Text("GUI"),
),
elem.Ol(nil,
elem.Li(nil,
elem.Text("ALT + Click the Tailscale icon in the menu and hover over the Debug menu")),
elem.Li(nil,
elem.Text("Under \"Custom Login Server\", select \"Add Account...\"")),
elem.Li(nil,
elem.Text(fmt.Sprintf("Enter \"%s\" of the headscale instance and press \"Add Account\"", url))),
elem.Li(nil,
elem.Text("Follow the login procedure in the browser")),
),
elem.H2(nil,
elem.Text("Apple configuration profiles (1.32.0 and lower)"),
),
elem.P(nil,
elem.Text("This page provides"),
elem.A(attrs.Props{
attrs.Href: "https://support.apple.com/guide/mdm/mdm-overview-mdmbf9e668/web",
},
elem.Text("configuration profiles"),
),
elem.Text("for the official Tailscale clients for"),
),
elem.Ul(nil,
elem.Li(nil,
elem.A(attrs.Props{
attrs.Href: "https://apps.apple.com/app/tailscale/id1475387142",
},
elem.Text("macOS - AppStore Client")),
),
elem.Li(nil,
elem.A(attrs.Props{
attrs.Href: "https://pkgs.tailscale.com/stable/#macos",
},
elem.Text("macOS - Standalone Client")),
),
),
elem.P(nil,
elem.Text("The profiles will configure Tailscale.app to use "),
elem.Code(nil,
elem.Text(fmt.Sprintf("%s", url)),
),
elem.Text("as its control server."),
),
elem.H3(nil,
elem.Text("Caution"),
),
elem.P(nil,
elem.Text("You should always download and inspect the profile before installing it:")),
elem.Ul(nil,
elem.Li(nil,
elem.Text("for app store client: "),
elem.Code(nil,
elem.Text(fmt.Sprintf("curl %s/apple/macos-app-store", url))),
),
elem.Li(nil,
elem.Text("for standalone client: "),
elem.Code(nil,
elem.Text(fmt.Sprintf("curl %s/apple/macos-standalone", url))),
),
),
elem.H2(nil,
elem.Text("Profiles")),
elem.H3(nil,
elem.Text("macOS")),
elem.P(nil,
elem.Text("Headscale can be set to the default server by installing a Headscale configuration profile:")),
elem.P(nil,
elem.A(attrs.Props{
attrs.Href: "/apple/macos-app-store",
attrs.Download: "headscale_macos.mobileconfig",
},
elem.Text("macOS AppStore profile")),
elem.A(attrs.Props{
attrs.Href: "/apple/macos-standalone",
attrs.Download: "headscale_macos.mobileconfig",
},
elem.Text("macOS Standalone profile")),
),
elem.Ol(nil,
elem.Li(nil,
elem.Text("Download the profile, then open it. When it has been opened, there should be a notification that a profile can be installed"),
),
elem.Li(nil,
elem.Text("Open System Preferences and go to \"Profiles\""),
),
elem.Li(nil,
elem.Text("Find and install the Headscale profile"),
),
elem.Li(nil,
elem.Text("Restart Tailscale.app and log in"),
),
),
elem.P(nil,
elem.Text("Or"),
),
elem.P(nil,
elem.Text("Use your terminal to configure the default setting for Tailscale by issuing:")),
elem.Ul(nil,
elem.Li(nil,
elem.Text("for app store client:"),
elem.Code(nil,
elem.Text(fmt.Sprintf("defaults write io.tailscale.ipn.macos ControlURL %s", url)),
),
),
elem.Li(nil,
elem.Text("for standalone client:"),
elem.Code(nil,
elem.Text(fmt.Sprintf("defaults write io.tailscale.ipn.macsys ControlURL %s", url)),
),
),
),
elem.P(nil,
elem.Text("Restart Tailscale.app and log in."),
),
elem.H1(nil,
elem.Text("headscale: iOS configuration"),
),
elem.H2(nil,
elem.Text("Recent Tailscale version (1.38.1 and higher)"),
),
elem.P(nil,
elem.Text("Tailscale 1.38.1 on"),
elem.A(attrs.Props{
attrs.Href: "https://apps.apple.com/app/tailscale/id1470499037",
},
elem.Text("iOS")),
elem.Text("added a configuration option to allow user to set an \"Alternate Coordination server\". This can be used to connect to your headscale server."),
),
elem.H3(nil,
elem.Text("GUI")),
elem.Ol(nil,
elem.Li(nil,
elem.Text("Install the official Tailscale iOS client from the"),
elem.A(attrs.Props{
attrs.Href: "https://apps.apple.com/app/tailscale/id1470499037",
},
elem.Text("App store")),
),
elem.Li(nil,
elem.Text("Open Tailscale and make sure you are "),
elem.I(nil,
elem.Text("not")),
elem.Text("logged in to any account")),
elem.Li(nil,
elem.Text("Open Settings on the iOS device")),
elem.Li(nil,
elem.Text("Scroll down to the \"third party apps\" section, under \"Game Center\" or \"TV Provider\"")),
elem.Li(nil,
elem.Text("Find Tailscale and select it"),
elem.Ul(nil,
elem.Li(nil,
elem.Text("If the iOS device was previously logged into Tailscale, switch the \"Reset Keychain\" toggle to \"on\"")),
),
),
elem.Li(nil,
elem.Text(fmt.Sprintf("Enter \"%s\" under \"Alternate Coordination Server URL\"", url))),
elem.Li(nil,
elem.Text("Restart the app by closing it from the iOS app switcher, open the app and select the regular sign in option "),
elem.I(nil,
elem.Text("(non-SSO)")),
elem.Text(". It should open up to the headscale authentication page."),
),
elem.Li(nil,
elem.Text("Enter your credentials and log in. Headscale should now be working on your iOS device")),
),
),
)
}

View file

@ -1,170 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>headscale - Apple</title>
<style>
body {
margin: 40px auto;
max-width: 800px;
line-height: 1.5;
font-size: 16px;
color: #444;
padding: 0 10px;
font-family: Sans-serif;
}
h1,
h2,
h3 {
line-height: 1.2;
}
</style>
</head>
<body>
<h1>headscale: macOS configuration</h1>
<h2>Recent Tailscale versions (1.34.0 and higher)</h2>
<p>
Tailscale added Fast User Switching in version 1.34 and you can now use
the new login command to connect to one or more headscale (and Tailscale)
servers. The previously used profiles does not have an effect anymore.
</p>
<h3>Command line</h3>
<p>Use Tailscale's login command to add your profile:</p>
<pre><code>tailscale login --login-server {{.URL}}</code></pre>
<h3>GUI</h3>
<ol>
<li>
ALT + Click the Tailscale icon in the menu and hover over the Debug menu
</li>
<li>Under "Custom Login Server", select "Add Account..."</li>
<li>
Enter "{{.URL}}" of the headscale instance and press "Add Account"
</li>
<li>Follow the login procedure in the browser</li>
</ol>
<h2>Apple configuration profiles (1.32.0 and lower)</h2>
<p>
This page provides
<a href="https://support.apple.com/guide/mdm/mdm-overview-mdmbf9e668/web"
>configuration profiles</a
>
for the official Tailscale clients for
</p>
<ul>
<li>
<a href="https://apps.apple.com/app/tailscale/id1475387142"
>macOS - AppStore Client</a
>.
</li>
<li>
<a href="https://pkgs.tailscale.com/stable/#macos"
>macOS - Standalone Client</a
>.
</li>
</ul>
<p>
The profiles will configure Tailscale.app to use <code>{{.URL}}</code> as
its control server.
</p>
<h3>Caution</h3>
<p>
You should always download and inspect the profile before installing it:
</p>
<ul>
<li>
for app store client: <code>curl {{.URL}}/apple/macos-app-store</code>
</li>
<li>
for standalone client: <code>curl {{.URL}}/apple/macos-standalone</code>
</li>
</ul>
<h2>Profiles</h2>
<h3>macOS</h3>
<p>
Headscale can be set to the default server by installing a Headscale
configuration profile:
</p>
<p>
<a href="/apple/macos-app-store" download="headscale_macos.mobileconfig"
>macOS AppStore profile</a
>
<a href="/apple/macos-standalone" download="headscale_macos.mobileconfig"
>macOS Standalone profile</a
>
</p>
<ol>
<li>
Download the profile, then open it. When it has been opened, there
should be a notification that a profile can be installed
</li>
<li>Open System Preferences and go to "Profiles"</li>
<li>Find and install the Headscale profile</li>
<li>Restart Tailscale.app and log in</li>
</ol>
<p>Or</p>
<p>
Use your terminal to configure the default setting for Tailscale by
issuing:
</p>
<ul>
<li>
for app store client:
<code>defaults write io.tailscale.ipn.macos ControlURL {{.URL}}</code>
</li>
<li>
for standalone client:
<code>defaults write io.tailscale.ipn.macsys ControlURL {{.URL}}</code>
</li>
</ul>
<p>Restart Tailscale.app and log in.</p>
<h1>headscale: iOS configuration</h1>
<h2>Recent Tailscale versions (1.38.1 and higher)</h2>
<p>
Tailscale 1.38.1 on
<a href="https://apps.apple.com/app/tailscale/id1470499037">iOS</a>
added a configuration option to allow user to set an "Alternate
Coordination server". This can be used to connect to your headscale
server.
</p>
<h3>GUI</h3>
<ol>
<li>
Install the official Tailscale iOS client from the
<a href="https://apps.apple.com/app/tailscale/id1470499037"
>App store</a
>
</li>
<li>
Open Tailscale and make sure you are <i>not</i> logged in to any account
</li>
<li>Open Settings on the iOS device</li>
<li>
Scroll down to the "third party apps" section, under "Game Center" or
"TV Provider"
</li>
<li>
Find Tailscale and select it
<ul>
<li>
If the iOS device was previously logged into Tailscale, switch the
"Reset Keychain" toggle to "on"
</li>
</ul>
</li>
<li>Enter "{{.URL}}" under "Alternate Coordination Server URL"</li>
<li>
Restart the app by closing it from the iOS app switcher, open the app
and select the regular sign in option <i>(non-SSO)</i>. It should open
up to the headscale authentication page.
</li>
<li>
Enter your credentials and log in. Headscale should now be working on
your iOS device
</li>
</ol>
</body>
</html>

View file

@ -1,45 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>headscale - Windows</title>
<style>
body {
margin: 40px auto;
max-width: 800px;
line-height: 1.5;
font-size: 16px;
color: #444;
padding: 0 10px;
font-family: Sans-serif;
}
h1,
h2,
h3 {
line-height: 1.2;
}
</style>
</head>
<body>
<h1>headscale: Windows configuration</h1>
<p>
Download
<a
href="https://tailscale.com/download/windows"
rel="noreferrer noopener"
target="_blank"
>Tailscale for Windows</a
>
and install it.
</p>
<p>
Open a Command Prompt or Powershell and use Tailscale's login command to
connect with headscale:
</p>
<pre><code>tailscale login --login-server {{.URL}}</code></pre>
</body>
</html>