mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
testing port picker. issues with auto login. keep investigating. made issue
This commit is contained in:
@@ -17,14 +17,14 @@ import (
|
||||
func SetJWT(client nodepb.NodeServiceClient, network string) (context.Context, error) {
|
||||
//home, err := os.UserHomeDir()
|
||||
home := "/etc/netclient"
|
||||
tokentext, err := ioutil.ReadFile(home + "/nettoken")
|
||||
tokentext, err := ioutil.ReadFile(home + "/nettoken-"+network)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading token. Logging in to retrieve new token.")
|
||||
err = AutoLogin(client, network)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong with Auto Login: %v", err))
|
||||
}
|
||||
tokentext, err = ioutil.ReadFile(home + "/nettoken")
|
||||
tokentext, err = ioutil.ReadFile(home + "/nettoken-"+network)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong: %v", err))
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func AutoLogin(client nodepb.NodeServiceClient, network string) error {
|
||||
return err
|
||||
}
|
||||
tokenstring := []byte(res.Accesstoken)
|
||||
err = ioutil.WriteFile(home + "/nettoken", tokenstring, 0644)
|
||||
err = ioutil.WriteFile(home + "/nettoken-"+network, tokenstring, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -29,6 +29,51 @@ var (
|
||||
wcclient nodepb.NodeServiceClient
|
||||
)
|
||||
|
||||
func ListPorts() error{
|
||||
wgclient, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
devices, err := wgclient.Devices()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Here are your ports:")
|
||||
for _, i := range devices {
|
||||
fmt.Println(i.ListenPort)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetFreePort(rangestart int32) (int32, error){
|
||||
wgclient, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
devices, err := wgclient.Devices()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var portno int32
|
||||
portno = 0
|
||||
for x := rangestart; x <= 60000; x++ {
|
||||
conflict := false
|
||||
for _, i := range devices {
|
||||
if int32(i.ListenPort) == x {
|
||||
conflict = true
|
||||
break;
|
||||
}
|
||||
}
|
||||
if conflict {
|
||||
continue
|
||||
}
|
||||
portno = x
|
||||
break
|
||||
}
|
||||
return portno, err
|
||||
}
|
||||
|
||||
|
||||
func Install(accesskey string, password string, server string, group string, noauto bool, accesstoken string) error {
|
||||
|
||||
|
||||
@@ -206,7 +251,14 @@ func Install(accesskey string, password string, server string, group string, noa
|
||||
if nodecfg.Port != 0 {
|
||||
listenport = nodecfg.Port
|
||||
}
|
||||
fmt.Println(" Port: " + string(listenport))
|
||||
if listenport == 0 {
|
||||
listenport, err = GetFreePort(51821)
|
||||
if err != nil {
|
||||
fmt.Printf("Error retrieving port: %v", err)
|
||||
}
|
||||
}
|
||||
fmt.Printf(" Port: %v", listenport)
|
||||
fmt.Println("")
|
||||
|
||||
if nodecfg.PrivateKey != "" {
|
||||
privkeystring = nodecfg.PrivateKey
|
||||
@@ -942,7 +994,7 @@ func CheckIn(network string) error {
|
||||
_, err := net.InterfaceByName(iface)
|
||||
if err != nil {
|
||||
fmt.Println("interface " + iface + " does not currently exist. Setting up WireGuard.")
|
||||
err = setWGConfig(network)
|
||||
err = setWGKeyConfig(network, servercfg.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Fatalf("Error: %v", err)
|
||||
@@ -1076,7 +1128,7 @@ func WipeLocal(network string) error{
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = os.Remove(home + "/nettoken")
|
||||
err = os.Remove(home + "/nettoken-"+network)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
@@ -71,6 +71,13 @@ func main() {
|
||||
}
|
||||
|
||||
switch *command {
|
||||
case "getport":
|
||||
portno, err := functions.GetFreePort(51821)
|
||||
fmt.Printf("Port Number: %v", portno)
|
||||
fmt.Println("")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
case "required":
|
||||
fmt.Println("command flag 'c' is required. Pick one of |install|checkin|update|remove|")
|
||||
os.Exit(1)
|
||||
|
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
sudo ip link del wc-skynet
|
||||
|
||||
curl -X DELETE -H "Authorization: Bearer secretkey" -H 'Content-Type: application/json' localhost:8081/api/skynet/nodes/8c:89:a5:03:f0:d7 | jq
|
||||
|
||||
sudo cp /root/.netconfig.bkup /root/.netconfig
|
||||
sudo rm /root/.nettoken
|
||||
sudo go run ./main.go remove
|
||||
|
||||
sudo wg show
|
Reference in New Issue
Block a user