mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-24 00:24:06 +03:00
Remove hardcoded values in the client config generation
This commit is contained in:
parent
e99a5ba92b
commit
deecd9c267
2 changed files with 28 additions and 11 deletions
15
util/util.go
15
util/util.go
|
@ -8,23 +8,18 @@ import (
|
|||
"github.com/ngoduykhanh/wireguard-ui/model"
|
||||
)
|
||||
|
||||
const wgConfigDNS = "1.1.1.1, 8.8.8.8"
|
||||
const wgConfigPersistentKeepalive = 15
|
||||
const wgConfigEndpoint = "wireguard.example.com:56231"
|
||||
const wgConfigServerPublicKey = "/OKCBc8PxIqCpgqlE9G1kSaTecdAvYf3loEwFj6MXDc="
|
||||
|
||||
// BuildClientConfig to create wireguard client config string
|
||||
func BuildClientConfig(client model.Client) string {
|
||||
func BuildClientConfig(client model.Client, server model.Server, setting model.GlobalSetting) string {
|
||||
// Interface section
|
||||
clientAddress := fmt.Sprintf("Address = %s", strings.Join(client.AllocatedIPs, ","))
|
||||
clientPrivateKey := fmt.Sprintf("PrivateKey = %s", client.PrivateKey)
|
||||
clientDNS := fmt.Sprintf("DNS = %s", wgConfigDNS)
|
||||
clientDNS := fmt.Sprintf("DNS = %s", strings.Join(setting.DNSServers, ","))
|
||||
|
||||
// Peer section
|
||||
peerPublicKey := fmt.Sprintf("PublicKey = %s", wgConfigServerPublicKey)
|
||||
peerPublicKey := fmt.Sprintf("PublicKey = %s", server.KeyPair.PublicKey)
|
||||
peerAllowedIPs := fmt.Sprintf("AllowedIPs = %s", strings.Join(client.AllowedIPs, ","))
|
||||
peerEndpoint := fmt.Sprintf("Endpoint = %s", wgConfigEndpoint)
|
||||
peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", wgConfigPersistentKeepalive)
|
||||
peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", setting.EndpointAddress, server.Interface.ListenPort)
|
||||
peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive)
|
||||
|
||||
// build the config as string
|
||||
strConfig := "[Interface]\n" +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue