#!/usr/bin/perl -w # ecrit et verifie au 19 oct 2004 use strict; use WWW::Mechanize; use Getopt::Long; if ( $#ARGV == -1 ) { print( "Syntaxe: perl bouygtelsms.pl -from 06xxxxxxxx -to 06xxxxxxxx -pass xxxx -msg 'mon message' [-pay]\n\n" ); print( "Pour obtenir votre mot de passe, il faut etre client Bouygtel et aller s'inscrire ici :\nhttp://www.services2.bouyguestelecom.fr/inscription/InscriptionSaisieCodeClient.asp\n" ); print( "Rappel: Bouygtel offre 1 SMS par jour a destination d'un numero bouygtel\nSi vous souhaitez envoyer plusieurs SMS par jour, ou envoyer un SMS au numero d'un autre operateur, vous devrez specifier l'option -pay\n" ); exit 1; } my $from = 06; my $to = 06; my $password = ""; my $msg = ""; my $pay = 0; # process des options my $result=GetOptions( "from=i"=> \$from, "to=i" => \$to, "pass=i"=> \$password, "msg=s" => \$msg, "pay" => \$pay ); if ( $ARGV[0] ) { foreach (@ARGV) { print "$_ "; } print "\n"; die "ERREUR: Options incorrectes\n"; } if ( ( length( $from ) != 10 ) || ( length( $to ) != 10 ) ) { die( "ERREUR: Les numeros de telephone doivent comporter 10 chiffres\n" ); } if ( length( $msg ) > 160 ) { die( "ERREUR: Message trop long (maxi 160 caracteres) : " . length( $msg ) . "\n" ); } if ( length( $msg ) == 0 ) { die( "ERREUR: Il faut entrer un message\n" ); } if ( length( $password ) == 0 ) { die( "ERREUR: Il faut entrer un password\n" ); } # ok c'est parti my $mech = WWW::Mechanize->new(autocheck => 1); $mech->get( "http://www.bouygtel.com/home.htm" ); $mech->follow_link( text => "Envoyer des SMS"); $mech->submit(); # ca fait un submit vers /afficherLogin.asp #$mech->current_form()->action("/verifPassword.asp"); my $html = $mech->content; # ajout de l'action /verifPassword.asp $html =~ s[
][]; $mech->update_html( $html ); $mech->form_number( 1 ); { local $^W = 0; $mech->field( MSISDN => $from ); $mech->field( code => $password ); $mech->field( ValidPage => "/SMS/TelemessagesClientProcess5.asp?" ); $mech->field( ErrorPhone => "0" ); $mech->field( txtTelephone => $from ); $mech->field( pwdTelephone => $password ); } $mech->submit(); #submit du password # on verifie que le password a ete accepte $html = $mech->content; if ( $html =~ m{que vous avez saisies sont incorrectes}s ) { die "ERREUR: Les donnees que vous avez saisies sont incorrectes : from=$from pass=$password\n"; } $mech->submit(); #submit d'un form temporaire qui confirme le password # et on arrive a la fenetre de composition du SMS $mech->form_number( 1 ); { local $^W = 0; $mech->field( msg => $msg ); $mech->field( destinataire => $to ); } $mech->submit(); #submit du SMS # si on n'a pas specifie qu'on est d'accord pour payer, on verifie que c'est gratuit $html = $mech->content; if ( $pay == 0 ) { $html =~ m{0 MESSAGE PAYANT}s or die "ERREUR: Bouygtel veut faire payer, et vous n'avez pas specifie -pay !\n"; } # on modifie le html pour ajouter l'action /SMS/TelemessagesValidByTelEnvoyeText.asp $html =~ s[][]; $mech->update_html( $html ); $mech->submit(); #confirmation de l'envoi du SMS et eventuellement de la facturation print( "SMS envoye' !\n" ); #print( $mech->content ); #$mech->success or die "post failed: ", $mech->response->status_line;