{{define "tunnelform"}} {{$t := .T}}{{$e := $t.Errors}}{{$csrf := .CSRF}}
{{if .New}}New tunnel{{else}}{{$t.Name}}{{end}} {{with index $e "name"}}{{.}}{{end}} {{with index $e "listenPort"}}{{.}}{{end}} {{with index $e "addresses"}}{{.}}{{end}}
More {{with index $e "interface"}}{{.}}{{end}} {{with index $e "zone"}}{{.}}{{end}} {{with index $e "mtu"}}{{.}}{{end}} {{with index $e "sourceAddresses"}}{{.}}{{end}}

{{if $t.KeyPresent}}Public key: {{$t.PublicKey}}{{else if not .New}}No private key.{{else}}A private key is generated for it unless you paste one.{{end}}

{{with index $e "privateKey"}}{{.}}{{end}} {{if not .New}}{{end}}
Peers of {{if .New}}the new tunnel{{else}}{{$t.Name}}{{end}}
{{range $i, $p := $t.Peers}} {{$st := index $t.Live $p.PublicKey}} {{range $f := list "name" "publicKey" "endpoint" "allowed" "keepalive" "psk"}}{{with index $e (printf "peers[%d].%s" $i $f)}}{{end}}{{end}} {{end}}
NamePublic keyEndpointAllowed IPsKeepalivePreshared keyNowRemove
{{if $p.PublicKey}}{{if not $st.Handshake.IsZero}}{{ago $st.Handshake}} ago {{bytes $st.RX}} in, {{bytes $st.TX}} out{{else if $st.RX}}no handshake{{else if $t.Live}}never{{end}}{{end}} {{if $p.Name}}{{end}}
{{$f}}: {{.}}

Fill in the last row to add a peer. Allowed IPs are the destinations sent into the tunnel (and what the router accepts from the peer). Pasted preshared keys are stored on the router and not shown again.

{{if not .New}}
The key file stays on the router.
{{end}} {{end}} {{define "content"}} {{with .Data}}

Changes are saved here and take effect when applied. Keys are made on the router and stay on it. {{if not .Live}}Live status is not available.{{end}}

{{range .Tunnels}}

{{.Name}} {{.Device}}

{{template "tunnelform" (tform . $.CSRF false)}}
{{end}}

Add a phone or laptop

{{if .Config}}

{{.Config.Name}}: scan this with the WireGuard app or save the text as a config file. It contains the client's private key and is shown only now; apply the settings so the router accepts it.

{{if .Config.QR}}
{{.Config.QR}}
{{end}}
{{.Config.Text}}
{{end}} {{if .Tunnels}} {{$c := .Client}}{{$e := $c.Errors}}
{{with index $e "tunnel"}}{{.}}{{end}} {{with index $e "name"}}{{.}}{{end}} {{with index $e "address"}}{{.}}{{end}} {{with index $e "endpoint"}}{{.}}{{end}} {{with index $e "allowed"}}{{.}}{{end}} {{with index $e "dns"}}{{.}}{{end}}
{{else}}

Add a tunnel first.

{{end}}

Import a tunnel

Paste an existing WireGuard config (a wg-quick file or wg showconf output). Its keys are stored on the router as root-only files and not shown again. Options the router has no equivalent for (DNS, PostUp, ...) are skipped, and a peer that sends everything (0.0.0.0/0) has to be changed to the networks you want through the tunnel.

New tunnel

{{template "tunnelform" (tform .New $.CSRF true)}}
{{end}} {{end}}