summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Unbound.hs
diff options
context:
space:
mode:
authorFélix Sipma2015-09-14 18:01:58 +0200
committerJoey Hess2015-09-14 14:58:01 -0400
commit0457c70623a86c872bdbdc731d74c96c432bbb1c (patch)
treed5a1a3b24a83dd4011adfe4adca6d04d36950440 /src/Propellor/Property/Unbound.hs
parent515f823c49e0eda9a07673bd938e36c33d9c1a80 (diff)
add Unbound property
Signed-off-by: Félix Sipma <felix.sipma@no-log.org>
Diffstat (limited to 'src/Propellor/Property/Unbound.hs')
-rw-r--r--src/Propellor/Property/Unbound.hs85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/Propellor/Property/Unbound.hs b/src/Propellor/Property/Unbound.hs
new file mode 100644
index 00000000..6708bb69
--- /dev/null
+++ b/src/Propellor/Property/Unbound.hs
@@ -0,0 +1,85 @@
+module Propellor.Property.Unbound
+ ( installed
+ , restarted
+ , reloaded
+ , genAddressNoTtl
+ , genAddress
+ , genMX
+ , genPTR
+ , revIP
+ , canonical
+ , genZoneStatic
+ , genZoneTransparent
+) where
+
+import Propellor
+import qualified Propellor.Property.Apt as Apt
+
+import Data.List
+import Data.String.Utils (split, replace)
+
+
+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 $ revIP ip ++ ". " ++ "PTR" ++ " " ++ dValue dom
+
+revIP :: IPAddr -> String
+revIP addr = case addr of
+ IPv4 addr' -> intercalate "." (reverse $ split "." addr') ++ ".in-addr.arpa"
+ IPv6 _ -> reverse (intersperse '.' $ replace ":" "" $ fromIPAddr $ canonical addr) ++ ".ip6.arpa"
+
+canonical :: IPAddr -> IPAddr
+canonical (IPv4 addr) = IPv4 addr
+canonical (IPv6 addr) = IPv6 $ intercalate ":" $ map canonicalGroup $ split ":" $ replaceImplicitGroups addr
+ where
+ canonicalGroup g = case length g of
+ 0 -> "0000"
+ 1 -> "000" ++ g
+ 2 -> "00" ++ g
+ 3 -> "0" ++ g
+ _ -> g
+ emptyGroups n = iterate (++ ":") "" !! n
+ numberOfImplicitGroups a = 8 - length (split ":" $ replace "::" "" a)
+ replaceImplicitGroups a = concat $ aux $ split "::" a
+ where
+ aux [] = []
+ aux (x : xs) = x : emptyGroups (numberOfImplicitGroups a) : xs
+
+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