markuspeloquin

google_voice_notify.cgi

Jul 18th, 2011
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.62 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # Copyright (c) 2011, Markus Peloquin <markus@cs.wisc.edu>
  4. #
  5. # Permission to use, copy, modify, and/or distribute this software for any
  6. # purpose with or without fee is hereby granted, provided that the above
  7. # copyright notice and this permission notice appear in all copies.
  8. #
  9. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  12. # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  14. # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16.  
  17. use strict;
  18. use warnings;
  19.  
  20. use CGI;
  21.  
  22. my @TARGET_ADDRS = qw/
  23.     addr1@host1
  24.     addr2@host2
  25. /;
  26.  
  27. my $q = CGI->new;
  28. my $found = $q->param('found');
  29.  
  30. my @found = split /,/, $found;
  31. my %found_map;
  32. $found_map{$_} = 1 for @found;
  33. my $area_code = @found > 1 ? 'area codes': 'area code';
  34.  
  35. my $msg = <<EOF;
  36. From: markus\@cs.wisc.edu
  37. Subject: GOOGLE VOICE NUMBER AVAILABLE
  38. $area_code with at least one number: @found
  39. EOF
  40.  
  41. for my $addr (@TARGET_ADDRS) {
  42.     open my $output, '|-', "/usr/sbin/sendmail $addr" or
  43.         die "$0: sendmail couldn't exec: $!";
  44.     print $output $msg or die "$0: failed to write email: $!";
  45.     close $output;
  46. }
  47.  
  48. # this actually doesn't matter since the google voice page is HTTPS so the
  49. # results are just ignored
  50. print $q->header(-type => 'text/javascript');
  51. printf "{ \"bluh_bluh\": \"%s\" }\n", $found;
Add Comment
Please, Sign In to add comment