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
|
2014-09-23 17:19:26 +00:00
|
|
|
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-11-11 09:42:29 +00:00
|
|
|
setup = mainConfig `File.hasContent`
|
2014-03-30 04:52:02 +00:00
|
|
|
[ "SocksPort 0"
|
|
|
|
, "ORPort 443"
|
|
|
|
, "BridgeRelay 1"
|
|
|
|
, "Exitpolicy reject *:*"
|
2014-09-23 17:19:26 +00:00
|
|
|
] `onChange` restarted
|
2014-03-30 04:38:16 +00:00
|
|
|
|
2014-11-11 09:42:29 +00:00
|
|
|
hiddenServiceAvailable :: HostName -> Int -> Property
|
|
|
|
hiddenServiceAvailable hn port = hiddenServiceHostName prop
|
2014-11-10 19:39:15 +00:00
|
|
|
where
|
2014-11-11 09:42:29 +00:00
|
|
|
prop = mainConfig `File.containsLines`
|
2014-11-11 10:31:17 +00:00
|
|
|
[ unlines ["HiddenServiceDir", varLib </> hn]
|
2014-11-11 09:42:29 +00:00
|
|
|
, unlines ["HiddenServicePort", show port, "127.0.0.1:" ++ show port]
|
2014-11-10 20:27:36 +00:00
|
|
|
]
|
|
|
|
`describe` "hidden service available"
|
|
|
|
`onChange` Service.reloaded "tor"
|
2014-11-10 19:39:15 +00:00
|
|
|
hiddenServiceHostName p = adjustProperty p $ \satisfy -> do
|
|
|
|
r <- satisfy
|
2014-11-11 10:31:17 +00:00
|
|
|
h <- liftIO $ readFile (varLib </> hn </> "hostname")
|
2014-11-10 19:39:15 +00:00
|
|
|
warningMessage $ unlines ["hidden service hostname:", h]
|
|
|
|
return r
|
|
|
|
|
2014-11-11 09:42:29 +00:00
|
|
|
hiddenService :: HostName -> Int -> Property
|
|
|
|
hiddenService hn port = mainConfig `File.containsLines`
|
2014-11-11 10:31:17 +00:00
|
|
|
[ unlines ["HiddenServiceDir", varLib </> hn]
|
2014-11-11 09:42:29 +00:00
|
|
|
, unlines ["HiddenServicePort", show port, "127.0.0.1:" ++ show port]
|
2014-11-10 19:39:15 +00:00
|
|
|
]
|
2014-11-11 09:42:29 +00:00
|
|
|
`describe` unlines ["hidden service available:", hn, show port]
|
|
|
|
`onChange` restarted
|
2014-11-10 19:39:15 +00:00
|
|
|
|
2014-09-23 17:19:26 +00:00
|
|
|
restarted :: Property
|
|
|
|
restarted = Service.restarted "tor"
|
2014-11-11 09:42:29 +00:00
|
|
|
|
|
|
|
mainConfig :: FilePath
|
|
|
|
mainConfig = "/etc/tor/torrc"
|
|
|
|
|
2014-11-11 10:31:17 +00:00
|
|
|
varLib :: FilePath
|
|
|
|
varLib = "/var/lib/tor"
|