diff --git a/main.go b/main.go index f4f9c15..3e0cfc5 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,10 @@ func movingTargetDefense(config state.Config) state.Config{ func indexAllInstances(config state.Config) state.Config { fmt.Println("Indexing instances") + for _, service := range config.MTD.Services { + service.Active = false + } + //index AWS instances awsNewInstanceCounter := 0 awsRemovedInstanceCounter := 0 @@ -77,9 +81,11 @@ func indexAllInstances(config state.Config) state.Config { func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (state.Config, bool) { found := false - for _, service := range config.MTD.Services { + var foundUUID state.CustomUUID + for u, service := range config.MTD.Services { if service.CloudID == cloudID { found = true + foundUUID = u break; } } @@ -87,9 +93,12 @@ func indexInstance(config state.Config, cloudID string, serviceIP netip.Addr) (s if !found { fmt.Println("New instance found:\t", cloudID) u := uuid.New() - config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP} + config.MTD.Services[state.CustomUUID(u)] = state.Service{CloudID: cloudID, ServiceIP: serviceIP, Active: true, AdminEnabled: true} state.SaveConf(ConfigPath, config) + } else { + config.MTD.Services[foundUUID] = state.Service{Active: true} + state.SaveConf(ConfigPath, config) } return config, found } diff --git a/mtdaws/mtd.go b/mtdaws/mtd.go index 7811a34..57633ca 100644 --- a/mtdaws/mtd.go +++ b/mtdaws/mtd.go @@ -68,16 +68,16 @@ func AWSMoveInstance(config state.Config) (state.Config) { return config } - if !isInstanceRunning(realInstance) { - fmt.Println("Error, Instance is not running!") - return config - } - if instance.AdminDisabled { + if !instance.AdminEnabled { fmt.Println("Error, Service is Disabled!") return config } - if instance.Inactive { - fmt.Println("Error, Service is Inactive!") + if !instance.Active { + fmt.Println("Error, Service is not active!") + return config + } + if !isInstanceRunning(realInstance) { + fmt.Println("Error, Instance is not running!") return config } diff --git a/state/config.go b/state/config.go index e96bfdb..67e3bee 100644 --- a/state/config.go +++ b/state/config.go @@ -24,8 +24,8 @@ type mtdconf struct { // Service contains all necessary information about a service to identify it in the cloud as well as configuring a proxy for it type Service struct { CloudID string `yaml:"cloud_id"` - AdminDisabled bool `yaml:"admin_disabled"` - Inactive bool `yaml:"inactive"` + AdminEnabled bool `yaml:"admin_enabled"` + Active bool `yaml:"active"` EntryIP netip.Addr `yaml:"entry_ip"` EntryPort uint16 `yaml:"entry_port"` ServiceIP netip.Addr `yaml:"service_ip"`