wg-portal/internal/wireguard/template.go

53 lines
1.3 KiB
Go
Raw Normal View History

2020-11-06 06:21:47 -05:00
package wireguard
var (
2020-11-10 16:23:05 -05:00
ClientCfgTpl = `#{{ .Client.Identifier }}
[Interface]
2020-11-06 06:21:47 -05:00
Address = {{ .Client.IPsStr }}
PrivateKey = {{ .Client.PrivateKey }}
2020-11-10 16:23:05 -05:00
{{if .Server.DNSStr -}}
2020-11-06 06:21:47 -05:00
DNS = {{ .Server.DNSStr }}
{{- end}}
2020-11-10 16:23:05 -05:00
{{- if ne .Server.Mtu 0 -}}
MTU = {{.Server.Mtu}}
{{- end -}}
2020-11-06 06:21:47 -05:00
[Peer]
PublicKey = {{ .Server.PublicKey }}
2020-11-10 16:23:05 -05:00
{{- if .Client.PresharedKey -}}
2020-11-06 06:21:47 -05:00
PresharedKey = {{ .Client.PresharedKey }}
2020-11-10 16:23:05 -05:00
{{- end -}}
2020-11-06 06:21:47 -05:00
AllowedIPs = {{ .Client.AllowedIPsStr }}
Endpoint = {{ .Server.Endpoint }}
2020-11-10 16:23:05 -05:00
{{if and (ne .Server.PersistentKeepalive 0) (not .Client.IgnorePersistentKeepalive) -}}
2020-11-06 06:21:47 -05:00
PersistentKeepalive = {{.Server.PersistentKeepalive}}
{{- end}}
`
2020-11-10 16:23:05 -05:00
DeviceCfgTpl = `# AUTOGENERATED FILE - DO NOT EDIT
# Updated: {{ .Server.UpdatedAt }} / Created: {{ .Server.CreatedAt }}
2020-11-09 14:26:34 -05:00
[Interface]
{{- range .Server.IPs }}
Address = {{ . }}
2020-11-10 16:23:05 -05:00
{{- end}}
2020-11-09 14:26:34 -05:00
ListenPort = {{ .Server.ListenPort }}
PrivateKey = {{ .Server.PrivateKey }}
2020-11-10 16:23:05 -05:00
{{- if ne .Server.Mtu 0 -}}
2020-11-09 14:26:34 -05:00
MTU = {{.Server.Mtu}}
2020-11-10 16:23:05 -05:00
{{- end -}}
2020-11-09 14:26:34 -05:00
PreUp = {{ .Server.PreUp }}
PostUp = {{ .Server.PostUp }}
PreDown = {{ .Server.PreDown }}
PostDown = {{ .Server.PostDown }}
2020-11-10 16:23:05 -05:00
{{range .Clients}}
{{if not .DeactivatedAt -}}
2020-11-09 14:26:34 -05:00
# {{.Identifier}} / {{.Email}} / Updated: {{.UpdatedAt}} / Created: {{.CreatedAt}}
[Peer]
PublicKey = {{ .PublicKey }}
2020-11-10 16:23:05 -05:00
{{- if .PresharedKey -}}
2020-11-09 14:26:34 -05:00
PresharedKey = {{ .PresharedKey }}
2020-11-10 16:23:05 -05:00
{{- end -}}
2020-11-09 14:26:34 -05:00
AllowedIPs = {{ StringsJoin .IPs ", " }}
2020-11-10 16:23:05 -05:00
{{- end}}
{{end}}`
2020-11-06 06:21:47 -05:00
)