Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # All rights to this script are hereby disclaimed and its contents released
- # into the public domain by the author.
- ###########################################
- # EDIT THE VARIABLES BELOW TO MATCH YOUR ACCOUNT AND SYSTEM
- ###########################################
- # If you leave the username blank, you will be prompted to enter it on the command line.
- USERNAME="your_username@bigpond.com"
- # If you leave the password blank, you will be prompted to enter it on the command line.
- PASSWORD="your_password"
- # Path to a writable directory to store temporary files.
- TEMP_DIR=/tmp
- # Path to the curl binary. You need version 7.18.0 or later.
- CURL=/usr/bin/curl
- # Path to the grep binary.
- GREP=/bin/grep
- # Path to html2text binary.
- HTML2TEXT=/usr/bin/html2text
- # Path to mktemp binary.
- MKTEMP=/bin/mktemp
- ##############################################
- # END OF USER VARIABLES. YOU SHOULDN'T NEED TO EDIT BELOW THIS LINE.
- ##############################################
- # Function to check that a binary exists and is executable.
- # Exits the script if either condition is false.
- check_binary()
- {
- if [ ! -f $1 ]
- then
- echo "$1 does not exist. Use your package manager to install it."
- exit -1
- fi
- if [ ! -x $1 ]
- then
- echo "$1 is not executable."
- exit -1
- fi
- }
- # Function to check that a directory exists and is writeable.
- # Exits the script if either condition is false.
- check_directory()
- {
- if [ ! -d $1 ]
- then
- echo "$1 is not a directory."
- exit -1
- fi
- if [ ! -w $1 ]
- then
- echo "$1 is not writeable."
- exit -1
- fi
- }
- check_binary $CURL
- check_binary $HTML2TEXT
- check_binary $GREP
- check_binary $MKTEMP
- check_directory $TEMP_DIR
- # Prompt user to enter username if not provided above.
- if [ "$USERNAME" == "" ]
- then
- read -p "username>" USERNAME
- fi
- # Prompt user to enter password if not provided above.
- if [ "$PASSWORD" == "" ]
- then
- read -p "password>" PASSWORD
- fi
- LOGIN_PAGE="https://signon.bigpond.com/login"
- MYACCOUNT_PAGE="https://myaccount.bigpond.com"
- SERVICE_PAGE="/MyServices.do"
- TEMP_HTML_FILE=$( $MKTEMP -u -p $TEMP_DIR XXXXXXXXXXXXXXXX )
- TEMP_TEXT_FILE=$( $MKTEMP -u -p $TEMP_DIR XXXXXXXXXXXXXXXX )
- COOKIE_FILE=$( $MKTEMP -u -p XXXXXXXXXXXXXXXX )
- USER_AGENT="Mozilla/5.0"
- CURL_OPTIONS="--insecure --silent --location"
- # Setup a signal handler to cleanup when the script exits.
- trap "{ rm -f $TEMP_HTML_FILE; rm -f $TEMP_TEXT_FILE; exit -1; }" EXIT
- # First, login and access the service page.
- $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
- if [ $? != 0 ]
- then
- exit -1
- fi
- # Get the link to the usage page for this account.
- USAGE_PAGE=$( $GREP MyServicesViewUsage $TEMP_HTML_FILE | cut -d\" -f2 )
- # Remove the downloaded page.
- rm $TEMP_HTML_FILE
- # Download the usage page.
- $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
- if [ $? != 0 ]
- then
- exit -1
- fi
- # Convert the page to text for easy parsing.
- $HTML2TEXT $TEMP_HTML_FILE > $TEMP_TEXT_FILE
- $GREP -m 1 'Current Account Usage' $TEMP_TEXT_FILE
- $GREP -m 1 'Monthly Plan Allowance' $TEMP_TEXT_FILE
- $GREP -m 1 'Current Bill Period' $TEMP_TEXT_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement