{-# LANGUAGE OverloadedStrings #-}
module NmcDom ( NmcDom(..)
+ , NmcRRService(..)
, emptyNmcDom
, seedNmcDom
, descendNmcDom
, domTls :: Maybe (Map String
(Map String [[String]]))
, domDs :: Maybe [[String]]
+ , domMx :: Maybe [String] -- Synthetic
} deriving (Show, Eq)
instance FromJSON NmcDom where
<*> o .:? "fingerprint"
<*> o .:? "tls"
<*> o .:? "ds"
+ <*> return Nothing -- domMx not parsed
parseJSON _ = empty
instance Mergeable NmcDom where
, domFingerprint = mergelm domFingerprint
, domTls = mergelm domTls
, domDs = mergelm domDs
+ , domMx = mergelm domMx
}
where
mergelm x = merge (x sub) (x dom)
emptyNmcDom = NmcDom Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing
+ Nothing
-- | Perform query and return error string or parsed domain object
queryNmcDom ::
translateNormalizer dom = case domTranslate dom of
Nothing -> dom
Just tr -> dom { domMap = Nothing }
- srvNormalizer dom = dom { domService = Nothing }
+ srvNormalizer dom = dom { domService = Nothing, domMx = makemx }
+ where
+ makemx = case domService dom of
+ Nothing -> Nothing
+ Just svl -> Just $ map makerec (filter needed svl)
+ where
+ needed sr = srvName sr == "smtp"
+ && srvProto sr == "tcp"
+ && srvPort sr == 25
+ makerec sr = (show (srvPrio sr)) ++ " " ++ (srvHost sr)
-- | Merge imports and Selfs and follow the maps tree to get dom
descendNmcDom ::
data RRType = RRTypeSRV | RRTypeA | RRTypeAAAA | RRTypeCNAME
| RRTypeDNAME | RRTypeSOA | RRTypeRP | RRTypeLOC
- | RRTypeNS | RRTypeDS
+ | RRTypeNS | RRTypeDS | RRTypeMX
| RRTypeANY | RRTypeError String
deriving (Show)
"LOC" -> RRTypeLOC
"NS" -> RRTypeNS
"DS" -> RRTypeDS
+ "MX" -> RRTypeMX
"ANY" -> RRTypeANY
_ -> RRTypeError qt
getLIp ver xs
nmc2pdns :: String -> RRType -> NmcDom -> [(String, String, String)]
nmc2pdns name RRTypeANY dom =
foldr (\r accum -> (nmc2pdns name r dom) ++ accum) []
- [RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME, -- no SRV here!
- RRTypeSOA, RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS]
-nmc2pdns name RRTypeSRV dom = [] -- FIXME
+ [RRTypeSRV, RRTypeA, RRTypeAAAA, RRTypeCNAME, RRTypeDNAME,
+ RRTypeSOA, RRTypeRP, RRTypeLOC, RRTypeNS, RRTypeDS, RRTypeMX]
+nmc2pdns name RRTypeSRV dom = makesrv name "SRV" $ domService dom
+nmc2pdns name RRTypeMX dom = mapto name "MX" $ domMx dom
nmc2pdns name RRTypeA dom = mapto name "A" $ domIp dom
nmc2pdns name RRTypeAAAA dom = mapto name "AAAA" $ domIp6 dom
nmc2pdns name RRTypeCNAME dom = takejust name "CNAME" $ domAlias dom
takejust name rrstr maybestr = case maybestr of
Nothing -> []
Just str -> [(name, rrstr, str)]
+
+makesrv name rrstr mayberl = case mayberl of
+ Nothing -> []
+ Just srl -> map (\x -> (name, rrstr, fmtsrv x)) srl
+ where
+ fmtsrv rl = (show (srvPrio rl)) ++ " "
+ ++ (show (srvWeight rl)) ++ " "
+ ++ (show (srvPort rl)) ++ " "
+ ++ (srvHost rl)
-{"service":[["smtp", "tcp", 0, 0, 143, "mail.host.com."]],"import":"d/extra2","ip":["1.2.3.4"],"alias":"extra1alias"}
+{"service":[["smtp", "tcp", 0, 0, 25, "mail.host.com."]],"import":"d/extra2","ip":["1.2.3.4"],"alias":"extra1alias"}