mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-12 20:20:52 +08:00
fixing model
This commit is contained in:
@@ -506,7 +506,7 @@ func createEgressGateway(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, error) {
|
func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, error) {
|
||||||
node, err := functions.GetNodeByMacAddress(gateway.NetID, gateway.NodeID)
|
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")
|
return models.Node{}, errors.New(node.OS + " is unsupported for egress gateways")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -635,7 +635,7 @@ func createIngressGateway(w http.ResponseWriter, r *http.Request) {
|
|||||||
func CreateIngressGateway(netid string, macaddress string) (models.Node, error) {
|
func CreateIngressGateway(netid string, macaddress string) (models.Node, error) {
|
||||||
|
|
||||||
node, err := functions.GetNodeByMacAddress(netid, macaddress)
|
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")
|
return models.Node{}, errors.New(node.OS + " is unsupported for ingress gateways")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ func createRelay(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func CreateRelay(relay models.RelayRequest) (models.Node, error) {
|
func CreateRelay(relay models.RelayRequest) (models.Node, error) {
|
||||||
node, err := functions.GetNodeByMacAddress(relay.NetID, relay.NodeID)
|
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")
|
return models.Node{}, errors.New(node.OS + " is unsupported for relay")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -132,5 +132,5 @@ type EgressGatewayRequest struct {
|
|||||||
type RelayRequest struct {
|
type RelayRequest struct {
|
||||||
NodeID string `json:"nodeid" bson:"nodeid"`
|
NodeID string `json:"nodeid" bson:"nodeid"`
|
||||||
NetID string `json:"netid" bson:"netid"`
|
NetID string `json:"netid" bson:"netid"`
|
||||||
RelayAddrs []string `json:"addrs" bson:"addrs"`
|
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs"`
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ func Join(cfg config.ClientConfig, privateKey string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cfg.Daemon != "off" {
|
if cfg.Daemon != "off" {
|
||||||
if !netclientutils.IsWindows() {
|
if netclientutils.IsLinux() {
|
||||||
err = local.RemoveSystemDServices(cfg.Network)
|
err = local.RemoveSystemDServices(cfg.Network)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,6 +51,8 @@ func Join(cfg config.ClientConfig, privateKey string) error {
|
|||||||
if cfg.Daemon != "off" {
|
if cfg.Daemon != "off" {
|
||||||
if netclientutils.IsWindows() {
|
if netclientutils.IsWindows() {
|
||||||
err = local.CreateAndRunWindowsDaemon()
|
err = local.CreateAndRunWindowsDaemon()
|
||||||
|
} else if netclientutils.IsMac() {
|
||||||
|
err = local.CreateAndRunMacDaemon()
|
||||||
} else {
|
} else {
|
||||||
err = functions.InstallDaemon(cfg)
|
err = functions.InstallDaemon(cfg)
|
||||||
}
|
}
|
||||||
|
@@ -230,7 +230,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !netclientutils.IsWindows() {
|
if netclientutils.IsLinux() {
|
||||||
setDNS(&resNode, servercfg, &cfg.Node)
|
setDNS(&resNode, servercfg, &cfg.Node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,8 +104,11 @@ func Uninstall() error {
|
|||||||
}
|
}
|
||||||
// clean up OS specific stuff
|
// clean up OS specific stuff
|
||||||
if netclientutils.IsWindows() {
|
if netclientutils.IsWindows() {
|
||||||
local.Cleanup()
|
local.CleanupWindows()
|
||||||
|
} else if netclientutils.IsWindows() {
|
||||||
|
local.CleanupMac()
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -121,6 +122,11 @@ func downloadWinsw() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateAndRunMacDaemon() error {
|
||||||
|
log.Println("TODO: Create Mac Daemon")
|
||||||
|
return errors.New("no mac daemon yet")
|
||||||
|
}
|
||||||
|
|
||||||
func CreateAndRunWindowsDaemon() error {
|
func CreateAndRunWindowsDaemon() error {
|
||||||
|
|
||||||
if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
|
if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
|
||||||
@@ -151,7 +157,7 @@ func CreateAndRunWindowsDaemon() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Cleanup() {
|
func CleanupWindows() {
|
||||||
if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
|
if !FileExists(netclientutils.GetNetclientPathSpecific() + "winsw.xml") {
|
||||||
writeServiceConfig()
|
writeServiceConfig()
|
||||||
}
|
}
|
||||||
@@ -160,3 +166,10 @@ func Cleanup() {
|
|||||||
os.RemoveAll(netclientutils.GetNetclientPath())
|
os.RemoveAll(netclientutils.GetNetclientPath())
|
||||||
log.Println("Netclient on Windows, uninstalled")
|
log.Println("Netclient on Windows, uninstalled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CleanupMac() {
|
||||||
|
//StopWindowsDaemon()
|
||||||
|
//RemoveWindowsDaemon()
|
||||||
|
//os.RemoveAll(netclientutils.GetNetclientPath())
|
||||||
|
log.Println("TODO: Not implemented yet")
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package netclientutils
|
package netclientutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -13,11 +14,11 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"crypto/tls"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/credentials"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
const NO_DB_RECORD = "no result found"
|
const NO_DB_RECORD = "no result found"
|
||||||
@@ -37,6 +38,14 @@ func IsWindows() bool {
|
|||||||
return runtime.GOOS == "windows"
|
return runtime.GOOS == "windows"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsMac() bool {
|
||||||
|
return runtime.GOOS == "macos"
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsLinux() bool {
|
||||||
|
return runtime.GOOS == "linux"
|
||||||
|
}
|
||||||
|
|
||||||
// == database returned nothing error ==
|
// == database returned nothing error ==
|
||||||
func IsEmptyRecord(err error) bool {
|
func IsEmptyRecord(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Reference in New Issue
Block a user