mirror of
https://github.com/h44z/wg-portal.git
synced 2025-12-16 19:36:17 +00:00
WIP: support different interface types: update config templates
This commit is contained in:
@@ -1,53 +1,20 @@
|
||||
package wireguard
|
||||
|
||||
var (
|
||||
ClientCfgTpl = `#{{ .Client.Identifier }}
|
||||
[Interface]
|
||||
Address = {{ .Client.IPsStr }}
|
||||
PrivateKey = {{ .Client.PrivateKey }}
|
||||
{{- if .Server.DNSStr}}
|
||||
DNS = {{ .Server.DNSStr }}
|
||||
{{- end}}
|
||||
{{- if ne .Server.Mtu 0}}
|
||||
MTU = {{.Server.Mtu}}
|
||||
{{- end}}
|
||||
|
||||
[Peer]
|
||||
PublicKey = {{ .Server.PublicKey }}
|
||||
{{- if .Client.PresharedKey}}
|
||||
PresharedKey = {{ .Client.PresharedKey }}
|
||||
{{- end}}
|
||||
AllowedIPs = {{ .Client.AllowedIPsStr }}
|
||||
Endpoint = {{ .Server.Endpoint }}
|
||||
{{- if and (ne .Server.PersistentKeepalive 0) (not .Client.IgnorePersistentKeepalive)}}
|
||||
PersistentKeepalive = {{.Server.PersistentKeepalive}}
|
||||
{{- end}}
|
||||
`
|
||||
DeviceCfgTpl = `# AUTOGENERATED FILE - DO NOT EDIT
|
||||
# Updated: {{ .Server.UpdatedAt }} / Created: {{ .Server.CreatedAt }}
|
||||
[Interface]
|
||||
{{- range .Server.IPs}}
|
||||
Address = {{ . }}
|
||||
{{- end}}
|
||||
ListenPort = {{ .Server.ListenPort }}
|
||||
PrivateKey = {{ .Server.PrivateKey }}
|
||||
{{- if ne .Server.Mtu 0}}
|
||||
MTU = {{.Server.Mtu}}
|
||||
{{- end}}
|
||||
PreUp = {{ .Server.PreUp }}
|
||||
PostUp = {{ .Server.PostUp }}
|
||||
PreDown = {{ .Server.PreDown }}
|
||||
PostDown = {{ .Server.PostDown }}
|
||||
|
||||
{{range .Clients}}
|
||||
{{if not .DeactivatedAt -}}
|
||||
# {{.Identifier}} / {{.Email}} / Updated: {{.UpdatedAt}} / Created: {{.CreatedAt}}
|
||||
[Peer]
|
||||
PublicKey = {{ .PublicKey }}
|
||||
{{- if .PresharedKey}}
|
||||
PresharedKey = {{ .PresharedKey }}
|
||||
{{- end}}
|
||||
AllowedIPs = {{ StringsJoin .IPs ", " }}
|
||||
{{- end}}
|
||||
{{end}}`
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed tpl/*
|
||||
var Templates embed.FS
|
||||
|
||||
var templateCache *template.Template
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
templateCache, err = template.New("server").Funcs(template.FuncMap{"StringsJoin": strings.Join}).ParseFS(Templates, "tpl/*.tpl")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user