1 module PowerDns ( RRType(..)
10 data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME
11 | RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC
12 | RRTypeNS | RRTypeDS | RRTypeMX
13 | RRTypeANY | RRTypeError String
16 data PdnsRequest = PdnsRequestQ
20 , remoteIpAddress :: String
21 , localIpAddress :: Maybe String
22 , ednsSubnetAddress :: Maybe String
24 | PdnsRequestAXFR String
34 "CNAME" -> RRTypeCNAME
35 "DNAME" -> RRTypeDNAME
45 | ver >= 2 = case xs of
50 | ver >= 3 = case xs of
56 "PING":[] -> Right PdnsRequestPing
57 "AXFR":x:[] -> Right (PdnsRequestAXFR x)
58 "Q":qn:"IN":qt:id:rip:xs -> Right (PdnsRequestQ
62 , remoteIpAddress = rip
63 , localIpAddress = getLIp ver xs
64 , ednsSubnetAddress = getRIp ver xs
66 _ -> Left $ "Unparseable PDNS Request: " ++ s
68 pdnsReport :: String -> String
70 "LOG\tError: " ++ err ++ "\nFAIL\n"
72 pdnsOut :: Int -> String -> String -> RRType -> Either String NmcDom -> String
73 pdnsOut ver id name rrtype edom = case edom of
74 Left err -> pdnsReport $ err ++ " in a query for " ++ name
75 Right dom -> foldr addLine "END\n" $ n2p rrtype
77 addLine (nm, ty, dt) accum =
78 "DATA\t" ++ v3ext ++ nm ++ "\tIN\t" ++ ty ++ "\t" ++ ttl ++
79 "\t" ++ id ++ "\t" ++ dt ++ "\n" ++ accum
86 foldr (\r accum -> (n2p r) ++ accum) []
87 [RRTypeSRV, RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME,
88 RRTypeSOA, RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS, RRTypeMX]
89 n2p RRTypeSRV = mapto "SRV" $ domSrv dom
90 n2p RRTypeMX = mapto "MX" $ domMx dom
91 n2p RRTypeA = mapto "A" $ domIp dom
92 n2p RRTypeAAAA = mapto "AAAA" $ domIp6 dom
93 n2p RRTypeCNAME = takejust "CNAME" $ domAlias dom
94 n2p RRTypeDNAME = takejust "DNAME" $ domTranslate dom
95 n2p RRTypeSOA = -- FIXME generate only for top domain
96 if dom == emptyNmcDom then []
99 email = case domEmail dom of
100 Nothing -> "hostmaster." ++ name
102 let (aname, adom) = break (== '@') addr
105 _ -> aname ++ "." ++ (tail adom)
106 in [(name, "SOA", email ++ " 99999999 10800 3600 604800 86400")]
107 n2p RRTypeRP = [] --FIXME
108 n2p RRTypeLOC = takejust "LOC" $ domLoc dom
109 n2p RRTypeNS = mapto "NS" $ domNs dom
110 n2p RRTypeDS = [] --FIXME
112 mapto rrstr maybel = case maybel of
114 Just l -> map (\x -> (name, rrstr, x)) l
115 takejust rrstr maybestr = case maybestr of
117 Just str -> [(name, rrstr, str)]