Hello linux-il's.
I wrote the following script for non-interactively sending messages
to Orange mobile phones. Great e.g. for sysops that may be paged by
the system if something happens. Note that you have to sign up at
www.orange.co.il to get a user and a password for sending the
messages.
Question: are there similar scripts for pelephone and cellcom phones?
Enjoy!
Dov
<<File: orange-sms>>
#!/usr/local/bin/perl
######################################################################
# A script to connect to Orange Partners SMS service and send a
# message noninteractively.
#
# Dov Grobgeld <[EMAIL PROTECTED]>
#
# Date: 1999-09-01
#
# Bugs: There is a problem sending messages with embedded newlines!
######################################################################
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use HTTP::Cookies;
use strict;
# Defaults
my($user);
my($password);
my $sender = "999"; # Put your default sender number here
my $message = "Yihaaa!"; # Default message
my $phonenumber = "05499999"; # Default orange phone number
# Parse command line
while($_ = $ARGV[0], /^-/) {
shift;
/^-help/ and do { print<<__; exit; };
sms-msg - send a message through Orange sms internet service
Syntax:
sms-msg [-user user] [-pw pw] [-phn fn] [-sender snd]
[-msg message]
Description:
sms-msg connects to orange.co.il and sends a text message that
was specified on the command line.
Options:
-user user Identification to the orange sms service.
-pw pw Password to the orange sms service.
-phn phn Phone number the message send to. E.g. 054789952 .
-sender snd Identification number of the sender.
-msg msg The contents of the message. Note that normal unix quoting
works and newlines may thus be embedded in the message.
A maximum of 108 characters is permitted for the message.
__
/^-user/ and do { $user = shift; next; };
/^-(pw|password)/ and do { $password = shift; next; };
/^-msg/ and do { $message = shift; next; };
/^-phn/ and do { $phonenumber = shift; next; };
/^-sender/ and do { $sender = shift; next; };
die "Unknown option $_!\n";
}
# Sanity checks
die "Too many characters in message!\n" if length($message) > 108;
die "Must have user and password!\n" unless $user && $password;
$phonenumber=~ tr/- //d;
die "Phonenumber must start with 054!\n" unless $phonenumber=~ /^054/;
$message=~ s/\n/\r/g;
# Global variables
my $cookie_jar = HTTP::Cookies->new;
######################################################################
# query does either a post or a get http query. It creates a http
# query and decoretes it with headers and cookies and then
# sends it out and gets a response in return. The response is parsed
# for more cookies that are added to the cookie jar.
######################################################################
sub query {
my ($action, $url, $query) = @_;
my $ua = LWP::UserAgent->new();
my $request;
if ($action eq "POST") {
$request = POST($url, $query);
} else {
$request = GET($url);
}
# This is how the proxy password is provided
if (-e "$ENV{HOME}/.http_header") {
open(HTTP, "$ENV{HOME}/.http_header");
foreach (<HTTP>) {
chomp;
next if/^\s*$/;
my($key, $value) = split(/:\s*/);
$request->push_header($key,$value);
}
close(HTTP);
}
# Tell user agent to use a proxy if the environment varible 'http_proxy'
# is defined.
$ua->proxy('http', $ENV{http_proxy}) if $ENV{http_proxy};
# Add all the cookies from the cookie jar to the request
$cookie_jar->add_cookie_header($request);
# Send out the request and get the response
my $response = $ua->request($request);
# Add all cookies in the response to the cookie jar
$cookie_jar->extract_cookies($response);
# Send back the raw response
return $response;
}
######################################################################
# Base address of orange sms page
######################################################################
my $base = "http://www.orange.co.il/orange_online/free_sms/scripts";
######################################################################
# First log in. This will set a cookie that we need for subsequent
# quearies.
######################################################################
my $login_msg = query("POST", "$base/login_check.asp",
["iccid"=>$password,
"mfn"=>$user]);
# check that login succeeded
unless ($login_msg->as_string=~ /Object moved.*smssend/s) {
die "Failed login into Orange!\n";
}
print "Login successful!\n";
######################################################################
# Now post the message to the
# requested phone number.
######################################################################
print "Sending \"$message\" to $phonenumber.\n";
my $smsprocess = query("POST", "$base/smsprocess.asp",
["mfn" => $phonenumber,
"sender" => $sender,
"message" => $message,
"counter" => 108-length($message)-length($sender)]);
# Check if the sending failed
my $scs = "\347\354\371\360 \351\360\345\370\350\367\354\340\344"
." \367\346\341\356\344";
unless ($smsprocess->as_string=~ /$scs/) {
open(TMP, ">/tmp/sms-failed-response.txt");
print TMP $smsprocess->as_string;
close(TMP);
die "Failed sending the message!\n";
}
print "The message was sent successfully!\n";
=================================================================
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]