summaryrefslogtreecommitdiff
path: root/manifests/daemon.pp
blob: 578fae711275d9ec8c3f35e4befdbc4029e99fbb (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# tor::daemon
class tor::daemon inherits tor::polipo {

  group { "debian-tor":
    ensure    => present,
    allowdupe => false,
  }

  Package[ "tor", "torsocks" ] {
    require => File["/var/tor"],
  }

  user { "debian-tor":
    allowdupe => false,
    comment   => "tor user,,,",
    ensure    => present,
    home      => "/var/tor",
    shell     => "/bin/sh",
    gid       => "debian-tor",
    require   => Group["debian-tor"], 
  }

  file { "/var/tor":
    ensure  => directory,
    mode    => 0755,
    owner   => debian-tor,
    group   => debian-tor,
    require => User["debian-tor"],
  }

  file { "/etc/tor":
    ensure  => directory,
    mode    => 0755,
    owner   => debian-tor,
    group   => debian-tor,
    require => User["debian-tor"],
  }

  file { "/etc/tor.d":
    ensure  => directory,
    mode    => 0755,
    owner   => debian-tor,
    group   => debian-tor,
    require => User["debian-tor"],
  }

  # configuration file
  define config(                 $log_rules = [ 'notice file /var/log/tor/notices.log' ],
                 $data_directory = '/var/tor',
                 $hidden_services = [],
                 $dir_port = 0,
                 $dir_listen_address = '',
                 $dir_port_front_page = '',
                 $exit_policies = [],
                 $bridge_relay = 0) {

  }

  concatenated_file { "/etc/tor/torrc":
    dir    => '/etc/tor.d',
    mode   => 0600,
    notify => Service["tor"],
  }

  exec { "rm -f /etc/tor.d/*":
      alias => 'clean-tor.d',
  }

  # socks definition
  define tor::socks( $socks_port = 9050,
                     $socks_listen_addresses = [ '127.0.0.1' ],
                     $socks_policies = [ 'accept 127.0.0.1/16', 'reject *' ], ) {
    file { "/etc/tor.d/01.socks":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  }

  # relay definition
  define tor::relay( $port                  = 0,
                     $listen_address        = '',
                     $nickname              = '',
                     $address               = $hostname,
                     $relay_bandwidth_rate  = 0,  # KB/s, 0 for no limit.
                     $relay_bandwidth_burst = 0, # KB/s, 0 for no limit.
                     $accounting_max        = 0,       # GB, 0 for no limit.
                     $accounting_start      = [],
                     $contact_info          = '',
                     $my_family             = '',
                     $ensure                = absent, ) {

    file { "/etc/tor.d/02.relay":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  } 

  # control definition
  define tor::control( $port                    = 0,
                       $hashed_control_password = '',
                       $ensure                  = absent ) {
    file { "/etc/tor.d/03.control":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  } 

  # hidden services definition
  define tor::hidden_service( $ports = [],
                              $ensure = present ) {
    file { "/etc/tor.d/04.hidden_service.$name":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  } 
  
  # directory advertising
  define tor::directory ( $ports = [],
                          $hashed_password = '',
                          $ensure = present, ) {
    file { "/etc/tor.d/05.directory":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  } 

  # exit policies
  define tor::exit_policy( $accept = [],
                           $reject = [],
                           $ensure = present, ) {
    file { "/etc/tor.d/06.exit_policy":
      require => File['/etc/tor.d'],
      notify  => Exec['concat_/etc/tor/torrc'],
      ensure  => $ensure,
      require => Exec['clean-tor.d'],
    }
  } 
}