| 1 | function preresolve ( remoteip, domain, qtype ) |
|---|
| 2 | print ("prequery handler called for: ", remoteip, getlocaladdress(), domain, qtype) |
|---|
| 3 | pdnslog("a test message.. received query from "..remoteip.." on "..getlocaladdress()); |
|---|
| 4 | |
|---|
| 5 | if domain == "www.donotcache.org." |
|---|
| 6 | then |
|---|
| 7 | print("making sure www.donotcache.org will never end up in the cache") |
|---|
| 8 | setvariable() |
|---|
| 9 | return -1, {} |
|---|
| 10 | end |
|---|
| 11 | |
|---|
| 12 | if domain == "www.powerdns.org." |
|---|
| 13 | then |
|---|
| 14 | ret={} |
|---|
| 15 | ret[1]= {qtype=pdns.A, content="85.17.220.215", ttl=86400} |
|---|
| 16 | print "dealing!" |
|---|
| 17 | return 0, ret |
|---|
| 18 | elseif domain == "www.baddomain.com." |
|---|
| 19 | then |
|---|
| 20 | print "dealing - faking nx" |
|---|
| 21 | return pdns.NXDOMAIN, {} |
|---|
| 22 | elseif domain == "echo." |
|---|
| 23 | then |
|---|
| 24 | print "dealing with echo!" |
|---|
| 25 | return 0, {{qtype=pdns.A, content=remoteip}} |
|---|
| 26 | elseif domain == "echo6." |
|---|
| 27 | then |
|---|
| 28 | print "dealing with echo6!" |
|---|
| 29 | return 0, {{qtype=pdns.AAAA, content=remoteip}} |
|---|
| 30 | else |
|---|
| 31 | print "not dealing!" |
|---|
| 32 | return -1, {} |
|---|
| 33 | end |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | function nxdomain ( remoteip, domain, qtype ) |
|---|
| 37 | print ("nxhandler called for: ", remoteip, getlocaladdress(), domain, qtype, pdns.AAAA) |
|---|
| 38 | if qtype ~= pdns.A then return -1, {} end -- only A records |
|---|
| 39 | if not string.find(domain, "^www%.") then return -1, {} end -- only things that start with www. |
|---|
| 40 | |
|---|
| 41 | if matchnetmask(remoteip, {"127.0.0.1/32", "10.1.0.0/16"}) |
|---|
| 42 | then |
|---|
| 43 | print "dealing" |
|---|
| 44 | ret={} |
|---|
| 45 | ret[1]={qtype=pdns.CNAME, content="www.webserver.com", ttl=3602} |
|---|
| 46 | ret[2]={qname="www.webserver.com", qtype=pdns.A, content="1.2.3.4", ttl=3602} |
|---|
| 47 | ret[3]={qname="webserver.com", qtype=pdns.NS, content="ns1.webserver.com", place=2} |
|---|
| 48 | -- ret[1]={15, "25 ds9a.nl", 3602} |
|---|
| 49 | return 0, ret |
|---|
| 50 | else |
|---|
| 51 | print "not dealing" |
|---|
| 52 | return -1, ret |
|---|
| 53 | end |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | function nodata ( remoteip, domain, qtype, records ) |
|---|
| 57 | print ("nodata called for: ", remoteip, getlocaladdress(), domain, qtype) |
|---|
| 58 | if qtype ~= pdns.AAAA then return -1, {} end -- only AAAA records |
|---|
| 59 | -- for key,val in ipairs(records) |
|---|
| 60 | -- do |
|---|
| 61 | -- print(val.qtype, val.ttl) |
|---|
| 62 | -- end |
|---|
| 63 | |
|---|
| 64 | setvariable() |
|---|
| 65 | return "getFakeAAAARecords", domain, "fe80::21b:77ff:0:0" |
|---|
| 66 | end |
|---|
| 67 | |
|---|
| 68 | -- records contains the entire packet, ready for your modifying pleasure |
|---|
| 69 | function postresolve ( remoteip, domain, qtype, records, origrcode ) |
|---|
| 70 | print ("postresolve called for: ", remoteip, getlocaladdress(), domain, qtype, origrcode) |
|---|
| 71 | |
|---|
| 72 | for key,val in ipairs(records) |
|---|
| 73 | do |
|---|
| 74 | if(val.content == '173.201.188.46' and val.qtype == pdns.A) |
|---|
| 75 | then |
|---|
| 76 | val.content = '127.0.0.1' |
|---|
| 77 | setvariable() |
|---|
| 78 | end |
|---|
| 79 | if val.qtype == pdns.A and matchnetmask(remoteip, "192.168.0.0/16") and matchnetmask(val.content, "85.17.219.0/24") |
|---|
| 80 | then |
|---|
| 81 | val.content = string.gsub(val.content, "^85.17.219.", "192.168.219.", 1) |
|---|
| 82 | setvariable() |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | -- print(val.content) |
|---|
| 86 | end |
|---|
| 87 | return origrcode, records |
|---|
| 88 | end |
|---|