#!/usr/bin/perl # Credits: # # The IDEA and MAJOR PART of the code were got from # http://www.quietearth.us/vx9800.htm, I just slightly modify # it to meet my requirement. # The original code can be downloaded at: # http://www.quietearth.us/src/verizonusage.txt # License: # # Since the original code is distributed without any licesne, # I don't put any license either. I personally prefer GPL. # Disclaimer: # # This software is provided as-is. Absolutely no warranty of any sort, # express or implied, is provided. The author of this program is not # responsible for data loss or any other type of damage this software # may do to your system. By using this software, you agree to run it AT # YOUR OWN RISK. # Configuration Section my $vzwuser = "VERIZION USERNAME"; # put your username of verizion web account my $vzwpass = "PASSWD"; # and the passed my $phone_num = "xxxxxxxxxx"; # your 10-digit phone number my $email_addr = "myemail\@gmail.com"; # your email address my $limit = 450; # the peak time limit of your plan my $threshold = 400; # the threshold, if your current # usage exceed the limit, a txt msg # will be sent to your phone my $quiet = "-q"; # change this to "" to turn on wget output my $sendmail = "/usr/sbin/sendmail"; # the path to your sendmail # End of Configuration Section # Do not modify the following code. package IdentityParse; use base "HTML::Parser"; my $tmpfile = "/tmp/vzw.$$"; my $usagefile = "/tmp/vzwusage.$$"; my $cookie1; my $cookie2; my $pf = 0; my $wf = 0; my $wn = ""; my $msg = ""; my $current_min = 0; my $flag_mail = 0; my $sendmailcmd = $sendmail . " -t"; my $totxt = $phone_num . "\@vtext.com"; my $subject = "Pay attention to the verizion monthly minute limit"; my $txtbody = ""; my $remain_min = 0; # main start unless ( -f $sendmail ) { print "$sendmail is not found: the text msg can not be sent\n"; $flag_mail = 0; } $flag_mail = 1; system "wget https://myaccount.verizonwireless.com/vzs/login $quiet --post-data \"j_username=$vzwuser\&j_password=$vzwpass\" -O $tmpfile --save-headers"; open IN, $tmpfile or die "can't open $tmpfile\n"; while () { $line = $_; chomp $line; if ( $line =~ /JSESSIONID=/ ) { @spl = split / /, $line; $cookie1 = $spl[1]; } if ( $line =~ /vzw.context=/ ) { @spl = split / /, $line; $cookie2 = $spl[1]; } } unless ( $cookie1 and $cookie2 ) { die "can't get cookies\n"; } #print "cookie1 $cookie1\n"; #print "cookie1 $cookie2\n"; #print "wget https://wbillpay.verizonwireless.com/vzw/overview/unbilled-usage-minutes.do $quiet --cookies=off --header \"Cookie: $cookie1\" --header \"Cookie: $cookie2\" -O $usagefile"; system "wget https://wbillpay.verizonwireless.com/vzw/overview/unbilled-usage-minutes.do $quiet --cookies=off --header \"Cookie: $cookie1\" --header \"Cookie: $cookie2\" -O $usagefile"; my $p = new IdentityParse; $p->parse_file("$usagefile"); sub text { my ( $self, $text ) = @_; if ( $text =~ /^[\s]*$/ ) { return; } #print "text $text\n"; if ($pf) { $text =~ s/[\D]//g; if ($wn) { $msg .= "Wireless usage for $wn is $text\n"; $current_min = $text; } else { $msg .= "error getting usage for wireless no $wn\n"; } #print "PEAK FOUND: $text\n"; $pf = 0; $wn = ""; } if ($wf) { #print "WIRELESS FOUND: $text\n"; $wf = 0; $wn = "$text"; } if ( $text =~ /^Peak Minutes/i ) { #print "PEAK MINUTES FOUND\n"; $pf++; } if ( $text =~ /^Wireless No/i ) { #print "WIRELESS NO FOUND\n"; $wf++; } } unlink $tmpfile; unlink $usagefile; print "$msg\n"; #print "current usage is $current_min\n"; if ($current_min) { if ( $current_min >= $threshold ) { $remain_min = $limit - $current_min; $txtbody = "Wireless usage for $phone_num is $current_min minutes. "; $txtbody = $txtbody . "The monthly limit is $limit minutes. "; $txtbody = $txtbody . "There are $remain_min minutes left.\n"; open( TXTMSG, "|$sendmail -oi -t" ); print TXTMSG "From: $email_addr\n"; print TXTMSG "To: $totxt\n"; print TXTMSG "Subject: $subject\n\n"; print TXTMSG "$txtbody\n"; close(TXTMSG); } }