mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 00:43:58 +08:00
GRA-408: wipe local fix
This commit is contained in:
@@ -264,32 +264,28 @@ func ReadConfig(network string) (*ClientConfig, error) {
|
|||||||
err := errors.New("no network provided - exiting")
|
err := errors.New("no network provided - exiting")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nofile := false
|
|
||||||
home := ncutils.GetNetclientPathSpecific()
|
home := ncutils.GetNetclientPathSpecific()
|
||||||
file := fmt.Sprintf(home + "netconfig-" + network)
|
file := fmt.Sprintf(home + "netconfig-" + network)
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err = ReplaceWithBackup(network); err != nil {
|
if err = ReplaceWithBackup(network); err != nil {
|
||||||
nofile = true
|
return nil, err
|
||||||
}
|
}
|
||||||
f, err = os.Open(file)
|
f, err = os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nofile = true
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
var cfg ClientConfig
|
var cfg ClientConfig
|
||||||
|
decoder := yaml.NewDecoder(f)
|
||||||
if !nofile {
|
err = decoder.Decode(&cfg)
|
||||||
decoder := yaml.NewDecoder(f)
|
if err != nil {
|
||||||
err = decoder.Decode(&cfg)
|
logger.Log(2, "trouble decoding file", err.Error())
|
||||||
if err != nil {
|
return nil, err
|
||||||
fmt.Println("trouble decoding file")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cfg, err
|
return &cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -193,7 +193,6 @@ func LeaveNetwork(network string) error {
|
|||||||
if wgErr == nil && removeIface != "" {
|
if wgErr == nil && removeIface != "" {
|
||||||
removeIface = macIface
|
removeIface = macIface
|
||||||
}
|
}
|
||||||
wgErr = nil
|
|
||||||
}
|
}
|
||||||
dev, devErr := wgClient.Device(removeIface)
|
dev, devErr := wgClient.Device(removeIface)
|
||||||
if devErr == nil {
|
if devErr == nil {
|
||||||
@@ -224,18 +223,24 @@ func DeleteInterface(ifacename string, postdown string) error {
|
|||||||
|
|
||||||
// WipeLocal - wipes local instance
|
// WipeLocal - wipes local instance
|
||||||
func WipeLocal(network string) error {
|
func WipeLocal(network string) error {
|
||||||
cfg, err := config.ReadConfig(network)
|
var ifacename string
|
||||||
if err != nil {
|
|
||||||
return err
|
if network == "" {
|
||||||
|
return errors.New("no network provided")
|
||||||
}
|
}
|
||||||
nodecfg := cfg.Node
|
cfg, err := config.ReadConfig(network)
|
||||||
ifacename := nodecfg.Interface
|
if err == nil {
|
||||||
if ifacename != "" {
|
nodecfg := cfg.Node
|
||||||
if err = wireguard.RemoveConf(ifacename, true); err == nil {
|
ifacename = nodecfg.Interface
|
||||||
logger.Log(1, "network:", nodecfg.Network, "removed WireGuard interface: ", ifacename)
|
if ifacename != "" {
|
||||||
} else if strings.Contains(err.Error(), "does not exist") {
|
if err = wireguard.RemoveConf(ifacename, true); err == nil {
|
||||||
err = nil
|
logger.Log(1, "network:", nodecfg.Network, "removed WireGuard interface: ", ifacename)
|
||||||
|
} else if strings.Contains(err.Error(), "does not exist") {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.Log(0, "failed to read "+network+" config: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
home := ncutils.GetNetclientPathSpecific()
|
home := ncutils.GetNetclientPathSpecific()
|
||||||
@@ -281,17 +286,20 @@ func WipeLocal(network string) error {
|
|||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ncutils.FileExists(home + ifacename + ".conf") {
|
if ifacename != "" {
|
||||||
err = os.Remove(home + ifacename + ".conf")
|
if ncutils.FileExists(home + ifacename + ".conf") {
|
||||||
|
err = os.Remove(home + ifacename + ".conf")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error removing .conf:")
|
||||||
|
log.Println(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = removeHostDNS(ifacename, ncutils.IsWindows())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error removing .conf:")
|
logger.Log(0, "failed to delete dns entries for", ifacename, err.Error())
|
||||||
log.Println(err.Error())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = removeHostDNS(ifacename, ncutils.IsWindows())
|
|
||||||
if err != nil {
|
|
||||||
logger.Log(0, "failed to delete dns entries for", ifacename, err.Error())
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user