mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-02 18:04:23 +08:00
changed logs
This commit is contained in:
parent
1c521934ba
commit
382901b124
17 changed files with 82 additions and 126 deletions
|
@ -73,10 +73,6 @@ func readConfig() *EnvironmentConfig {
|
|||
f, err := os.Open(file)
|
||||
var cfg EnvironmentConfig
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
//os.Exit(2)
|
||||
//log.Println("Unable to open config file at config/environments/" + getEnv())
|
||||
//log.Println("Will proceed with defaults or enironment variables (no config file).")
|
||||
return &cfg
|
||||
}
|
||||
defer f.Close()
|
||||
|
|
|
@ -2,11 +2,9 @@ package controller
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
|
@ -23,20 +21,19 @@ func GetPeersList(networkName string) ([]models.Node, error) {
|
|||
if database.IsEmptyRecord(err) {
|
||||
return peers, nil
|
||||
}
|
||||
log.Println(err)
|
||||
functions.PrintUserLog("",err.Error(),2)
|
||||
return nil, err
|
||||
}
|
||||
udppeers, errN := database.GetPeers(networkName)
|
||||
if errN != nil {
|
||||
log.Println("failed to collect udp peers")
|
||||
log.Println(errN)
|
||||
functions.PrintUserLog("",errN.Error(),2)
|
||||
}
|
||||
for _, value := range collection {
|
||||
var node models.Node
|
||||
var peer models.Node
|
||||
err := json.Unmarshal([]byte(value), &node)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
functions.PrintUserLog("",err.Error(),2)
|
||||
continue
|
||||
}
|
||||
if node.IsEgressGateway == "yes" { // handle egress stuff
|
||||
|
@ -62,7 +59,7 @@ func GetPeersList(networkName string) ([]models.Node, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
functions.PrintUserLog("netmaker", "sending peer "+peer.MacAddress+" "+peer.Endpoint, 2)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "sending peer "+peer.MacAddress+" "+peer.Endpoint, 2)
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
}
|
||||
|
@ -87,12 +84,12 @@ func GetExtPeersList(macaddress string, networkName string) ([]models.ExtPeersRe
|
|||
var extClient models.ExtClient
|
||||
err = json.Unmarshal([]byte(value), &peer)
|
||||
if err != nil {
|
||||
functions.PrintUserLog("netmaker", "failed to unmarshal peer", 2)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "failed to unmarshal peer", 2)
|
||||
continue
|
||||
}
|
||||
err = json.Unmarshal([]byte(value), &extClient)
|
||||
if err != nil {
|
||||
functions.PrintUserLog("netmaker", "failed to unmarshal ext client", 2)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "failed to unmarshal ext client", 2)
|
||||
continue
|
||||
}
|
||||
if extClient.Network == networkName && extClient.IngressGatewayID == macaddress {
|
||||
|
@ -125,7 +122,7 @@ func DeleteNode(key string, exterminate bool) error {
|
|||
}
|
||||
} else {
|
||||
if err := database.DeleteRecord(database.DELETED_NODES_TABLE_NAME, key); err != nil {
|
||||
log.Println(err)
|
||||
functions.PrintUserLog("",err.Error(),2)
|
||||
}
|
||||
}
|
||||
if err := database.DeleteRecord(database.NODES_TABLE_NAME, key); err != nil {
|
||||
|
@ -197,6 +194,12 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
|||
|
||||
node.Network = networkName
|
||||
|
||||
if node.Name == models.NODE_SERVER_NAME {
|
||||
if node.CheckIsServer() {
|
||||
node.IsServer = "yes"
|
||||
}
|
||||
}
|
||||
|
||||
node.SetDefaults()
|
||||
node.Address, err = functions.UniqueAddress(networkName)
|
||||
if err != nil {
|
||||
|
@ -216,7 +219,6 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
|||
if err != nil {
|
||||
return node, err
|
||||
}
|
||||
|
||||
key, err := functions.GetRecordKey(node.MacAddress, node.Network)
|
||||
if err != nil {
|
||||
return node, err
|
||||
|
@ -242,12 +244,11 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
|||
func SetNetworkServerPeers(networkName string) {
|
||||
if currentPeersList, err := serverctl.GetPeers(networkName); err == nil {
|
||||
if database.SetPeers(currentPeersList, networkName) {
|
||||
log.Println("set new peers on network", networkName)
|
||||
} else {
|
||||
log.Println("attempted to set peers on network", networkName)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME,"set new peers on network "+networkName,1)
|
||||
}
|
||||
} else {
|
||||
log.Println("could not set server peers on network", networkName)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME,"could not set peers on network "+networkName,1)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME,err.Error(),1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
|
|
|
@ -2,10 +2,7 @@ package controller
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -319,7 +316,7 @@ func deleteDNS(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
entrytext := params["domain"] + "." + params["network"]
|
||||
functions.PrintUserLog("netmaker", "deleted dns entry: "+entrytext, 1)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "deleted dns entry: "+entrytext, 1)
|
||||
err = SetDNS()
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
|
@ -401,7 +398,7 @@ func pushDNS(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
log.Println("pushed DNS updates to nameserver")
|
||||
functions.PrintUserLog(r.Header.Get("user"),"pushed DNS updates to nameserver",1)
|
||||
json.NewEncoder(w).Encode("DNS Pushed to CoreDNS")
|
||||
}
|
||||
|
||||
|
@ -422,7 +419,7 @@ func ValidateDNSCreate(entry models.DNSEntry) error {
|
|||
err := v.Struct(entry)
|
||||
if err != nil {
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
fmt.Println(e)
|
||||
functions.PrintUserLog("", e.Error(),1)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
@ -442,7 +439,9 @@ func ValidateDNSUpdate(change models.DNSEntry, entry models.DNSEntry) error {
|
|||
})
|
||||
_ = v.RegisterValidation("network_exists", func(fl validator.FieldLevel) bool {
|
||||
_, err := functions.GetParentNetwork(change.Network)
|
||||
fmt.Println(err, entry.Network)
|
||||
if err != nil {
|
||||
functions.PrintUserLog("",err.Error(),0)
|
||||
}
|
||||
return err == nil
|
||||
})
|
||||
|
||||
|
@ -464,7 +463,7 @@ func ValidateDNSUpdate(change models.DNSEntry, entry models.DNSEntry) error {
|
|||
|
||||
if err != nil {
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
fmt.Println(e)
|
||||
functions.PrintUserLog("", e.Error(),1)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -6,12 +6,9 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
|
||||
// "fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
|
@ -31,43 +28,6 @@ func extClientHandlers(r *mux.Router) {
|
|||
r.HandleFunc("/api/extclients/{network}/{macaddress}", securityCheck(false, http.HandlerFunc(createExtClient))).Methods("POST")
|
||||
}
|
||||
|
||||
// TODO: Implement Validation
|
||||
func ValidateExtClientCreate(networkName string, extclient models.ExtClient) error {
|
||||
// v := validator.New()
|
||||
// _ = v.RegisterValidation("macaddress_unique", func(fl validator.FieldLevel) bool {
|
||||
// var isFieldUnique bool = functions.IsFieldUnique(networkName, "macaddress", extclient.MacAddress)
|
||||
// return isFieldUnique
|
||||
// })
|
||||
// _ = v.RegisterValidation("network_exists", func(fl validator.FieldLevel) bool {
|
||||
// _, err := extclient.GetNetwork()
|
||||
// return err == nil
|
||||
// })
|
||||
// err := v.Struct(extclient)
|
||||
|
||||
// if err != nil {
|
||||
// for _, e := range err.(validator.ValidationErrors) {
|
||||
// fmt.Println(e)
|
||||
// }
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Implement Validation
|
||||
func ValidateExtClientUpdate(networkName string, extclient models.ExtClient) error {
|
||||
// v := validator.New()
|
||||
// _ = v.RegisterValidation("network_exists", func(fl validator.FieldLevel) bool {
|
||||
// _, err := extclient.GetNetwork()
|
||||
// return err == nil
|
||||
// })
|
||||
// err := v.Struct(extclient)
|
||||
// if err != nil {
|
||||
// for _, e := range err.(validator.ValidationErrors) {
|
||||
// fmt.Println(e)
|
||||
// }
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkIngressExists(network string, macaddress string) bool {
|
||||
node, err := functions.GetNodeByMacAddress(network, macaddress)
|
||||
if err != nil {
|
||||
|
@ -178,14 +138,14 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
gwnode, err := functions.GetNodeByMacAddress(client.Network, client.IngressGatewayID)
|
||||
if err != nil {
|
||||
fmt.Println("Could not retrieve Ingress Gateway Node " + client.IngressGatewayID)
|
||||
functions.PrintUserLog(r.Header.Get("user"),"Could not retrieve Ingress Gateway Node " + client.IngressGatewayID,1)
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
|
||||
network, err := functions.GetParentNetwork(client.Network)
|
||||
if err != nil {
|
||||
fmt.Println("Could not retrieve Ingress Gateway Network " + client.Network)
|
||||
functions.PrintUserLog(r.Header.Get("user"),"Could not retrieve Ingress Gateway Network " + client.Network,1)
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
|
@ -238,7 +198,7 @@ Endpoint = %s
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
functions.PrintUserLog(r.Header.Get("user"),"retrieved ext client config",2)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(client)
|
||||
}
|
||||
|
@ -263,9 +223,7 @@ func CreateExtClient(extclient models.ExtClient) error {
|
|||
}
|
||||
|
||||
if extclient.ClientID == "" {
|
||||
clientid := StringWithCharset(7, charset)
|
||||
clientname := "client-" + clientid
|
||||
extclient.ClientID = clientname
|
||||
extclient.ClientID = models.GenerateNodeName()
|
||||
}
|
||||
|
||||
extclient.LastModified = time.Now().Unix()
|
||||
|
@ -284,10 +242,10 @@ func CreateExtClient(extclient models.ExtClient) error {
|
|||
err = SetNetworkNodesLastModified(extclient.Network)
|
||||
return err
|
||||
}
|
||||
|
||||
//This one's a doozy
|
||||
//To create a extclient
|
||||
//Must have valid key and be unique
|
||||
/**
|
||||
* To create a extclient
|
||||
* Must have valid key and be unique
|
||||
*/
|
||||
func createExtClient(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
|
@ -295,9 +253,6 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
networkName := params["network"]
|
||||
macaddress := params["macaddress"]
|
||||
//Check if network exists first
|
||||
//TODO: This is inefficient. Let's find a better way.
|
||||
//Just a few rows down we grab the network anyway
|
||||
ingressExists := checkIngressExists(networkName, macaddress)
|
||||
if !ingressExists {
|
||||
returnErrorResponse(w, r, formatError(errors.New("ingress does not exist"), "internal"))
|
||||
|
@ -319,11 +274,6 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
err = ValidateExtClientCreate(params["network"], extclient)
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "badrequest"))
|
||||
return
|
||||
}
|
||||
err = CreateExtClient(extclient)
|
||||
|
||||
if err != nil {
|
||||
|
@ -340,14 +290,8 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var newExtClient models.ExtClient
|
||||
var oldExtClient models.ExtClient
|
||||
// we decode our body request params
|
||||
_ = json.NewDecoder(r.Body).Decode(&newExtClient)
|
||||
// TODO: Validation for update.
|
||||
// err := ValidateExtClientUpdate(params["network"], params["clientid"], newExtClient)
|
||||
// if err != nil {
|
||||
// returnErrorResponse(w, r, formatError(err, "badrequest"))
|
||||
// return
|
||||
// }
|
||||
|
||||
key, err := functions.GetRecordKey(params["clientid"], params["network"])
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
|
@ -362,7 +306,6 @@ func updateExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
|
||||
newclient, err := UpdateExtClient(newExtClient.ClientID, params["network"], oldExtClient)
|
||||
if err != nil {
|
||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||
|
@ -404,7 +347,7 @@ func DeleteGatewayExtClients(gatewayID string, networkName string) error {
|
|||
for _, extClient := range currentExtClients {
|
||||
if extClient.IngressGatewayID == gatewayID {
|
||||
if err = DeleteExtClient(networkName, extClient.ClientID); err != nil {
|
||||
functions.PrintUserLog("netmaker", "failed to remove ext client "+extClient.ClientID, 2)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "failed to remove ext client "+extClient.ClientID, 2)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -181,7 +179,7 @@ func ValidateNetworkUpdate(network models.Network) error {
|
|||
|
||||
if err != nil {
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
log.Println(e)
|
||||
functions.PrintUserLog("validator",e.Error(),1)
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
@ -517,7 +515,7 @@ func CreateAccessKey(accesskey models.AccessKey, network models.Network) (models
|
|||
err = v.Struct(accesskey)
|
||||
if err != nil {
|
||||
for _, e := range err.(validator.ValidationErrors) {
|
||||
log.Println(e)
|
||||
functions.PrintUserLog("validator",e.Error(),1)
|
||||
}
|
||||
return models.AccessKey{}, err
|
||||
}
|
||||
|
|
|
@ -4,9 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
nodepb "github.com/gravitl/netmaker/grpc"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
|
@ -25,7 +23,6 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.Object) (*
|
|||
}
|
||||
node, err := GetNode(macAndNetwork[0], macAndNetwork[1])
|
||||
if err != nil {
|
||||
log.Println("could not get node "+macAndNetwork[0]+" "+macAndNetwork[1], err)
|
||||
return nil, err
|
||||
}
|
||||
node.SetLastCheckIn()
|
||||
|
@ -71,7 +68,6 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
|
|||
|
||||
node, err = CreateNode(node, node.Network)
|
||||
if err != nil {
|
||||
log.Println("could not create node on network " + node.Network + " (gRPC controller)")
|
||||
return nil, err
|
||||
}
|
||||
nodeData, err := json.Marshal(&node)
|
||||
|
@ -121,7 +117,6 @@ func (s *NodeServiceServer) DeleteNode(ctx context.Context, req *nodepb.Object)
|
|||
|
||||
err := DeleteNode(nodeID, true)
|
||||
if err != nil {
|
||||
log.Println("Error deleting node (gRPC controller).")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -139,7 +134,7 @@ func (s *NodeServiceServer) GetPeers(ctx context.Context, req *nodepb.Object) (*
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if node.Name == "netmaker" {
|
||||
if node.IsServer == "yes" {
|
||||
SetNetworkServerPeers(macAndNetwork[1])
|
||||
}
|
||||
peers, err := GetPeersList(macAndNetwork[1])
|
||||
|
|
|
@ -3,11 +3,9 @@ package controller
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/functions"
|
||||
|
@ -648,7 +646,6 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
|
|||
|
||||
network, err := functions.GetParentNetwork(netid)
|
||||
if err != nil {
|
||||
log.Println("Could not find network.")
|
||||
return models.Node{}, err
|
||||
}
|
||||
node.IsIngressGateway = "yes"
|
||||
|
|
|
@ -396,7 +396,7 @@ func UpdateUser(userchange models.User, user models.User) (models.User, error) {
|
|||
if err = database.Insert(user.UserName, string(data), database.USERS_TABLE_NAME); err != nil {
|
||||
return models.User{}, err
|
||||
}
|
||||
functions.PrintUserLog("netmaker", "updated user "+queryUser, 1)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "updated user "+queryUser, 1)
|
||||
return user, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
gconf.ServerGRPC = "localhost:8081"
|
||||
gconf.PortGRPC = "50051"
|
||||
//err := SetGlobalConfig(gconf)
|
||||
collection := REMOVE.Client.Database("netmaker").Collection("config")
|
||||
collection := REMOVE.Client.Database(models.NODE_SERVER_NAME).Collection("config")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
//create, _, err := functions.GetGlobalConfig()
|
||||
|
@ -24,7 +24,7 @@ import (
|
|||
//drop network, nodes, and user collections
|
||||
var collections = []string{"networks", "nodes", "users", "dns"}
|
||||
for _, table := range collections {
|
||||
collection := REMOVE.Client.Database("netmaker").Collection(table)
|
||||
collection := REMOVE.Client.Database(models.NODE_SERVER_NAME).Collection(table)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
err := collection.Drop(ctx)
|
||||
|
|
|
@ -131,6 +131,5 @@ func FetchRecords(tableName string) (map[string]string, error) {
|
|||
if len(records) == 0 {
|
||||
return nil, errors.New(NO_RECORDS)
|
||||
}
|
||||
// log.Println(records)
|
||||
return records, nil
|
||||
}
|
||||
|
|
|
@ -252,6 +252,9 @@ func NetworkNodesUpdateAction(networkName string, action string) error {
|
|||
fmt.Println("error in node address assignment!")
|
||||
return err
|
||||
}
|
||||
if action == models.NODE_UPDATE_KEY && node.StaticPubKey == "yes" {
|
||||
continue
|
||||
}
|
||||
if node.Network == networkName {
|
||||
node.Action = action
|
||||
data, err := json.Marshal(&node)
|
||||
|
@ -261,8 +264,7 @@ func NetworkNodesUpdateAction(networkName string, action string) error {
|
|||
node.SetID()
|
||||
database.Insert(node.ID, string(data), database.NODES_TABLE_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -763,7 +765,7 @@ func DecrimentKey(networkName string, keyvalue string) {
|
|||
}
|
||||
|
||||
if newNetworkData, err := json.Marshal(&network); err != nil {
|
||||
PrintUserLog("netmaker", "failed to decrement key", 2)
|
||||
PrintUserLog(models.NODE_SERVER_NAME, "failed to decrement key", 2)
|
||||
return
|
||||
} else {
|
||||
database.Insert(network.NetID, string(newNetworkData), database.NETWORKS_TABLE_NAME)
|
||||
|
|
|
@ -2,7 +2,6 @@ package functions
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -23,7 +22,7 @@ func SetDNSDir() error {
|
|||
if os.IsNotExist(err) {
|
||||
os.Mkdir(dir+"/config/dnsconfig", 744)
|
||||
} else if err != nil {
|
||||
log.Println("couldnt find or create /config/dnsconfig")
|
||||
PrintUserLog("","couldnt find or create /config/dnsconfig",0)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -38,7 +37,7 @@ func SetCorefile(domains string) error {
|
|||
if os.IsNotExist(err) {
|
||||
os.Mkdir(dir+"/config/dnsconfig", 744)
|
||||
} else if err != nil {
|
||||
log.Println("couldnt find or create /config/dnsconfig")
|
||||
PrintUserLog("","couldnt find or create /config/dnsconfig",0)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -55,8 +54,6 @@ func SetCorefile(domains string) error {
|
|||
|
||||
err = ioutil.WriteFile(dir+"/config/dnsconfig/Corefile", corebytes, 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Println("")
|
||||
return err
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -18,6 +18,7 @@ const TEN_YEARS_IN_SECONDS = 300000000
|
|||
|
||||
// == ACTIONS == (can only be set by GRPC)
|
||||
const NODE_UPDATE_KEY = "updatekey"
|
||||
const NODE_SERVER_NAME = "netmaker"
|
||||
const NODE_DELETE = "delete"
|
||||
const NODE_IS_PENDING = "pending"
|
||||
const NODE_NOOP = "noop"
|
||||
|
@ -56,12 +57,13 @@ type Node struct {
|
|||
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
|
||||
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
|
||||
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
||||
StaticIP string `json:"staticip" bson:"staticip" yaml:"staticip"`
|
||||
StaticPubKey string `json:"staticpubkey" bson:"staticpubkey" yaml:"staticpubkey"`
|
||||
StaticPubKey string `json:"staticpubkey" bson:"staticpubkey" yaml:"staticpubkey" validate:"checkyesorno"`
|
||||
StaticIP string `json:"staticip" bson:"staticip" yaml:"staticip" validate:"checkyesorno"`
|
||||
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
||||
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
|
||||
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
||||
IsDualStack string `json:"isdualstack" bson:"isdualstack" yaml:"isdualstack" validate:"checkyesorno"`
|
||||
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
||||
Action string `json:"action" bson:"action" yaml:"action"`
|
||||
IsLocal string `json:"islocal" bson:"islocal" yaml:"islocal" validate:"checkyesorno"`
|
||||
LocalRange string `json:"localrange" bson:"localrange" yaml:"localrange"`
|
||||
|
@ -111,6 +113,12 @@ func (node *Node) SetIsDualStackDefault() {
|
|||
}
|
||||
}
|
||||
|
||||
func (node *Node) SetIsServerDefault() {
|
||||
if node.IsServer != "yes" {
|
||||
node.IsServer = "no"
|
||||
}
|
||||
}
|
||||
|
||||
func (node *Node) SetLastModified() {
|
||||
node.LastModified = time.Now().Unix()
|
||||
}
|
||||
|
@ -137,6 +145,23 @@ func (node *Node) SetDefaultName() {
|
|||
}
|
||||
}
|
||||
|
||||
func (node *Node) CheckIsServer() bool {
|
||||
nodeData, err := database.FetchRecords(database.NODES_TABLE_NAME)
|
||||
if err != nil && !database.IsEmptyRecord(err) {
|
||||
return false
|
||||
}
|
||||
for _, value := range nodeData {
|
||||
var tmpNode Node
|
||||
if err := json.Unmarshal([]byte(value), &tmpNode); err != nil {
|
||||
continue
|
||||
}
|
||||
if tmpNode.Network == node.Network && tmpNode.MacAddress != node.MacAddress {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (node *Node) GetNetwork() (Network, error) {
|
||||
|
||||
var network Network
|
||||
|
@ -204,6 +229,7 @@ func (node *Node) SetDefaults() {
|
|||
node.SetPullChangesDefault()
|
||||
node.SetDefaultAction()
|
||||
node.SetID()
|
||||
node.SetIsServerDefault()
|
||||
node.KeyUpdateTimeStamp = time.Now().Unix()
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
|
|||
}
|
||||
allowedips = append(allowedips, addr6)
|
||||
}
|
||||
if nodecfg.Name == "netmaker" {
|
||||
if nodecfg.IsServer == "yes" {
|
||||
peer = wgtypes.PeerConfig{
|
||||
PublicKey: pubkey,
|
||||
PersistentKeepaliveInterval: &keepaliveserver,
|
||||
|
|
|
@ -80,7 +80,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
nodeport = int(node.ListenPort)
|
||||
|
||||
conf := wgtypes.Config{}
|
||||
if nodecfg.UDPHolePunch == "yes" && nodecfg.Name != "netmaker" {
|
||||
if nodecfg.UDPHolePunch == "yes" &&
|
||||
nodecfg.IsServer == "no" &&
|
||||
nodecfg.IsIngressGateway == "no" {
|
||||
conf = wgtypes.Config{
|
||||
PrivateKey: &key,
|
||||
ReplacePeers: true,
|
||||
|
|
|
@ -163,10 +163,12 @@ func AddNetwork(network string) (bool, error) {
|
|||
log.Println("could not change netclient directory permissions")
|
||||
return false, err
|
||||
}
|
||||
log.Println("executing network join: " + "/etc/netclient/netclient " + "join " + "-t " + token + " -name " + "netmaker" + " -endpoint " + pubip)
|
||||
functions.PrintUserLog(models.NODE_SERVER_NAME,"executing network join: " + "/etc/netclient/netclient " + "join " + "-t " + token + " -name " + models.NODE_SERVER_NAME + " -endpoint " + pubip,0)
|
||||
|
||||
joinCMD := exec.Command("/etc/netclient/netclient", "join", "-t", token, "-name", "netmaker", "-endpoint", pubip)
|
||||
joinCMD := exec.Command("/etc/netclient/netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip)
|
||||
err = joinCMD.Start()
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue