1 module PowerDns ( RRType(..)
11 data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME
12 | RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC
13 | RRTypeNS | RRTypeDS | RRTypeMX
14 | RRTypeANY | RRTypeError String
17 data PdnsRequest = PdnsRequestQ
21 , remoteIpAddress :: String
22 , localIpAddress :: Maybe String
23 , ednsSubnetAddress :: Maybe String
31 getInt s = case reads s :: [(Int, String)] of
38 "CNAME" -> RRTypeCNAME
39 "DNAME" -> RRTypeDNAME
49 | ver >= 2 = case xs of
54 | ver >= 3 = case xs of
60 "PING":[] -> Right PdnsRequestPing
61 "AXFR":x:[] -> Right (PdnsRequestAXFR (getInt x))
62 "Q":qn:"IN":qt:id:rip:xs -> Right (PdnsRequestQ
66 , remoteIpAddress = rip
67 , localIpAddress = getLIp ver xs
68 , ednsSubnetAddress = getRIp ver xs
70 _ -> Left $ "Unparseable PDNS Request: " ++ s
72 pdnsReport :: String -> String
74 "LOG\tError: " ++ err ++ "\nFAIL\n"
76 pdnsOut :: Int -> Int -> String -> RRType -> Either String NmcDom -> String
77 pdnsOut ver id name rrtype edom = case edom of
78 Left err -> pdnsReport $ err ++ " in a query for " ++ name
79 Right dom -> foldr addLine "END\n" $ n2p rrtype
81 addLine (nm, ty, dt) accum =
82 "DATA\t" ++ v3ext ++ nm ++ "\tIN\t" ++ ty ++ "\t" ++ ttl ++
83 "\t" ++ (show id) ++ "\t" ++ dt ++ "\n" ++ accum
90 foldr (\r accum -> (n2p r) ++ accum) []
91 [RRTypeSRV, RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME,
92 RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS, RRTypeMX]
93 n2p RRTypeSRV = mapto "SRV" $ domSrv dom
94 n2p RRTypeMX = mapto "MX" $ domMx dom
95 n2p RRTypeA = mapto "A" $ domIp dom
96 n2p RRTypeAAAA = mapto "AAAA" $ domIp6 dom
97 n2p RRTypeCNAME = takejust "CNAME" $ domAlias dom
98 n2p RRTypeDNAME = takejust "DNAME" $ domTranslate dom
99 n2p RRTypeSOA = -- FIXME generate only for top domain
100 -- FIXME make realistic version field
101 -- FIXME make realistic nameserver field
102 if dom == emptyNmcDom then []
103 else [(name, "SOA", "ns " ++ email ++ " 99999 10800 3600 604800 86400")]
105 email = case domEmail dom of
106 Nothing -> "hostmaster." ++ name
107 Just addr -> dotmail addr
108 n2p RRTypeRP = case domEmail dom of
110 Just addr -> [(name, "RP", (dotmail addr) ++ " .")]
111 n2p RRTypeLOC = takejust "LOC" $ domLoc dom
112 n2p RRTypeNS = mapto "NS" $ domNs dom
113 n2p RRTypeDS = case domDs dom of
115 Just dss -> map (\x -> (name, "DS", dsStr x)) dss
117 dsStr x = (show (dsKeyTag x)) ++ " "
118 ++ (show (dsAlgo x)) ++ " "
119 ++ (show (dsHashType x)) ++ " "
123 let (aname, adom) = break (== '@') addr
126 _ -> aname ++ "." ++ (tail adom)
128 mapto rrstr maybel = case maybel of
130 Just l -> map (\x -> (name, rrstr, x)) l
131 takejust rrstr maybestr = case maybestr of
133 Just str -> [(name, rrstr, str)]
135 pdnsOutXfr :: Int -> Int -> String -> Either String NmcDom -> String
136 pdnsOutXfr ver id name edom = case edom of
137 Left err -> pdnsReport $ err ++ " in a query for " ++ name
138 Right dom -> pdnsReport $ "AXFR unsupported in a query for " ++ name