From 0d188bf5f6a1ad519a660e06d7e74c6cf683ff32 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 18 Jul 2014 14:33:30 -0400 Subject: propellor spin --- src/Propellor/Property/Postfix.hs | 33 +++++++++++++++++++----- src/Propellor/Property/SiteSpecific/JoeySites.hs | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Propellor/Property/Postfix.hs b/src/Propellor/Property/Postfix.hs index 52c329bd..96bc1bc1 100644 --- a/src/Propellor/Property/Postfix.hs +++ b/src/Propellor/Property/Postfix.hs @@ -38,14 +38,14 @@ satellite = check norelayhost setup , ("postfix/destinations", "string", " ") , ("postfix/mailname", "string", hn) ] - , mainCf `containsLine` ("relayhost = " ++ domain) - `onChange` dedupMainCf + , mainCf ("relayhost", domain) `onChange` reloaded ] norelayhost = not . any relayhostset . lines <$> readProcess "postconf" [] relayhostset l | l == "relayhost =" = False + | l == "relayhost = " = False | "relayhost =" `isPrefixOf` l = True | otherwise = False @@ -61,6 +61,29 @@ mappedFile f setup = setup f newaliases :: Property newaliases = trivial $ cmdProperty "newaliases" [] +-- | The main config file for postfix. +mainCfFile :: FilePath +mainCfFile = "/etc/postfix/main.cf" + +-- | Sets a main.cf name=value pair. Does not reload postfix immediately. +mainCf :: (String, String) -> Property +mainCf (name, value) = check notset set + `describe` ("postfix main.cf " ++ setting) + where + setting = name ++ "=" ++ value + notset = (/= Just value) <$> getMainCf name + set = cmdProperty "postconf" ["-e", setting] + +-- | Gets a man.cf setting. +getMainCf :: String -> IO (Maybe String) +getMainCf name = parse . lines <$> readProcess "postconf" [name] + where + parse (l:_) = Just $ + case separate (== '=') l of + (_, (' ':v)) -> v + (_, v) -> v + parse [] = Nothing + -- | Parses main.cf, and removes any initial configuration lines that are -- overridden to other values later in the file. -- @@ -74,7 +97,7 @@ newaliases = trivial $ cmdProperty "newaliases" [] -- Note that multiline configurations that continue onto the next line -- are not currently supported. dedupMainCf :: Property -dedupMainCf = fileProperty "postfix main.cf dedupped" dedupCf mainCf +dedupMainCf = fileProperty "postfix main.cf dedupped" dedupCf mainCfFile dedupCf :: [String] -> [String] dedupCf ls = @@ -96,7 +119,3 @@ dedupCf ls = dedup c kc ((Right (k, v)):rest) = case M.lookup k kc of Just n | n > 1 -> dedup c (M.insert k (n - 1) kc) rest _ -> dedup (fmt k v:c) kc rest - --- | The main config file for postfix. -mainCf :: FilePath -mainCf = "/etc/postfix/main.cf" diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs index d1f22fc1..14cae614 100644 --- a/src/Propellor/Property/SiteSpecific/JoeySites.hs +++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs @@ -461,7 +461,7 @@ kiteMailServer = propertyList "kitenet.net mail server" `onChange` Postfix.reloaded , Postfix.mappedFile "/etc/postfix/relay_clientcerts" $ flip File.hasPrivContentExposed ctx - , Postfix.mainCf `File.containsLines` + , Postfix.mainCfFile `File.containsLines` [ "myhostname = kitenet.net" , "mydomain = $myhostname" , "append_dot_mydomain = no" -- cgit v1.2.3