Skip to content

Commit

Permalink
Merge pull request #9 from FMotalleb/dev
Browse files Browse the repository at this point in the history
[Fix]<RawResponse>: now support templates
  • Loading branch information
FMotalleb authored Aug 4, 2023
2 parents 99a5858 + ee57242 commit 733b72a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
13 changes: 4 additions & 9 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ rules:
matcher: regex
matcherParams:
- (.*\.)?accounts\.ea\.com.*
raw:
A: accounts.ea.com. 60 IN A 50.7.87.85
- name: Ea Acc proxy
matcher: regex
matcherParams:
- (.*\.)?signin\.ea.com\.*
raw:
A: signin.ea.com. 60 IN A 50.7.87.85
A: "{{ .address }} 60 IN A 50.7.87.85"

- name: Ea proxy
matcher: regex
matcherParams:
Expand Down Expand Up @@ -127,5 +122,5 @@ rules:
matcherParams:
- raw.raw.
raw:
A: raw.raw. 60 IN A 1.2.3.4
AAAA: raw.raw. 60 IN AAAA FFFF:FFFF:FFFF:FFFF::FFFF
A: "{{ .address }} 60 IN A 1.2.3.4"
AAAA: "{{ .address }} 60 IN AAAA FFFF:FFFF:FFFF:FFFF::FFFF"
21 changes: 20 additions & 1 deletion lib/config/router_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
package config

import (
"bytes"
"net"
"strings"
"text/template"

"github.com/FMotalleb/dns-reverse-proxy-docker/lib/provider"

Expand All @@ -31,7 +33,10 @@ func (c *Config) Route(w dns.ResponseWriter, req *dns.Msg) {

raw := rule.GetRaw(dns.TypeToString[req.Question[0].Qtype])
if raw != nil {
msg, err := dns.NewRR(*raw)
mapper := make(map[string]string, 0)
mapper["address"] = lcName
msg, err := dns.NewRR(formatString(*raw, mapper))

if err != nil {
log.Debug().Msgf("cannot parse raw response: %v", err)
}
Expand Down Expand Up @@ -84,3 +89,17 @@ func (c *Config) allowed(w dns.ResponseWriter, req *dns.Msg) bool {
}
return false
}

func formatString(text string, hashmap map[string]string) string {

tmpl, err := template.New("Mapper").Parse(text)
if err != nil {
panic(err)
}
writer := bytes.NewBuffer(nil)
err = tmpl.Execute(writer, hashmap)
if err != nil {
panic(err)
}
return writer.String()
}
1 change: 0 additions & 1 deletion lib/provider/proxy_handler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !test
// +build !test

package provider

Expand Down

0 comments on commit 733b72a

Please sign in to comment.