• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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...
12PORT=8000
13# any extra args to the listening "nc", for instance "-s inside-net-addr"
14XNC=''
15
16# functionality switch, which has to be done fast to start the next listener
17case "${1}${RDEST}" in
18  "")
19    echo needs hostname
20    exit 1
21  ;;
22esac
23
24case "${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  ;;
31esac
32
33# Fall here for setup; this can now be slower.
34RDEST="$1"
35RPORT="$2"
36test "$RPORT" || RPORT=80
37export 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.
41nc -v -w 600 -l -p $PORT -e "$0" $XNC < /dev/null > /dev/null &
42echo \
43  "Relay to ${RDEST}:${RPORT} running -- point your browser here on port $PORT"
44exit 0
45