URI:
       tmycosmos - scripts - random scripts
  HTML git clone https://git.parazyd.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
       tmycosmos (1661B)
       ---
            1 #!/bin/sh
            2 
            3 # send sms messages using the mail.mycosmos.gr service
            4 # depends: curl
            5 
            6 if test -z "$4"
            7 then
            8     echo usage: $0 user pass target message
            9     exit
           10 fi
           11 
           12 USER=$1
           13 PASS=$2
           14 TARGET=$3
           15 MESSAGE="$4"
           16 
           17 # should be 140 chars max
           18 if test "$(echo -n $MESSAGE | wc -m)" -gt 140
           19 then
           20     echo message too long
           21     exit
           22 fi
           23 
           24 LOGINURL='http://mail.mycosmos.gr/mycosmos/login.aspx'
           25 SENDURL='http://mail.mycosmos.gr/mycosmos/SMS_Send.aspx'
           26 COOKIEJAR=$(mktemp)
           27 
           28 # visit login page
           29 VIEWSTATE=$(curl --cookie-jar $COOKIEJAR $LOGINURL 2> /dev/null \
           30     | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/')
           31 FRESH=$(grep mycosmos $COOKIEJAR \
           32     | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//')
           33 COOKIES=$FRESH
           34 
           35 # do login
           36 curl --cookie-jar $COOKIEJAR \
           37     --cookie "$COOKIES" \
           38     --form "__VIEWSTATE=$VIEWSTATE" \
           39     --form "tbUsername=$USER" \
           40     --form "tbPassword=$PASS" \
           41     --form "btLogin=Log On" \
           42     --silent $LOGINURL > /dev/null
           43 
           44 FRESH=$(grep mycosmos $COOKIEJAR \
           45     | awk '{print $6"="$7";"}' | tr '\n' ' ' | sed 's/; $//')
           46 COOKIES="$COOKIES; $FRESH"
           47 
           48 # clear cookies
           49 rm $COOKIEJAR
           50 
           51 # visit send page
           52 VIEWSTATE=$(curl --cookie "$COOKIES" $SENDURL 2> /dev/null \
           53     | grep VIEWSTATE | sed 's/.*value="\(.*\)".*/\1/')
           54 
           55 # send text message
           56 STAT=$(curl --cookie "$COOKIES" \
           57     --form "__VIEWSTATE=$VIEWSTATE" \
           58     --form "txtMobile=$TARGET" \
           59     --form "txtMessage=$MESSAGE" \
           60     --form "btnSend=Send" \
           61     --silent $SENDURL)
           62 
           63 # report status
           64 if test "$(echo $STAT | grep 'Success=True')"
           65     then SENT=yes
           66     else SENT=no
           67 fi
           68 if test "$(echo $STAT | grep 'LimitReached=false')"
           69     then LAST=no
           70     else LAST=yes
           71 fi
           72 echo "sent=$SENT last=$LAST"