summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Aiccu.hs
blob: 8bf3f28399b8686fcc1cc0196c661eac732363e0 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{-# LANGUAGE TypeFamilies #-}

-- | Maintainer: Jelmer Vernooij <jelmer@samba.org>

module Propellor.Property.Aiccu (
	installed,
	restarted,
	confPath,
	UserName,
	TunnelId,
	hasConfig,
) where

import Propellor.Base
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
import qualified Propellor.Property.File as File

installed :: Property DebianLike
installed = Apt.installed ["aiccu"]

restarted :: Property DebianLike
restarted = Service.restarted "aiccu"

confPath :: FilePath
confPath = "/etc/aiccu.conf"

type TunnelId = String

config :: UserName -> TunnelId -> PrivData -> [File.Line]
config u t p = 
	[ "protocol tic"
	, "server tic.sixxs.net"
	, "username " ++ u
	, "password " ++ privDataVal p
	, "ipv6_interface sixxs"
	, "tunnel_id " ++ t
	, "daemonize true"
	, "automatic true"
	, "requiretls true"
	, "makebeats true"
	]

-- | Configures an ipv6 tunnel using sixxs.net, with the given TunneId
-- and sixx.net UserName.
hasConfig :: TunnelId -> UserName -> Property (HasInfo + DebianLike)
hasConfig t u = prop `onChange` restarted
  where
  	prop :: Property (HasInfo + UnixLike)
	prop = withSomePrivData [(Password (u++"/"++t)), (Password u)] (Context "aiccu") $ \getpassword ->
		property' "aiccu configured" $ \w -> getpassword $ ensureProperty w . go
	go (Password u', p) = confPath `File.hasContentProtected` config u' t p
	go (f, _) = error $ "Unexpected type of privdata: " ++ show f