From 54229f73bc3a1e6a88168183a9cf9f62b07476c2 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 5 May 2019 15:13:08 +0200 Subject: ui: check for duplicate names always Signed-off-by: Jason A. Donenfeld --- ui/editdialog.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ui/editdialog.go b/ui/editdialog.go index 77a044a0..724d40f3 100644 --- a/ui/editdialog.go +++ b/ui/editdialog.go @@ -22,7 +22,6 @@ type EditDialog struct { syntaxEdit *syntax.SyntaxEdit blockUntunneledTrafficCB *walk.CheckBox saveButton *walk.PushButton - tunnel *service.Tunnel config conf.Config lastPrivateKey string blockUntunneledTraficCheckGuard bool @@ -34,7 +33,7 @@ func runTunnelEditDialog(owner walk.Form, tunnel *service.Tunnel) *conf.Config { name string ) - dlg := &EditDialog{tunnel: tunnel} + dlg := &EditDialog{} if tunnel == nil { // Creating a new tunnel, create a new private key and use the default template @@ -250,19 +249,16 @@ func (dlg *EditDialog) onSaveButtonClicked() { return } - if dlg.tunnel != nil && dlg.tunnel.Name != newName { - names, err := conf.ListConfigNames() - if err != nil { - walk.MsgBox(dlg, "Unable to list existing tunnels", err.Error(), walk.MsgBoxIconError) + names, err := conf.ListConfigNames() + if err != nil { + walk.MsgBox(dlg, "Unable to list existing tunnels", err.Error(), walk.MsgBoxIconError) + return + } + for _, name := range names { + if strings.ToLower(name) == strings.ToLower(newName) { + walk.MsgBox(dlg, "Tunnel already exists", fmt.Sprintf("Another tunnel already exists with the name ā€˜%sā€™.", newName), walk.MsgBoxIconWarning) return } - - for _, name := range names { - if strings.ToLower(name) == strings.ToLower(newName) { - walk.MsgBox(dlg, "Invalid configuration", fmt.Sprintf("Another tunnel already exists with the name ā€˜%sā€™.", newName), walk.MsgBoxIconWarning) - return - } - } } cfg, err := conf.FromWgQuick(dlg.syntaxEdit.Text(), newName) -- cgit v1.2.3-59-g8ed1b