summaryrefslogtreecommitdiff
path: root/Command/EnableTor.hs
blob: 369ea75093621eed1943a952139c150a45e3f4ad (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
{- 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 Utility.Tor

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

seek :: CmdParams -> CommandSeek
seek = withWords start

start :: CmdParams -> CommandStart
start (suserid:uuid:[]) = case readish suserid of
	Nothing -> error "Bad userid"
	Just userid -> do
		(onionaddr, onionport, onionsocket) <- liftIO $
			addHiddenService userid uuid
		liftIO $ putStrLn $
			onionaddr ++ ":" ++ 
			show onionport ++ " " ++
			show onionsocket
		stop
start _ = error "Bad params"