changed indentation for consistency with the rest of propellor

This commit is contained in:
Joey Hess 2014-10-31 10:20:34 -04:00
parent 63560cde90
commit 3a1f058c64
1 changed files with 46 additions and 41 deletions

View File

@ -5,7 +5,12 @@
module Propellor.Property.Firewall (
rule,
installed,
Chain(..),Target(..),Proto(..),Rules(..),ConnectionState(..)) where
Chain(..),
Target(..),
Proto(..),
Rules(..),
ConnectionState(..)
) where
import Data.Monoid
import Data.Char
@ -26,16 +31,17 @@ rule c t rs = property ("firewall rule: " <> show r) addIpTable
addIpTable = liftIO $ do
let args = toIpTable r
exist <- boolSystem "/sbin/iptables" (chk args)
if exist then
return NoChange
if exist
then return NoChange
else ifM (boolSystem "/sbin/iptables" (add args))
( return MadeChange , return FailedChange)
add params = (Param "-A") : params
chk params = (Param "-C") : params
toIpTable :: Rule -> [CommandParam]
toIpTable r = map Param ((show $ ruleChain r) :
(toIpTableArg (ruleRules r)) ++ [ "-j" , show $ ruleTarget r ])
toIpTable r = map Param $
(show $ ruleChain r) :
(toIpTableArg (ruleRules r)) ++ [ "-j" , show $ ruleTarget r ]
toIpTableArg :: Rules -> [String]
toIpTableArg Everything = []
@ -46,8 +52,8 @@ toIpTableArg (IFace iface) = ["-i", iface]
toIpTableArg (Ctstate states) = ["-m", "conntrack","--ctstate", concat $ intersperse "," (map show states)]
toIpTableArg (r :- r') = toIpTableArg r <> toIpTableArg r'
data Rule = Rule {
ruleChain :: Chain
data Rule = Rule
{ ruleChain :: Chain
, ruleTarget :: Target
, ruleRules :: Rules
} deriving (Eq, Show, Read)
@ -66,7 +72,8 @@ type Port = Int
data ConnectionState = ESTABLISHED | RELATED | NEW | INVALID
deriving (Eq,Show,Read)
data Rules = Everything
data Rules
= Everything
| Proto Proto
-- ^There is actually some order dependency between proto and port so this should be a specific
-- data type with proto + ports
@ -82,5 +89,3 @@ infixl 0 :-
instance Monoid Rules where
mempty = Everything
mappend = (:-)