#!/usr/bin/perl -W # SMSsend # # SMSsend 1.0 # Script d'envoi de SMS via LeSMS.com # # Copyright (C) 2004 Guillaume Chevillot # Email: guillaume AT chevillot DOT net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use strict; use Switch; use Getopt::Long; use Pod::Usage; use LWP::UserAgent; # url de base pour envoyer les SMS my $base = 'http://www.leSMS.com/http.php'; # Declaration des variables my $email = ""; my $pass = ""; my $numero = ""; my $message = ""; my $help = 0; my $man = 0; my $verbose = 0; my $quiet = 0; my $rcode = 0; my $url = $base; # Obtient les options GetOptions( 'email|e=s' => \$email, 'pass|p=s' => \$pass, 'number|n=s' => \$numero, 'message|m=s'=> \$message, 'help|h|?' => \$help, 'man' => \$man, 'verbose|v' => \$verbose, 'quiet|q' => \$quiet ) or pod2usage(2); pod2usage(1) if $help; pod2usage(-exitstatus => 0, -verbose => 2) if $man; # Prendre l'entre standart pour le message s'il n'est pas specifie $message = <> if not $message; # Nettoie $message d'eventuel espace ou retour a la ligne en fin de chaine $message =~ s/\n*$//; $message =~ s/\s*$//; # Verifie les options die "Please specify an email.\nType 'SMSsend --help' for more informations.\n" if not $email; die "Please specify a password.\nType 'SMSsend --help' for more informations.\n" if not $pass; die "Please specify a phone number.\nType 'SMSsend --help' for more informations.\n" if not $numero; die "Please specify a message to send.\nType 'SMSsend --help' for more informations.\n" if not $message; die "You can not use quiet and verbose options together.\n" if $verbose and $quiet; die "Not a valid phone number !\n" if $numero =~ /[\t\s\na-zA-Z_]+/; # Genere l'adresse http pour l'envoi du SMS $url .= '?email='; $url .= rfc1738($email); $url .= '&pass='; $url .= rfc1738($pass); $url .= '&numero='; $url .= rfc1738($numero); $url .= '&message='; $url .= rfc1738($message); # Affiche l'url generee pour le deboguage #print "$url\n"; # Cree un agent et une requete pour l'envoi du message par http my $ua = LWP::UserAgent->new( agent => "SMSsend/1.0"); my $request = HTTP::Request->new( GET => $url); # Envoi le SMS et recoit la reponse my $response = $ua->request($request); die $response->status_line if not $response->is_success; # Traite la reponse $rcode = $response->content(); die "No response code from lesms.com !\nPlease, check that you entered good parameters.\n" if not $rcode; # Affiche la reponse pour deboguage #print "$rcode\n"; if(!$quiet) { switch($rcode) { case 82 { print STDERR "Le login et/ou le mot n'est pas valide.\n"; } case 83 { print STDERR "Vous devez crediter votre compte.\n"; } case 84 { print STDERR "Le numero GSM est invalide.\n"; } case 85 { print STDERR "Le format d'envoi differe n'est pas valide.\n"; } case 86 { print STDERR "Le groupe de contacts est vide.\n"; } case 87 { # ce cas la ne doit pas arriver normalement print STDERR "La valeur email est vide.\n"; } case 88 { # ce cas la ne doit pas arriver normalement print STDERR "La valeur pass est vide.\n"; } case 89 { # ce cas la ne doit pas arriver normalement print STDERR "La valeur numero est vide.\n"; } case 90 { # ce cas la ne doit pas arriver normalement print STDERR "La valeur message est vide.\n"; } case 91 { print STDERR "Le message a deja ete envoye a ce numero ce jour.\n"; } } } if($verbose) { switch($rcode) { case 80 { print STDOUT "Le message a ete envoye.\n"; } case 81 { print STDOUT "Le message a ete enregistre pour un envoi differe.\n"; } } } # Adapte la string $url a la RFC 1738 sub rfc1738 { my $chaine = shift; $chaine =~ s/\%/%25/g; $chaine =~ s/\t/%09/g; $chaine =~ s/\s/%20/g; $chaine =~ s/\"/%22/g; $chaine =~ s/\#/%23/g; $chaine =~ s/\&/%26/g; $chaine =~ s/\(/%28/g; $chaine =~ s/\)/%29/g; $chaine =~ s/\,/%2C/g; $chaine =~ s/\./%2E/g; $chaine =~ s/\//%2F/g; $chaine =~ s/\:/%3A/g; $chaine =~ s/\;/%3B/g; $chaine =~ s/\/%3E/g; $chaine =~ s/\?/%3F/g; $chaine =~ s/\@/%40/g; $chaine =~ s/\[/%5B/g; $chaine =~ s/\\/%5C/g; $chaine =~ s/\]/%5D/g; $chaine =~ s/\^/%5E/g; $chaine =~ s/\'/%60/g; $chaine =~ s/\{/%7B/g; $chaine =~ s/\|/%7C/g; $chaine =~ s/\}/%7D/g; $chaine =~ s/\~/%7E/g; return $chaine; } __END__ =head1 NAME SMSsend 1.0 =head1 SYNOPSIS SMSsend [options] -e -p -n -m email, pass, numero and message options are required. The message can be passed through STDIN. example: echo "Hi honey !" | SMSsend -e -p -n =head1 OPTIONS =over 8 =item B<-e, --email=STRING> Your login email for LeSMS.com =item B<-p, --pass=STRING> Your account password. =item B<-n, --number=STRING> The phone number to send the SMS. =item B<-m, --message=STRING> The message to send. The message can be passed through STDIN. =item B<-v, --verbose> Verbose LeSMS.com response even if SMS is succesfully sent. By default, responses are displayed only when errors occurs. =item B<-q, --quiet> Stay quiet even if the SMS is not sent. =item B<-h, --help> Print a brief help message and exits. =item B<--man> Prints the manual page and exits. =back =head1 DEXCRIPTION B will send a SMS via http using your LeSMS.com account. Reports bugs to guillaume+LeSMS AT chevillot DOT net