| version 1.13, 2002/06/20 10:50:37 |
version 1.14, 2002/06/21 16:23:34 |
|
|
| # sms.sh - sity.sk SMS sender |
# sms.sh - sity.sk SMS sender |
| # |
# |
| # Written by Martin Karas. |
# Written by Martin Karas. |
| # Alias support by Ondrej Jombik [20/6/2002] |
# Alias support by Ondrej Jombik [20/06/2002] |
| |
# Alias support simplification by Lubomir Host [21/06/2002] |
| # Based on script flash.sh by Ondrej Jombik |
# Based on script flash.sh by Ondrej Jombik |
| # Copyright (c) 2002 Platon SDG, http://www.platon.sk/ |
# Copyright (c) 2002 Platon SDG, http://www.platon.sk/ |
| # |
# |
| |
|
| # $Id$ |
# $Id$ |
| |
|
| |
umask 077 |
| |
|
| CONFIG_FILE="$HOME/.sms.sh.conf"; |
CONFIG_FILE="$HOME/.sms.sh.conf"; |
| ALIAS_FILE="$HOME/.sms.sh.alias"; |
ALIAS_FILE="$HOME/.sms.sh.alias"; |
| |
|
| |
WWW="http://www.sity.sk/pls/sity" |
| |
TMP_FILE1=`tempfile -p sms.sh || mktemp /tmp/sms.shXXXXXX || echo /tmp/sms.sh$$` |
| |
TMP_FILE2=`tempfile -p sms.sh || mktemp /tmp/sms.shXXXXXX || echo /tmp/sms.sh$$` |
| |
|
| if [ $# -lt 1 ]; then |
if [ $# -lt 1 ]; then |
| echo -e "Usage:\n $0 <number-or-alias>\n"; |
echo -e "Usage:\n $0 <number-or-alias>\n"; |
| echo "Message is taken from standart input. Only one line is allowed."; |
echo "Message is taken from standart input. Only one line is allowed."; |
| Line 48 if [ -z "$number" ]; then |
|
| Line 55 if [ -z "$number" ]; then |
|
| exit; |
exit; |
| fi |
fi |
| |
|
| |
#if [ -f "$CONFIG_FILE" ]; then |
| |
# NAME=`grep -v '^#' "$CONFIG_FILE" \ |
| |
# | grep -E '^username[ ]*=[ ]*' \ |
| |
# | sed 's/^username[ ]*=[ ]*\(.*\)[ ]*$/\1/' \ |
| |
# | head -n 1`; |
| |
# PASS=`grep -v '^#' "$CONFIG_FILE" \ |
| |
# | grep -E '^password[ ]*=[ ]*' \ |
| |
# | sed 's/^password[ ]*=[ ]*\(.*\)[ ]*$/\1/' \ |
| |
# | head -n 1`; |
| |
#fi |
| |
|
| |
# Lines begining with "^#" are comments and are ignored. |
| |
# equal sign '=' is not needed |
| |
# username, usernam userna, .. user supported |
| |
# password, ... supported |
| if [ -f "$CONFIG_FILE" ]; then |
if [ -f "$CONFIG_FILE" ]; then |
| NAME=`grep -v '^#' "$CONFIG_FILE" \ |
NAME=`awk '/^#/ { next; } // { gsub(/=/, ""); } /^user/ { print $2; exit;}' "$CONFIG_FILE"`; |
| | grep -E '^username[ ]*=[ ]*' \ |
PASS=`awk '/^#/ { next; } // { gsub(/=/, ""); } /^pass/ { print $2; exit;}' "$CONFIG_FILE"`; |
| | sed 's/^username[ ]*=[ ]*\(.*\)[ ]*$/\1/' \ |
|
| | head -n 1`; |
|
| PASS=`grep -v '^#' "$CONFIG_FILE" \ |
|
| | grep -E '^password[ ]*=[ ]*' \ |
|
| | sed 's/^password[ ]*=[ ]*\(.*\)[ ]*$/\1/' \ |
|
| | head -n 1`; |
|
| fi |
fi |
| |
|
| if [ -z "$NAME" ]; then |
if [ -z "$NAME" ]; then |
|
|
| text=`echo "$text" | sed 's/%/%25/g; s/\+/%2B/g; s/ /+/g; s/&/%26/g'`; |
text=`echo "$text" | sed 's/%/%25/g; s/\+/%2B/g; s/ /+/g; s/&/%26/g'`; |
| |
|
| # download the file via special wget which stores session cookie to a file |
# download the file via special wget which stores session cookie to a file |
| |
# Cookies format: |
| |
#Set-Cookie: SITY=32E0DDB9AF9293E774AA1C0B5BCC0992;path=/ |
| echo 'Logging in...'; |
echo 'Logging in...'; |
| COOKIE=`GET -e -H "Cookie: SITY=SITY" \ |
COOKIE=`GET -e -H "Cookie: SITY=SITY" \ |
| http://www.sity.sk/pls/sity/u_registrate2.login2?NAME="$NAME"\&PASSWD="$PASS"\&ASERVICE=0\&CMD=%21u_sms.home\&SERVICE=0 \ |
$WWW/u_registrate2.login2?NAME="$NAME"\&PASSWD="$PASS"\&ASERVICE=0\&CMD=%21u_sms.home\&SERVICE=0 \ |
| | grep '^Set-Cookie' | sed 's/^Set-Cookie: SITY=\([0-9A-F]*\).*/\1/'`; |
| awk 'BEGIN { FS="[=;]" } /^Set-Cookie:/ { print $2; }'`; |
| |
# | grep '^Set-Cookie' | sed 's/^Set-Cookie: SITY=\([0-9A-F]*\).*/\1/'`; |
| |
|
| echo -n 'Checking number of free SMSs... '; |
echo -n 'Checking number of free SMSs... '; |
| GET -H "Cookie: SITY=$COOKIE" \ |
#GET -H "Cookie: SITY=$COOKIE" \ |
| http://www.sity.sk/pls/sity/u_profil.show_stat > tmp.html; |
# $WWW/u_profil.show_stat > $TMP_FILE1; |
| |
#smss_sent=`grep '^<TD>[0-9]\+</TD>$' $TMP_FILE1 | head -n 1 | sed 's/<TD>\([0-9]\+\).*/\1/'`; |
| smss_sent=`grep '^<TD>[0-9]\+</TD>$' tmp.html | head -n 1 | sed 's/<TD>\([0-9]\+\).*/\1/'`; |
smss_sent=`GET -H "Cookie: SITY=$COOKIE" \ |
| |
$WWW/u_profil.show_stat | awk '/^<TD>[0-9]\+</TD>$/ { gsub(/[><]/, " "); print $2; exit; } '`; |
| |
|
| echo "100-$smss_sent" | bc; |
echo "100-$smss_sent" | bc; |
| |
|
| echo 'Retrieving submit forms...'; |
echo 'Retrieving submit forms...'; |
| GET -H "Cookie: SITY=$COOKIE" \ |
GET -H "Cookie: SITY=$COOKIE" \ |
| http://www.sity.sk/pls/sity/\!u_sms.home >tmp.html; |
$WWW/\!u_sms.home >$TMP_FILE1; |
| |
|
| #we now extract textarea name, which will be used later |
#we now extract textarea name, which will be used later |
| textareaname=`grep 'textarea cols' tmp.html | sed 's/.*name="\([^"]*\)".*/\1/g'`; |
textareaname=`grep 'textarea cols' $TMP_FILE1 | sed 's/.*name="\([^"]*\)".*/\1/g'`; |
| detailvalue=`grep 'DETAIL' tmp.html | sed 's/.*value="\([^"]*\)".*/\1/g'`; |
detailvalue=`grep 'DETAIL' $TMP_FILE1 | sed 's/.*value="\([^"]*\)".*/\1/g'`; |
| |
|
| echo 'Hold still, we need to wait 4 seconds.'; |
echo 'Hold still, we need to wait 4 seconds.'; |
| sleep 4; |
sleep 4; |
| |
|
| echo 'Submitting SMS...'; |
echo 'Submitting SMS...'; |
| GET -H "Cookie: SITY=$COOKIE" \ |
GET -H "Cookie: SITY=$COOKIE" \ |
| http://www.sity.sk/pls/sity/\!u_sms.send_sms?MSG_TEXT="$text"\&SMSMsgLen=480\&SMScount=\&"$textareaname"="$number"\&BT.x=0\&BT.y=0\&DETAIL="$detailvalue" \ |
$WWW/\!u_sms.send_sms?MSG_TEXT="$text"\&SMSMsgLen=480\&SMScount=\&"$textareaname"="$number"\&BT.x=0\&BT.y=0\&DETAIL="$detailvalue" \ |
| > tmp2.html; |
> $TMP_FILE2; |
| |
|
| smss_left=`grep "Tento mesiac" tmp2.html | sed 's/.*va \([0-9]*\) spr.*/\1/'` ; |
smss_left=`grep "Tento mesiac" $TMP_FILE2 | sed 's/.*va \([0-9]*\) spr.*/\1/'` ; |
| |
|
| if [ $smss_left ]; then |
if [ $smss_left ]; then |
| echo "Message sent. $smss_left SMSs left for this month."; |
echo "Message sent. $smss_left SMSs left for this month."; |
| rm -f tmp.html; |
rm -f $TMP_FILE1; |
| rm -f tmp2.html; |
rm -f $TMP_FILE2; |
| else |
else |
| echo 'Something went wrong, see debug files (tmp.html, tmp2.html).'; |
echo 'Something went wrong, see debug files ($TMP_FILE1, $TMP_FILE2).'; |
| fi |
fi |
| |
|