#!/bin/bash # # Copyright Hank Leininger , VERSION='$Id: imap-login,v 1.2 2005/05/11 16:28:10 hlein Exp $' VERSION=`echo "$VERSION" | sed 's/.*,v //; s/ .*//;'` # Log in to an SSL-IMAP server and drop the connection. # (Just enough to prove to any auth-before-Something tool that we are allowed.) # Turns off local-echo when prompting for password, so it will not print. # Requires stunnel 3.x # IP address of the server to log into; # you must change this, or use the -s option SERVER=127.255.255.254 # Default username will be read from the environment; # update this if your remote name is different ##USER=foo # Default timeout. You might have to increase this # if you are behind a very very slow link TIMEOUT=8 # Default port to use for the local stunnel listener LOCAL_PORT=1430 BASENAME=`echo "$0" | sed 's%.*/%%'` USAGE=" Usage: $BASENAME [-s serverip] [-u username] [-t timeout] [-p localport] All arguments are optional, to override defaults in the script. -s current default: $SERVER -u current default: $USER -t current default: $TIMEOUT -p current default: $LOCAL_PORT $BASENAME v$VERSION " while getopts s:u:t:p:vh? c ; do case $c in s) SERVER="$OPTARG" ;; u) USER="$OPTARG" ;; t) TIMEOUT="$OPTARG" ;; p) LOCAL_PORT="$OPTARG" ;; *) echo "$USAGE" >&2 ; exit 1 ;; esac done if [ -z "$SERVER" -o "$SERVER" = "127.255.255.254" ]; then echo "Not a valid server: '$SERVER'" >&2 echo "$USAGE" >&2 ; exit 1 fi PORT_LISTENING=`netstat -an | egrep "tcp.*[.:]${LOCAL_PORT}[^0-9.:].*LISTEN"` if [ -n "$PORT_LISTENING" ]; then echo "Port ${LOCAL_PORT} in use, please specify an alternate one." >&2 echo "$USAGE" >&2 ; exit 1 fi # We should probably respect TMPDIR if set to a # private tempdir, but oh well mkdir -p ~/tmp stty -echo stunnel -c -D crit -d "127.0.0.1:${LOCAL_PORT}" -r "${SERVER}:993" \ -P ~/tmp/imap-stunnel.$$ echo -n "Password: " read PASSWORD stty echo echo cat </dev/null` 2>/dev/null sleep 1 rm -f ~/tmp/imap-stunnel.$$ 2>/dev/null