mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-03 19:54:22 +08:00
add global nameservers in case of internet gw
This commit is contained in:
parent
b55d512141
commit
4e8ab0ec3c
4 changed files with 81 additions and 4 deletions
|
@ -44,6 +44,21 @@ func dnsHandlers(r *mux.Router) {
|
|||
r.HandleFunc("/api/v1/nameserver", logic.SecurityCheck(true, http.HandlerFunc(listNs))).Methods(http.MethodGet)
|
||||
r.HandleFunc("/api/v1/nameserver", logic.SecurityCheck(true, http.HandlerFunc(updateNs))).Methods(http.MethodPut)
|
||||
r.HandleFunc("/api/v1/nameserver", logic.SecurityCheck(true, http.HandlerFunc(deleteNs))).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/api/v1/nameserver/global", logic.SecurityCheck(true, http.HandlerFunc(getGlobalNs))).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
// @Summary List Global Nameservers
|
||||
// @Router /api/v1/nameserver/global [get]
|
||||
// @Tags Auth
|
||||
// @Accept json
|
||||
// @Param query network string
|
||||
// @Success 200 {object} models.SuccessResponse
|
||||
// @Failure 400 {object} models.ErrorResponse
|
||||
// @Failure 401 {object} models.ErrorResponse
|
||||
// @Failure 500 {object} models.ErrorResponse
|
||||
func getGlobalNs(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
logic.ReturnSuccessResponseWithJson(w, r, logic.GlobalNsList, "fetched nameservers")
|
||||
}
|
||||
|
||||
// @Summary Create Nameserver
|
||||
|
@ -72,6 +87,9 @@ func createNs(w http.ResponseWriter, r *http.Request) {
|
|||
if req.Tags == nil {
|
||||
req.Tags = make(datatypes.JSONMap)
|
||||
}
|
||||
if gNs, ok := logic.GlobalNsList[req.Name]; ok {
|
||||
req.Servers = gNs.IPs
|
||||
}
|
||||
ns := schema.Nameserver{
|
||||
ID: uuid.New().String(),
|
||||
Name: req.Name,
|
||||
|
|
44
logic/dns.go
44
logic/dns.go
|
@ -19,6 +19,41 @@ import (
|
|||
"github.com/txn2/txeh"
|
||||
)
|
||||
|
||||
type GlobalNs struct {
|
||||
ID string `json:"id"`
|
||||
IPs []string `json:"ips"`
|
||||
}
|
||||
|
||||
var GlobalNsList = map[string]GlobalNs{
|
||||
"Google": {
|
||||
ID: "Google",
|
||||
IPs: []string{
|
||||
"8.8.8.8",
|
||||
"8.8.4.4",
|
||||
"2001:4860:4860::8888",
|
||||
"2001:4860:4860::8844",
|
||||
},
|
||||
},
|
||||
"Cloudflare": {
|
||||
ID: "Cloudflare",
|
||||
IPs: []string{
|
||||
"1.1.1.1",
|
||||
"1.0.0.1",
|
||||
"2606:4700:4700::1111",
|
||||
"2606:4700:4700::1001",
|
||||
},
|
||||
},
|
||||
"Quad9": {
|
||||
ID: "Quad9",
|
||||
IPs: []string{
|
||||
"9.9.9.9",
|
||||
"149.112.112.112",
|
||||
"2620:fe::fe",
|
||||
"2620:fe::9",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// SetDNS - sets the dns on file
|
||||
func SetDNS() error {
|
||||
hostfile, err := txeh.NewHosts(&txeh.HostsConfig{})
|
||||
|
@ -393,6 +428,15 @@ func GetNameserversForHost(h *models.Host) (returnNsLi []models.Nameserver) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if node.IsInternetGateway {
|
||||
globalNs := models.Nameserver{
|
||||
MatchDomain: ".",
|
||||
}
|
||||
for _, nsI := range GlobalNsList {
|
||||
globalNs.IPs = append(globalNs.IPs, nsI.IPs...)
|
||||
}
|
||||
returnNsLi = append(returnNsLi, globalNs)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ type UserRemoteGws struct {
|
|||
Status NodeStatus `json:"status"`
|
||||
DnsAddress string `json:"dns_address"`
|
||||
Addresses string `json:"addresses"`
|
||||
MatchDomains []string `json:"match_domains"`
|
||||
}
|
||||
|
||||
// UserRAGs - struct for user access gws
|
||||
|
|
|
@ -1311,7 +1311,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
|
|||
logic.GetPeerListenPort(host),
|
||||
)
|
||||
extClient.AllowedIPs = logic.GetExtclientAllowedIPs(extClient)
|
||||
gws = append(gws, models.UserRemoteGws{
|
||||
gw := models.UserRemoteGws{
|
||||
GwID: node.ID.String(),
|
||||
GWName: host.Name,
|
||||
Network: node.Network,
|
||||
|
@ -1326,7 +1326,14 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
|
|||
Status: node.Status,
|
||||
DnsAddress: node.IngressDNS,
|
||||
Addresses: utils.NoEmptyStringToCsv(node.Address.String(), node.Address6.String()),
|
||||
})
|
||||
}
|
||||
if !node.IsInternetGateway {
|
||||
hNs := logic.GetNameserversForHost(host)
|
||||
for _, nsI := range hNs {
|
||||
gw.MatchDomains = append(gw.MatchDomains, nsI.MatchDomain)
|
||||
}
|
||||
}
|
||||
gws = append(gws, gw)
|
||||
userGws[node.Network] = gws
|
||||
delete(userGwNodes, node.ID.String())
|
||||
}
|
||||
|
@ -1357,7 +1364,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
gws := userGws[node.Network]
|
||||
|
||||
gws = append(gws, models.UserRemoteGws{
|
||||
gw := models.UserRemoteGws{
|
||||
GwID: node.ID.String(),
|
||||
GWName: host.Name,
|
||||
Network: node.Network,
|
||||
|
@ -1370,7 +1377,14 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
|
|||
Status: node.Status,
|
||||
DnsAddress: node.IngressDNS,
|
||||
Addresses: utils.NoEmptyStringToCsv(node.Address.String(), node.Address6.String()),
|
||||
})
|
||||
}
|
||||
if !node.IsInternetGateway {
|
||||
hNs := logic.GetNameserversForHost(host)
|
||||
for _, nsI := range hNs {
|
||||
gw.MatchDomains = append(gw.MatchDomains, nsI.MatchDomain)
|
||||
}
|
||||
}
|
||||
gws = append(gws, gw)
|
||||
userGws[node.Network] = gws
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue