#!/bin/sh echo "* try to open tronlab's moleflap" HOST='moleflap.hq.c3d2.de' STORE=~/.moletoken.c3d2 WLAN_NAME="<<>" PREFIX_LEN=4 # END CONFIG PORT=80 STORE_ENC="$STORE.enc" STORE_TMP="$STORE.tmp" LOCKFILE="$STORE.lock" FORCE_PGP=0 WGET="wget" checkhost() { # checks if host is reachable. returns 0 on success ping6 -c 1 $HOST >/dev/null 2>/dev/null if [ $? -eq 0 ]; then WGET="wget --prefer-family=IPv6" return 0; fi if [ "cygwin" = `uname -o | tr [:upper:] [:lower:]` ] then ping $HOST 56 1 >/dev/null 2>/dev/null else ping -c 1 $HOST >/dev/null 2>/dev/null fi if [ $? -eq 0 ]; then return 0; fi return 1; } n800() { # nokia maemo connection methode for i in `gconftool /system/osso/connectivity/IAP --all-dirs`; do NAME=`gconftool --get $i/name`; if [ "x$NAME" == "x$WLAN_NAME" ]; then dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:${i##/system/osso/connectivity/IAP/} uint32:0; echo -n "connect & wait..."; for j in $(seq 1 1 15); do checkhost if [ $? -eq 0 ]; then break; fi echo -n . sleep 1; done echo break; fi; done; } PREFIX="" prefix() { if [ -e $STORE ]; then PREFIX=`cat $STORE | cut -c1-$PREFIX_LEN` fi if [ "$PREFIX" = "" ]; then echo "Please enter your prefix:" read PREFIX fi } do_pgp() { # do pgp handling prefix if [ "$PREFIX" = "" ]; then return 1 else $WGET -qO $STORE_ENC http://$HOST:$PORT/recover?$PREFIX # download failed if [ $? != 0 ]; then return 2 fi if [ -e $STORE ]; then CSUM=`head -n 1 $STORE_ENC` OSUM=`cat $STORE | cut -c1-${#CSUM}` else CSUM="1" OSUM="2" fi if [ "x$CSUM" != "x$OSUM" ] || [ $FORCE_PGP != 0 ]; then rm -f $STORE_TMP tail -n +3 $STORE_ENC | gpg --decrypt --output $STORE_TMP if [ $? = 0 ]; then mv $STORE_TMP $STORE NSUM=`cat $STORE | cut -c1-${#CSUM}` return 0 else return 3 fi fi return 0 fi } usage() { cat << EOF usage: $0 options try to open tronlab's moleflap --force-pgp force pgp decrypt --n800 nokia n8xx/n9xx connect mode --help help EOF exit } removelock() { rm $LOCKFILE } # Process command line arguments for i in $@; do case "$i" in "--force-pgp") FORCE_PGP=1;; "--n800" ) CONNECT=n800;; "--help" ) usage;; * ) echo "Error!"; usage;; esac done # lockfile if [ -e $LOCKFILE ] then echo "lockfile exists ... exiting" exit 1 else echo $(date) > $LOCKFILE fi # test for connection checkhost if [ "$?" -eq "1" ] then if [ "x$CONNECT" = "x" ]; then echo "can't ping host $HOST ... exiting" removelock exit 1; else $CONNECT; fi fi do_pgp if [ $? -gt 2 ]; then echo "fatal error ... exiting" removelock exit 1 fi if [ -e $STORE ] then token=`cat $STORE` else echo "Please enter your valid token:" read token # save new token first echo "$token" > $STORE fi newtoken=`$WGET -qO - http://$HOST:$PORT/open?$token` if [ "$?" -eq "0" ] then echo "* check door ..." echo "$newtoken" > $STORE else echo "* moleflap unreachable" fi removelock