mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +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) {
|
||||
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")
|
||||
}
|
||||
|
||||
|
@@ -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 {
|
||||
|
@@ -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"`
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -230,7 +230,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !netclientutils.IsWindows() {
|
||||
if netclientutils.IsLinux() {
|
||||
setDNS(&resNode, servercfg, &cfg.Node)
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
@@ -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")
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user