saving netclient changes

This commit is contained in:
afeiszli
2021-05-05 20:51:59 -04:00
parent 09e0eca54a
commit 1fd30c0a71
7 changed files with 105 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

60
netmaker-install-v3.sh Executable file
View File

@@ -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<<EOL
server:
host: "$SERVER_DOMAIN"
apiport: "8081"
grpcport: "50051"
masterkey: "secretkey"
allowedorigin: "*"
restbackend: true
agentbackend: true
defaultnetname: "default"
defaultnetrange: "10.10.10.0/24"
createdefault: true
mongoconn:
user: "mongoadmin"
pass: "mongopass"
host: "localhost"
port: "27017"
opts: '/?authSource=admin'
EOL
cat >/etc/netmaker/config/Corefile<<EOL
. {
hosts /root/netmaker.hosts
}
EOL
cat >/etc/systemd/system/netmaker.service<<EOL
[Unit]
Description=Netmaker Server
After=network.target
[Service]
Type=simple
Restart=on-failure
WorkingDirectory=/etc/netmaker
ExecStart=/etc/netmaker/netmaker
[Install]
WantedBy=multi-user.target
EOL
systemctl daemon-reload
systemctl start netmaker.service
docker run -d --name netmaker-ui -p 80:80 -e BACKEND_URL="http://$SERVER_DOMAIN:8081" gravitl/netmaker-ui:v0.2
docker run -d --name coredns --restart=always --volume=/etc/netmaker/config/:/root/ -p 52:53/udp coredns/coredns -conf /root/Corefile