mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
saving netclient changes
This commit is contained in:
@@ -530,6 +530,7 @@ func UniqueAddress6(networkName string) (string, error) {
|
|||||||
|
|
||||||
var network models.Network
|
var network models.Network
|
||||||
network, err := GetParentNetwork(networkName)
|
network, err := GetParentNetwork(networkName)
|
||||||
|
dualstack := *network.IsDualStack
|
||||||
if !*network.IsDualStack {
|
if !*network.IsDualStack {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
@@ -44,7 +44,8 @@ message Node {
|
|||||||
string postchanges = 21;
|
string postchanges = 21;
|
||||||
string allowedips = 22;
|
string allowedips = 22;
|
||||||
bool islocal = 23;
|
bool islocal = 23;
|
||||||
string localrange = 24;
|
bool dnsoff = 24;
|
||||||
|
string localrange = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CheckInResponse {
|
message CheckInResponse {
|
||||||
|
@@ -31,7 +31,9 @@ type NodeConfig struct {
|
|||||||
MacAddress string `yaml:"macaddress"`
|
MacAddress string `yaml:"macaddress"`
|
||||||
LocalAddress string `yaml:"localaddress"`
|
LocalAddress string `yaml:"localaddress"`
|
||||||
WGAddress string `yaml:"wgaddress"`
|
WGAddress string `yaml:"wgaddress"`
|
||||||
|
WGAddress6 string `yaml:"wgaddress6"`
|
||||||
RoamingOff bool `yaml:"roamingoff"`
|
RoamingOff bool `yaml:"roamingoff"`
|
||||||
|
DNSOff bool `yaml:"dnsoff"`
|
||||||
IsLocal bool `yaml:"islocal"`
|
IsLocal bool `yaml:"islocal"`
|
||||||
AllowedIPs string `yaml:"allowedips"`
|
AllowedIPs string `yaml:"allowedips"`
|
||||||
LocalRange string `yaml:"localrange"`
|
LocalRange string `yaml:"localrange"`
|
||||||
|
@@ -72,7 +72,7 @@ func GetFreePort(rangestart int32) (int32, error){
|
|||||||
return portno, err
|
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 := ""
|
tserver := ""
|
||||||
tnetwork := ""
|
tnetwork := ""
|
||||||
@@ -143,6 +143,8 @@ func Install(accesskey string, password string, server string, network string, n
|
|||||||
servercfg := cfg.Server
|
servercfg := cfg.Server
|
||||||
fmt.Println("SERVER SETTINGS:")
|
fmt.Println("SERVER SETTINGS:")
|
||||||
|
|
||||||
|
nodecfg.DNSOff = dnsoff
|
||||||
|
|
||||||
if server == "" {
|
if server == "" {
|
||||||
if servercfg.Address == "" && tserver == "" {
|
if servercfg.Address == "" && tserver == "" {
|
||||||
log.Fatal("no server provided")
|
log.Fatal("no server provided")
|
||||||
@@ -588,6 +590,9 @@ func modConfig(node *nodepb.Node) error{
|
|||||||
if node.Address != ""{
|
if node.Address != ""{
|
||||||
nodecfg.WGAddress = node.Address
|
nodecfg.WGAddress = node.Address
|
||||||
}
|
}
|
||||||
|
if node.Address != ""{
|
||||||
|
nodecfg.WGAddress = node.Address
|
||||||
|
}
|
||||||
if node.Postchanges != "" {
|
if node.Postchanges != "" {
|
||||||
nodecfg.PostChanges = node.Postchanges
|
nodecfg.PostChanges = node.Postchanges
|
||||||
}
|
}
|
||||||
@@ -952,6 +957,15 @@ func CheckIn(network string) error {
|
|||||||
setupcheck := true
|
setupcheck := true
|
||||||
ipchange := false
|
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.RoamingOff {
|
||||||
if !nodecfg.IsLocal {
|
if !nodecfg.IsLocal {
|
||||||
fmt.Println("Checking to see if public addresses have changed")
|
fmt.Println("Checking to see if public addresses have changed")
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -20,6 +21,27 @@ func FileExists(f string) bool {
|
|||||||
return !info.IsDir()
|
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 {
|
func ConfigureSystemD(network string) error {
|
||||||
/*
|
/*
|
||||||
path, err := os.Getwd()
|
path, err := os.Getwd()
|
||||||
|
@@ -39,7 +39,8 @@ func main() {
|
|||||||
tname := flag.String("name", "noname", "give the node a name at runtime")
|
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.")
|
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.")
|
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")
|
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")
|
command := flag.String("c", "required", "The command to run")
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Beginning agent installation.")
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Error encountered while installing.")
|
fmt.Println("Error encountered while installing.")
|
||||||
if !strings.Contains(err.Error(), "ALREADY_INSTALLED") {
|
if !strings.Contains(err.Error(), "ALREADY_INSTALLED") {
|
||||||
|
60
netmaker-install-v3.sh
Executable file
60
netmaker-install-v3.sh
Executable 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
|
Reference in New Issue
Block a user