Set name and label at creation of client. Fixes #48 (#49)

* Set name and label at creation of client. Fixes #48

Changes behaviour of the add button from directly creating an
configuration to directing the user to an "create configuration" view.

If no name is given the default name is used same way as before.
This means that the go backend works with the old frontend as well with the new.

* Follow best practice in writing json.

Also handle err.

* 2 Bug fixes.

1. Fix bug introduced in last commit.
Don't try to json encode data that is already encoded.

2. Honor --max-number-client-config
When the creation moved from Clients.svelte to NewClient.svelte the
check in returned json for errors got lost. Now it is back.
This commit is contained in:
Björn Bohman
2020-04-14 15:26:34 +02:00
committed by GitHub
parent fb5cf90751
commit ffeb822a21
5 changed files with 115 additions and 27 deletions
+3 -3
View File
@@ -93,18 +93,18 @@ func (cfg *ServerConfig) GetUserConfig(user string) *UserConfig {
}
// NewClientConfig initiates a new client, returning a reference to the new config
func NewClientConfig(ip net.IP) *ClientConfig {
func NewClientConfig(ip net.IP, Name, Notes string) *ClientConfig {
key, err := wgtypes.GeneratePrivateKey()
if err != nil {
log.Fatal(err)
}
cfg := ClientConfig{
Name: "Unnamed Client",
Name: Name,
PrivateKey: key.String(),
PublicKey: key.PublicKey().String(),
IP: ip,
Notes: "",
Notes: Notes,
Created: time.Now().Format(time.RFC3339),
Modified: time.Now().Format(time.RFC3339),
}