Use DefaultNameServer for doing queries

This commit is contained in:
nemunaire 2019-07-16 16:44:54 +02:00
parent 54a104dc72
commit 1858e61321
3 changed files with 18 additions and 19 deletions

View File

@ -4,6 +4,8 @@ import (
"github.com/julienschmidt/httprouter"
)
var DefaultNameServer = "127.0.0.1:53"
var router = httprouter.New()
func Router() *httprouter.Router {

View File

@ -18,7 +18,7 @@ func init() {
router.DELETE("/api/zones/:zone/", apiHandler(zoneHandler(delRR)))
}
func getZones(p httprouter.Params, body io.Reader) (Response) {
func getZones(p httprouter.Params, body io.Reader) Response {
return APIResponse{
response: map[string][]string{
"zones": []string{
@ -28,9 +28,8 @@ func getZones(p httprouter.Params, body io.Reader) (Response) {
}
}
func zoneHandler(f func(string, io.Reader) (Response)) func(httprouter.Params, io.Reader) (Response) {
return func(ps httprouter.Params, body io.Reader) (Response) {
func zoneHandler(f func(string, io.Reader) Response) func(httprouter.Params, io.Reader) Response {
return func(ps httprouter.Params, body io.Reader) Response {
zone := ps.ByName("zone")
if zone[len(zone)-1] != '.' {
@ -43,7 +42,7 @@ func zoneHandler(f func(string, io.Reader) (Response)) func(httprouter.Params, i
}
}
func axfrZone(zone string, body io.Reader) (Response) {
func axfrZone(zone string, body io.Reader) Response {
t := new(dns.Transfer)
m := new(dns.Msg)
@ -51,11 +50,11 @@ func axfrZone(zone string, body io.Reader) (Response) {
m.SetAxfr(zone)
m.SetTsig("ddns.", dns.HmacSHA256, 300, time.Now().Unix())
c, err := t.In(m, "127.0.0.1:53")
c, err := t.In(m, DefaultNameServer)
if err != nil {
return APIErrorResponse{
status: http.StatusInternalServerError,
err: err,
err: err,
}
}
@ -67,7 +66,7 @@ func axfrZone(zone string, body io.Reader) (Response) {
}
if len(rrs) > 0 {
rrs = rrs[0:len(rrs)-1]
rrs = rrs[0 : len(rrs)-1]
}
return APIResponse{
@ -81,7 +80,7 @@ type uploadedRR struct {
RR string `json:"rr"`
}
func addRR(zone string, body io.Reader) (Response) {
func addRR(zone string, body io.Reader) Response {
var urr uploadedRR
err := json.NewDecoder(body).Decode(&urr)
if err != nil {
@ -109,23 +108,23 @@ func addRR(zone string, body io.Reader) (Response) {
c.TsigSecret = map[string]string{"ddns.": "so6ZGir4GPAqINNh9U5c3A=="}
m.SetTsig("ddns.", dns.HmacSHA256, 300, time.Now().Unix())
in, rtt, err := c.Exchange(m, "127.0.0.1:53")
in, rtt, err := c.Exchange(m, DefaultNameServer)
if err != nil {
return APIErrorResponse{
status: http.StatusInternalServerError,
err: err,
err: err,
}
}
return APIResponse{
response: map[string]interface{}{
"in": *in,
"in": *in,
"rtt": rtt,
},
}
}
func delRR(zone string, body io.Reader) (Response) {
func delRR(zone string, body io.Reader) Response {
var urr uploadedRR
err := json.NewDecoder(body).Decode(&urr)
if err != nil {
@ -153,17 +152,17 @@ func delRR(zone string, body io.Reader) (Response) {
c.TsigSecret = map[string]string{"ddns.": "so6ZGir4GPAqINNh9U5c3A=="}
m.SetTsig("ddns.", dns.HmacSHA256, 300, time.Now().Unix())
in, rtt, err := c.Exchange(m, "127.0.0.1:53")
in, rtt, err := c.Exchange(m, DefaultNameServer)
if err != nil {
return APIErrorResponse{
status: http.StatusInternalServerError,
err: err,
err: err,
}
}
return APIResponse{
response: map[string]interface{}{
"in": *in,
"in": *in,
"rtt": rtt,
},
}

View File

@ -11,8 +11,6 @@ import (
"git.nemunai.re/libredns/api"
)
var DefaultNameServer = "127.0.0.1:53"
type ResponseWriterPrefix struct {
real http.ResponseWriter
prefix string
@ -58,7 +56,7 @@ func main() {
var bind = flag.String("bind", ":8081", "Bind port/socket")
var dsn = flag.String("dsn", DSNGenerator(), "DSN to connect to the MySQL server")
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
flag.StringVar(&DefaultNameServer, "defaultns", DefaultNameServer, "Adress to the default name server")
flag.StringVar(&api.DefaultNameServer, "defaultns", api.DefaultNameServer, "Adress to the default name server")
flag.Parse()
// Sanitize options