scripts

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

commit b88f696d00dc0c723693a4c0f4340fea179ca3ac
parent f194ef9a467249aaa370722e28c94b7ad67dffb6
Author: lostd <lostd@2f30.org>
Date:   Wed Aug  7 03:49:53 +0300

undo indent, exit if len check fails

Diffstat:
mycosmos | 91+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 45 insertions(+), 46 deletions(-)
diff --git a/mycosmos b/mycosmos @@ -11,60 +11,59 @@ PASS=$2 TARGET=$3 MESSAGE="$4" +# should be 140 chars max +if test "$(echo -n $MESSAGE | wc -m)" -gt 140 +then + echo message too long + exit +fi + LOGINURL='http://mail.mycosmos.gr/mycosmos/login.aspx' SENDURL='http://mail.mycosmos.gr/mycosmos/SMS_Send.aspx' COOKIEJAR=$(mktemp) -MSGLENGTH=$(echo "$MESSAGE" | wc -m) +# 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 -if [[ $MSGLENGTH -lt 140 ]]; then +# 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 - # 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 +FRESH=$(grep mycosmos $COOKIEJAR \ + | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') +COOKIES="$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 +# clear cookies +rm $COOKIEJAR - FRESH=$(grep mycosmos $COOKIEJAR \ - | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//') - COOKIES="$COOKIES; $FRESH" +# visit send page +VIEWSTATE=$(curl --cookie "$COOKIES" $SENDURL 2> /dev/null \ + | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/') - # clear cookies - rm $COOKIEJAR +# send text message +STAT=$(curl --cookie "$COOKIES" \ + --form "__VIEWSTATE=$VIEWSTATE" \ + --form "txtMobile=$TARGET" \ + --form "txtMessage=$MESSAGE" \ + --form "btnSend=Send" \ + --silent $SENDURL) - # 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" +# 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"