Advertisement
Guest User

BigPond usage

a guest
Oct 18th, 2012
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # All rights to this script are hereby disclaimed and its contents released
  4. # into the public domain by the author.
  5.  
  6. ###########################################
  7. # EDIT THE VARIABLES BELOW TO MATCH YOUR ACCOUNT AND SYSTEM
  8. ###########################################
  9.  
  10. # If you leave the username blank, you will be prompted to enter it on the command line.
  11. USERNAME="your_username@bigpond.com"
  12.  
  13. # If you leave the password blank, you will be prompted to enter it on the command line.
  14. PASSWORD="your_password"
  15.  
  16. # Path to a writable directory to store temporary files.
  17. TEMP_DIR=/tmp
  18.  
  19. # Path to the curl binary. You need version 7.18.0 or later.
  20. CURL=/usr/bin/curl
  21.  
  22. # Path to the grep binary.
  23. GREP=/bin/grep
  24.  
  25. # Path to html2text binary.
  26. HTML2TEXT=/usr/bin/html2text
  27.  
  28. # Path to mktemp binary.
  29. MKTEMP=/bin/mktemp
  30.  
  31. ##############################################
  32. # END OF USER VARIABLES. YOU SHOULDN'T NEED TO EDIT BELOW THIS LINE.
  33. ##############################################
  34.  
  35. # Function to check that a binary exists and is executable.
  36. # Exits the script if either condition is false.
  37. check_binary()
  38. {
  39.     if [ ! -f $1 ]
  40.     then
  41.         echo "$1 does not exist. Use your package manager to install it."
  42.         exit -1
  43.     fi
  44.  
  45.     if [ ! -x $1 ]
  46.     then
  47.         echo "$1 is not executable."
  48.         exit -1
  49.     fi
  50. }
  51.  
  52. # Function to check that a directory exists and is writeable.
  53. # Exits the script if either condition is false.
  54. check_directory()
  55. {
  56. if [ ! -d $1 ]
  57.     then
  58.         echo "$1 is not a directory."
  59.         exit -1
  60.     fi
  61.  
  62.     if [ ! -w $1 ]
  63.     then
  64.         echo "$1 is not writeable."
  65.         exit -1
  66.     fi
  67. }
  68.  
  69.  
  70. check_binary $CURL
  71. check_binary $HTML2TEXT
  72. check_binary $GREP
  73. check_binary $MKTEMP
  74.  
  75. check_directory $TEMP_DIR
  76.  
  77. # Prompt user to enter username if not provided above.
  78. if [ "$USERNAME" == "" ]
  79. then
  80.     read -p "username>" USERNAME
  81. fi
  82.  
  83. # Prompt user to enter password if not provided above.
  84. if [ "$PASSWORD" == "" ]
  85. then
  86.     read -p "password>" PASSWORD
  87. fi
  88.  
  89. LOGIN_PAGE="https://signon.bigpond.com/login"
  90. MYACCOUNT_PAGE="https://myaccount.bigpond.com"
  91. SERVICE_PAGE="/MyServices.do"
  92. TEMP_HTML_FILE=$( $MKTEMP -u -p $TEMP_DIR XXXXXXXXXXXXXXXX )
  93. TEMP_TEXT_FILE=$( $MKTEMP -u -p $TEMP_DIR XXXXXXXXXXXXXXXX )
  94. COOKIE_FILE=$( $MKTEMP -u -p XXXXXXXXXXXXXXXX )
  95. USER_AGENT="Mozilla/5.0"
  96. CURL_OPTIONS="--insecure --silent --location"
  97.  
  98. # Setup a signal handler to cleanup when the script exits.
  99. trap "{ rm -f $TEMP_HTML_FILE; rm -f $TEMP_TEXT_FILE; exit -1; }" EXIT
  100.  
  101. # First, login and access the service page.
  102. $CURL $CURL_OPTIONS --user-agent \"$USER_AGENT\" --cookie \"$COOKIE_FILE\" --output $TEMP_HTML_FILE --data-urlencode goto=$SERVICE_PAGE --data-urlencode username=$USERNAME --data-urlencode password=$PASSWORD $LOGIN_PAGE?goto=$MYACCOUNT_PAGE$SERVICE_PAGE
  103. if [ $? != 0 ]
  104. then
  105.     exit -1
  106. fi
  107.  
  108. # Get the link to the usage page for this account.
  109. USAGE_PAGE=$( $GREP MyServicesViewUsage $TEMP_HTML_FILE | cut -d\" -f2 )
  110.  
  111. # Remove the downloaded page.
  112. rm $TEMP_HTML_FILE
  113.  
  114. # Download the usage page.
  115. $CURL $CURL_OPTIONS --user-agent \"$USER_AGENT\" --cookie \"$COOKIE_FILE\" --output $TEMP_HTML_FILE --data-urlencode goto=$USAGE_PAGE --data-urlencode username=$USERNAME --data-urlencode password=$PASSWORD $LOGIN_PAGE?goto=$MYACCOUNT_PAGE$USAGE_PAGE
  116. if [ $? != 0 ]
  117. then
  118.     exit -1
  119. fi
  120.  
  121. # Convert the page to text for easy parsing.
  122. $HTML2TEXT $TEMP_HTML_FILE > $TEMP_TEXT_FILE
  123.  
  124. $GREP -m 1 'Current Account Usage' $TEMP_TEXT_FILE
  125. $GREP -m 1 'Monthly Plan Allowance' $TEMP_TEXT_FILE
  126. $GREP -m 1 'Current Bill Period' $TEMP_TEXT_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement