diff --git a/controllers/common.go b/controllers/common.go index ffa830c69..a062f599f 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -204,7 +204,7 @@ func UpdateNode(nodechange models.Node, node models.Node) (models.Node, error) { {"expdatetime", node.ExpirationDateTime}, {"endpoint", node.Endpoint}, {"postup", node.PostUp}, - {"preup", node.PostDown}, + {"postdown", node.PostDown}, {"macaddress", node.MacAddress}, {"localaddress", node.LocalAddress}, {"persistentkeepalive", node.PersistentKeepalive}, diff --git a/controllers/networkHttpController.go b/controllers/networkHttpController.go index bd6b21c29..d13a41c73 100644 --- a/controllers/networkHttpController.go +++ b/controllers/networkHttpController.go @@ -218,25 +218,25 @@ func keyUpdate(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - filter := bson.M{"netid": params["networkname"]} - // prepare update model. - update := bson.D{ - {"$set", bson.D{ - {"addressrange", network.AddressRange}, - {"displayname", network.DisplayName}, - {"defaultlistenport", network.DefaultListenPort}, - {"defaultpostup", network.DefaultPostUp}, - {"defaultpreup", network.DefaultPostDown}, - {"defaultkeepalive", network.DefaultKeepalive}, - {"keyupdatetimestamp", network.KeyUpdateTimeStamp}, - {"defaultsaveconfig", network.DefaultSaveConfig}, - {"defaultinterface", network.DefaultInterface}, - {"nodeslastmodified", network.NodesLastModified}, - {"networklastmodified", network.NetworkLastModified}, - {"allowmanualsignup", network.AllowManualSignUp}, - {"defaultcheckininterval", network.DefaultCheckInInterval}, - }}, - } + filter := bson.M{"netid": params["networkname"]} + // prepare update model. + update := bson.D{ + {"$set", bson.D{ + {"addressrange", network.AddressRange}, + {"displayname", network.DisplayName}, + {"defaultlistenport", network.DefaultListenPort}, + {"defaultpostup", network.DefaultPostUp}, + {"defaultpostdown", network.DefaultPostDown}, + {"defaultkeepalive", network.DefaultKeepalive}, + {"keyupdatetimestamp", network.KeyUpdateTimeStamp}, + {"defaultsaveconfig", network.DefaultSaveConfig}, + {"defaultinterface", network.DefaultInterface}, + {"nodeslastmodified", network.NodesLastModified}, + {"networklastmodified", network.NetworkLastModified}, + {"allowmanualsignup", network.AllowManualSignUp}, + {"defaultcheckininterval", network.DefaultCheckInInterval}, + }}, + } err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&network) @@ -390,25 +390,24 @@ func updateNetwork(w http.ResponseWriter, r *http.Request) { if haschange { network.SetNetworkLastModified() } - - // prepare update model. - update := bson.D{ - {"$set", bson.D{ - {"addressrange", network.AddressRange}, - {"displayname", network.DisplayName}, - {"defaultlistenport", network.DefaultListenPort}, - {"defaultpostup", network.DefaultPostUp}, - {"defaultpreup", network.DefaultPostDown}, - {"defaultkeepalive", network.DefaultKeepalive}, - {"defaultsaveconfig", network.DefaultSaveConfig}, - {"defaultinterface", network.DefaultInterface}, - {"nodeslastmodified", network.NodesLastModified}, - {"networklastmodified", network.NetworkLastModified}, - {"allowmanualsignup", network.AllowManualSignUp}, - {"localrange", network.LocalRange}, - {"islocal", network.IsLocal}, - {"defaultcheckininterval", network.DefaultCheckInInterval}, - }}, + // prepare update model. + update := bson.D{ + {"$set", bson.D{ + {"addressrange", network.AddressRange}, + {"displayname", network.DisplayName}, + {"defaultlistenport", network.DefaultListenPort}, + {"defaultpostup", network.DefaultPostUp}, + {"defaultpostdown", network.DefaultPostDown}, + {"defaultkeepalive", network.DefaultKeepalive}, + {"defaultsaveconfig", network.DefaultSaveConfig}, + {"defaultinterface", network.DefaultInterface}, + {"nodeslastmodified", network.NodesLastModified}, + {"networklastmodified", network.NetworkLastModified}, + {"allowmanualsignup", network.AllowManualSignUp}, + {"localrange", network.LocalRange}, + {"islocal", network.IsLocal}, + {"defaultcheckininterval", network.DefaultCheckInInterval}, + }}, } err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&network) diff --git a/controllers/nodeHttpController.go b/controllers/nodeHttpController.go index dfc6a33c4..1152afd97 100644 --- a/controllers/nodeHttpController.go +++ b/controllers/nodeHttpController.go @@ -686,7 +686,7 @@ func deleteGateway(w http.ResponseWriter, r *http.Request) { update := bson.D{ {"$set", bson.D{ {"postup", nodechange.PostUp}, - {"preup", nodechange.PostDown}, + {"postdown", nodechange.PostDown}, {"isgateway", nodechange.IsGateway}, {"gatewayrange", nodechange.GatewayRange}, {"lastmodified", nodechange.LastModified}, @@ -703,7 +703,7 @@ func deleteGateway(w http.ResponseWriter, r *http.Request) { return } - err = SetNetworkNodesLastModified(params["networkname"]) + err = SetNetworkNodesLastModified(params["network"]) if err != nil { returnErrorResponse(w,r,formatError(err, "internal")) return diff --git a/group_test.go b/group_test.go index 50bc65f04..674ac2a81 100644 --- a/group_test.go +++ b/group_test.go @@ -495,19 +495,19 @@ func TestUpdateNetwork(t *testing.T) { assert.Nil(t, err, err) assert.Equal(t, network.DefaultPostUp, returnedNetwork.DefaultPostUp) }) - t.Run("UpdatePreUP", func(t *testing.T) { + t.Run("UpdatePostDown", func(t *testing.T) { type Network struct { - DefaultPreUp string + DefaultPostDown string } var network Network - network.DefaultPreUp = "test string" + network.DefaultPostDown = "test string" response, err := api(t, network, http.MethodPut, "http://localhost:8081/api/networks/skynet", "secretkey") assert.Nil(t, err, err) assert.Equal(t, http.StatusOK, response.StatusCode) defer response.Body.Close() err = json.NewDecoder(response.Body).Decode(&returnedNetwork) assert.Nil(t, err, err) - assert.Equal(t, network.DefaultPreUp, returnedNetwork.DefaultPreUp) + assert.Equal(t, network.DefaultPostDown, returnedNetwork.DefaultPostDown) }) t.Run("UpdateKeepAlive", func(t *testing.T) { type Network struct { diff --git a/models/network.go b/models/network.go index 1a461e42c..4183f9baa 100644 --- a/models/network.go +++ b/models/network.go @@ -18,7 +18,7 @@ type Network struct { DefaultInterface string `json:"defaultinterface" bson:"defaultinterface"` DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,numeric,min=1024,max=65535"` DefaultPostUp string `json:"defaultpostup" bson:"defaultpostup"` - DefaultPostDown string `json:"defaultpreup" bson:"defaultpreup"` + DefaultPostDown string `json:"defaultpostdown" bson:"defaultpostdown"` KeyUpdateTimeStamp int64 `json:"keyupdatetimestamp" bson:"keyupdatetimestamp"` DefaultKeepalive int32 `json:"defaultkeepalive" bson:"defaultkeepalive" validate: "omitempty,numeric,max=1000"` DefaultSaveConfig *bool `json:"defaultsaveconfig" bson:"defaultsaveconfig"` diff --git a/models/returnNode.go b/models/returnNode.go index 2061605c9..df87c5ea7 100644 --- a/models/returnNode.go +++ b/models/returnNode.go @@ -12,7 +12,7 @@ type ReturnNode struct { PublicKey string `json:"publickey" bson:"publickey" validate:"base64"` Endpoint string `json:"endpoint" bson:"endpoint" validate:"required,ipv4"` PostUp string `json:"postup" bson:"postup"` - PostDown string `json:"preup" bson:"preup"` + PostDown string `json:"postdown" bson:"postdown"` PersistentKeepalive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"` SaveConfig *bool `json:"saveconfig" bson:"saveconfig"` Interface string `json:"interface" bson:"interface"` diff --git a/netclient/functions/common.go b/netclient/functions/common.go index 24b57720f..70783809b 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -1090,8 +1090,11 @@ func CheckIn(network string) error { if err != nil { fmt.Println("ERROR DELETING INTERFACE: " + currentiface) } - } err = setWGConfig(network) + if err != nil { + log.Printf("Error updating interface: %v", err) + } + } } if checkinres.Checkinresponse.Needconfigupdate { diff --git a/test/group_test.go b/test/group_test.go index 497715f8f..faeed90d5 100644 --- a/test/group_test.go +++ b/test/group_test.go @@ -472,7 +472,7 @@ func TestUpdateNetwork(t *testing.T) { assert.Nil(t, err, err) assert.Equal(t, network.DefaultPostUp, returnedNetwork.DefaultPostUp) }) - t.Run("UpdatePreUp", func(t *testing.T) { + t.Run("UpdatePostDown", func(t *testing.T) { // -------needs fixing ------ // mismatch in models.Network between struc name and json/bson name // does not get updated.