Here's a script for cellcom SMSs. It also requires registring in Cellcom's
site (http://text.cellcom.co.il/webp/Cgi/PU/PU_Login.exe?Lang=Eng) to obtain
a username and password.
It also doesn't work with newlines in the message.
---------------------------------------------------------------------------
#!/usr/local/bin/perl -w
# Copyright (C) 1999 Nadav Har'El. All rights reserved.
require 5.004;
use Carp;
use LWP::UserAgent;
use URI::Escape;
#############################################################################
### User-specific information: later, this information should be got from
### a user configuration file.
# Cellcom SMS service registration: registration is free at at
# http://text.cellcom.co.il/webp/Cgi/PU/PU_Login.exe?Lang=Eng
my $CELLCOMTEXT_USER="username"; my $CELLCOMTEXT_PASSWORD="password";
if($#ARGV+1 != 3){
print STDERR "Usage: $0 phonenum sender message\n";
exit 1;
}
my $phonenum=$ARGV[0];
# remove optional spaces, parantheses, or hyphens from phone number
$phonenum =~ s/[ ()-]//go;
my $sender=$ARGV[1];
my $message=$ARGV[2];
print "Sending to $phonenum: $message ($sender)\n";
##################################
my ($ua,$req);
$ua = new LWP::UserAgent;
$ua->agent("perl");
if($phonenum =~ m/^05[23][0-9][0-9][0-9][0-9][0-9][0-9]/){
############################ CELLCOM #######################################
my ($hiddenfields);
$req = new HTTP::Request 'GET' =>
"http://text.cellcom.co.il/webp/Cgi/PU/PU_CheckLogin.exe?Lang=Eng&UserName=$CELLCOMTEXT_USER&PASSWORD=$CELLCOMTEXT_PASSWORD";
$req->header('Accept' => 'text/html');
$res = $ua->request($req);
if ($res->is_success) {
my (@tmplist,$s);
# look for hidden fields in the returned form (res->content)
# but not RecipientString, which we will change:
@tmplist=split '\n', $res->content;
$hiddenfields="";
foreach $s (grep /"Hidden"/, @tmplist){
next if $s =~ /RecipientString/;
$s =~ s/^.*NAME="//o;
$s =~ s/"[ \t]*VALUE="/=/o;
$s =~ s/">/\&/;
$hiddenfields=$hiddenfields . $s;
}
} else {
# TODO: retry several times, sleeping between tries.
print STDERR "Error: " . $res->status_line . "\n";
exit 3;
}
if($hiddenfields eq ""){
# TODO: try to recover somehow (use another account?)
# maybe try to figure out what went wrong by looking
# at $res->content.
print STDERR "Error: bad response from Cellcom's site\n";
exit 4;
}
# now that we have session information ($hiddenfields), send the
# sms.
# TODO: change newlines to spaces, because it seems we don't get
# anything after the first newline. BTW, a newline at the end of
# the message is a way not to the the "(sender)" line! :)
$req = new HTTP::Request 'GET' =>
"http://text.cellcom.co.il/webp/Cgi/PU/PU_SendMessage.exe?" .
"$hiddenfields&SenderName=" . uri_escape($sender, "^A-Za-z") .
"&CurrMsg=" . uri_escape($message, "^A-Za-z") .
"&Urgency=Normal&RecipientString=$phonenum";
$req->header('Accept' => 'text/html');
$res = $ua->request($req);
if ($res->is_success) {
# TODO: check that the returned text is correct, then we'll
# be really sure the message was sent.
if($res->content =~ /Sent successfully/){
print "Sent successfully.\n";
} else {
# TODO: try to recover somehow maybe try to figure out
# what went wrong by looking at $res->content.
print "Error: unexpected response from Celcom's site\n";
exit 6;
}
} else {
# TODO: retry several times, sleeping between tries.
print STDERR "Error: " . $res->status_line . "\n";
exit 5;
}
# TODO: I didn't copy here the old logout code from my old sendsms.
# I'm not sure if it's needed: or worse - what it does. Maybe it
# makes sendsms non-reentrant? So far I didn't get any problems
# because I don't "log out".
# $WGET -O $TMPF
"http://text.cellcom.co.il/webp/Cgi/PU/PU_Logout.exe?UserName=$CELLCOMTEXT_USER&Lang=Eng"
############################################################################
} elsif($phonenum =~ m/^054[0-9][0-9][0-9][0-9][0-9][0-9]/){
print STDERR "Sorry, Orange number $phonenum not yet supported.\n";
} elsif($phonenum =~ m/^05[01][0-9][0-9][0-9][0-9][0-9][0-9]/){
print STDERR "Sorry, Pelephone number $phonenum not yet supported.\n";
} else {
print STDERR "Sorry, unrecognized cellphone number $phonenum.\n";
print STDERR "Currently, recognized numbers must begin with 052, 053\n";
print STDERR "followed by exactly 6 digits.";
exit 2;
}
1;
--
Nadav Har'El | ###### ######## # | <-- Sorry if
Email: [EMAIL PROTECTED] | # # # | you can't
Department of Mathematics, Technion | # # # | read Hebrew.
Israel Institute of Technology | ######## # ###### | Nadav. ;)
WWW page: http://harel.org.il/nadav ICQ #13349191
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]