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=EngUserName=$CELLCOMTEXT_USERPASSWORD=$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?" .
"$hiddenfieldsSenderName=" . uri_escape($sender, "^A-Za-z") .
"CurrMsg=" . uri_escape($message, "^A-Za-z") .
"Urgency=NormalRecipientString=$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_USERLang=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