]>
Commit | Line | Data |
---|---|---|
b312967c MT |
1 | #!/bin/sh |
2 | ######################################################################## | |
3 | # Begin $rc_base/init.d/tor | |
4 | # | |
5 | # Description : Anonymizing overlay network for TCP | |
6 | # | |
7 | ######################################################################## | |
8 | ||
9 | . /etc/sysconfig/rc | |
10 | . ${rc_functions} | |
11 | ||
ae650f95 MT |
12 | eval $(/usr/local/bin/readhash /var/ipfire/tor/settings) |
13 | ||
529ac19c MT |
14 | function tor_is_enabled() { |
15 | [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ] | |
16 | } | |
17 | ||
c60301c0 | 18 | function setup_firewall() { |
c60301c0 MT |
19 | # Flush all rules. |
20 | flush_firewall | |
21 | ||
22 | if [ "${TOR_RELAY_ENABLED}" = "on" -a -n "${TOR_RELAY_PORT}" ]; then | |
23 | iptables -A TOR_INPUT -p tcp --dport "${TOR_RELAY_PORT}" -j ACCEPT | |
24 | fi | |
e122dd63 JPT |
25 | |
26 | if [ "${TOR_RELAY_ENABLED}" = "on" -a -n "${TOR_RELAY_DIRPORT}" ] && [ "${TOR_RELAY_DIRPORT}" -ne 0 ]; then | |
27 | iptables -A TOR_INPUT -p tcp --dport "${TOR_RELAY_DIRPORT}" -j ACCEPT | |
28 | fi | |
c60301c0 MT |
29 | } |
30 | ||
31 | function flush_firewall() { | |
32 | # Flush all rules. | |
33 | iptables -F TOR_INPUT | |
34 | } | |
35 | ||
b312967c MT |
36 | case "${1}" in |
37 | start) | |
529ac19c MT |
38 | tor_is_enabled || exit 0 |
39 | ||
c60301c0 MT |
40 | # Setup firewall. |
41 | setup_firewall | |
42 | ||
b312967c MT |
43 | boot_mesg "Starting tor..." |
44 | loadproc /usr/bin/tor \ | |
45 | --runasdaemon 1 \ | |
46 | --defaults-torrc /usr/share/tor/defaults-torrc \ | |
47 | -f /etc/tor/torrc \ | |
48 | --quiet | |
49 | ;; | |
50 | ||
51 | stop) | |
c60301c0 MT |
52 | # Flush firewall. |
53 | flush_firewall | |
54 | ||
b312967c MT |
55 | boot_mesg "Stopping tor..." |
56 | killproc /usr/bin/tor | |
57 | ;; | |
58 | ||
59 | reload) | |
c60301c0 MT |
60 | # Setup firewall. |
61 | setup_firewall | |
62 | ||
b312967c MT |
63 | boot_mesg "Reloading tor..." |
64 | reloadproc /usr/bin/tor | |
65 | ;; | |
66 | ||
67 | restart) | |
68 | ${0} stop | |
69 | sleep 1 | |
70 | ${0} start | |
71 | ;; | |
72 | ||
27cb7805 MT |
73 | reload-or-restart) |
74 | # Reload the process if it is already running. Otherwise, restart. | |
75 | if pidofproc -s /usr/bin/tor; then | |
76 | $0 reload | |
77 | else | |
78 | $0 restart | |
79 | fi | |
80 | ;; | |
81 | ||
b312967c MT |
82 | status) |
83 | statusproc /usr/bin/tor | |
84 | ;; | |
85 | ||
86 | *) | |
27cb7805 | 87 | echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}" |
b312967c MT |
88 | exit 1 |
89 | ;; | |
90 | esac | |
91 | ||
92 | # End $rc_base/init.d/tor |