propellor/src/Propellor/Property/Tor.hs

44 lines
1.4 KiB
Haskell
Raw Normal View History

2014-03-31 03:37:54 +00:00
module Propellor.Property.Tor where
2014-03-30 04:38:16 +00:00
2014-03-31 03:55:59 +00:00
import Propellor
2014-03-31 03:37:54 +00:00
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
2014-03-30 04:38:16 +00:00
isBridge :: Property
2014-03-30 04:52:02 +00:00
isBridge = setup `requires` Apt.installed ["tor"]
2014-03-30 19:53:35 +00:00
`describe` "tor bridge"
2014-03-30 04:52:02 +00:00
where
2014-03-30 17:12:33 +00:00
setup = "/etc/tor/torrc" `File.hasContent`
2014-03-30 04:52:02 +00:00
[ "SocksPort 0"
, "ORPort 443"
, "BridgeRelay 1"
, "Exitpolicy reject *:*"
] `onChange` restarted
2014-03-30 04:38:16 +00:00
hiddenServiceAvailable :: FilePath -> Int -> Property
hiddenServiceAvailable dir port = hiddenServiceHostName prop
where
prop = "/etc/tor/torrc" `File.containsLines`
[ "HiddenServiceDir " ++ dir
, "HiddenServicePort " ++ show port ++ " 127.0.0.1:" ++ show port
]
`describe` "hidden service available"
`onChange` Service.reloaded "tor"
hiddenServiceHostName p = adjustProperty p $ \satisfy -> do
r <- satisfy
h <- liftIO $ readFile (dir </> "hostname")
warningMessage $ unlines ["hidden service hostname:", h]
return r
hiddenService :: FilePath -> Int -> Property
hiddenService dir port = "/etc/tor/torrc" `File.containsLines`
[ "HiddenServiceDir " ++ dir
, "HiddenServicePort " ++ show port ++ " 127.0.0.1:" ++ show port
]
`describe` ("hidden service (" ++ dir ++ " " ++ show port ++ ") available")
`onChange` Service.reloaded "tor"
restarted :: Property
restarted = Service.restarted "tor"