Skip to content

Instantly share code, notes, and snippets.

@odiak
Created June 15, 2011 15:15
Show Gist options
  • Save odiak/1027313 to your computer and use it in GitHub Desktop.
Save odiak/1027313 to your computer and use it in GitHub Desktop.
#!/bin/bash
file="$HOME/.knct_login"
tim=100
url="http://10.10.10.10/cgi-bin/opengate"
if [ ! -f $file ]; then
:> $file
fi
while getopts :it:h OPT
do
case $OPT in
"t" )
count=`echo $OPTARG | wc -c`
count_=`echo $OPTARG | sed -e 's/[^0-9]//g' | wc -c`
if [ $count -eq $count_ -a $count -ge 1 -a $count -le 3 ]; then
if [ $OPTARG -ge 0 -a $OPTARG -le 100 ]; then
tim=$OPTARG
fi
fi
;;
"i" )
:> $file
;;
* )
if [ "$OPT" != "h" ]; then
echo "illegal option!!"
fi
echo "*options*"
echo " -i : initialize password and userid"
echo " -t : specify time of logged in"
echo " -h : help"
exit 1
;;
esac
done
if [ `cat $file | wc -l` -ge 2 ]; then
count=0
while read line; do
case $count in
0) id=$line;;
1) pswd=$line;;
*) break;;
esac
count=`expr $count + 1`
done < $file
id=`echo $id | openssl enc -d -base64`
pswd=`echo $pswd | openssl enc -d -base64`
else
printf "id:"
read id
printf "pswd:"
stty -echo
read pswd
stty echo
echo
id_=`echo $id | openssl enc -base64`
pswd_=`echo $pswd | openssl enc -base64`
:> $file
echo $id_ >> $file
echo $pswd_ >> $file
fi
printf "logging in KurumeNCT network"
timeout=20
res=`curl -L \
--connect-timeout $timeout \
-d "UID=${id}" \
-d "PWD=${pswd}" \
-d "TIM=${tim}" \
${url} \
2>/dev/null`
res_=`curl -L \
--connect-timeout $timeout \
${url} 2>/dev/null`
printf "\t\t"
if [ "${res}" = "${res_}" -o -z "${res}" ]; then
printf "[FAILED]"
else
printf "[OK]"
fi
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment