// UpgradeConfig updates the config, if needed. func UpgradeConfig() (bool, error) { currentConrfigMu.Lock() defer currentConrfigMu.Unlock() if !currentConfig.configRead { return false, errors.New("config not read") } prevVer := currentConfig.Settings.Version switch currentConfig.Settings.Version { case 0: // when config file was created from template currentConfig.Settings.Version = 1 fallthrough case 1: lg.Infoln("updating configuration to v1") m := &modifyConnections{ Connections: currentConfig.Settings.Connections, Add: []string{ "aieyJ0Ijoib2JmczQiLCJzIjoiXCJjZXJ0PUdzVFAxVmNwcjBJeE9aUkNnUHZ0Z1JsZVJWQzFTRmpYWVhxSDVvSEhYVFJ4M25QVnZXN2xHK2RkREhKWmw4YjBOVFZ1VGc7aWF0LW1vZGU9MFwiIiwiYSI6IjEzOS4xNjIuMjIxLjEyMzo0NDMifQ==", "aieyJ0Ijoib2JmczQiLCJzIjoiXCJjZXJ0PTMzdXNkSUVDemFyRUpsWFpQM0w0Y2x0bi9vNXdhVUlOcHRUU0JSYk5BQVpVcVlsajhiZm5MWGYyb3BFNHE2c0NlYzY3Ync7aWF0LW1vZGU9MFwiIiwiYSI6IjQ2LjIxLjEwMi4xMDk6NDQzIn0=", }, Remove: []string{ // NOTE: old hash function used, not a current format ID "xFa9T1i6bJMJIvK6kxFA1xvQGfW58BY3OLkrPXbpvAY=", }, } currentConfig.Settings.Connections = m.Update() currentConfig.Settings.Version = 2 fallthrough case 2: m := &modifyConnections{ Connections: currentConfig.Settings.Connections, Protect: []string{ "z0VZS-Kx9tMfoBEyX6br19GaJgKDe0IK0i6JKyhKp2s", "ipJ2oW8xr9TFDvfU92qGvDaPwZttf_GSjGZ4KW7inBI", }, Remove: []string{ "Ul3D2G1dI3_Z4sLXQ9IUQdIFH4pSDyNjTwf_auy93Os", }, } currentConfig.Settings.Connections = m.Update() currentConfig.Settings.Version = 3 fallthrough case 3: key := browsercode.NewKey() currentConfig.Settings.Local.ClientAuthKey = key currentConfig.Settings.Local.ClientBindAddr = "127.0.0.1:8899" currentConfig.Settings.Version = 4 fallthrough case 4: lg.Infoln("Settings version", currentConfig.Settings.Version) default: lg.Errorln("Future configuration version!", currentConfig.Settings.Version) } return currentConfig.Settings.Version != prevVer, nil }
// UpgradeConfig updates the config, if needed. func UpgradeConfig() (bool, error) { currentConrfigMu.Lock() if centralAddr == "" { centralAddr = "https://localhost:8080" lg.Warningln("WARNING centralAddr not set, defaulting to dev value: ", centralAddr) } defer currentConrfigMu.Unlock() if !currentConfig.configRead { return false, errors.New("config not read") } prevVer := currentConfig.Settings.Version switch currentConfig.Settings.Version { case 0: // when config file was created from template currentConfig.Settings.Version = 1 currentConfig.Settings.Local.CentralAddr = centralAddr fallthrough case 1: lg.Infoln("updating configuration to v1") m := &modifyConnections{ Connections: currentConfig.Settings.Connections, Add: []string{ "aieyJ0Ijoib2JmczQiLCJzIjoiXCJjZXJ0PUdzVFAxVmNwcjBJeE9aUkNnUHZ0Z1JsZVJWQzFTRmpYWVhxSDVvSEhYVFJ4M25QVnZXN2xHK2RkREhKWmw4YjBOVFZ1VGc7aWF0LW1vZGU9MFwiIiwiYSI6IjEzOS4xNjIuMjIxLjEyMzo0NDMifQ==", "aieyJ0Ijoib2JmczQiLCJzIjoiXCJjZXJ0PTMzdXNkSUVDemFyRUpsWFpQM0w0Y2x0bi9vNXdhVUlOcHRUU0JSYk5BQVpVcVlsajhiZm5MWGYyb3BFNHE2c0NlYzY3Ync7aWF0LW1vZGU9MFwiIiwiYSI6IjQ2LjIxLjEwMi4xMDk6NDQzIn0=", }, Remove: []string{ // NOTE: old hash function used, not a current format ID "xFa9T1i6bJMJIvK6kxFA1xvQGfW58BY3OLkrPXbpvAY=", }, } currentConfig.Settings.Connections = m.Update() currentConfig.Settings.Version = 2 fallthrough case 2: m := &modifyConnections{ Connections: currentConfig.Settings.Connections, Protect: []string{ "z0VZS-Kx9tMfoBEyX6br19GaJgKDe0IK0i6JKyhKp2s", "ipJ2oW8xr9TFDvfU92qGvDaPwZttf_GSjGZ4KW7inBI", }, Remove: []string{ "Ul3D2G1dI3_Z4sLXQ9IUQdIFH4pSDyNjTwf_auy93Os", }, } currentConfig.Settings.Connections = m.Update() currentConfig.Settings.Version = 3 fallthrough case 3: key := browsercode.NewKey() currentConfig.Settings.Local.ClientAuthKey = key currentConfig.Settings.Local.ClientBindAddr = "127.0.0.1:8899" currentConfig.Settings.Version = 4 fallthrough case 4: // If the beta url to central server was set, replace it with the default value s := md5.New() s.Write([]byte(currentConfig.Settings.Local.CentralAddr)) hsum := hex.EncodeToString(s.Sum(nil)) if hsum == "796547bd38f0d8722c2e0802de34b53f" { currentConfig.Settings.Local.CentralAddr = centralAddr } currentConfig.Settings.Version = 5 fallthrough case 5: m := &modifyConnections{ Connections: currentConfig.Settings.Connections, Remove: []string{ "ipJ2oW8xr9TFDvfU92qGvDaPwZttf_GSjGZ4KW7inBI", }, Add: []string{ "aieyJ0Ijoib2JmczQiLCJzIjoiXCJjZXJ0PWpvaUcwTFdzYmNDUWIvSG5zOWlWKytvUzMvSDBORGZ0RlJDRnZNbEpiYjRNZXByYThLZ2tLS2tMWDVaK3ZIV3M4ZWliQmc7aWF0LW1vZGU9MFwiIiwiYSI6IjEyOC4xOTkuOTkuMTY0OjQ0MyJ9", }, } currentConfig.Settings.Connections = m.Update() currentConfig.Settings.Version = 6 fallthrough case 6: lg.Infoln("Settings version", currentConfig.Settings.Version) default: lg.Errorln("Future configuration version!", currentConfig.Settings.Version) } return currentConfig.Settings.Version != prevVer, nil }