mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-16 22:01:19 +08:00
fixed netclient
This commit is contained in:
@@ -44,9 +44,10 @@ func CreateServerToken(netID string) (string, error) {
|
|||||||
if *network.IsLocal {
|
if *network.IsLocal {
|
||||||
privAddr = network.LocalRange
|
privAddr = network.LocalRange
|
||||||
}
|
}
|
||||||
|
accessstringdec := servercfg.GetGRPCWGPort() + "|" + address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
|
||||||
|
|
||||||
accessstringdec := " " + "|"+ address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
|
|
||||||
|
|
||||||
|
log.Println("Access String: " + accessstringdec)
|
||||||
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
|
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
|
||||||
|
|
||||||
network.AccessKeys = append(network.AccessKeys, accesskey)
|
network.AccessKeys = append(network.AccessKeys, accesskey)
|
||||||
|
@@ -8,11 +8,11 @@ type IntClient struct {
|
|||||||
Address string `json:"address" bson:"address"`
|
Address string `json:"address" bson:"address"`
|
||||||
Address6 string `json:"address6" bson:"address6"`
|
Address6 string `json:"address6" bson:"address6"`
|
||||||
Network string `json:"network" bson:"network"`
|
Network string `json:"network" bson:"network"`
|
||||||
ServerPublicEndpoint string `json:"serverwgendpoint" bson:"serverwgendpoint"`
|
ServerPublicEndpoint string `json:"serverpublicendpoint" bson:"serverpublicendpoint"`
|
||||||
ServerAPIPort string `json:"serverapiendpoint" bson:"serverapiendpoint"`
|
ServerAPIPort string `json:"serverapiport" bson:"serverapiport"`
|
||||||
ServerPrivateAddress string `json:"serveraddress" bson:"serveraddress"`
|
ServerPrivateAddress string `json:"serverprivateaddress" bson:"serverprivateaddress"`
|
||||||
ServerWGPort string `json:"serverport" bson:"serverport"`
|
ServerWGPort string `json:"serverwgport" bson:"serverwgport"`
|
||||||
ServerGRPCPort string `json:"serverport" bson:"serverport"`
|
ServerGRPCPort string `json:"servergrpcport" bson:"servergrpcport"`
|
||||||
ServerKey string `json:"serverkey" bson:"serverkey"`
|
ServerKey string `json:"serverkey" bson:"serverkey"`
|
||||||
IsServer string `json:"isserver" bson:"isserver"`
|
IsServer string `json:"isserver" bson:"isserver"`
|
||||||
}
|
}
|
||||||
|
@@ -273,6 +273,13 @@ func ModGlobalConfig(cfg models.IntClient) error{
|
|||||||
if cfg.ServerKey != ""{
|
if cfg.ServerKey != ""{
|
||||||
modconfig.Client.ServerKey = cfg.ServerKey
|
modconfig.Client.ServerKey = cfg.ServerKey
|
||||||
}
|
}
|
||||||
|
if cfg.AccessKey != ""{
|
||||||
|
modconfig.Client.AccessKey = cfg.AccessKey
|
||||||
|
}
|
||||||
|
if cfg.ClientID != ""{
|
||||||
|
modconfig.Client.ClientID = cfg.ClientID
|
||||||
|
}
|
||||||
|
|
||||||
err = WriteGlobal(&modconfig)
|
err = WriteGlobal(&modconfig)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,8 @@ func Register(cfg config.GlobalConfig) error {
|
|||||||
return errors.New("request to server failed: " + res.Status)
|
return errors.New("request to server failed: " + res.Status)
|
||||||
}
|
}
|
||||||
bodyBytes, err := ioutil.ReadAll(res.Body)
|
bodyBytes, err := ioutil.ReadAll(res.Body)
|
||||||
|
bodyString := string(bodyBytes)
|
||||||
|
spew.Dump(bodyString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -74,6 +76,7 @@ func Register(cfg config.GlobalConfig) error {
|
|||||||
func Unregister(cfg config.GlobalConfig) error {
|
func Unregister(cfg config.GlobalConfig) error {
|
||||||
client := &http.Client{ Timeout: 7 * time.Second,}
|
client := &http.Client{ Timeout: 7 * time.Second,}
|
||||||
publicaddress := cfg.Client.ServerPublicEndpoint + ":" + cfg.Client.ServerAPIPort
|
publicaddress := cfg.Client.ServerPublicEndpoint + ":" + cfg.Client.ServerAPIPort
|
||||||
|
log.Println("sending delete request to: " + "http://"+publicaddress+"/api/intclient/"+cfg.Client.ClientID)
|
||||||
req, err := http.NewRequest("DELETE", "http://"+publicaddress+"/api/intclient/"+cfg.Client.ClientID, nil)
|
req, err := http.NewRequest("DELETE", "http://"+publicaddress+"/api/intclient/"+cfg.Client.ClientID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -94,17 +97,3 @@ func Unregister(cfg config.GlobalConfig) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reregister(cfg config.GlobalConfig) error {
|
|
||||||
err := Unregister(cfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("failed to un-register")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = Register(cfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("failed to re-register after unregistering")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -199,22 +199,6 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "reregister",
|
|
||||||
Usage: "Re-Register with Netmaker Server for secure GRPC communications.",
|
|
||||||
Flags: cliFlags,
|
|
||||||
Action: func(c *cli.Context) error {
|
|
||||||
cfg, err := config.ReadGlobalConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var gconf config.GlobalConfig
|
|
||||||
gconf = *cfg
|
|
||||||
|
|
||||||
err = command.Reregister(gconf)
|
|
||||||
return err
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "join",
|
Name: "join",
|
||||||
Usage: "Join a Netmaker network.",
|
Usage: "Join a Netmaker network.",
|
||||||
|
Reference in New Issue
Block a user