Fix for revproxy; adding simple-web script.

This commit is contained in:
root 2017-01-30 12:12:05 -06:00
parent 66f8fdde63
commit 9910b9ced8
3 changed files with 14 additions and 6 deletions

View File

@ -1,4 +1,4 @@
LIST=arch-update clean-exim clean-exim-input close-guest fix-sound log-guest open-guest restart-service silent-guardian proxy LIST=arch-update clean-exim clean-exim-input close-guest fix-sound log-guest open-guest restart-service silent-guardian proxy simple-web
LOCATION=/root/bin LOCATION=/root/bin
PERMISSION=0700 PERMISSION=0700
compile: compile:

16
Admin/proxy → Admin/revproxy Normal file → Executable file
View File

@ -2,6 +2,10 @@
# Establish iptables-based reverse proxy # Establish iptables-based reverse proxy
# Thanks to user55518 in http://unix.stackexchange.com/questions/111841/regular-expression-in-bash-to-validate-ip-address#111843
re='^[1-2]\{0,1\}[0-9]\{0,1\}[0-9]\{1\}\.[1-2]\{0,1\}[0-9]\{0,1\}[0-9]\{1\}\.[1-2]\{0,1\}[0-9]\{0,1\}[0-9]\{1\}\.[1-2]\{0,1\}[0-9]\{0,1\}[0-9]\{1\}$'
if [ ! -z "$1" ] && [ "$1" == "--reset" ]; then if [ ! -z "$1" ] && [ "$1" == "--reset" ]; then
iptables -F -t nat iptables -F -t nat
exit $? exit $?
@ -12,8 +16,8 @@ if [ ! -z "$1" ] && [ "$1" == "--list" ]; then
exit $? exit $?
fi fi
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then if [ -z "$1" ] || [ -z "$2" ] || ! (echo "$2" | grep -x "$re" &> /dev/null) || [ -z "$3" ]; then
printf "Usage: $0 localport remotehost remoteport [ --local ]\n" printf "Usage: $0 localport remoteIP remoteport [ --local ]\n"
printf " $0 --reset\n" printf " $0 --reset\n"
printf " $0 --list\n" printf " $0 --list\n"
exit 1 exit 1
@ -22,9 +26,6 @@ fi
# Tell the kernel to allow forwarding packets. # Tell the kernel to allow forwarding packets.
echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward
# Default forwarding rule
iptables -t nat -A PREROUTING -p tcp -m tcp --dport "$1" -j DNAT --to-destination "$2":"$3"
# Set up masquerading if not already done # Set up masquerading if not already done
if [ `iptables -S -t nat | grep -c '\-A POSTROUTING -j MASQUERADE'` -ne 1 ]; then if [ `iptables -S -t nat | grep -c '\-A POSTROUTING -j MASQUERADE'` -ne 1 ]; then
iptables -t nat -A POSTROUTING -j MASQUERADE; iptables -t nat -A POSTROUTING -j MASQUERADE;
@ -33,4 +34,9 @@ fi
# Handle local forwarding. # Handle local forwarding.
if [ "$4" == "--local" ] || [ "$2" == "127.0.0.1" ]; then if [ "$4" == "--local" ] || [ "$2" == "127.0.0.1" ]; then
iptables -t nat -I OUTPUT -p tcp -o lo --dport "$1" -j REDIRECT --to-ports "$3" iptables -t nat -I OUTPUT -p tcp -o lo --dport "$1" -j REDIRECT --to-ports "$3"
iptables -t nat -A PREROUTING -p tcp --dport "$1" -j REDIRECT --to "$3"
else # Handle remote
iptables -t nat -A PREROUTING -p tcp -m tcp --dport "$1" -j DNAT --to-destination "$2":"$3"
fi fi
echo Done -- all traffic connecting to port "$1" will be redirected to "$2":"$3"

2
Admin/simple-web Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
python3 -m http.server 8000