summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2016-09-10 11:39:05 -0400
committerJoey Hess2016-09-10 11:39:05 -0400
commit8742377d83147302c65f5cc824420538ff2f36be (patch)
treea749d73cf9146f7b3172401e02be282899b0247f /src
parentc41c85b9ca9a7c5d6f1f7d4c76c9c61edb81b12b (diff)
parentfa64c0e49355b29e44d86371c827a632bc27d49a (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Tor.hs31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs
index 92dbd507..2fe97e4e 100644
--- a/src/Propellor/Property/Tor.hs
+++ b/src/Propellor/Property/Tor.hs
@@ -119,17 +119,12 @@ bandwidthRate' s divby = case readSize dataUnits s of
`describe` ("tor BandwidthRate " ++ v)
Nothing -> property ("unable to parse " ++ s) noChange
-hiddenServiceAvailable :: HiddenServiceName -> Int -> Property DebianLike
-hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port
- where
- hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do
- r <- satisfy
- h <- liftIO $ readFile (varLib </> hn </> "hostname")
- warningMessage $ unwords ["hidden service hostname:", h]
- return r
-
-hiddenService :: HiddenServiceName -> Int -> Property DebianLike
-hiddenService hn port = ConfFile.adjustSection
+-- | Enables a hidden service for a given port.
+--
+-- If used without `hiddenServiceData`, tor will generate a new
+-- private key.
+hiddenService :: HiddenServiceName -> Port -> Property DebianLike
+hiddenService hn (Port port) = ConfFile.adjustSection
(unwords ["hidden service", hn, "available on port", show port])
(== oniondir)
(not . isPrefixOf "HiddenServicePort")
@@ -141,6 +136,20 @@ hiddenService hn port = ConfFile.adjustSection
oniondir = unwords ["HiddenServiceDir", varLib </> hn]
onionport = unwords ["HiddenServicePort", show port, "127.0.0.1:" ++ show port]
+-- | Same as `hiddenService` but also causes propellor to display
+-- the onion address of the hidden service.
+hiddenServiceAvailable :: HiddenServiceName -> Port -> Property DebianLike
+hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port
+ where
+ hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do
+ r <- satisfy
+ mh <- liftIO $ tryIO $ readFile (varLib </> hn </> "hostname")
+ case mh of
+ Right h -> warningMessage $ unwords ["hidden service hostname:", h]
+ Left _e -> warningMessage "hidden service hostname not available yet"
+ return r
+
+-- | Load the private key for a hidden service from the privdata.
hiddenServiceData :: IsContext c => HiddenServiceName -> c -> Property (HasInfo + DebianLike)
hiddenServiceData hn context = combineProperties desc $ props
& installonion "hostname"