From 1fd30c0a71b34acee1283ceb9ed11a7654f39c20 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Wed, 5 May 2021 20:51:59 -0400 Subject: [PATCH] saving netclient changes --- functions/helpers.go | 1 + grpc/node.proto | 3 +- netclient/config/config.go | 2 ++ netclient/functions/common.go | 16 +++++++++- netclient/functions/local.go | 22 +++++++++++++ netclient/main.go | 5 +-- netmaker-install-v3.sh | 60 +++++++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 4 deletions(-) create mode 100755 netmaker-install-v3.sh diff --git a/functions/helpers.go b/functions/helpers.go index 7a9f89a9..13ea21eb 100644 --- a/functions/helpers.go +++ b/functions/helpers.go @@ -530,6 +530,7 @@ func UniqueAddress6(networkName string) (string, error) { var network models.Network network, err := GetParentNetwork(networkName) + dualstack := *network.IsDualStack if !*network.IsDualStack { return "", nil } diff --git a/grpc/node.proto b/grpc/node.proto index 2218cffd..a50f53b2 100644 --- a/grpc/node.proto +++ b/grpc/node.proto @@ -44,7 +44,8 @@ message Node { string postchanges = 21; string allowedips = 22; bool islocal = 23; - string localrange = 24; + bool dnsoff = 24; + string localrange = 25; } message CheckInResponse { diff --git a/netclient/config/config.go b/netclient/config/config.go index a0da4b02..dc5a0612 100644 --- a/netclient/config/config.go +++ b/netclient/config/config.go @@ -31,7 +31,9 @@ type NodeConfig struct { MacAddress string `yaml:"macaddress"` LocalAddress string `yaml:"localaddress"` WGAddress string `yaml:"wgaddress"` + WGAddress6 string `yaml:"wgaddress6"` RoamingOff bool `yaml:"roamingoff"` + DNSOff bool `yaml:"dnsoff"` IsLocal bool `yaml:"islocal"` AllowedIPs string `yaml:"allowedips"` LocalRange string `yaml:"localrange"` diff --git a/netclient/functions/common.go b/netclient/functions/common.go index 70783809..5aa2f46b 100644 --- a/netclient/functions/common.go +++ b/netclient/functions/common.go @@ -72,7 +72,7 @@ func GetFreePort(rangestart int32) (int32, error){ return portno, err } -func Install(accesskey string, password string, server string, network string, noauto bool, accesstoken string, inputname string) error { +func Install(accesskey string, password string, server string, network string, noauto bool, accesstoken string, inputname string, dnsoff bool) error { tserver := "" tnetwork := "" @@ -143,6 +143,8 @@ func Install(accesskey string, password string, server string, network string, n servercfg := cfg.Server fmt.Println("SERVER SETTINGS:") + nodecfg.DNSOff = dnsoff + if server == "" { if servercfg.Address == "" && tserver == "" { log.Fatal("no server provided") @@ -588,6 +590,9 @@ func modConfig(node *nodepb.Node) error{ if node.Address != ""{ nodecfg.WGAddress = node.Address } + if node.Address != ""{ + nodecfg.WGAddress = node.Address + } if node.Postchanges != "" { nodecfg.PostChanges = node.Postchanges } @@ -952,6 +957,15 @@ func CheckIn(network string) error { setupcheck := true ipchange := false + if !nodecfg.DNSOff { + vals := strings.Split(servercfg.Address, ":") + server := vals[0] + err = SetDNS(server) + if err != nil { + fmt.Printf("Error encountered setting dns: %v", err) + } + } + if !nodecfg.RoamingOff { if !nodecfg.IsLocal { fmt.Println("Checking to see if public addresses have changed") diff --git a/netclient/functions/local.go b/netclient/functions/local.go index c2962655..69011344 100644 --- a/netclient/functions/local.go +++ b/netclient/functions/local.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "io" + "strings" "log" "os" "os/exec" @@ -20,6 +21,27 @@ func FileExists(f string) bool { return !info.IsDir() } +func SetDNS(nameserver string) error { + bytes, err := ioutil.ReadFile("/etc/resolv.conf") + if err != nil { + return err + } + resolvstring := string(bytes) + // //check whether s contains substring text + hasdns := strings.Contains(resolvstring, nameserver) + if hasdns { + return nil + } + resolv, err := os.OpenFile("/etc/resolv.conf",os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer resolv.Close() + _, err = resolv.WriteString("nameserver " + nameserver + "\n") + + return err +} + func ConfigureSystemD(network string) error { /* path, err := os.Getwd() diff --git a/netclient/main.go b/netclient/main.go index 86247f09..cc466f1b 100644 --- a/netclient/main.go +++ b/netclient/main.go @@ -39,7 +39,8 @@ func main() { tname := flag.String("name", "noname", "give the node a name at runtime") tserver := flag.String("s", "localhost:50051", "The location (including port) of the remote gRPC server.") tnetwork := flag.String("n", "nonetwork", "The node network you are attempting to join.") - tnoauto := flag.Bool("na", false, "No auto mode. If true, netmclient will not be installed as a system service and you will have to retrieve updates manually via checkin command.") + tnoauto := flag.Bool("na", false, "No auto mode. If true, netclient will not be installed as a system service and you will have to retrieve updates manually via checkin command.") + tdnsoff := flag.Bool("dnsoff", false, "No dns mode. If true, netclient will not alter system dns.") tnoforward := flag.Bool("nf", false, "No Forward mode. If true, netclient will not check for IP forwarding. This may break functionality") command := flag.String("c", "required", "The command to run") @@ -108,7 +109,7 @@ func main() { } fmt.Println("Beginning agent installation.") - err := functions.Install(*taccesskey, *tpassword, *tserver, *tnetwork, *tnoauto, *taccesstoken, *tname) + err := functions.Install(*taccesskey, *tpassword, *tserver, *tnetwork, *tnoauto, *taccesstoken, *tname, *tdnsoff) if err != nil { fmt.Println("Error encountered while installing.") if !strings.Contains(err.Error(), "ALREADY_INSTALLED") { diff --git a/netmaker-install-v3.sh b/netmaker-install-v3.sh new file mode 100755 index 00000000..158000e0 --- /dev/null +++ b/netmaker-install-v3.sh @@ -0,0 +1,60 @@ +#!/bin/sh +set -e + +[ -z "$SERVER_DOMAIN" ] && echo "Need to set SERVER_DOMAIN (format: 1.2.3.4 or mybackend.com)" && exit 1; + + +docker volume create mongovol && docker run -d --name mongodb -v mongovol:/data/db --network host -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=mongopass mongo --bind_ip 0.0.0.0 + +mkdir -p /etc/netmaker/config/environments +wget -O /etc/netmaker/netmaker https://github.com/gravitl/netmaker/releases/download/latest/netmaker +chmod +x /etc/netmaker/netmaker + + +cat >/etc/netmaker/config/environments/dev.yaml</etc/netmaker/config/Corefile</etc/systemd/system/netmaker.service<