#!/bin/bash # # This is the client program. # # Usage: ssh -oProxyCommand="./this.sh %h" user@domain.com # # Robert McKay # # Requires: curl, nc # # Homepage: http://wari.mckay.com/~rm/proxy2ssh/ # # # Configure me cgi_server="www.mywebserver.com" cgi_server_port=80 cgi_uri="/cgi-bin/ssh.cgi" cgi_max_content=1000000000 proxy_host="squid.acme.com" proxy_port="3128" # Proxies sometimes virus scan content. this means they won't allow streaming # however they often exempt certain common mime-types from scanning in order # to allow streaming media to work. We need streaming in order for this to work # so set a mime type that works. Try them all.. try different ones.. try # making one up. pretend_content=video/avi pretend_content=video/x-ms-asf pretend_content=video/x-ms-wm pretend_content=video/x-ms-wmx pretend_content=video/msvideo pretend_content=video-x-msvideo pretend_content=video/xmpg2 pretend_content=application/x-troff-msvideo pretend_content=audio/avi pretend_content=audio/asf pretend_content=audio/vnd.rn-realaudio # Set the User-Agent header ua_get="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" ua_post="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" # Padding to get things kicked off padding=4096 # Shouldn't need editing after here. host=$1 cgi_url="http://${cgi_server}:${cgi_server_port}${cgi_uri}" # Are we using a proxy? Or just directly connecting to an http server? if [ ! -z "${proxy_host}" ]; then connect_url=${cgi_url} connect_to=${proxy_host} connect_port=${proxy_port} proxyopts="-x ${proxy_host}:${proxy_port}" else connect_url=${cgi_uri} connect_to=${cgi_server} connect_port=${cgi_server_port} proxyopts= fi sessionkey="/tmp/sessionkey.$$" if [ -f "${sessionkey}" ]; then echo "Session ${sessionkey} exists! stale?" exit 1; fi touch "${sessionkey}" # create the sessionkey file chmod 600 "${sessionkey}" # secure the sessionkey file # Make the first request. This will initialize the remote end, # and it will give us a session key. Then the link will become our # regular receive channel for data coming from the server. curl ${proxyopts} -A "${ua_get}" -sN "${cgi_url}?host=${host}" | ( head -2 > "${sessionkey}" ; # save the session key cat - # process channel output (forever) )& lynxpid=`jobs -p` #lynxpid=$! # Try and clean up when we die trap "kill ${lynxpid}" SIGTERM SIGHUP SIGPIPE # The first connection was made in the background, so we may not # have the key yet. This busy-waits for the key to arrive. while [ -z "$key" ]; do key=`tail -1 "${sessionkey}" 2>/dev/null |grep ^Key: | cut -f2 -d":"` done rm -f "${sessionkey}" # we've got the key now. clean up. # The receive (GET) channel is up and we have a key to it # Now we make a second connection for the send (POST) channel # using the same key. ( cat<