Home | History | Annotate | Download | only in scripts
      1 #! /bin/sh
      2 ## web relay -- a degenerate version of webproxy, usable with browsers that
      3 ## don't understand proxies.  This just forwards connections to a given server.
      4 ## No query logging, no access control [although you can add it to XNC for
      5 ## your own run], and full-URL links will undoubtedly confuse the browser
      6 ## if it can't reach the server directly.  This was actually written before
      7 ## the full proxy was, and it shows.
      8 ## The arguments in this case are the destination server and optional port.
      9 ## Please flame pinheads who use self-referential absolute links.
     10 
     11 # set these as you wish: proxy port...
     12 PORT=8000
     13 # any extra args to the listening "nc", for instance "-s inside-net-addr"
     14 XNC=''
     15 
     16 # functionality switch, which has to be done fast to start the next listener
     17 case "${1}${RDEST}" in
     18   "")
     19     echo needs hostname
     20     exit 1
     21   ;;
     22 esac
     23 
     24 case "${1}" in
     25   "")
     26 # no args: fire off new relayer process NOW.  Will hang around for 10 minutes
     27     nc -w 600 -l -n -p $PORT -e "$0" $XNC < /dev/null > /dev/null 2>&1 &
     28 # and handle this request, which will simply fail if vars not set yet.
     29     exec nc -w 15 $RDEST $RPORT
     30   ;;
     31 esac
     32 
     33 # Fall here for setup; this can now be slower.
     34 RDEST="$1"
     35 RPORT="$2"
     36 test "$RPORT" || RPORT=80
     37 export RDEST RPORT
     38 
     39 # Launch the first relayer same as above, but let its error msgs show up
     40 # will hang around for a minute, and exit if no new connections arrive.
     41 nc -v -w 600 -l -p $PORT -e "$0" $XNC < /dev/null > /dev/null &
     42 echo \
     43   "Relay to ${RDEST}:${RPORT} running -- point your browser here on port $PORT"
     44 exit 0
     45