| version 1.44, 2002/09/12 17:58:53 |
version 1.45, 2002/09/12 19:57:01 |
|
|
| #GET="/usr/bin/GET" |
#GET="/usr/bin/GET" |
| GET="make_http_request_GET" # use build-in function |
GET="make_http_request_GET" # use build-in function |
| |
|
| |
# default |
| 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" |
WWW="http://www.sity.sk" |
| |
|
| # Function usage() {{{ |
# Function usage() {{{ |
| usage() |
usage() |
| { |
{ |
|
|
| make_http_request_GET() |
make_http_request_GET() |
| { |
{ |
| |
|
| for option |
# if --debug option is specified, save output from $GET to $TMP_FILE, |
| do |
echo "## Time: " >> $TMP_FILE |
| case "$option" in |
echo "## Request: $* {{{" >> $TMP_FILE |
| |
|
| -*) ;; # ignore |
for option |
| |
do |
| Cookie:*) cookies="`echo $option | sed 's/^Cookie: //;'`" ;; |
case "$option" in |
| http:*) http="$option" ;; |
|
| |
|
| esac |
-*) ;; # ignore |
| done |
|
| if [ ! -z "$DEBUG" ]; then |
|
| echo "GET -H 'Cookie: $cookies' '$http'" > /dev/stderr |
|
| fi |
|
| echo "$cookies $http" | perl -w -e ' |
|
| #!/usr/bin/perl -w |
|
| |
|
| use IO::Socket; |
Cookie:*) cookies="`echo $option | sed 's/^Cookie: //;'`" ;; |
| $| = 1; # autoflush |
http:*) http="$option" ;; |
| |
|
| sub http_get |
esac |
| { |
done |
| my $proxy = shift; |
if [ ! -z "$DEBUG" ]; then |
| my $url = shift; |
echo "GET -H 'Cookie: $cookies' '$http'" > /dev/stderr |
| my $cookies = shift; |
fi |
| my $port = 80; |
echo "$cookies $http" | perl -w -e ' |
| |
#!/usr/bin/perl -w |
| my $msg = ""; |
|
| my $sock = undef; |
use IO::Socket; |
| my $tries = 0; |
$| = 1; # autoflush |
| |
|
| while ( !$sock && $tries < 5 ) { |
sub http_get |
| $sock = new IO::Socket::INET( Proto => "tcp", |
{ |
| PeerAddr => $proxy, |
my $proxy = shift; |
| PeerPort => $port, |
my $url = shift; |
| Type => SOCK_STREAM, |
my $cookies = shift; |
| ); |
my $port = 80; |
| if ( !$sock ) { |
|
| print; |
my $msg = ""; |
| print "Can NOT connect to ${proxy}:${port} ! Trying again ..."; |
my $sock = undef; |
| $tries++; |
my $tries = 0; |
| } |
|
| } |
while ( !$sock && $tries < 5 ) { |
| if ( !$sock ) { |
$sock = new IO::Socket::INET( Proto => "tcp", |
| print "$proxy is death... :(\n\n"; |
PeerAddr => $proxy, |
| return; |
PeerPort => $port, |
| } |
Type => SOCK_STREAM, |
| |
); |
| # make http request |
if ( !$sock ) { |
| print $sock "GET $url HTTP/1.1\r\n"; |
print; |
| print $sock "TE: deflate, gzip;q=0.3\r\n"; |
print "Can NOT connect to ${proxy}:${port} ! Trying again ..."; |
| print $sock "Connection: TE, close\r\n"; |
$tries++; |
| print $sock "Host: $proxy\r\n"; |
} |
| print $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Linux [en]\r\n"; |
} |
| if ($cookies =~ "Cookie: ") { |
if ( !$sock ) { |
| print $sock "$cookies\r\n"; |
print "$proxy is death... :(\n\n"; |
| |
return; |
| |
} |
| |
|
| |
# make http request |
| |
print $sock "GET $url HTTP/1.1\r\n"; |
| |
print $sock "TE: deflate, gzip;q=0.3\r\n"; |
| |
print $sock "Connection: TE, close\r\n"; |
| |
print $sock "Host: $proxy\r\n"; |
| |
print $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Linux [en]\r\n"; |
| |
if ($cookies =~ "Cookie: ") { |
| |
print $sock "$cookies\r\n"; |
| |
} |
| |
print $sock "\r\n"; |
| |
|
| |
|
| |
$sock->flush(); |
| |
while (<$sock>) { |
| |
print; |
| |
} |
| |
$sock->close(); |
| |
return; |
| } |
} |
| print $sock "\r\n"; |
|
| |
|
| |
while (<STDIN>) { |
| |
my $http; |
| |
my $server; |
| |
my $url; |
| |
my $cookies = ""; |
| |
|
| |
chomp; |
| |
($cookies, $http) = split /http:\/\//, $_, 2; |
| |
#$http =~ s|^http://||; |
| |
($server, $url) = split /\//, $http, 2; |
| |
substr($cookies, 0, 0) = "Cookie: "; # put string at begin |
| |
substr($url, 0, 0) = "/"; |
| |
|
| $sock->flush(); |
#print "http=$http\ncookies=$cookies\nurl=$url\nserver=$server\n"; |
| while (<$sock>) { |
http_get($server, $url, $cookies); |
| print; |
} |
| } |
exit;' | tee -a $TMP_FILE |
| $sock->close(); |
echo "## }}} request done " >> $TMP_FILE |
| return; |
|
| } |
|
| |
|
| while (<STDIN>) { |
|
| my $http; |
|
| my $server; |
|
| my $url; |
|
| my $cookies = ""; |
|
| |
|
| chomp; |
|
| ($cookies, $http) = split /http:\/\//, $_, 2; |
|
| #$http =~ s|^http://||; |
|
| ($server, $url) = split /\//, $http, 2; |
|
| substr($cookies, 0, 0) = "Cookie: "; # put string at begin |
|
| substr($url, 0, 0) = "/"; |
|
| |
|
| #print "http=$http\ncookies=$cookies\nurl=$url\nserver=$server\n"; |
|
| http_get($server, $url, $cookies); |
|
| } |
|
| exit;' |
|
| } |
} |
| |
|
| # make_http_request_GET() }}} |
# make_http_request_GET() }}} |
| # implementation of img2text {{{ |
# implementation of img2text {{{ |
| img2text() |
img2text() |
| { |
{ |
| |
|
| awk '#!/usr/bin/awk -f |
awk '#!/usr/bin/awk -f |
| |
|
| # $Id$ |
# $Id$ |
| |
|
| # Author: Lubomir Host rajo <rajo AT host.sk> |
# Author: Lubomir Host rajo <rajo AT host.sk> |
| # License: GNU GPL |
# License: GNU GPL |
| |
|
| # Script for converting images to text files. |
# Script for converting images to text files. |
| # Usefull for script, which will send SMS message over public SMS gateway. ;) |
# Usefull for script, which will send SMS message over public SMS gateway. ;) |
| |
|
| # Usage: cat img.png | convert - text:- | ./img2text |
# Usage: cat img.png | convert - text:- | ./img2text |
| # Enjoy flooding sms gateway! ;)) |
# Enjoy flooding sms gateway! ;)) |
| |
|
| BEGIN { |
BEGIN { |
| FS="[,:# \t]+" |
FS="[,:# \t]+" |
| prev_line = 0; |
prev_line = 0; |
| line = 1; |
line = 1; |
| column = 0; |
column = 0; |
| color = ""; |
color = ""; |
| start_char = 41; |
start_char = 41; |
| } |
} |
| |
|
| { |
{ |
| n = split($0, a, FS); |
n = split($0, a, FS); |
| |
|
| column = a[1]; |
column = a[1]; |
| line = a[2]; |
line = a[2]; |
| color = a[6]; |
color = a[6]; |
| if (colormap[color] == 0) { |
if (colormap[color] == 0) { |
| #printf "adding color %s to colormap\n", color; |
#printf "adding color %s to colormap\n", color; |
| colormap[color] = ++start_char; |
colormap[color] = ++start_char; |
| |
} |
| |
if (column == 0 && line == 0) { |
| |
# first pixel 0,0 is probably background color, |
| |
# we will background filled with spaces |
| |
colormap[color] = 32; |
| |
} |
| |
output[line] = sprintf("%s%c", output[line], colormap[color]); |
| } |
} |
| if (column == 0 && line == 0) { |
|
| # first pixel 0,0 is probably background color, |
END { |
| # we will background filled with spaces |
|
| colormap[color] = 32; |
|
| } |
|
| output[line] = sprintf("%s%c", output[line], colormap[color]); |
|
| } |
|
| |
|
| END { |
|
| for (i = 0; i <= line; i++) { |
for (i = 0; i <= line; i++) { |
| if (output[i] !~ /^ +$/) |
if (output[i] !~ /^ +$/) |
| printf "%s\n", output[i]; |
printf "%s\n", output[i]; |
| } |
} |
| }' |
}' |
| |
|
| } # }}} |
} # }}} img2text() |
| |
|
| if [ $# -lt 1 ]; then |
if [ "$#" -lt 1 ]; then |
| usage |
usage |
| fi |
fi |
| |
|
| Line 300 if [ ! -z "$DEBUG" ]; then |
|
| Line 309 if [ ! -z "$DEBUG" ]; then |
|
| && TMP_FILE=`tempfile -p sms. -s .html \ |
&& TMP_FILE=`tempfile -p sms. -s .html \ |
| || mktemp /tmp/sms.XXXXXX \ |
|| mktemp /tmp/sms.XXXXXX \ |
| || echo /tmp/sms.$$.html` |
|| echo /tmp/sms.$$.html` |
| |
echo "Saving debug output to $TMP_FILE" |
| |
else |
| |
test -z "$TMP_FILE" \ |
| |
&& TMP_FILE="/dev/null" |
| fi |
fi |
| |
|
| number=`echo "$prev_number" | grep '^[0-9]\+$'`; |
number=`echo "$prev_number" | grep '^[0-9]\+$'`; |
| Line 417 COOKIE=`$GET -P -e -H "Cookie: SITY=SITY |
|
| Line 430 COOKIE=`$GET -P -e -H "Cookie: SITY=SITY |
|
| # Retrieving submit forms... {{{ |
# Retrieving submit forms... {{{ |
| echo 'Retrieving submit forms...'; |
echo 'Retrieving submit forms...'; |
| |
|
| # if --debug option is specified, save output from $GET to $TMP_FILE, |
|
| # else do nothing |
|
| if [ ! -z "$NAME" ]; then |
|
| SAVE_DEBUG_OUTPUT="| tee -a $TMP_FILE " |
|
| else |
|
| SAVE_DEBUG_OUTPUT="" |
|
| fi |
|
| |
|
| #we now extract textarea name, which will be used later |
#we now extract textarea name, which will be used later |
| request=` $GET -P -H "Cookie: $COOKIE" \ |
request=` $GET -P -H "Cookie: $COOKIE" \ |
| $WWW/pls/sity/\!u_sms.home $SAVE_DEBUG_OUTPUT \ |
$WWW/pls/sity/\!u_sms.home \ |
| | awk -v number="$number" ' |
| awk -v number="$number" ' |
| BEGIN { printf "&SMSMsgLen=480&SMScount=&"; } |
BEGIN { printf "&SMSMsgLen=480&SMScount=&"; } |
| /textarea cols/ { |
/textarea cols/ { |