Service improvements

* Created start/stop methods to make service management easier

* Added start/stop functions. Added iptables-save/restore functionality.

---------

Co-authored-by: strepsil <hm@bitlabs.co.za>
This commit is contained in:
mullerhx 2023-03-20 21:45:15 +02:00 committed by GitHub
parent 34738887a0
commit d0734de5c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 41 deletions

View file

@ -1,4 +1,17 @@
#!/bin/bash #!/bin/bash
RULES="/var/tmp/tor-router.save"
# Tor's TransPort
TRANS_PORT="9040"
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 # Executable file to create rules for transparent proxy
# Destinations you do not want routed through Tor # Destinations you do not want routed through Tor
NON_TOR="192.168.1.0/24 192.168.0.0/24" NON_TOR="192.168.1.0/24 192.168.0.0/24"
@ -14,9 +27,6 @@ else
exit exit
fi fi
# Tor's TransPort
TRANS_PORT="9040"
if ! command -v tor > /dev/null; then if ! command -v tor > /dev/null; then
echo "You need to install the tor package." echo "You need to install the tor package."
exit exit
@ -46,3 +56,23 @@ else
iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
iptables -A OUTPUT -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

View file

@ -4,9 +4,9 @@
[Service] [Service]
Type=simple Type=simple
ExecStart=/usr/bin/tor-router ExecStart=/usr/bin/tor-router start
RemainAfterExit=yes RemainAfterExit=yes
ExecStop=/usr/bin/iptables -F OUTPUT ExecStop=/usr/bin/tor-router stop
TimeoutStopSec=180 TimeoutStopSec=180
KillMode=process KillMode=process
KillSignal=SIGINT KillSignal=SIGINT