fixing model

This commit is contained in:
afeiszli
2021-09-18 11:01:34 -04:00
parent 74b15a6a13
commit b828f7b6d9
8 changed files with 48 additions and 21 deletions

View File

@@ -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")
}

View File

@@ -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 {

View File

@@ -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"`
}

View File

@@ -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)
}

View File

@@ -230,7 +230,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
}
}
}
if !netclientutils.IsWindows() {
if netclientutils.IsLinux() {
setDNS(&resNode, servercfg, &cfg.Node)
}

View File

@@ -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
}

View File

@@ -1,6 +1,7 @@
package local
import (
"errors"
"fmt"
"io"
"io/ioutil"
@@ -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") {
@@ -151,7 +157,7 @@ func CreateAndRunWindowsDaemon() error {
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")
}

View File

@@ -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 {