JetIB Login Tool v0.2

Second version of JetIB script.

#!/bin/sh
#
# Jetib Login Tool (v0.2)
# 
# Author: Timothy White http://weirdo.bur.st/
# 
# This script will log you in to a jetib (Jet Internet Billing) system
#
#
# It will first attempt to load your credentials from .jetibcreds
# If this file doesn't exist, it will fall back to asking for your
# credentials first via zenity, and if zenity isn't installed then via
# normal shell input
#
# curl must be installed and in your path for this tool to work

#### Changelog
#
#   0.2
#    * Fix up string handling and screen scraping of status text
#    * Make Ctrl-C handling look cleaner
#
#   0.1 
#    * Initial Release
#
#
#
#


# Curtin University settings are as follows
#DOMAIN="jetib.curtin.edu.au"
#LOGIN_PAGE="/curtin/portal/login"
#STATUS_PAGE="/curtin/portal/popup_text_refresh"
#OGOFF_PAGE="/curtin/portal/logout"

DOMAIN="jetib.curtin.edu.au"
LOGIN_PAGE="/curtin/portal/login"
STATUS_PAGE="/curtin/portal/popup_text_refresh"
LOGOFF_PAGE="/curtin/portal/logout"

# .jetibcreds file in users home directory
# containing login credentials in the format of
# username:password
JETLOGIN="$HOME/.jetibcreds"

# User agent to pretend to be (just incase they block scripts, pretend to be a browser)
USER_AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1 (.NET CLR 3.5.30729)"

# Find location of curl and zenity
CURL=$(which curl)
ZENITY=$(which zenity)


# Catch ctrl_c requests and logout and cleanup
ctrl_c() {
    stty echo # Turn TTY echo back ON!
    # (Maybe we caught Ctrl-c when they were supposed to be entering password)
    echo ""
    echo "Logging you off..."
    # Send logoff request
    curl -s https://$DOMAIN$LOGOFF_PAGE -c cookies.txt -b cookies.txt |grep "

"|sed -e :a -e 's/<[^<]*>/ /g;/.*'|grep -o '[0-9]*') quota=$(echo "$status_text" | grep -i quota|egrep -o ':[^<]*' |grep -o '[0-9.]*') thismonth=$(echo "$status_text" | grep -i "this month"|grep -o '[^<]*'|grep 'this'|grep -o '[0-9.]*') thismonth=${thismonth#*:} # Strip everything before : thismonth=${thismonth#"${thismonth%%[! ]*}"} # Strip White Space thissession=$(echo "$status_text" | grep -i "this session"|grep -o '[^<]*'|grep 'this'|grep -o '[0-9.]*') thissession=${thissession#*:} # Strip everything before : thissession=${thissession#"${thissession%%[! ]*}"} # Strip White Space # Display status page clear echo "Logged in as: $loggedinas" echo "Quota Remaining: $remaining MB" echo "Monthly Quota: $quota MB" echo "Used this month: $thismonth MB" echo "Used this session: $thissession MB" echo "" echo "Press Ctrl-C to disconnect" } if [ -x "$CURL" ] then if [ -r "$JETLOGIN" ] then # .jetibcreds file in users home directory # containing login credentials in the format of # username:password creds=$(cat $JETLOGIN) USERNAME=${creds%%:*} PASSWORD=${creds#*:} else # Credentials not saved, ask for them if [ -x "$ZENITY" ] then # Use Zenity to ask for credentials USERNAME=$(zenity --entry --title="Internet Login" --text="Username") PASSWORD=$(zenity --entry --title="Internet Login" --text="Password" --hide-text) else # Zenity not installed, falling back to shell to ask for credentials echo -n "Username: " read USERNAME echo "" echo -n "Password: " # trap ctrl-c and call ctrl_c() trap ctrl_c INT stty -echo # Turn off TTY echo so password is hidden read PASSWORD stty echo # Turn TTY echo back ON! echo "" # force a carriage return to be output fi fi # Submit login request to server (No error checking yet) echo "Attempting to log you into the JetIB server..." curl -s -A "$USER_AGENT" -F "targeturl=''" -F "submit=Logon" -F "username=$USERNAME" -F "password=$PASSWORD" -c cookies.txt https://$DOMAIN$LOGIN_PAGE > /dev/null echo "Verifying login..." # trap ctrl-c and call ctrl_c() trap ctrl_c INT stty -echo # Turn off TTY echo while true do # Loop updating status page every minute until Ctrl-C is pressed status_page ; sleep 1m done else echo "This Jetib login tool requires curl to be installed and in the PATH"; fi

2 thoughts on “JetIB Login Tool v0.2

Comments are closed.