made the sound cycle slower so the script is less annoying when disconnected.
[feisty_meow.git] / scripts / security / start_tunnels.sh
1 #!/bin/bash
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
6 # server.
7
8 #hmmm:  none of the user info below will work for others: parameterize it.
9
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.
12
13 ##############
14
15 # these variables are configurable from plug-ins.
16
17 soundfile=$FEISTY_MEOW_DIR/database/sounds/woouoo.wav
18 if [ ! -z "$1" ]; then
19   soundfile=$1
20 fi
21
22 ##############
23
24 # provides a list of properly formatted tunnels for ssh to create.  if this list
25 # is empty, then we do nothing.
26 # TUNNEL_LIST=()
27
28 # set this to the hostname that will be providing the tunnel.  this is
29 # usually a remote system.
30 USER_PLUS_HOST=""
31
32 # set this to your key file, plus the -i flag, such as: 
33 #   SECURITY_KEY="-i $HOME/.ssh/id_rsa" 
34 SECURITY_KEY=""
35
36 ##############
37
38 #hmmm:move to fred configs!
39 TUNNEL_LIST+=(-L 14008:localhost:25)
40 USER_PLUS_HOST="fred@serene.feistymeow.org"
41 SECURITY_KEY="-i $HOME/.ssh/id_dsa_fred" 
42
43 ##############
44
45 # how often to play sounds when reconnecting.
46 NOISE_PERIOD=60
47
48 # when we last played a sound.
49 LAST_SOUND_TIME=0
50
51 play_sound_periodically()
52 {
53   CURRENT_TIME=$(date +"%s")
54   if (( $CURRENT_TIME - $LAST_SOUND_TIME >= $NOISE_PERIOD )); then
55     echo playing sound now.
56     bash $FEISTY_MEOW_SCRIPTS/multimedia/sound_play.sh $soundfile &>/dev/null </dev/null &
57 #hmmm: parameterize this for the sound to be played.  doofus.
58     LAST_SOUND_TIME=$CURRENT_TIME
59   fi
60 }
61
62 ##############
63
64 while true; do
65   echo Connecting sendmail to serenely zooty.
66   ssh  -2 -N -v ${TUNNEL_LIST[*]} "$USER_PLUS_HOST"
67   echo "Got dumped from tunnels; re-establishing connection."
68   play_sound_periodically
69   echo "Note: if you're being asked for a password, you haven't set up an RSA key yet."
70   sleep 1
71 done
72
73 #-L 8028:localhost:3128 
74
75 #-L 8043:localhost:443 
76
77 # ports sometimes used:
78 #     25 is the sendmail tunnel.
79 #   3128 is the squid proxy server.
80 #    443 is the https version of squid.
81
82 # ssh flags in use sometimes:
83 #   -f   go into the background once connected.
84 #   -2   enforce ssh version 2.
85 #   -N   don't execute any command; just forward data between the ports.
86 #   -L   (port:host:hostport) connect the local machine's "port" to the
87 #        remote port "hostport" on the "host" specified.  the local "port"
88 #        becomes an alias for the remote port.  note that the connection
89 #        being made to host and hostport is from the perspective of the ssh
90 #        server, not the local host.
91
92