#!/usr/bin/perl -w # smp: the perlific sms sender # # --------------****-------------- # _____ __ __ _____ # / ___/ | \ / | / ___/ # / / | \/ | / / # \ \___ | | | | \ \___ # \___ \ | | | | \___ \ # \ \ |_| |_| \ \ # ____/ / ____/ / # /_____/ perlific /_____/ # # send sms from commandline to cellphone using sms.a1.net # you need a valid account there to login using this script # # thp # # $Log: smp,v $ # Revision 1.8 2007/06/03 14:18:36 thp # Fixed typo bug # # Revision 1.7 2007/05/29 18:36:56 thp # Add LWP SSL library as dependency # # Revision 1.6 2007/05/29 18:32:06 thp # Add monthly limit detection # # Revision 1.5 2007/04/20 14:39:27 thp # add support for using smp as cgi script # # Revision 1.4 2007/04/04 15:22:15 thp # support for piping input into smp (cron, etc..) # # Revision 1.3 2007/02/15 21:01:34 thp # support for command line argument # # Revision 1.2 2006/10/19 20:00:40 thp # added support for config/phonebook # # # dependencies: # * libconfig-tiny-perl # * libwww-mechanize-perl # * libcrypt-ssleay-perl (for SSL) # use WWW::Mechanize; use Config::Tiny; use File::Basename; use CGI qw(:standard); my $cfg; my $pbf; my $cgi_request = $ENV{'REQUEST_METHOD'}; my $to; my $message; sub confget { my ($section, $name) = @_; if( !$cfg->{$section}->{$name}) { print( (($section eq 'book')?('number'):('value'))." for $section/$name: "); chomp( $cfg->{$section}->{$name} = ); } return $cfg->{$section}->{$name}; } if( defined $cgi_request) { $pbf = $ENV{SMPRC}; $cfg = Config::Tiny->read( $pbf); print "Content-Type: text/html\n\n"; if( $cgi_request eq 'GET') { my $numbers = "\n"; print "smp cgi interface<body leftmargin=100 topmargin=100><h3>welcome to <code>smp-cgi</code> on <code>$ENV{HTTP_HOST}</code></h3><p>presented to you in ultra quirks mode.<hr align=left color=red width=200><form method=post><table>\ <tr><td>To:<td>$numbers\ <tr><td>Message:<td><input type=text name=message><br>\ <tr><td><td><input type=submit value=send>"; exit 0; } else { $q = new CGI; $to = confget( 'book', $q->param('to')); $message = $q->param('message'); print "<table><tr><td>sending to:<th>$to</tr>\ <tr><td>message:<th>$message</tr> <tr><td>status:<th>"; } } else { $pbf = glob( '~/.smprc'); $cfg = Config::Tiny->read( $pbf); if( ($#ARGV == -1) and ! -t STDIN) { print "If input is piped, please specify the receiver as command-line argument.\n"; exit -1; } if( $#ARGV == -1) { print "I already know: [ ". join( ', ', keys( %{$cfg->{book}})) . " ]\n"; print "To: "; chomp( $to = <STDIN>); } else { chomp( $to = $ARGV[0]); } $to = confget( 'book', $to); if( -t STDIN) { print "\nGo ahead, type your message. End with [ENTER].\n\n"; } chomp( $message = <STDIN>); if( -t STDIN) { print "Send? (y/n) "; chomp( my $yesno = <STDIN>); exit 0 unless $yesno eq 'y'; } } if( !defined $cgi_request) { syswrite( STDOUT, "sending to $to.."); } my $mech = WWW::Mechanize->new(); $mech->get( 'http://sms.a1.net/'); $mech->submit_form( fields => { UserID => confget( 'auth', 'user'), Password => confget( 'auth', 'pass'), } ); $mech->submit_form( fields => { address => $to, msg => $message, } ); if( $mech->content() =~ /berschreiten Ihr monatliches Limit/) { syswrite( STDOUT, "monthly limit reached.\n"); } else { syswrite( STDOUT, "done.\n"); if( not defined $cgi_request) { $cfg->write( $pbf); } }