scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit c9bf1cb3f656d62dbef085becaadef7a7fa7723b
parent 7b8b6460769e8f8ef6947ae71128322b5865aa39
Author: Haris <haris@feanor.lan>
Date:   Mon, 22 Jul 2013 14:23:25 +0300

Character limit check.

Diffstat:
Mmycosmos | 96+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 52 insertions(+), 44 deletions(-)

diff --git a/mycosmos b/mycosmos @@ -15,48 +15,56 @@ LOGINURL='http://mail.mycosmos.gr/mycosmos/login.aspx' SENDURL='http://mail.mycosmos.gr/mycosmos/SMS_Send.aspx' COOKIEJAR=$(mktemp) -# visit login page -VIEWSTATE=$(curl --cookie-jar $COOKIEJAR $LOGINURL 2> /dev/null \ - | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') -FRESH=$(grep mycosmos $COOKIEJAR \ - | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') -COOKIES=$FRESH - -# do login -curl --cookie-jar $COOKIEJAR \ - --cookie "$COOKIES" \ - --form "__VIEWSTATE=$VIEWSTATE" \ - --form "tbUsername=$USER" \ - --form "tbPassword=$PASS" \ - --form "btLogin=Log On" \ - --silent $LOGINURL > /dev/null - -FRESH=$(grep mycosmos $COOKIEJAR \ - | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') -COOKIES="$COOKIES; $FRESH" - -# clear cookies -rm $COOKIEJAR - -# visit send page -VIEWSTATE=$(curl --cookie "$COOKIES" $SENDURL 2> /dev/null \ - | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') - -# send text message -STAT=$(curl --cookie "$COOKIES" \ - --form "__VIEWSTATE=$VIEWSTATE" \ - --form "txtMobile=$TARGET" \ - --form "txtMessage=$MESSAGE" \ - --form "btnSend=Send" \ - --silent $SENDURL) - -# report status -if test "$(echo $STAT | grep 'Success=True')" - then SENT=yes - else SENT=no -fi -if test "$(echo $STAT | grep 'LimitReached=false')" - then LAST=no - else LAST=yes +MSGLENGTH=$(echo "$MESSAGE" | wc -m) + +if [[ $MSGLENGTH -lt 140 ]]; then + + # visit login page + VIEWSTATE=$(curl --cookie-jar $COOKIEJAR $LOGINURL 2> /dev/null \ + | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') + FRESH=$(grep mycosmos $COOKIEJAR \ + | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') + COOKIES=$FRESH + + # do login + curl --cookie-jar $COOKIEJAR \ + --cookie "$COOKIES" \ + --form "__VIEWSTATE=$VIEWSTATE" \ + --form "tbUsername=$USER" \ + --form "tbPassword=$PASS" \ + --form "btLogin=Log On" \ + --silent $LOGINURL > /dev/null + + FRESH=$(grep mycosmos $COOKIEJAR \ + | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') + COOKIES="$COOKIES; $FRESH" + + # clear cookies + rm $COOKIEJAR + + # visit send page + VIEWSTATE=$(curl --cookie "$COOKIES" $SENDURL 2> /dev/null \ + | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') + + # send text message + STAT=$(curl --cookie "$COOKIES" \ + --form "__VIEWSTATE=$VIEWSTATE" \ + --form "txtMobile=$TARGET" \ + --form "txtMessage=$MESSAGE" \ + --form "btnSend=Send" \ + --silent $SENDURL) + + # report status + if test "$(echo $STAT | grep 'Success=True')" + then SENT=yes + else SENT=no + fi + if test "$(echo $STAT | grep 'LimitReached=false')" + then LAST=no + else LAST=yes + fi + echo "sent=$SENT last=$LAST" + +else + echo "Your message is too big" fi -echo "sent=$SENT last=$LAST"