Browse Source

fixing model

afeiszli 3 years ago
parent
commit
b828f7b6d9

+ 2 - 2
controllers/nodeHttpController.go

@@ -506,7 +506,7 @@ func createEgressGateway(w http.ResponseWriter, r *http.Request) {
 
 func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, error) {
 	node, err := functions.GetNodeByMacAddress(gateway.NetID, gateway.NodeID)
-	if node.OS == "windows" { // add in darwin later
+	if node.OS == "windows" || node.OS == "macos" { // add in darwin later
 		return models.Node{}, errors.New(node.OS + " is unsupported for egress gateways")
 	}
 	if err != nil {
@@ -635,7 +635,7 @@ func createIngressGateway(w http.ResponseWriter, r *http.Request) {
 func CreateIngressGateway(netid string, macaddress string) (models.Node, error) {
 
 	node, err := functions.GetNodeByMacAddress(netid, macaddress)
-	if node.OS == "windows" { // add in darwin later
+	if node.OS == "windows" || node.OS == "macos" { // add in darwin later
 		return models.Node{}, errors.New(node.OS + " is unsupported for ingress gateways")
 	}
 

+ 1 - 1
controllers/relay.go

@@ -35,7 +35,7 @@ func createRelay(w http.ResponseWriter, r *http.Request) {
 
 func CreateRelay(relay models.RelayRequest) (models.Node, error) {
 	node, err := functions.GetNodeByMacAddress(relay.NetID, relay.NodeID)
-	if node.OS == "windows" { // add in darwin later
+	if node.OS == "windows" || node.OS == "macos" { // add in darwin later
 		return models.Node{}, errors.New(node.OS + " is unsupported for relay")
 	}
 	if err != nil {

+ 1 - 1
models/structs.go

@@ -132,5 +132,5 @@ type EgressGatewayRequest struct {
 type RelayRequest struct {
 	NodeID     string   `json:"nodeid" bson:"nodeid"`
 	NetID      string   `json:"netid" bson:"netid"`
-	RelayAddrs []string `json:"addrs" bson:"addrs"`
+	RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs"`
 }

+ 3 - 1
netclient/command/commands.go

@@ -37,7 +37,7 @@ func Join(cfg config.ClientConfig, privateKey string) error {
 				}
 			}
 			if cfg.Daemon != "off" {
-				if !netclientutils.IsWindows() {
+				if netclientutils.IsLinux() {
 					err = local.RemoveSystemDServices(cfg.Network)
 				}
 				if err != nil {
@@ -51,6 +51,8 @@ func Join(cfg config.ClientConfig, privateKey string) error {
 	if cfg.Daemon != "off" {
 		if netclientutils.IsWindows() {
 			err = local.CreateAndRunWindowsDaemon()
+		} else if netclientutils.IsMac() {
+			err = local.CreateAndRunMacDaemon()
 		} else {
 			err = functions.InstallDaemon(cfg)
 		}

+ 3 - 3
netclient/functions/checkin.go

@@ -166,7 +166,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
 			return nil, err
 		}
 	}
-	conn, err := grpc.Dial(cfg.Server.GRPCAddress, 
+	conn, err := grpc.Dial(cfg.Server.GRPCAddress,
 		netclientutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
 	if err != nil {
 		log.Println("Cant dial GRPC server:", err)
@@ -230,7 +230,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
 			}
 		}
 	}
-	if !netclientutils.IsWindows() {
+	if netclientutils.IsLinux() {
 		setDNS(&resNode, servercfg, &cfg.Node)
 	}
 
@@ -248,7 +248,7 @@ func Push(network string) error {
 	var header metadata.MD
 
 	var wcclient nodepb.NodeServiceClient
-	conn, err := grpc.Dial(cfg.Server.GRPCAddress, 
+	conn, err := grpc.Dial(cfg.Server.GRPCAddress,
 		netclientutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
 	if err != nil {
 		log.Println("Cant dial GRPC server:", err)

+ 6 - 3
netclient/functions/common.go

@@ -104,8 +104,11 @@ func Uninstall() error {
 	}
 	// clean up OS specific stuff
 	if netclientutils.IsWindows() {
-		local.Cleanup()
+		local.CleanupWindows()
+	} else if netclientutils.IsWindows() {
+		local.CleanupMac()
 	}
+
 	return err
 }
 
@@ -119,7 +122,7 @@ func LeaveNetwork(network string) error {
 	node := cfg.Node
 
 	var wcclient nodepb.NodeServiceClient
-	conn, err := grpc.Dial(cfg.Server.GRPCAddress, 
+	conn, err := grpc.Dial(cfg.Server.GRPCAddress,
 		netclientutils.GRPCRequestOpts(cfg.Server.GRPCSSL))
 	if err != nil {
 		log.Printf("Unable to establish client connection to "+servercfg.GRPCAddress+": %v", err)
@@ -183,7 +186,7 @@ func DeleteInterface(ifacename string, postdown string) error {
 		if err != nil {
 			log.Println(err)
 		}
-		_, err = local.RunCmd(ipExec + " link del " + ifacename, false)
+		_, err = local.RunCmd(ipExec+" link del "+ifacename, false)
 		if postdown != "" {
 			runcmds := strings.Split(postdown, "; ")
 			err = local.RunCmds(runcmds, true)

+ 20 - 7
netclient/local/windows.go

@@ -1,6 +1,7 @@
 package local
 
 import (
+	"errors"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -21,14 +22,14 @@ func IsWindowsWGInstalled() bool {
 }
 
 func ApplyWindowsConf(confPath string) error {
-	if _, err := RunCmd("wireguard.exe /installtunnelservice " + confPath, true); err != nil {
+	if _, err := RunCmd("wireguard.exe /installtunnelservice "+confPath, true); err != nil {
 		return err
 	}
 	return nil
 }
 
 func RemoveWindowsConf(ifacename string) error {
-	if _, err := RunCmd("wireguard.exe /uninstalltunnelservice " + ifacename, true); err != nil {
+	if _, err := RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, true); err != nil {
 		return err
 	}
 	return nil
@@ -58,12 +59,12 @@ func writeServiceConfig() error {
 func StopWindowsDaemon() {
 	netclientutils.Log("no networks detected, stopping Windows, Netclient daemon")
 	// stop daemon, will not overwrite
-	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe stop`, true)
+	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true)
 }
 
 func RemoveWindowsDaemon() {
 	// uninstall daemon, will not restart or start another
-	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe uninstall`, true)
+	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe uninstall`, true)
 	netclientutils.Log("uninstalled Windows, Netclient daemon")
 }
 
@@ -121,6 +122,11 @@ func downloadWinsw() error {
 	return nil
 }
 
+func CreateAndRunMacDaemon() error {
+	log.Println("TODO: Create Mac Daemon")
+	return errors.New("no mac daemon yet")
+}
+
 func CreateAndRunWindowsDaemon() error {
 
 	if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
@@ -144,14 +150,14 @@ func CreateAndRunWindowsDaemon() error {
 		netclientutils.Log("finished daemon setup")
 	}
 	// install daemon, will not overwrite
-	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe install`, true)
+	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, true)
 	// start daemon, will not restart or start another
-	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`, true)
+	RunCmd(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, true)
 	netclientutils.Log(strings.Replace(netclientutils.GetNetclientPathSpecific(), `\\`, `\`, -1) + `winsw.exe start`)
 	return nil
 }
 
-func Cleanup() {
+func CleanupWindows() {
 	if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
 		writeServiceConfig()
 	}
@@ -160,3 +166,10 @@ func Cleanup() {
 	os.RemoveAll(netclientutils.GetNetclientPath())
 	log.Println("Netclient on Windows, uninstalled")
 }
+
+func CleanupMac() {
+	//StopWindowsDaemon()
+	//RemoveWindowsDaemon()
+	//os.RemoveAll(netclientutils.GetNetclientPath())
+	log.Println("TODO: Not implemented yet")
+}

+ 12 - 3
netclient/netclientutils/netclientutils.go

@@ -1,6 +1,7 @@
 package netclientutils
 
 import (
+	"crypto/tls"
 	"errors"
 	"fmt"
 	"io/ioutil"
@@ -13,11 +14,11 @@ import (
 	"strconv"
 	"strings"
 	"time"
-	"crypto/tls"
-	"google.golang.org/grpc"
-	"google.golang.org/grpc/credentials"
+
 	"golang.zx2c4.com/wireguard/wgctrl"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
+	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials"
 )
 
 const NO_DB_RECORD = "no result found"
@@ -37,6 +38,14 @@ func IsWindows() bool {
 	return runtime.GOOS == "windows"
 }
 
+func IsMac() bool {
+	return runtime.GOOS == "macos"
+}
+
+func IsLinux() bool {
+	return runtime.GOOS == "linux"
+}
+
 // == database returned nothing error ==
 func IsEmptyRecord(err error) bool {
 	if err == nil {