2016-11-14 17:26:34 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.EnableTor where
|
|
|
|
|
|
|
|
import Command
|
2016-11-29 21:30:27 +00:00
|
|
|
import P2P.Address
|
2016-11-14 17:26:34 +00:00
|
|
|
import Utility.Tor
|
2016-11-29 21:30:27 +00:00
|
|
|
import Annex.UUID
|
2016-11-14 17:26:34 +00:00
|
|
|
|
2016-11-14 20:35:45 +00:00
|
|
|
-- This runs as root, so avoid making any commits or initializing
|
2016-11-29 21:30:27 +00:00
|
|
|
-- git-annex, or doing other things that create root-owned files.
|
2016-11-14 17:26:34 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = noCommit $ dontCheck repoExists $
|
2016-11-29 21:30:27 +00:00
|
|
|
command "enable-tor" SectionSetup "enable tor hidden service"
|
|
|
|
"uid" (withParams seek)
|
2016-11-14 17:26:34 +00:00
|
|
|
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
|
|
seek = withWords start
|
|
|
|
|
2016-11-29 21:30:27 +00:00
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start ps = case readish =<< headMaybe ps of
|
|
|
|
Nothing -> giveup "Bad params"
|
2016-11-14 20:35:45 +00:00
|
|
|
Just userid -> do
|
2016-11-29 21:30:27 +00:00
|
|
|
uuid <- getUUID
|
|
|
|
when (uuid == NoUUID) $
|
|
|
|
giveup "This can only be run in a git-annex repository."
|
|
|
|
(onionaddr, onionport) <- liftIO $
|
|
|
|
addHiddenService userid (fromUUID uuid)
|
|
|
|
storeP2PAddress $ TorAnnex onionaddr onionport
|
2016-11-14 17:26:34 +00:00
|
|
|
stop
|