mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
v0.7
This commit is contained in:
60
backup.nginx.conf
Normal file
60
backup.nginx.conf
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
|
server_name dashboard.stage.netmaker.org; # The external URL
|
||||||
|
client_max_body_size 0;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
|
||||||
|
# if you use a custom resolver to find your app, needed with swag proxy
|
||||||
|
# resolver 127.0.0.11 valid=30s;
|
||||||
|
set $upstream_app dashboard; # The internal URL
|
||||||
|
set $upstream_port 3000; # The internal Port
|
||||||
|
set $upstream_proto http; # the protocol that is being used
|
||||||
|
proxy_pass $upstream_proto://$upstream_app:$upstream_port; # combine the set variables from above
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
listen [::]:80 default_server;
|
||||||
|
|
||||||
|
server_name api.stage.netmaker.org; # The external URL
|
||||||
|
client_max_body_size 0;
|
||||||
|
underscores_in_headers on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
# if you use a custom resolver to find your app, needed with swag proxy
|
||||||
|
# resolver 127.0.0.11 valid=30s;
|
||||||
|
|
||||||
|
set $upstream_app netmaker; # The internal URL
|
||||||
|
set $upstream_port 8081; # The internal Port
|
||||||
|
set $upstream_proto http; # the protocol that is being used
|
||||||
|
proxy_pass $upstream_proto://$upstream_app:$upstream_port; # combine the set variables from above
|
||||||
|
|
||||||
|
# Forces the header to be the one that is visible from the outside
|
||||||
|
proxy_set_header Host api.stage.netmaker.org; # Please cange to your URL
|
||||||
|
|
||||||
|
# Pass all headers through to the backend
|
||||||
|
proxy_pass_request_headers on;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 http2;
|
||||||
|
server_name grpc.stage.netmaker.org
|
||||||
|
client_max_body_size 0;
|
||||||
|
underscores_in_headers on;
|
||||||
|
|
||||||
|
|
||||||
|
# Forces the header to be the one that is visible from the outside
|
||||||
|
proxy_set_header Host api.stage.netmaker.org; # Please change to your URL
|
||||||
|
|
||||||
|
# Pass all headers through to the backend
|
||||||
|
proxy_pass_request_headers on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
grpc_pass grpc://localhost:50051;
|
||||||
|
}
|
||||||
|
}
|
70
backup2.nginx.conf
Normal file
70
backup2.nginx.conf
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
server {
|
||||||
|
listen 443;
|
||||||
|
listen [::]:443;
|
||||||
|
|
||||||
|
server_name dashboard.stage.netmaker.org; # The external URL
|
||||||
|
client_max_body_size 0;
|
||||||
|
ssl_certificate /etc/letsencrypt/live/stage.netmaker.org/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/stage.netmaker.org/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
location / {
|
||||||
|
|
||||||
|
# if you use a custom resolver to find your app, needed with swag proxy
|
||||||
|
# resolver 127.0.0.11 valid=30s;
|
||||||
|
set $upstream_app dashboard; # The internal URL
|
||||||
|
set $upstream_port 3000; # The internal Port
|
||||||
|
set $upstream_proto http2; # the protocol that is being used
|
||||||
|
proxy_pass $upstream_proto://$upstream_app:$upstream_port; # combine the set variables from above
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443;
|
||||||
|
listen [::]:443;
|
||||||
|
|
||||||
|
server_name api.stage.netmaker.org; # The external URL
|
||||||
|
client_max_body_size 0;
|
||||||
|
underscores_in_headers on;
|
||||||
|
ssl_certificate /etc/letsencrypt/live/stage.netmaker.org/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/stage.netmaker.org/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
location / {
|
||||||
|
# if you use a custom resolver to find your app, needed with swag proxy
|
||||||
|
# resolver 127.0.0.11 valid=30s;
|
||||||
|
|
||||||
|
set $upstream_app netmaker; # The internal URL
|
||||||
|
set $upstream_port 8081; # The internal Port
|
||||||
|
set $upstream_proto http2; # the protocol that is being used
|
||||||
|
proxy_pass $upstream_proto://$upstream_app:$upstream_port; # combine the set variables from above
|
||||||
|
|
||||||
|
# Forces the header to be the one that is visible from the outside
|
||||||
|
proxy_set_header Host api.stage.netmaker.org; # Please cange to your URL
|
||||||
|
|
||||||
|
# Pass all headers through to the backend
|
||||||
|
proxy_pass_request_headers on;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 http2;
|
||||||
|
server_name grpc.stage.netmaker.org
|
||||||
|
client_max_body_size 0;
|
||||||
|
underscores_in_headers on;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/stage.netmaker.org/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/stage.netmaker.org/privkey.pem;
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
|
||||||
|
# Forces the header to be the one that is visible from the outside
|
||||||
|
proxy_set_header Host api.stage.netmaker.org; # Please change to your URL
|
||||||
|
|
||||||
|
# Pass all headers through to the backend
|
||||||
|
proxy_pass_request_headers on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
grpc_pass grpc://localhost:50051;
|
||||||
|
}
|
||||||
|
}
|
12
compose/docker-compose.coredns.yml
Normal file
12
compose/docker-compose.coredns.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: "3.4"
|
||||||
|
|
||||||
|
services:
|
||||||
|
coredns:
|
||||||
|
image: coredns/coredns
|
||||||
|
command: -conf /root/dnsconfig/Corefile
|
||||||
|
container_name: coredns
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "53:53/udp"
|
||||||
|
volumes:
|
||||||
|
- /root/netmaker/config/dnsconfig:/root/dnsconfig
|
@@ -1,4 +1,4 @@
|
|||||||
comms my-net one-more other-net {
|
pissant comms {
|
||||||
reload 15s
|
reload 15s
|
||||||
hosts /root/dnsconfig/netmaker.hosts {
|
hosts /root/dnsconfig/netmaker.hosts {
|
||||||
fallthrough
|
fallthrough
|
||||||
|
@@ -1 +1,5 @@
|
|||||||
10.10.0.12 node-nokdw.my-net
|
11.22.44.1 netmaker.pissant
|
||||||
|
11.22.44.3 node-mtxy5.pissant
|
||||||
|
11.22.44.5 node-vnqlu.pissant
|
||||||
|
11.22.44.4 ubuntu-do.pissant ubuntu.pissant
|
||||||
|
11.22.44.2 alex-laptop.pissant porngood.pissant
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"log"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gravitl/netmaker/database"
|
"github.com/gravitl/netmaker/database"
|
||||||
@@ -125,8 +125,7 @@ func GetCustomDNS(network string) ([]models.DNSEntry, error) {
|
|||||||
}
|
}
|
||||||
for _, value := range collection { // filter for entries based on network
|
for _, value := range collection { // filter for entries based on network
|
||||||
var entry models.DNSEntry
|
var entry models.DNSEntry
|
||||||
|
if err := json.Unmarshal([]byte(value), &entry); err != nil {
|
||||||
if err := json.Unmarshal([]byte(value), entry); err != nil {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +244,11 @@ func createDNS(w http.ResponseWriter, r *http.Request) {
|
|||||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err = SetDNS()
|
||||||
|
if err != nil {
|
||||||
|
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||||
|
return
|
||||||
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(entry)
|
json.NewEncoder(w).Encode(entry)
|
||||||
}
|
}
|
||||||
@@ -295,7 +299,11 @@ func updateDNS(w http.ResponseWriter, r *http.Request) {
|
|||||||
returnErrorResponse(w, r, formatError(err, "badrequest"))
|
returnErrorResponse(w, r, formatError(err, "badrequest"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err = SetDNS()
|
||||||
|
if err != nil {
|
||||||
|
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||||
|
return
|
||||||
|
}
|
||||||
json.NewEncoder(w).Encode(entry)
|
json.NewEncoder(w).Encode(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +322,11 @@ func deleteDNS(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
entrytext := params["domain"] + "." + params["network"]
|
entrytext := params["domain"] + "." + params["network"]
|
||||||
functions.PrintUserLog("netmaker", "deleted dns entry: "+entrytext, 1)
|
functions.PrintUserLog("netmaker", "deleted dns entry: "+entrytext, 1)
|
||||||
|
err = SetDNS()
|
||||||
|
if err != nil {
|
||||||
|
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||||
|
return
|
||||||
|
}
|
||||||
json.NewEncoder(w).Encode(entrytext + " deleted.")
|
json.NewEncoder(w).Encode(entrytext + " deleted.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,15 +403,13 @@ func pushDNS(w http.ResponseWriter, r *http.Request) {
|
|||||||
returnErrorResponse(w, r, formatError(err, "internal"))
|
returnErrorResponse(w, r, formatError(err, "internal"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Println("pushed DNS updates to nameserver")
|
||||||
json.NewEncoder(w).Encode("DNS Pushed to CoreDNS")
|
json.NewEncoder(w).Encode("DNS Pushed to CoreDNS")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateDNSCreate(entry models.DNSEntry) error {
|
func ValidateDNSCreate(entry models.DNSEntry) error {
|
||||||
|
|
||||||
v := validator.New()
|
v := validator.New()
|
||||||
fmt.Println("Validating DNS: " + entry.Name)
|
|
||||||
fmt.Println(" Address: " + entry.Address)
|
|
||||||
fmt.Println(" Network: " + entry.Network)
|
|
||||||
|
|
||||||
_ = v.RegisterValidation("name_unique", func(fl validator.FieldLevel) bool {
|
_ = v.RegisterValidation("name_unique", func(fl validator.FieldLevel) bool {
|
||||||
num, err := GetDNSEntryNum(entry.Name, entry.Network)
|
num, err := GetDNSEntryNum(entry.Name, entry.Network)
|
||||||
|
@@ -559,8 +559,6 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Node{}, err
|
return models.Node{}, err
|
||||||
}
|
}
|
||||||
log.Println("GATEWAY:",gateway)
|
|
||||||
log.Println("NODE:",node)
|
|
||||||
err = ValidateEgressGateway(gateway)
|
err = ValidateEgressGateway(gateway)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Node{}, err
|
return models.Node{}, err
|
||||||
@@ -699,16 +697,17 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
|
|||||||
postDownCmd := "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
postDownCmd := "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
|
||||||
if node.PostUp != "" {
|
if node.PostUp != "" {
|
||||||
if !strings.Contains(node.PostUp, postUpCmd) {
|
if !strings.Contains(node.PostUp, postUpCmd) {
|
||||||
node.PostUp = node.PostUp + "; " + postUpCmd
|
postUpCmd = node.PostUp + "; " + postUpCmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.PostDown != "" {
|
if node.PostDown != "" {
|
||||||
if !strings.Contains(node.PostDown, postDownCmd) {
|
if !strings.Contains(node.PostDown, postDownCmd) {
|
||||||
node.PostDown = node.PostDown + "; " + postDownCmd
|
postDownCmd = node.PostDown + "; " + postDownCmd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.SetLastModified()
|
node.SetLastModified()
|
||||||
|
node.PostUp = postUpCmd
|
||||||
|
node.PostDown = postDownCmd
|
||||||
key, err := functions.GetRecordKey(node.MacAddress, node.Network)
|
key, err := functions.GetRecordKey(node.MacAddress, node.Network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Node{}, err
|
return models.Node{}, err
|
||||||
|
@@ -3,6 +3,6 @@ package models
|
|||||||
|
|
||||||
type DNSEntry struct {
|
type DNSEntry struct {
|
||||||
Address string `json:"address" bson:"address" validate:"required,ip"`
|
Address string `json:"address" bson:"address" validate:"required,ip"`
|
||||||
Name string `json:"name" bson:"name" validate:"required,alphanum,name_unique,max=120"`
|
Name string `json:"name" bson:"name" validate:"required,name_unique,min=1,max=192"`
|
||||||
Network string `json:"network" bson:"network" validate:"network_exists"`
|
Network string `json:"network" bson:"network" validate:"network_exists"`
|
||||||
}
|
}
|
||||||
|
@@ -296,3 +296,32 @@ func (currentNetwork *Network) Update(newNetwork *Network) (bool, bool, error) {
|
|||||||
// copy values
|
// copy values
|
||||||
return false, false, errors.New("failed to update network " + newNetwork.NetID + ", cannot change netid.")
|
return false, false, errors.New("failed to update network " + newNetwork.NetID + ", cannot change netid.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (network *Network) SetNetworkNodesLastModified() error {
|
||||||
|
|
||||||
|
timestamp := time.Now().Unix()
|
||||||
|
|
||||||
|
network.NodesLastModified = timestamp
|
||||||
|
data, err := json.Marshal(&network)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = database.Insert(network.NetID, string(data), database.NETWORKS_TABLE_NAME)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetwork(networkname string) (Network, error) {
|
||||||
|
|
||||||
|
var network Network
|
||||||
|
networkData, err := database.FetchRecord(database.NETWORKS_TABLE_NAME, networkname)
|
||||||
|
if err != nil {
|
||||||
|
return network, err
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal([]byte(networkData), &network); err != nil {
|
||||||
|
return Network{}, err
|
||||||
|
}
|
||||||
|
return network, nil
|
||||||
|
}
|
||||||
|
@@ -274,11 +274,14 @@ func (currentNode *Node) Update(newNode *Node) error {
|
|||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
newNode.SetLastModified()
|
newNode.SetLastModified()
|
||||||
err = database.Insert(newNode.ID, string(data), database.NODES_TABLE_NAME)
|
if err = database.Insert(newNode.ID, string(data), database.NODES_TABLE_NAME); err == nil {
|
||||||
|
if network, err := GetNetwork(newNode.Network); err == nil {
|
||||||
|
err = network.SetNetworkNodesLastModified()
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// copy values
|
|
||||||
return errors.New("failed to update node " + newNode.MacAddress + ", cannot change macaddress.")
|
return errors.New("failed to update node " + newNode.MacAddress + ", cannot change macaddress.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
netclient/local/.dns.go.swp
Normal file
BIN
netclient/local/.dns.go.swp
Normal file
Binary file not shown.
@@ -40,12 +40,12 @@ func UpdateDNS(ifacename string, network string, nameserver string) error {
|
|||||||
_, err = exec.Command("resolvectl", "domain", ifacename, "~"+network).Output()
|
_, err = exec.Command("resolvectl", "domain", ifacename, "~"+network).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("WARNING: Error encountered setting dns. Aborted setting dns.")
|
log.Println("WARNING: Error encountered setting domain on dns. Aborted setting dns.")
|
||||||
} else {
|
} else {
|
||||||
_, err = exec.Command("resolvectl", "default-route", ifacename, "false").Output()
|
_, err = exec.Command("resolvectl", "default-route", ifacename, "false").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("WARNING: Error encountered setting dns. Aborted setting dns.")
|
log.Println("WARNING: Error encountered setting default-route on dns. Aborted setting dns.")
|
||||||
} else {
|
} else {
|
||||||
_, err = exec.Command("resolvectl", "dns", ifacename, nameserver).Output()
|
_, err = exec.Command("resolvectl", "dns", ifacename, nameserver).Output()
|
||||||
if err!= nil {
|
if err!= nil {
|
||||||
|
@@ -267,6 +267,7 @@ func InitWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//=========DNS Setup==========\\
|
//=========DNS Setup==========\\
|
||||||
|
log.Println("NODECFG.DNS:",nodecfg.DNS)
|
||||||
if nodecfg.DNS == "on" {
|
if nodecfg.DNS == "on" {
|
||||||
_ = local.UpdateDNS(ifacename, network, nameserver)
|
_ = local.UpdateDNS(ifacename, network, nameserver)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user