1 module PowerDns ( RRType(..)
10 data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME
11 | RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC
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
44 | ver >= 2 = case xs of
49 | ver >= 3 = case xs of
55 "PING":[] -> Right PdnsRequestPing
56 "AXFR":x:[] -> Right (PdnsRequestAXFR x)
57 "Q":qn:"IN":qt:id:rip:xs -> Right (PdnsRequestQ
61 , remoteIpAddress = rip
62 , localIpAddress = getLIp ver xs
63 , ednsSubnetAddress = getRIp ver xs
65 _ -> Left $ "Unparseable PDNS Request: " ++ s
67 pdnsReport :: String -> String
69 "LOG\tError: " ++ err ++ "\nFAIL\n"
71 pdnsOut :: Int -> String -> String -> RRType -> Either String NmcDom -> String
72 pdnsOut ver id name rrtype edom =
74 Left err -> pdnsReport err
75 Right dom -> foldr addLine "END\n" $ nmc2pdns name rrtype dom
77 addLine (nm, ty, dt) accum =
78 "DATA\t" ++ v3ext ++ nm ++ "\tIN\t" ++ ty ++ "\t" ++ ttl ++
79 "\t" ++ id ++ "\t" ++ dt ++ "\n" ++ accum
85 nmc2pdns :: String -> RRType -> NmcDom -> [(String, String, String)]
86 nmc2pdns name RRTypeANY dom =
87 foldr (\r accum -> (nmc2pdns name r dom) ++ accum) []
88 [RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME, -- no SRV here!
89 RRTypeSOA, RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS]
90 nmc2pdns name RRTypeSRV dom = [] -- FIXME
91 nmc2pdns name RRTypeA dom = mapto name "A" $ domIp dom
92 nmc2pdns name RRTypeAAAA dom = mapto name "AAAA" $ domIp6 dom
93 nmc2pdns name RRTypeCNAME dom = takejust name "CNAME" $ domAlias dom
94 nmc2pdns name RRTypeDNAME dom = takejust name "DNAME" $ domTranslate dom
95 nmc2pdns name RRTypeSOA dom =
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 nmc2pdns name RRTypeRP dom = [] --FIXME
108 nmc2pdns name RRTypeLOC dom = takejust name "LOC" $ domLoc dom
109 nmc2pdns name RRTypeNS dom = mapto name "NS" $ domNs dom
110 nmc2pdns name RRTypeDS dom = [] --FIXME
112 mapto name rrstr maybel = case maybel of
114 Just l -> map (\x -> (name, rrstr, x)) l
116 takejust name rrstr maybestr = case maybestr of
118 Just str -> [(name, rrstr, str)]