fixed server node problems

This commit is contained in:
afeiszli 2021-06-01 01:13:25 +00:00
parent 963a3d1b92
commit 71799992ff
2 changed files with 4 additions and 10 deletions

View file

@ -27,7 +27,6 @@ import (
//node has that value for the same field within the network
func CreateServerToken(netID string) (string, error) {
fmt.Println("Creating token.")
var network models.Network
var accesskey models.AccessKey
@ -46,12 +45,10 @@ func CreateServerToken(netID string) (string, error) {
privAddr = network.LocalRange
}
accessstringdec := address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
accessstringdec := address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
fmt.Println(" access string: " + accesskey.AccessString)
network.AccessKeys = append(network.AccessKeys, accesskey)
collection := mongoconn.Client.Database("netmaker").Collection("networks")

View file

@ -54,7 +54,6 @@ func CreateDefaultNetwork() (bool, error) {
if err == nil {
iscreated = true
}
log.Println("1")
return iscreated, err
@ -208,17 +207,14 @@ func AddNetwork(network string) (bool, error) {
log.Println("could not find or create /etc/netclient")
return false, err
}
log.Println("Directory is ready.")
token, err := functions.CreateServerToken(network)
if err != nil {
log.Println("could not create server token for " + network)
return false, err
}
log.Println("Token is ready.")
_, err = os.Stat("/etc/netclient/netclient")
if os.IsNotExist(err) {
err = DownloadNetclient()
log.Println("could not download netclient")
if err != nil {
return false, err
}
@ -228,9 +224,10 @@ func AddNetwork(network string) (bool, error) {
log.Println("could not change netclient directory permissions")
return false, err
}
log.Println("Client is ready. Running install.")
out, err := exec.Command("/etc/netclient/netclient","join","-t",token,"-name","netmaker","-endpoint",pubip).Output()
log.Println(string(out))
if string(out) != "" {
log.Println(string(out))
}
if err != nil {
return false, errors.New(string(out) + err.Error())
}