summaryrefslogtreecommitdiff
path: root/Command/EnableTor.hs
blob: c6d477b4e73d7139b7d1f51fc823faa7269ff0d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{- 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
import P2P.Address
import Utility.Tor
import Annex.UUID

-- This runs as root, so avoid making any commits or initializing
-- git-annex, or doing other things that create root-owned files.
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
	command "enable-tor" SectionSetup "enable tor hidden service"
		"uid" (withParams seek)

seek :: CmdParams -> CommandSeek
seek = withWords start

start :: [String] -> CommandStart
start ps = case readish =<< headMaybe ps of
	Nothing -> giveup "Bad params"
	Just userid -> do
		uuid <- getUUID
		when (uuid == NoUUID) $
			giveup "This can only be run in a git-annex repository."
		(onionaddr, onionport) <- liftIO $
			addHiddenService "tor-annex" userid (fromUUID uuid)
		storeP2PAddress $ TorAnnex onionaddr onionport
		stop