|
@@ -29,338 +29,326 @@
|
29
|
29
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
30
|
30
|
|
31
|
31
|
function wait_for_onion_service {
|
32
|
|
- onion_service_name="$1"
|
33
|
|
-
|
34
|
|
- sleep_ctr=0
|
35
|
|
- while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
36
|
|
- sleep 1
|
37
|
|
- sleep_ctr=$((sleep_ctr + 1))
|
38
|
|
- if [ $sleep_ctr -gt 10 ]; then
|
39
|
|
- break
|
40
|
|
- fi
|
41
|
|
- done
|
42
|
|
-
|
43
|
|
- if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
44
|
|
- # restart and try a second time
|
45
|
|
- systemctl restart tor
|
46
|
|
- sleep_ctr=0
|
47
|
|
- while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
48
|
|
- sleep 1
|
49
|
|
- sleep_ctr=$((sleep_ctr + 1))
|
50
|
|
- if [ $sleep_ctr -gt 10 ]; then
|
51
|
|
- break
|
52
|
|
- fi
|
53
|
|
- done
|
54
|
|
- fi
|
|
32
|
+ onion_service_name="$1"
|
|
33
|
+
|
|
34
|
+ sleep_ctr=0
|
|
35
|
+ while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
|
36
|
+ sleep 1
|
|
37
|
+ sleep_ctr=$((sleep_ctr + 1))
|
|
38
|
+ if [ $sleep_ctr -gt 10 ]; then
|
|
39
|
+ break
|
|
40
|
+ fi
|
|
41
|
+ done
|
|
42
|
+
|
|
43
|
+ if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
44
|
+ # restart and try a second time
|
|
45
|
+ systemctl restart tor
|
|
46
|
+ sleep_ctr=0
|
|
47
|
+ while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
|
48
|
+ sleep 1
|
|
49
|
+ sleep_ctr=$((sleep_ctr + 1))
|
|
50
|
+ if [ $sleep_ctr -gt 10 ]; then
|
|
51
|
+ break
|
|
52
|
+ fi
|
|
53
|
+ done
|
|
54
|
+ fi
|
55
|
55
|
}
|
56
|
56
|
|
57
|
57
|
function remove_onion_service {
|
58
|
|
- onion_service_name="$1"
|
59
|
|
- onion_service_port_to=$2
|
60
|
|
- sed -i "/hidden_service_${onion_service_name}/d" /etc/tor/torrc
|
61
|
|
- sed -i "/127.0.0.1:${onion_service_port_to}/d" /etc/tor/torrc
|
62
|
|
- if [ $3 ]; then
|
63
|
|
- sed -i "/127.0.0.1:${3}/d" /etc/tor/torrc
|
64
|
|
- if [ $4 ]; then
|
65
|
|
- sed -i "/127.0.0.1:${4}/d" /etc/tor/torrc
|
66
|
|
- if [ $5 ]; then
|
67
|
|
- sed -i "/127.0.0.1:${5}/d" /etc/tor/torrc
|
68
|
|
- fi
|
69
|
|
- fi
|
70
|
|
- fi
|
71
|
|
- systemctl restart tor
|
|
58
|
+ onion_service_name="$1"
|
|
59
|
+ onion_service_port_to=$2
|
|
60
|
+ sed -i "/hidden_service_${onion_service_name}/d" /etc/tor/torrc
|
|
61
|
+ sed -i "/127.0.0.1:${onion_service_port_to}/d" /etc/tor/torrc
|
|
62
|
+ if [ $3 ]; then
|
|
63
|
+ sed -i "/127.0.0.1:${3}/d" /etc/tor/torrc
|
|
64
|
+ if [ $4 ]; then
|
|
65
|
+ sed -i "/127.0.0.1:${4}/d" /etc/tor/torrc
|
|
66
|
+ if [ $5 ]; then
|
|
67
|
+ sed -i "/127.0.0.1:${5}/d" /etc/tor/torrc
|
|
68
|
+ fi
|
|
69
|
+ fi
|
|
70
|
+ fi
|
|
71
|
+ systemctl restart tor
|
72
|
72
|
}
|
73
|
73
|
|
74
|
74
|
function add_onion_service {
|
75
|
|
- onion_service_name="$1"
|
76
|
|
- onion_service_port_from=$2
|
77
|
|
- onion_service_port_to=$3
|
78
|
|
-
|
79
|
|
- if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
80
|
|
- echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
|
81
|
|
- return
|
82
|
|
- fi
|
83
|
|
-
|
84
|
|
- if [ ! -d /var/lib/tor ]; then
|
85
|
|
- echo $"No Tor installation found. ${onion_service_name} onion site cannot be configured."
|
86
|
|
- exit 877367
|
87
|
|
- fi
|
88
|
|
- if ! grep -q "hidden_service_${onion_service_name}" /etc/tor/torrc; then
|
89
|
|
- echo "HiddenServiceDir /var/lib/tor/hidden_service_${onion_service_name}/" >> /etc/tor/torrc
|
90
|
|
- echo "HiddenServicePort ${onion_service_port_from} 127.0.0.1:${onion_service_port_to}" >> /etc/tor/torrc
|
91
|
|
- fi
|
92
|
|
-
|
93
|
|
- systemctl restart tor
|
94
|
|
-
|
95
|
|
- function_check wait_for_onion_service
|
96
|
|
- wait_for_onion_service ${onion_service_name}
|
97
|
|
-
|
98
|
|
- if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
99
|
|
- echo $"${onion_service_name} onion site hostname not found"
|
100
|
|
- exit 76362
|
101
|
|
- fi
|
102
|
|
- echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
|
|
75
|
+ onion_service_name="$1"
|
|
76
|
+ onion_service_port_from=$2
|
|
77
|
+ onion_service_port_to=$3
|
|
78
|
+
|
|
79
|
+ if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
80
|
+ echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
|
|
81
|
+ return
|
|
82
|
+ fi
|
|
83
|
+
|
|
84
|
+ if [ ! -d /var/lib/tor ]; then
|
|
85
|
+ echo $"No Tor installation found. ${onion_service_name} onion site cannot be configured."
|
|
86
|
+ exit 877367
|
|
87
|
+ fi
|
|
88
|
+ if ! grep -q "hidden_service_${onion_service_name}" /etc/tor/torrc; then
|
|
89
|
+ echo "HiddenServiceDir /var/lib/tor/hidden_service_${onion_service_name}/" >> /etc/tor/torrc
|
|
90
|
+ echo "HiddenServicePort ${onion_service_port_from} 127.0.0.1:${onion_service_port_to}" >> /etc/tor/torrc
|
|
91
|
+ fi
|
|
92
|
+
|
|
93
|
+ systemctl restart tor
|
|
94
|
+
|
|
95
|
+ function_check wait_for_onion_service
|
|
96
|
+ wait_for_onion_service ${onion_service_name}
|
|
97
|
+
|
|
98
|
+ if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
99
|
+ echo $"${onion_service_name} onion site hostname not found"
|
|
100
|
+ exit 76362
|
|
101
|
+ fi
|
|
102
|
+ echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
|
103
|
103
|
}
|
104
|
104
|
|
105
|
105
|
function set_default_onion_domains {
|
106
|
|
- # If sites are only visible via Tor then for installation
|
107
|
|
- # purposes assign them some default domain names
|
108
|
|
- if [[ $ONION_ONLY == "no" ]]; then
|
109
|
|
- return
|
110
|
|
- fi
|
111
|
|
-
|
112
|
|
- if [ ${#MICROBLOG_DOMAIN_NAME} -gt 1 ]; then
|
113
|
|
- MICROBLOG_DOMAIN_NAME='microblog.local'
|
114
|
|
- fi
|
115
|
|
- if [ ${#FULLBLOG_DOMAIN_NAME} -gt 1 ]; then
|
116
|
|
- FULLBLOG_DOMAIN_NAME='blog.local'
|
117
|
|
- fi
|
118
|
|
- if [ ${#WIKI_DOMAIN_NAME} -gt 1 ]; then
|
119
|
|
- WIKI_DOMAIN_NAME='wiki.local'
|
120
|
|
- fi
|
121
|
|
- if [ ${#DEFAULT_DOMAIN_NAME} -gt 1 ]; then
|
122
|
|
- DEFAULT_DOMAIN_NAME="${PROJECT_NAME}.local"
|
123
|
|
- fi
|
124
|
|
- if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then
|
125
|
|
- GIT_DOMAIN_NAME='git.local'
|
126
|
|
- fi
|
127
|
|
- if [ ${#MEDIAGOBLIN_DOMAIN_NAME} -gt 1 ]; then
|
128
|
|
- MEDIAGOBLIN_DOMAIN_NAME='media.local'
|
129
|
|
- fi
|
|
106
|
+ # If sites are only visible via Tor then for installation
|
|
107
|
+ # purposes assign them some default domain names
|
|
108
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
109
|
+ return
|
|
110
|
+ fi
|
|
111
|
+
|
|
112
|
+ MICROBLOG_DOMAIN_NAME='microblog.local'
|
|
113
|
+ FULLBLOG_DOMAIN_NAME='blog.local'
|
|
114
|
+ WIKI_DOMAIN_NAME='wiki.local'
|
|
115
|
+ DEFAULT_DOMAIN_NAME="${PROJECT_NAME}.local"
|
|
116
|
+ GIT_DOMAIN_NAME='git.local'
|
|
117
|
+ MEDIAGOBLIN_DOMAIN_NAME='media.local'
|
130
|
118
|
}
|
131
|
119
|
|
132
|
120
|
function create_avahi_onion_domains {
|
133
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
134
|
|
- return
|
135
|
|
- fi
|
136
|
|
- if [ ! -d /etc/avahi/services ]; then
|
137
|
|
- return
|
138
|
|
- fi
|
139
|
|
- if [ $MICROBLOG_DOMAIN_NAME ]; then
|
140
|
|
- function_check create_avahi_service
|
141
|
|
- create_avahi_service microblog http tcp $MICROBLOG_ONION_PORT
|
142
|
|
- fi
|
143
|
|
- if [ $FULLBLOG_DOMAIN_NAME ]; then
|
144
|
|
- function_check create_avahi_service
|
145
|
|
- create_avahi_service blog http tcp $BLOG_ONION_PORT
|
146
|
|
- fi
|
147
|
|
- if [ $GIT_DOMAIN_NAME ]; then
|
148
|
|
- function_check create_avahi_service
|
149
|
|
- create_avahi_service git http tcp $GIT_ONION_PORT
|
150
|
|
- fi
|
151
|
|
- if [ $WIKI_DOMAIN_NAME ]; then
|
152
|
|
- function_check create_avahi_service
|
153
|
|
- create_avahi_service wiki http tcp $WIKI_ONION_PORT
|
154
|
|
- fi
|
|
121
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
122
|
+ return
|
|
123
|
+ fi
|
|
124
|
+ if [ ! -d /etc/avahi/services ]; then
|
|
125
|
+ return
|
|
126
|
+ fi
|
|
127
|
+ if [ $MICROBLOG_DOMAIN_NAME ]; then
|
|
128
|
+ function_check create_avahi_service
|
|
129
|
+ create_avahi_service microblog http tcp $MICROBLOG_ONION_PORT
|
|
130
|
+ fi
|
|
131
|
+ if [ $FULLBLOG_DOMAIN_NAME ]; then
|
|
132
|
+ function_check create_avahi_service
|
|
133
|
+ create_avahi_service blog http tcp $BLOG_ONION_PORT
|
|
134
|
+ fi
|
|
135
|
+ if [ $GIT_DOMAIN_NAME ]; then
|
|
136
|
+ function_check create_avahi_service
|
|
137
|
+ create_avahi_service git http tcp $GIT_ONION_PORT
|
|
138
|
+ fi
|
|
139
|
+ if [ $WIKI_DOMAIN_NAME ]; then
|
|
140
|
+ function_check create_avahi_service
|
|
141
|
+ create_avahi_service wiki http tcp $WIKI_ONION_PORT
|
|
142
|
+ fi
|
155
|
143
|
}
|
156
|
144
|
|
157
|
145
|
function allow_ssh_to_onion_address {
|
158
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
159
|
|
- return
|
160
|
|
- fi
|
161
|
|
- if [ ! -d /home/$MY_USERNAME/.ssh ]; then
|
162
|
|
- mkdir /home/$MY_USERNAME/.ssh
|
163
|
|
- fi
|
164
|
|
- if [ ! -d /etc/tor ]; then
|
165
|
|
- echo $'Tor not found when updating ssh'
|
166
|
|
- exit 528257
|
167
|
|
- fi
|
168
|
|
- if ! grep -q "onion" /home/$MY_USERNAME/.ssh/config; then
|
169
|
|
- echo 'Host *.onion' >> /home/$MY_USERNAME/.ssh/config
|
170
|
|
- echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /home/$MY_USERNAME/.ssh/config
|
171
|
|
- fi
|
|
146
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
147
|
+ return
|
|
148
|
+ fi
|
|
149
|
+ if [ ! -d /home/$MY_USERNAME/.ssh ]; then
|
|
150
|
+ mkdir /home/$MY_USERNAME/.ssh
|
|
151
|
+ fi
|
|
152
|
+ if [ ! -d /etc/tor ]; then
|
|
153
|
+ echo $'Tor not found when updating ssh'
|
|
154
|
+ exit 528257
|
|
155
|
+ fi
|
|
156
|
+ if ! grep -q "onion" /home/$MY_USERNAME/.ssh/config; then
|
|
157
|
+ echo 'Host *.onion' >> /home/$MY_USERNAME/.ssh/config
|
|
158
|
+ echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /home/$MY_USERNAME/.ssh/config
|
|
159
|
+ fi
|
172
|
160
|
}
|
173
|
161
|
|
174
|
162
|
function enable_ssh_via_onion {
|
175
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
176
|
|
- return
|
177
|
|
- fi
|
178
|
|
- if grep -Fxq "enable_ssh_via_onion" $COMPLETION_FILE; then
|
179
|
|
- return
|
180
|
|
- fi
|
181
|
|
- apt-get -y install tor connect-proxy
|
182
|
|
- if ! grep -q 'Host *.onion' /home/$MY_USERNAME/.ssh/config; then
|
183
|
|
- if [ ! -d /home/$MY_USERNAME/.ssh ]; then
|
184
|
|
- mkdir /home/$MY_USERNAME/.ssh
|
185
|
|
- fi
|
186
|
|
- echo 'Host *.onion' >> /home/$MY_USERNAME/.ssh/config
|
187
|
|
- echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /home/$MY_USERNAME/.ssh/config
|
188
|
|
- chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
|
189
|
|
- chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh/config
|
190
|
|
- fi
|
191
|
|
- if ! grep -q 'Host *.onion' /root/.ssh/config; then
|
192
|
|
- if [ ! -d /root/.ssh ]; then
|
193
|
|
- mkdir /root/.ssh
|
194
|
|
- fi
|
195
|
|
- echo 'Host *.onion' >> /root/.ssh/config
|
196
|
|
- echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /root/.ssh/config
|
197
|
|
- fi
|
198
|
|
- echo 'enable_ssh_via_onion' >> $COMPLETION_FILE
|
|
163
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
164
|
+ return
|
|
165
|
+ fi
|
|
166
|
+ if grep -Fxq "enable_ssh_via_onion" $COMPLETION_FILE; then
|
|
167
|
+ return
|
|
168
|
+ fi
|
|
169
|
+ apt-get -y install tor connect-proxy
|
|
170
|
+ if ! grep -q 'Host *.onion' /home/$MY_USERNAME/.ssh/config; then
|
|
171
|
+ if [ ! -d /home/$MY_USERNAME/.ssh ]; then
|
|
172
|
+ mkdir /home/$MY_USERNAME/.ssh
|
|
173
|
+ fi
|
|
174
|
+ echo 'Host *.onion' >> /home/$MY_USERNAME/.ssh/config
|
|
175
|
+ echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /home/$MY_USERNAME/.ssh/config
|
|
176
|
+ chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
|
|
177
|
+ chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh/config
|
|
178
|
+ fi
|
|
179
|
+ if ! grep -q 'Host *.onion' /root/.ssh/config; then
|
|
180
|
+ if [ ! -d /root/.ssh ]; then
|
|
181
|
+ mkdir /root/.ssh
|
|
182
|
+ fi
|
|
183
|
+ echo 'Host *.onion' >> /root/.ssh/config
|
|
184
|
+ echo 'ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p' >> /root/.ssh/config
|
|
185
|
+ fi
|
|
186
|
+ echo 'enable_ssh_via_onion' >> $COMPLETION_FILE
|
199
|
187
|
}
|
200
|
188
|
|
201
|
189
|
function configure_ssh_onion {
|
202
|
|
- if grep -Fxq "configure_ssh_onion" $COMPLETION_FILE; then
|
203
|
|
- return
|
204
|
|
- fi
|
205
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
206
|
|
- return
|
207
|
|
- fi
|
208
|
|
-
|
209
|
|
- SSH_ONION_HOSTNAME=$(add_onion_service ssh ${SSH_PORT} ${SSH_PORT})
|
210
|
|
-
|
211
|
|
- if ! grep -q "ssh onion domain" $COMPLETION_FILE; then
|
212
|
|
- echo "ssh onion domain:${SSH_ONION_HOSTNAME}" >> $COMPLETION_FILE
|
213
|
|
- else
|
214
|
|
- sed -i "s|ssh onion domain.*|ssh onion domain:${SSH_ONION_HOSTNAME}|g" $COMPLETION_FILE
|
215
|
|
- fi
|
216
|
|
-
|
217
|
|
- echo 'configure_ssh_onion' >> $COMPLETION_FILE
|
|
190
|
+ if grep -Fxq "configure_ssh_onion" $COMPLETION_FILE; then
|
|
191
|
+ return
|
|
192
|
+ fi
|
|
193
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
194
|
+ return
|
|
195
|
+ fi
|
|
196
|
+
|
|
197
|
+ SSH_ONION_HOSTNAME=$(add_onion_service ssh ${SSH_PORT} ${SSH_PORT})
|
|
198
|
+
|
|
199
|
+ if ! grep -q "ssh onion domain" $COMPLETION_FILE; then
|
|
200
|
+ echo "ssh onion domain:${SSH_ONION_HOSTNAME}" >> $COMPLETION_FILE
|
|
201
|
+ else
|
|
202
|
+ sed -i "s|ssh onion domain.*|ssh onion domain:${SSH_ONION_HOSTNAME}|g" $COMPLETION_FILE
|
|
203
|
+ fi
|
|
204
|
+
|
|
205
|
+ echo 'configure_ssh_onion' >> $COMPLETION_FILE
|
218
|
206
|
}
|
219
|
207
|
|
220
|
208
|
function install_tor {
|
221
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
222
|
|
- return
|
223
|
|
- fi
|
224
|
|
- if grep -Fxq "install_tor" $COMPLETION_FILE; then
|
225
|
|
- return
|
226
|
|
- fi
|
227
|
|
- apt-get -y install tor
|
228
|
|
- if [ ! -f /etc/tor/torrc ]; then
|
229
|
|
- echo 'Tor failed to install'
|
230
|
|
- exit 38259
|
231
|
|
- fi
|
232
|
|
- echo 'install_tor' >> $COMPLETION_FILE
|
|
209
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
210
|
+ return
|
|
211
|
+ fi
|
|
212
|
+ if grep -Fxq "install_tor" $COMPLETION_FILE; then
|
|
213
|
+ return
|
|
214
|
+ fi
|
|
215
|
+ apt-get -y install tor
|
|
216
|
+ if [ ! -f /etc/tor/torrc ]; then
|
|
217
|
+ echo 'Tor failed to install'
|
|
218
|
+ exit 38259
|
|
219
|
+ fi
|
|
220
|
+ echo 'install_tor' >> $COMPLETION_FILE
|
233
|
221
|
}
|
234
|
222
|
|
235
|
223
|
function resolve_dns_via_tor {
|
236
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
237
|
|
- return
|
238
|
|
- fi
|
239
|
|
- if grep -Fxq "resolve_dns_via_tor" $COMPLETION_FILE; then
|
240
|
|
- return
|
241
|
|
- fi
|
242
|
|
- if [ ! -f /etc/tor/torrc ]; then
|
243
|
|
- echo $'tor was not installed'
|
244
|
|
- exit 52952
|
245
|
|
- fi
|
246
|
|
-
|
247
|
|
- # resolve DNS via tor
|
248
|
|
- if ! grep 'DNSPort 53' /etc/tor/torrc; then
|
249
|
|
- echo 'DNSPort 53' >> /etc/tor/torrc
|
250
|
|
- echo 'AutomapHostsOnResolve 1' >> /etc/tor/torrc
|
251
|
|
- echo 'AutomapHostsSuffixes .exit,.onion' >> /etc/tor/torrc
|
252
|
|
- systemctl restart tor
|
253
|
|
- fi
|
254
|
|
-
|
255
|
|
- # don't change resolv.conf
|
256
|
|
- sed -i 's|, domain-name-servers||g' /etc/dhcp/dhclient.conf
|
257
|
|
-
|
258
|
|
- # point resolv.conf to tor
|
259
|
|
- echo 'nameserver 127.0.0.1:53' > /etc/resolv.conf
|
260
|
|
-
|
261
|
|
- # prevent resolv.conf from changing
|
262
|
|
- chattr +i /etc/resolv.conf
|
263
|
|
-
|
264
|
|
- echo 'resolve_dns_via_tor' >> $COMPLETION_FILE
|
|
224
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
225
|
+ return
|
|
226
|
+ fi
|
|
227
|
+ if grep -Fxq "resolve_dns_via_tor" $COMPLETION_FILE; then
|
|
228
|
+ return
|
|
229
|
+ fi
|
|
230
|
+ if [ ! -f /etc/tor/torrc ]; then
|
|
231
|
+ echo $'tor was not installed'
|
|
232
|
+ exit 52952
|
|
233
|
+ fi
|
|
234
|
+
|
|
235
|
+ # resolve DNS via tor
|
|
236
|
+ if ! grep 'DNSPort 53' /etc/tor/torrc; then
|
|
237
|
+ echo 'DNSPort 53' >> /etc/tor/torrc
|
|
238
|
+ echo 'AutomapHostsOnResolve 1' >> /etc/tor/torrc
|
|
239
|
+ echo 'AutomapHostsSuffixes .exit,.onion' >> /etc/tor/torrc
|
|
240
|
+ systemctl restart tor
|
|
241
|
+ fi
|
|
242
|
+
|
|
243
|
+ # don't change resolv.conf
|
|
244
|
+ sed -i 's|, domain-name-servers||g' /etc/dhcp/dhclient.conf
|
|
245
|
+
|
|
246
|
+ # point resolv.conf to tor
|
|
247
|
+ echo 'nameserver 127.0.0.1:53' > /etc/resolv.conf
|
|
248
|
+
|
|
249
|
+ # prevent resolv.conf from changing
|
|
250
|
+ chattr +i /etc/resolv.conf
|
|
251
|
+
|
|
252
|
+ echo 'resolve_dns_via_tor' >> $COMPLETION_FILE
|
265
|
253
|
}
|
266
|
254
|
|
267
|
255
|
# see https://trac.torproject.org/projects/tor/wiki/doc/TransparentProxy
|
268
|
256
|
# Local Redirection and Anonymizing Middlebox
|
269
|
257
|
function route_outgoing_traffic_through_tor {
|
270
|
|
- if grep -Fxq "route_outgoing_traffic_through_tor" $COMPLETION_FILE; then
|
271
|
|
- return
|
272
|
|
- fi
|
273
|
|
- if [[ $ROUTE_THROUGH_TOR != "yes" ]]; then
|
274
|
|
- return
|
275
|
|
- fi
|
276
|
|
- apt-get -y install tor tor-arm
|
277
|
|
-
|
278
|
|
- ### set variables
|
279
|
|
- # Destinations you don't want routed through Tor
|
280
|
|
- _non_tor="192.168.1.0/24 192.168.0.0/24"
|
281
|
|
-
|
282
|
|
- # The user that Tor runs as
|
283
|
|
- _tor_uid="debian-tor"
|
284
|
|
-
|
285
|
|
- # Tor's TransPort
|
286
|
|
- _trans_port="9040"
|
287
|
|
-
|
288
|
|
- # Your internal interface
|
289
|
|
- _int_if="eth0"
|
290
|
|
-
|
291
|
|
- ### Set iptables *nat
|
292
|
|
- iptables -t nat -A OUTPUT -o lo -j RETURN
|
293
|
|
- iptables -t nat -A OUTPUT -m owner --uid-owner $_tor_uid -j RETURN
|
294
|
|
- iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 53
|
295
|
|
-
|
296
|
|
- # Allow clearnet access for hosts in $_non_tor
|
297
|
|
- for _clearnet in $_non_tor; do
|
298
|
|
- iptables -t nat -A OUTPUT -d $_clearnet -j RETURN
|
299
|
|
- iptables -t nat -A PREROUTING -i $_int_if -d $_clearnet -j RETURN
|
300
|
|
- done
|
301
|
|
-
|
302
|
|
- # Redirect all other pre-routing and output to Tor
|
303
|
|
- iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $_trans_port
|
304
|
|
- iptables -t nat -A PREROUTING -i $_int_if -p udp --dport 53 -j REDIRECT --to-ports 53
|
305
|
|
- iptables -t nat -A PREROUTING -i $_int_if -p tcp --syn -j REDIRECT --to-ports $_trans_port
|
306
|
|
-
|
307
|
|
- ### set iptables *filter
|
308
|
|
- iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
309
|
|
-
|
310
|
|
- # Allow clearnet access for hosts in $_non_tor
|
311
|
|
- for _clearnet in $_non_tor 127.0.0.0/8; do
|
312
|
|
- iptables -A OUTPUT -d $_clearnet -j ACCEPT
|
313
|
|
- done
|
314
|
|
-
|
315
|
|
- # Allow only Tor output
|
316
|
|
- iptables -A OUTPUT -m owner --uid-owner $_tor_uid -j ACCEPT
|
317
|
|
- iptables -A OUTPUT -j REJECT
|
318
|
|
-
|
319
|
|
- function_check save_firewall_settings
|
320
|
|
- save_firewall_settings
|
321
|
|
-
|
322
|
|
- if ! grep -q "fs.file-max" /etc/sysctl.conf; then
|
323
|
|
- echo "fs.file-max=100000" >> /etc/sysctl.conf
|
324
|
|
- /sbin/sysctl -p
|
325
|
|
- fi
|
326
|
|
-
|
327
|
|
- echo 'domain localdomain' > /etc/resolv.conf
|
328
|
|
- echo 'search localdomain' >> /etc/resolv.conf
|
329
|
|
- echo 'nameserver 127.0.0.1' >> /etc/resolv.conf
|
330
|
|
-
|
331
|
|
- if ! grep -q "VirtualAddrNetworkIPv4" /etc/tor/torrc; then
|
332
|
|
- echo 'VirtualAddrNetworkIPv4 10.192.0.0/10' >> /etc/tor/torrc
|
333
|
|
- fi
|
334
|
|
-
|
335
|
|
- if ! grep -q "AutomapHostsOnResolve" /etc/tor/torrc; then
|
336
|
|
- echo 'AutomapHostsOnResolve 1' >> /etc/tor/torrc
|
337
|
|
- fi
|
338
|
|
-
|
339
|
|
- if ! grep -q "TransPort" /etc/tor/torrc; then
|
340
|
|
- echo 'TransPort 9040' >> /etc/tor/torrc
|
341
|
|
- fi
|
342
|
|
-
|
343
|
|
- if ! grep -q "TransListenAddress 127.0.0.1" /etc/tor/torrc; then
|
344
|
|
- echo 'TransListenAddress 127.0.0.1' >> /etc/tor/torrc
|
345
|
|
- fi
|
346
|
|
-
|
347
|
|
- if ! grep -q "TransListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" /etc/tor/torrc; then
|
348
|
|
- echo "TransListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/tor/torrc
|
349
|
|
- fi
|
350
|
|
-
|
351
|
|
- if ! grep -q "DNSPort" /etc/tor/torrc; then
|
352
|
|
- echo 'DNSPort 53' >> /etc/tor/torrc
|
353
|
|
- fi
|
354
|
|
-
|
355
|
|
- if ! grep -q "DNSListenAddress 127.0.0.1" /etc/tor/torrc; then
|
356
|
|
- echo 'DNSListenAddress 127.0.0.1' >> /etc/tor/torrc
|
357
|
|
- fi
|
358
|
|
-
|
359
|
|
- if ! grep -q "DNSListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" /etc/tor/torrc; then
|
360
|
|
- echo "DNSListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/tor/torrc
|
361
|
|
- fi
|
362
|
|
-
|
363
|
|
- echo 'route_outgoing_traffic_through_tor' >> $COMPLETION_FILE
|
|
258
|
+ if grep -Fxq "route_outgoing_traffic_through_tor" $COMPLETION_FILE; then
|
|
259
|
+ return
|
|
260
|
+ fi
|
|
261
|
+ if [[ $ROUTE_THROUGH_TOR != "yes" ]]; then
|
|
262
|
+ return
|
|
263
|
+ fi
|
|
264
|
+ apt-get -y install tor tor-arm
|
|
265
|
+
|
|
266
|
+ ### set variables
|
|
267
|
+ # Destinations you don't want routed through Tor
|
|
268
|
+ _non_tor="192.168.1.0/24 192.168.0.0/24"
|
|
269
|
+
|
|
270
|
+ # The user that Tor runs as
|
|
271
|
+ _tor_uid="debian-tor"
|
|
272
|
+
|
|
273
|
+ # Tor's TransPort
|
|
274
|
+ _trans_port="9040"
|
|
275
|
+
|
|
276
|
+ # Your internal interface
|
|
277
|
+ _int_if="eth0"
|
|
278
|
+
|
|
279
|
+ ### Set iptables *nat
|
|
280
|
+ iptables -t nat -A OUTPUT -o lo -j RETURN
|
|
281
|
+ iptables -t nat -A OUTPUT -m owner --uid-owner $_tor_uid -j RETURN
|
|
282
|
+ iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 53
|
|
283
|
+
|
|
284
|
+ # Allow clearnet access for hosts in $_non_tor
|
|
285
|
+ for _clearnet in $_non_tor; do
|
|
286
|
+ iptables -t nat -A OUTPUT -d $_clearnet -j RETURN
|
|
287
|
+ iptables -t nat -A PREROUTING -i $_int_if -d $_clearnet -j RETURN
|
|
288
|
+ done
|
|
289
|
+
|
|
290
|
+ # Redirect all other pre-routing and output to Tor
|
|
291
|
+ iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $_trans_port
|
|
292
|
+ iptables -t nat -A PREROUTING -i $_int_if -p udp --dport 53 -j REDIRECT --to-ports 53
|
|
293
|
+ iptables -t nat -A PREROUTING -i $_int_if -p tcp --syn -j REDIRECT --to-ports $_trans_port
|
|
294
|
+
|
|
295
|
+ ### set iptables *filter
|
|
296
|
+ iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
297
|
+
|
|
298
|
+ # Allow clearnet access for hosts in $_non_tor
|
|
299
|
+ for _clearnet in $_non_tor 127.0.0.0/8; do
|
|
300
|
+ iptables -A OUTPUT -d $_clearnet -j ACCEPT
|
|
301
|
+ done
|
|
302
|
+
|
|
303
|
+ # Allow only Tor output
|
|
304
|
+ iptables -A OUTPUT -m owner --uid-owner $_tor_uid -j ACCEPT
|
|
305
|
+ iptables -A OUTPUT -j REJECT
|
|
306
|
+
|
|
307
|
+ function_check save_firewall_settings
|
|
308
|
+ save_firewall_settings
|
|
309
|
+
|
|
310
|
+ if ! grep -q "fs.file-max" /etc/sysctl.conf; then
|
|
311
|
+ echo "fs.file-max=100000" >> /etc/sysctl.conf
|
|
312
|
+ /sbin/sysctl -p
|
|
313
|
+ fi
|
|
314
|
+
|
|
315
|
+ echo 'domain localdomain' > /etc/resolv.conf
|
|
316
|
+ echo 'search localdomain' >> /etc/resolv.conf
|
|
317
|
+ echo 'nameserver 127.0.0.1' >> /etc/resolv.conf
|
|
318
|
+
|
|
319
|
+ if ! grep -q "VirtualAddrNetworkIPv4" /etc/tor/torrc; then
|
|
320
|
+ echo 'VirtualAddrNetworkIPv4 10.192.0.0/10' >> /etc/tor/torrc
|
|
321
|
+ fi
|
|
322
|
+
|
|
323
|
+ if ! grep -q "AutomapHostsOnResolve" /etc/tor/torrc; then
|
|
324
|
+ echo 'AutomapHostsOnResolve 1' >> /etc/tor/torrc
|
|
325
|
+ fi
|
|
326
|
+
|
|
327
|
+ if ! grep -q "TransPort" /etc/tor/torrc; then
|
|
328
|
+ echo 'TransPort 9040' >> /etc/tor/torrc
|
|
329
|
+ fi
|
|
330
|
+
|
|
331
|
+ if ! grep -q "TransListenAddress 127.0.0.1" /etc/tor/torrc; then
|
|
332
|
+ echo 'TransListenAddress 127.0.0.1' >> /etc/tor/torrc
|
|
333
|
+ fi
|
|
334
|
+
|
|
335
|
+ if ! grep -q "TransListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" /etc/tor/torrc; then
|
|
336
|
+ echo "TransListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/tor/torrc
|
|
337
|
+ fi
|
|
338
|
+
|
|
339
|
+ if ! grep -q "DNSPort" /etc/tor/torrc; then
|
|
340
|
+ echo 'DNSPort 53' >> /etc/tor/torrc
|
|
341
|
+ fi
|
|
342
|
+
|
|
343
|
+ if ! grep -q "DNSListenAddress 127.0.0.1" /etc/tor/torrc; then
|
|
344
|
+ echo 'DNSListenAddress 127.0.0.1' >> /etc/tor/torrc
|
|
345
|
+ fi
|
|
346
|
+
|
|
347
|
+ if ! grep -q "DNSListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" /etc/tor/torrc; then
|
|
348
|
+ echo "DNSListenAddress $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/tor/torrc
|
|
349
|
+ fi
|
|
350
|
+
|
|
351
|
+ echo 'route_outgoing_traffic_through_tor' >> $COMPLETION_FILE
|
364
|
352
|
}
|
365
|
353
|
|
366
|
354
|
# NOTE: deliberately no exit 0
|