mirror of
https://github.com/edu4rdshl/tor-router.git
synced 2026-07-17 23:24:48 +00:00
Added start/stop functions. Added iptables-save/restore functionality.
This commit is contained in:
parent
fdb9279486
commit
7c091df56b
1 changed files with 69 additions and 39 deletions
|
|
@ -1,32 +1,42 @@
|
|||
#!/bin/bash
|
||||
# Executable file to create rules for transparent proxy
|
||||
# Destinations you do not want routed through Tor
|
||||
NON_TOR="192.168.1.0/24 192.168.0.0/24"
|
||||
# the UID Tor runs as, actually only support for Debian, ArchLinux and Fedora as been added.
|
||||
if command -v pacman > /dev/null; then
|
||||
TOR_UID=$(id -u tor)
|
||||
elif command -v apt > /dev/null; then
|
||||
TOR_UID=$(id -u debian-tor)
|
||||
elif command -v dnf > /dev/null; then
|
||||
TOR_UID=$(id -u toranon)
|
||||
else
|
||||
echo "Unknown distro, please create report the issue to https://github.com/edu4rdshl/tor-router/issues"
|
||||
exit
|
||||
fi
|
||||
|
||||
RULES="/var/tmp/tor-router.save"
|
||||
|
||||
# Tor's TransPort
|
||||
TRANS_PORT="9040"
|
||||
|
||||
if ! command -v tor > /dev/null; then
|
||||
case "$1" in
|
||||
start)
|
||||
if test -f "$RULES"; then
|
||||
echo "$RULES exists. Either delete it, or stop tor-router first."
|
||||
exit
|
||||
else
|
||||
iptables-save > $RULES
|
||||
# Executable file to create rules for transparent proxy
|
||||
# Destinations you do not want routed through Tor
|
||||
NON_TOR="192.168.1.0/24 192.168.0.0/24"
|
||||
# the UID Tor runs as, actually only support for Debian, ArchLinux and Fedora as been added.
|
||||
if command -v pacman > /dev/null; then
|
||||
TOR_UID=$(id -u tor)
|
||||
elif command -v apt > /dev/null; then
|
||||
TOR_UID=$(id -u debian-tor)
|
||||
elif command -v dnf > /dev/null; then
|
||||
TOR_UID=$(id -u toranon)
|
||||
else
|
||||
echo "Unknown distro, please create report the issue to https://github.com/edu4rdshl/tor-router/issues"
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! command -v tor > /dev/null; then
|
||||
echo "You need to install the tor package."
|
||||
exit
|
||||
elif ! systemctl is-active tor.service > /dev/null; then
|
||||
elif ! systemctl is-active tor.service > /dev/null; then
|
||||
echo "The tor service is not active, please start the tor service before running the script."
|
||||
exit
|
||||
elif ! command -v iptables > /dev/null; then
|
||||
elif ! command -v iptables > /dev/null; then
|
||||
echo "You need to install the iptables package."
|
||||
exit
|
||||
else
|
||||
else
|
||||
iptables -F
|
||||
iptables -t nat -F
|
||||
iptables -t nat -A OUTPUT -m owner --uid-owner $TOR_UID -j RETURN
|
||||
|
|
@ -45,4 +55,24 @@ else
|
|||
|
||||
iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
|
||||
iptables -A OUTPUT -j ACCEPT
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if ! -f "$RULES"; then
|
||||
echo "$RULES does not exist. Not doing anything."
|
||||
exit
|
||||
else
|
||||
iptables -t nat -F
|
||||
iptables-restore < $RULES
|
||||
rm $RULES
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue