summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/scripts/webproxy
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/nc/scripts/webproxy')
-rw-r--r--src/usr.bin/nc/scripts/webproxy140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/usr.bin/nc/scripts/webproxy b/src/usr.bin/nc/scripts/webproxy
deleted file mode 100644
index f670e4d644..0000000000
--- a/src/usr.bin/nc/scripts/webproxy
+++ /dev/null
@@ -1,140 +0,0 @@
1#! /bin/sh
2# $OpenBSD: webproxy,v 1.2 2001/01/29 01:58:13 niklas Exp $
3
4## Web proxy, following the grand tradition of Web things being handled by
5## gross scripts. Uses netcat to listen on a high port [default 8000],
6## picks apart requests and sends them on to the right place. Point this
7## at the browser client machine you'll be coming from [to limit access to
8## only it], and point the browser's concept of an HTTP proxy to the
9## machine running this. Takes a single argument of the client that will
10## be using it, and rejects connections from elsewhere. LOGS the queries
11## to a configurable logfile, which can be an interesting read later on!
12## If the argument is "reset", the listener and logfile are cleaned up.
13##
14## This works surprisingly fast and well, for a shell script, although may
15## randomly fail when hammered by a browser that tries to open several
16## connections at once. Drop the "maximum connections" in your browser if
17## this is a problem.
18##
19## A more degenerate case of this, or preferably a small C program that
20## does the same thing under inetd, could handle a small site's worth of
21## proxy queries. Given the way browsers are evolving, proxies like this
22## can play an important role in protecting your own privacy.
23##
24## If you grabbed this in ASCII mode, search down for "eew" and make sure
25## the embedded-CR check is intact, or requests might hang.
26##
27## Doesn't handle POST forms. Who cares, if you're just watching HTTV?
28## Dumbness here has a highly desirable side effect: it only sends the first
29## GET line, since that's all you really ever need to send, and suppresses
30## the other somewhat revealing trash that most browsers insist on sending.
31
32# set these as you wish: proxy port...
33PORT=8000
34# logfile spec: a real file or /dev/null if you don't care
35LFILE=${0}.log
36# optional: where to dump connect info, so you can see if anything went wrong
37# CFILE=${0}.conn
38# optional extra args to the listener "nc", for instance "-s inside-net-addr"
39# XNC=''
40
41# functionality switch has to be done fast, so the next listener can start
42# prelaunch check: if no current client and no args, bail.
43case "${1}${CLIENT}" in
44 "")
45 echo needs client hostname
46 exit 1
47 ;;
48esac
49
50case "${1}" in
51 "")
52# Make like inetd, and run the next relayer process NOW. All the redirection
53# is necessary so this shell has NO remaining channel open to the net.
54# This will hang around for 10 minutes, and exit if no new connections arrive.
55# Using -n for speed, avoiding any DNS/port lookups.
56 nc -w 600 -n -l -p $PORT -e "$0" $XNC "$CLIENT" < /dev/null > /dev/null \
57 2> $CFILE &
58 ;;
59esac
60
61# no client yet and had an arg, this checking can be much slower now
62umask 077
63
64if test "$1" ; then
65# if magic arg, just clean up and then hit our own port to cause server exit
66 if test "$1" = "reset" ; then
67 rm -f $LFILE
68 test -f "$CFILE" && rm -f $CFILE
69 nc -w 1 -n 127.0.0.1 $PORT < /dev/null > /dev/null 2>&1
70 exit 0
71 fi
72# find our ass with both hands
73 test ! -f "$0" && echo "Oops, cannot find my own corporeal being" && exit 1
74# correct launch: set up client access control, passed along thru environment.
75 CLIENT="$1"
76 export CLIENT
77 test "$CFILE" || CFILE=/dev/null
78 export CFILE
79 touch "$CFILE"
80# tell us what happened during the last run, if possible
81 if test -f "$CFILE" ; then
82 echo "Last connection results:"
83 cat $CFILE
84 fi
85
86# ping client machine and get its bare IP address
87 CLIENT=`nc -z -v -w 8 "$1" 22000 2>&1 | sed 's/.*\[\(..*\)\].*/\1/'`
88 test ! "$CLIENT" && echo "Can't find address of $1" && exit 1
89
90# if this was an initial launch, be informative about it
91 echo "=== Launch: $CLIENT" >> $LFILE
92 echo "Proxy running -- will accept connections on $PORT from $CLIENT"
93 echo " Logging queries to $LFILE"
94 test -f "$CFILE" && echo " and connection fuckups to $CFILE"
95
96# and run the first listener, showing us output just for the first hit
97 nc -v -w 600 -n -l -p $PORT -e "$0" $XNC "$CLIENT" &
98 exit 0
99fi
100
101# Fall here to handle a page.
102# GET type://host.name:80/file/path HTTP/1.0
103# Additional: trash
104# More: trash
105# <newline>
106
107read x1 x2 x3 x4
108echo "=== query: $x1 $x2 $x3 $x4" >> $LFILE
109test "$x4" && echo "extra junk after request: $x4" && exit 0
110# nuke questionable characters and split up the request
111hurl=`echo "$x2" | sed -e "s+.*//++" -e 's+[\`'\''|$;<>{}\\!*()"]++g'`
112# echo massaged hurl: $hurl >> $LFILE
113hh=`echo "$hurl" | sed -e "s+/.*++" -e "s+:.*++"`
114hp=`echo "$hurl" | sed -e "s+.*:++" -e "s+/.*++"`
115test "$hp" = "$hh" && hp=80
116hf=`echo "$hurl" | sed -e "s+[^/]*++"`
117# echo total split: $hh : $hp : $hf >> $LFILE
118# suck in and log the entire request, because we're curious
119# Fails on multipart stuff like forms; oh well...
120if test "$x3" ; then
121 while read xx ; do
122 echo "${xx}" >> $LFILE
123 test "${xx}" || break
124# eew, buried returns, gross but necessary for DOS stupidity:
125 test "${xx}" = " " && break
126 done
127fi
128# check for non-GET *after* we log the query...
129test "$x1" != "GET" && echo "sorry, this proxy only does GETs" && exit 0
130# no, you can *not* phone home, you miserable piece of shit
131test "`echo $hh | fgrep -i netscap`" && \
132 echo "access to Netscam's servers <b>DENIED.</b>" && exit 0
133# Do it. 30 sec net-wait time oughta be *plenty*...
134# Some braindead servers have forgotten how to handle the simple-query syntax.
135# If necessary, replace below with (echo "$x1 $hf" ; echo '') | nc...
136echo "$x1 $hf" | nc -w 30 "$hh" "$hp" 2> /dev/null || \
137 echo "oops, can't get to $hh : $hp".
138echo "sent \"$x1 $hf\" to $hh : $hp" >> $LFILE
139exit 0
140