wok-4.x rev 4658

ajaxterm: add question/answer support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 28 09:04:55 2009 +0100 (2009-12-28)
parents f62b09adf785
children bfad3f8f9d92
files ajaxterm/stuff/usr/share/ajaxterm/login
line diff
     1.1 --- a/ajaxterm/stuff/usr/share/ajaxterm/login	Sun Dec 27 18:39:23 2009 +0100
     1.2 +++ b/ajaxterm/stuff/usr/share/ajaxterm/login	Mon Dec 28 09:04:55 2009 +0100
     1.3 @@ -1,16 +1,38 @@
     1.4  #!/bin/sh
     1.5  
     1.6 +# Optional: check user with a random question
     1.7 +file=/usr/share/ajaxterm/questions
     1.8 +if [ -s $file -a -r $file ]; then
     1.9 +	line=1
    1.10 +	while read md5 question; do
    1.11 +		[ $(( $(date +%s) % $line )) -ne 0 ] && continue
    1.12 +		ask_question="$question"
    1.13 +		ask_md5="$md5"
    1.14 +		line=$(($line+1))
    1.15 +	done < $file
    1.16 +	echo -n "$ask_question "
    1.17 +	read -t 30 answer
    1.18 +	[ $ask_md5 == $(echo $answer | md5sum | cut -d\  -f1) ] || exit 1
    1.19 +fi
    1.20 +
    1.21 +# Get SSH server
    1.22  server=""
    1.23  if [ -x /usr/bin/ssh ]; then
    1.24  	echo -n "SSH server: "
    1.25  	read -t 300 server || exit 1
    1.26  fi
    1.27 +
    1.28 +# No SSH server given ? Try login
    1.29  [ -n "$server" ] || exec /bin/login
    1.30 +
    1.31 +# Allow non default SSH port with format server:port
    1.32  sshport=""
    1.33  case "$server" in
    1.34  *:*)	sshport="-p ${server#*:}"
    1.35  	server=${server%:*};;
    1.36  esac
    1.37 +
    1.38 +# heading ! in server name means open remote ssh port with a knock sequence
    1.39  if [ -x /usr/bin/knock ]; then
    1.40  	case "$server" in
    1.41  	!*)	server=${server#*!}
    1.42 @@ -18,12 +40,16 @@
    1.43  		read -t 30 sequence && knock ${server#*@} $sequence
    1.44  	esac
    1.45  fi
    1.46 +
    1.47 +# Get SSH user if missing
    1.48  case "$server" in
    1.49  *@*)	;;
    1.50  *)	echo -n "$server login: "
    1.51  	read -t 30 user || exit 1
    1.52  	server="$user@$server";;
    1.53  esac
    1.54 +
    1.55 +# Launch OpenSSH or Dropbear
    1.56  sshargs="-oPreferredAuthentications=keyboard-interactive,password -oNoHostAuthenticationForLocalhost=yes -oLogLevel=FATAL -F/dev/null";
    1.57  [ -L /usr/bin/ssh ] && sshargs=""
    1.58  exec ssh $sshport $sshargs $server