]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | eval $(/usr/local/bin/readhash /var/ipfire/tor/settings) | |
13 | ||
14 | function tor_is_enabled() { | |
15 | [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ] | |
16 | } | |
17 | ||
18 | function setup_firewall() { | |
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 | |
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 | |
29 | } | |
30 | ||
31 | function flush_firewall() { | |
32 | # Flush all rules. | |
33 | iptables -F TOR_INPUT | |
34 | } | |
35 | ||
36 | case "${1}" in | |
37 | start) | |
38 | tor_is_enabled || exit 0 | |
39 | ||
40 | # Setup firewall. | |
41 | setup_firewall | |
42 | ||
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) | |
52 | # Flush firewall. | |
53 | flush_firewall | |
54 | ||
55 | boot_mesg "Stopping tor..." | |
56 | killproc /usr/bin/tor | |
57 | ;; | |
58 | ||
59 | reload) | |
60 | # Setup firewall. | |
61 | setup_firewall | |
62 | ||
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 | ||
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 | ||
82 | status) | |
83 | statusproc /usr/bin/tor | |
84 | ;; | |
85 | ||
86 | *) | |
87 | echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}" | |
88 | exit 1 | |
89 | ;; | |
90 | esac | |
91 | ||
92 | # End $rc_base/init.d/tor |