2 # this script makes a tunnel for SMTP traffic and others. a remote ssh server
3 # is required. this is especially useful for routing around firewalls using
4 # a web proxy like squid. when used for SMTP, it ensures that none of the
5 # text is seen on whatever network one is on before it's sent from the remote
8 #hmmm: none of the user info below will work for others: parameterize it.
10 #hmmm: maybe we need a base function that takes all the disparate values,
11 # and this script could call it with known feisty meow settings.
15 # check for parameters on the command line.
21 if [ "$launch_it" == "go" ]; then
27 # these variables are configurable from plug-ins.
30 soundfile=$FEISTY_MEOW_DIR/database/sounds/woouoo.wav
31 if [ ! -z "$1" ]; then
37 # provides a list of properly formatted tunnels for ssh to create. if this list
38 # is empty, then we do nothing.
41 # set this to the hostname that will be providing the tunnel. this is
42 # usually a remote system.
43 TUNNEL_USER_PLUS_HOST=""
45 # set this to your key file, plus the -i flag, such as:
46 # SECURITY_KEY="-i $HOME/.ssh/id_rsa"
47 TUNNEL_SECURITY_KEY=""
49 # this variable should be set to the name for the tunnel. one can then
50 # open the tunnel screen with: screen -r -S "name"
51 TUNNEL_SCREEN_NAME="tunnely"
53 # a comment for when we make the connection
54 TUNNEL_COMMENT="Connecting tunnel to destination..."
58 #hmmm:move to fred configs!
59 TUNNEL_LIST+=(-L 14008:localhost:25)
60 TUNNEL_USER_PLUS_HOST="fred@serene.feistymeow.org"
61 TUNNEL_SECURITY_KEY="-i $HOME/.ssh/id_dsa_fred"
62 TUNNEL_COMMENT="Connecting sendmail to serenely zooty."
63 TUNNEL_SCREEN_NAME="zooty"
67 # how often to play sounds when reconnecting.
70 # when we last played a sound.
73 play_sound_periodically()
75 CURRENT_TIME=$(date +"%s")
76 if (( $CURRENT_TIME - $LAST_SOUND_TIME >= $NOISE_PERIOD )); then
77 echo playing sound now.
78 bash $FEISTY_MEOW_SCRIPTS/multimedia/sound_play.sh $soundfile &>/dev/null </dev/null &
79 #hmmm: parameterize this for the sound to be played. doofus.
80 LAST_SOUND_TIME=$CURRENT_TIME
86 function main_tunnely_loop()
89 echo "$TUNNEL_COMMENT"
90 ssh -2 -N -v ${TUNNEL_LIST[*]} "$TUNNEL_SECURITY_KEY" "$TUNNEL_USER_PLUS_HOST"
91 echo "Got dumped from tunnels; re-establishing connection."
92 play_sound_periodically
93 echo "Note: if you're being asked for a password, you haven't set up an RSA key yet."
100 #-L 8028:localhost:3128
102 #-L 8043:localhost:443
104 # ports sometimes used:
105 # 25 is the sendmail tunnel.
106 # 3128 is the squid proxy server.
107 # 443 is the https version of squid.
109 # ssh flags in use sometimes:
110 # -f go into the background once connected.
111 # -2 enforce ssh version 2.
112 # -N don't execute any command; just forward data between the ports.
113 # -L (port:host:hostport) connect the local machine's "port" to the
114 # remote port "hostport" on the "host" specified. the local "port"
115 # becomes an alias for the remote port. note that the connection
116 # being made to host and hostport is from the perspective of the ssh
117 # server, not the local host.
119 if [ $LAUNCHING_TUNNEL -eq 1 ]; then
120 # this version is already ready to tunnel already, so let's tunnel.
122 # loop does not exit on its own.
124 # this version re-launches the script but tells it to start the tunnel.
125 screen -L -S "$TUNNEL_SCREEN_NAME" -d -m bash $0 go