propellor/src/Propellor/Types/Dns.hs

93 lines
2.2 KiB
Haskell
Raw Normal View History

2014-04-18 21:19:28 +00:00
module Propellor.Types.Dns where
2014-04-23 19:04:35 +00:00
import Propellor.Types.OS (HostName)
2014-04-18 23:06:55 +00:00
import Data.Word
2014-04-18 21:19:28 +00:00
type Domain = String
data IPAddr = IPv4 String | IPv6 String
deriving (Read, Show, Eq, Ord)
fromIPAddr :: IPAddr -> String
fromIPAddr (IPv4 addr) = addr
fromIPAddr (IPv6 addr) = addr
-- | Represents a bind 9 named.conf file.
data NamedConf = NamedConf
{ confDomain :: Domain
2014-04-23 19:04:35 +00:00
, confDnsServerType :: DnsServerType
2014-04-18 21:19:28 +00:00
, confFile :: FilePath
, confMasters :: [IPAddr]
2014-04-23 19:04:35 +00:00
, confAllowTransfer :: [IPAddr]
2014-04-18 21:19:28 +00:00
, confLines :: [String]
}
deriving (Show, Eq, Ord)
2014-04-18 21:19:28 +00:00
2014-04-23 19:04:35 +00:00
data DnsServerType = Master | Secondary
deriving (Show, Eq, Ord)
2014-04-18 21:19:28 +00:00
-- | Represents a bind 9 zone file.
data Zone = Zone
{ zDomain :: Domain
, zSOA :: SOA
, zHosts :: [(BindDomain, Record)]
2014-04-18 21:19:28 +00:00
}
deriving (Read, Show, Eq)
-- | Every domain has a SOA record, which is big and complicated.
data SOA = SOA
{ sDomain :: BindDomain
-- ^ Typically ns1.your.domain
, sSerial :: SerialNumber
-- ^ The most important parameter is the serial number,
-- which must increase after each change.
, sRefresh :: Integer
, sRetry :: Integer
, sExpire :: Integer
2014-04-19 02:57:51 +00:00
, sNegativeCacheTTL :: Integer
2014-04-18 21:19:28 +00:00
}
deriving (Read, Show, Eq)
-- | Types of DNS records.
--
-- This is not a complete list, more can be added.
data Record
= Address IPAddr
| CNAME BindDomain
| MX Int BindDomain
| NS BindDomain
| TXT String
2014-04-19 03:29:01 +00:00
| SRV Word16 Word16 Word16 BindDomain
2014-04-18 21:19:28 +00:00
deriving (Read, Show, Eq, Ord)
getIPAddr :: Record -> Maybe IPAddr
getIPAddr (Address addr) = Just addr
getIPAddr _ = Nothing
getCNAME :: Record -> Maybe BindDomain
getCNAME (CNAME d) = Just d
getCNAME _ = Nothing
2014-04-23 19:04:35 +00:00
getNS :: Record -> Maybe BindDomain
getNS (NS d) = Just d
getNS _ = Nothing
2014-04-18 21:19:28 +00:00
-- | Bind serial numbers are unsigned, 32 bit integers.
2014-04-18 23:06:55 +00:00
type SerialNumber = Word32
2014-04-18 21:19:28 +00:00
-- | Domains in the zone file must end with a period if they are absolute.
--
-- Let's use a type to keep absolute domains straight from relative
-- domains.
--
-- The RootDomain refers to the top level of the domain, so can be used
-- to add nameservers, MX's, etc to a domain.
data BindDomain = RelDomain Domain | AbsDomain Domain | RootDomain
2014-04-18 21:19:28 +00:00
deriving (Read, Show, Eq, Ord)
2014-04-23 19:04:35 +00:00
domainHostName :: BindDomain -> Maybe HostName
domainHostName (RelDomain d) = Just d
domainHostName (AbsDomain d) = Just d
domainHostName RootDomain = Nothing