From 16523355f3a68b80a95200555665d2f6c007e102 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 14 Apr 2013 11:20:35 -0400 Subject: [PATCH] probably a breaking change to move up to new abstracted tunneling script. the screened tunneler makes an ssh tunnel solely based on the command line parameters, which sounds obvious but is actually a big improvement. start tunnels is now called tunnel zooty, at the moment anyway, and that's the user of the screened tunneler. if this works nicely, other tunnel scripts can also be converted. --- scripts/security/screened_tunneler.sh | 116 +++++++++++++++++++++++ scripts/security/start_tunnels.sh | 128 -------------------------- scripts/security/tunnel_zooty.sh | 15 +++ 3 files changed, 131 insertions(+), 128 deletions(-) create mode 100755 scripts/security/screened_tunneler.sh delete mode 100755 scripts/security/start_tunnels.sh create mode 100755 scripts/security/tunnel_zooty.sh diff --git a/scripts/security/screened_tunneler.sh b/scripts/security/screened_tunneler.sh new file mode 100755 index 00000000..8e855bff --- /dev/null +++ b/scripts/security/screened_tunneler.sh @@ -0,0 +1,116 @@ +#!/bin/bash +# this script manages one ssh tunnel inside a named 'screen' session. + +############## + +# this section scavenges and documents the command line parameters... + +# set this to the user and hostname that serve the tunnel on the remote +# side. for example: geoffrey@chaucertales.com +TUNNEL_USER_PLUS_HOST="$1"; shift + +# a tunnel command for ssh that gives us a link between here and there. +# this should be in the form: +# "-L ${sourcePort}:${tunnelHost}:${destinationPort}" +# such as this example that connects a local port 12000 to the remote port +# of 25 in order to create a tunnel for smtp traffic: +# "-L 12000:localhost:25" +# other ssh commands can be used here if they are properly formatted. +TUNNEL_LINK="$1"; shift + +# this variable should be set to the name for the tunnel. one can then +# open the tunnel screen with: screen -r -S "name" +TUNNEL_SCREEN_NAME="$1"; shift + +# set this to your key file, plus the -i flag, such as: +# SECURITY_KEY="-i $HOME/.ssh/id_rsa" +# if you do not have a special one set up or the default is fine, then just +# pass a blank parameter (e.g. ""). +TUNNEL_SECURITY_KEY="$1"; shift + +# if this is set, it means we're through the script the second time, inside +# a screen session, and we need to actually do the work now. +LAUNCH_IT="$1"; shift + +############## + +function print_instructions() +{ + echo "\ +$(basename $0): This script requires at least three parameters and can\n\ +take up to five. The parameters are (1) tunnel user at hostname, (2) ssh tunnel\n\ +link command, (3) tunnel screen name, (4) tunnel security key, (5) the launch\n\ +command 'go'. An example command is shown below, but many more details are\n\ +explained inside this script:\n\ + $(basename $0) "geoffrey@chaucertales.com" "-L 12000:localhost:25" \\\n\ +"tunz" "-i mykey.pem"\n\ +The fifth flag is really only needed internally, but often the other four\n\ +parameters are specified." +} + +############## + +# make sure the required parameters are provided. +if [ -z "$TUNNEL_USER_PLUS_HOST" -o -z "$TUNNEL_LINK" -o -z "$TUNNEL_SCREEN_NAME" ]; then + print_instructions + exit 1 +fi + +############## + +# translate command line parameters if desired. +LAUNCHING_TUNNEL=0 +if [ "$LAUNCH_IT" == "go" ]; then + LAUNCHING_TUNNEL=1 +fi + +############## + +#hmmm: these variables should be configurable from plug-ins someday. + +TUNNEL_ALERT_SOUND=$FEISTY_MEOW_DIR/database/sounds/woouoo.wav +if [ ! -z "$1" ]; then + TUNNEL_ALERT_SOUND=$1 +fi + +# how often to play sounds when reconnecting. +NOISE_PERIOD=180 + +# when we last played a sound. +LAST_SOUND_TIME=0 + +############## + +play_sound_periodically() +{ + CURRENT_TIME=$(date +"%s") + if (( $CURRENT_TIME - $LAST_SOUND_TIME >= $NOISE_PERIOD )); then + echo playing sound now. + bash $FEISTY_MEOW_SCRIPTS/multimedia/sound_play.sh $TUNNEL_ALERT_SOUND &>/dev/null = $NOISE_PERIOD )); then - echo playing sound now. - bash $FEISTY_MEOW_SCRIPTS/multimedia/sound_play.sh $soundfile &>/dev/null