blob: 205c9ddba713cdd936156e751df0531d7684d04f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
-- | Properties for the Unbound caching DNS server
module Propellor.Property.Unbound
( installed
, restarted
, reloaded
, genAddressNoTtl
, genAddress
, genMX
, genPTR
, genZoneStatic
, genZoneTransparent
) where
import Propellor
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
installed :: Property NoInfo
installed = Apt.installed ["unbound"]
restarted :: Property NoInfo
restarted = Service.restarted "unbound"
reloaded :: Property NoInfo
reloaded = Service.reloaded "unbound"
dValue :: BindDomain -> String
dValue (RelDomain d) = d
dValue (AbsDomain d) = d ++ "."
dValue (RootDomain) = "@"
genAddressNoTtl :: BindDomain -> IPAddr -> String
genAddressNoTtl dom = genAddress dom Nothing
genAddress :: BindDomain -> Maybe Int -> IPAddr -> String
genAddress dom ttl addr = case addr of
IPv4 _ -> genAddress' "A" dom ttl addr
IPv6 _ -> genAddress' "AAAA" dom ttl addr
genAddress' :: String -> BindDomain -> Maybe Int -> IPAddr -> String
genAddress' recordtype dom ttl addr = localData $ dValue dom ++ " " ++ maybe "" (\ttl' -> show ttl' ++ " ") ttl ++ "IN " ++ recordtype ++ " " ++ fromIPAddr addr
genMX :: BindDomain -> BindDomain -> Int -> String
genMX dom dest priority = localData $ dValue dom ++ " " ++ "MX" ++ " " ++ show priority ++ " " ++ dValue dest
genPTR :: BindDomain -> IPAddr -> String
genPTR dom ip = localData $ reverseIP ip ++ ". " ++ "PTR" ++ " " ++ dValue dom
localData :: String -> String
localData conf = " local-data: \"" ++ conf ++ "\""
genZoneStatic :: BindDomain -> String
genZoneStatic dom = localZone (dValue dom) "static"
genZoneTransparent :: BindDomain -> String
genZoneTransparent dom = localZone (dValue dom) "transparent"
localZone :: String -> String -> String
localZone zone confzone = " local-zone: \"" ++ zone ++ "\" " ++ confzone
|