| version 1.30, 2002/07/04 20:07:35 |
version 1.31, 2002/07/10 15:25:06 |
|
|
| |
|
| umask 077 |
umask 077 |
| |
|
| GET="/usr/bin/GET" |
# Uncoment following line, if you will use /usr/bin/GET, or specify |
| |
# to your own 'GET' program. Program must accept '-e' '-P' '-H' options |
| |
# and use cookies. |
| |
#GET="/usr/bin/GET" |
| |
GET="make_http_request_GET" # use build-in function |
| |
|
| CONFIG_FILE="$HOME/.sms.sh.conf"; |
CONFIG_FILE="$HOME/.sms.sh.conf"; |
| ALIAS_FILE="$HOME/.sms.sh.alias"; |
ALIAS_FILE="$HOME/.sms.sh.alias"; |
| Line 24 TMP_FILE=`tempfile -p sms. -s .html \ |
|
| Line 28 TMP_FILE=`tempfile -p sms. -s .html \ |
|
| || mktemp /tmp/sms.XXXXXX \ |
|| mktemp /tmp/sms.XXXXXX \ |
| || echo /tmp/sms.$$.html` |
|| echo /tmp/sms.$$.html` |
| |
|
| |
# Function usage() {{{ |
| usage() |
usage() |
| { |
{ |
| # calculate number of spaces used in aligment of usage message |
# calculate number of spaces used in aligment of usage message |
| Line 46 specified, default values are used. |
|
| Line 51 specified, default values are used. |
|
| EOF |
EOF |
| exit 1; |
exit 1; |
| } |
} |
| |
# usage() }}} |
| |
# Function make_http_request_GET() {{{ |
| |
make_http_request_GET() |
| |
{ |
| |
|
| |
for option |
| |
do |
| |
case "$option" in |
| |
|
| |
-*) ;; # ignore |
| |
|
| |
Cookie:*) cookies=`echo $option | sed 's/^Cookie: //;'` ;; |
| |
http:*) http="$option" ;; |
| |
|
| |
esac |
| |
done |
| |
echo "$cookies $http" | perl -w -e ' |
| |
#!/usr/bin/perl -w |
| |
|
| |
use IO::Socket; |
| |
$| = 1; # autoflush |
| |
|
| |
sub http_get |
| |
{ |
| |
my $proxy = shift; |
| |
my $url = shift; |
| |
my $cookies = shift; |
| |
my $port = 80; |
| |
|
| |
my $msg = ""; |
| |
my $sock = undef; |
| |
my $tries = 0; |
| |
|
| |
while ( !$sock && $tries < 5 ) { |
| |
$sock = new IO::Socket::INET( Proto => "tcp", |
| |
PeerAddr => $proxy, |
| |
PeerPort => $port, |
| |
Type => SOCK_STREAM, |
| |
); |
| |
if ( !$sock ) { |
| |
print; |
| |
print "Can NOT connect to ${proxy}:${port} ! Trying again ..."; |
| |
$tries++; |
| |
} |
| |
} |
| |
if ( !$sock ) { |
| |
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; |
| |
} |
| |
|
| |
while (<STDIN>) { |
| |
my $http; |
| |
my $server; |
| |
my $url; |
| |
my $cookies = ""; |
| |
|
| |
chop; |
| |
($cookies, $http) = split / /, $_, 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() }}} |
| |
|
| if [ $# -lt 1 ]; then |
if [ $# -lt 1 ]; then |
| usage |
usage |
|
|
| -use=* | -us=* | -u=*) |
-use=* | -us=* | -u=*) |
| NAME="$optarg" ;; |
NAME="$optarg" ;; |
| |
|
| |
--debug | --debu | --deb | --de | --d | \ |
| |
-debug | -debu | -deb | -de | -d) |
| |
DEBUG="yes" ;; |
| |
--debug=* | --debu=* | --deb=* | --de=* | --d=* | \ |
| |
-debug=* | -debu=* | -deb=* | -de=* | -d=*) |
| |
DEBUG="$optarg" ;; |
| |
|
| |
|
| --help | --hel | --he | --h | -help | -hel | -he | -h) |
--help | --hel | --he | --h | -help | -hel | -he | -h) |
| usage; |
usage; |
| Line 141 number=`echo "$prev_number" | grep '^[0- |
|
| Line 242 number=`echo "$prev_number" | grep '^[0- |
|
| |
|
| # check for alias {{{ |
# check for alias {{{ |
| if [ -z "$number" ]; then |
if [ -z "$number" ]; then |
| echo "Parameter '$prev_number' treated as an alias."; |
if [ ! -z "$DEBUG" ]; then |
| echo -n "Looking for alias file '$ALIAS_FILE'... "; |
echo "Parameter '$prev_number' treated as an alias."; |
| |
echo -n "Looking for alias file '$ALIAS_FILE'... "; |
| |
fi |
| if [ -f "$ALIAS_FILE" ]; then |
if [ -f "$ALIAS_FILE" ]; then |
| echo "found."; |
if [ ! -z "$DEBUG" ]; then |
| |
echo "found."; |
| |
fi |
| echo -n "Looking for alias '$prev_number'... "; |
echo -n "Looking for alias '$prev_number'... "; |
| number=`awk "BEGIN { alias=tolower(\"$prev_number\"); } \ |
number=`awk "BEGIN { alias=tolower(\"$prev_number\"); } \ |
| /^#/ { next; } \ |
/^#/ { next; } \ |
| Line 158 if [ -z "$number" ]; then |
|
| Line 263 if [ -z "$number" ]; then |
|
| exit 1; |
exit 1; |
| fi |
fi |
| else |
else |
| echo "not found."; |
if [ ! -z "$DEBUG" ]; then |
| |
echo "not found."; |
| |
else |
| |
echo "Alias file '$ALIAS_FILE' not found."; |
| |
fi |
| exit 1; |
exit 1; |
| fi |
fi |
| fi |
fi |
|
|
| # equal sign '=' is not needed |
# equal sign '=' is not needed |
| # username, usernam userna, .. user supported |
# username, usernam userna, .. user supported |
| # password, ... supported |
# password, ... supported |
| echo -n "Looking for config file '$CONFIG_FILE'... "; |
if [ ! -z "$DEBUG" ]; then |
| |
echo -n "Looking for config file '$CONFIG_FILE'... "; |
| |
fi |
| if [ -f "$CONFIG_FILE" ]; then |
if [ -f "$CONFIG_FILE" ]; then |
| echo "found."; |
if [ ! -z "$DEBUG" ]; then |
| |
echo "found."; |
| |
fi |
| if [ -z "$NAME" ]; then # username was not specified on cmdline |
if [ -z "$NAME" ]; then # username was not specified on cmdline |
| echo -n "Looking for username... "; |
echo -n "Looking for username... "; |
| NAME=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
NAME=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
| Line 180 if [ -f "$CONFIG_FILE" ]; then |
|
| Line 293 if [ -f "$CONFIG_FILE" ]; then |
|
| if [ -z "$NAME" ]; then |
if [ -z "$NAME" ]; then |
| echo "not found."; |
echo "not found."; |
| else |
else |
| echo "'$NAME'"; |
echo "found '$NAME'"; |
| fi |
fi |
| fi |
fi |
| |
|
| echo -n "Looking for password... "; |
if [ ! -z "$DEBUG" ]; then |
| |
echo -n "Looking for password... "; |
| |
fi |
| PASS=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
PASS=`awk 'BEGIN { FS="[ =]+" } /^#/ { next; } \ |
| /^pass/ { if (NF > 2) { print $3; exit; } \ |
/^pass/ { if (NF > 2) { print $3; exit; } \ |
| else { print $2; } exit; }' "$CONFIG_FILE"`; |
else { print $2; } exit; }' "$CONFIG_FILE"`; |
| if [ -z "$PASS" ]; then |
if [ ! -z "$DEBUG" ]; then |
| |
if [ -z "$PASS" ]; then |
| |
echo "not found."; |
| |
else |
| |
echo "found."; |
| |
fi |
| |
fi |
| |
else |
| |
if [ ! -z "$DEBUG" ]; then |
| echo "not found."; |
echo "not found."; |
| else |
else |
| echo "found."; |
echo "Config file '$CONFIG_FILE' not found."; |
| fi |
fi |
| else |
|
| echo "not found."; |
|
| fi |
fi |
| # }}} |
# }}} |
| |
|