Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You're sitting at a table with your cow-orkers while the head beancounter goes through his drone about how the bar on the chart for last quater is clearly larger than the bar for the quarter before, and you're starting to wonder if you can slip a certain almond-tasting chemical into the beancounter's coffee.

No worry. You covertly slip your 802.11-enabled PDA out of your pocket and browse to your web server, where you've kept the CGI below for this very situation. Not long after, you receive an SMS on your cell telling you about some emergency or other. You glance at your phone, bolt out of the room, and take an early lunch.

This CGI is for use under mod_perl2, but it shouldn't be hard to modify for regular CGI use.

The send_sms() routine gets a string containing the message to send, and returns true on success, false on failure. It's coded to use Sprint's web form for sending the message. You'll have to change it for your provider. See also: WWW::SMS.

The constant MESSAGES is an arrayref containing the messages to send. Be sure they are <= 160 chars (SMS limit). You can set which message to send with the 'emg' parameter ("emg=0" is the first message, "emg=1" is the second, etc.). The first message is used by default.

You'll need to replace the TO and FROM constants with your phone number.

#!/usr/bin/perl use strict; use warnings; use constant TO => 'xxxx'; use constant FROM => 'xxxx'; use constant MAX_CHARS => 160; use constant PAGE => 'http://messaging.sprintpcs.com/textmessaging/co +mpose'; use constant AGENT => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041118 +' . 'Firefox/1.0'; use constant MESSAGES => [ # Each message must be <= 160 chars (SMS l +imit) 'Run away', ]; sub send_sms { my $msg = shift; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( PAGE ); $mech->submit_form( form_name => 'composeForm', fields => { phoneNumber => TO, callBackNumber => FROM, message => $msg, characters => MAX_CHARS - length($msg), }, ); return $mech->success(); } { use Apache::RequestUtil; my $r = Apache->request; my %in = $r->args(); my $msg_num = $in{emg} || 0; send_sms( substr( MESSAGES->[$msg_num], 0, 160 ) ) or die "Couldn't send message\n"; $r->content_type( 'text/plain' ); $r->print( MESSAGES->[$msg_num] ); }

Update: Added ikegami's change to make sure send_sms() never gets a message over 160 chars.

Update (2): Added readmore tags.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.


In reply to Get Out of a Dull Meeting by hardburn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-20 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found