A simple script to login to the JetIB (Jet Internet Billing system) without using a web browser. For example, if you just want to ssh or run a backup job, or for example you are logged into a machine without a graphical browser.
Some of the organisations that may use the JetIB system are:
- Curtin University (Bentley Campus)
- James Cook University
- UNSW (University of New South Wales) – ADFA (Australian Defence Force Academy) (Canberra)
You will need to modify the script for each location.
It should run on just about any Linux/Unix/BSD system that has a POSIX shell, and curl installed. It should run on a OS X Mac as well.
If you have zenity installed, it’ll use that to ask for your credentials, otherwise it’ll just ask for them in the terminal. If your credentials are stored in a .jetibcreds file in your home directory it will use them instead. (Format of username:password)
Once connected, it’ll loop around updating your shell display with the terminal of your session (this should also perform as a keep alive for your session), pressing ctrl-c will exit that loop and log you out, and clean up the session cookie.
Edit: New version available at http://weirdo.bur.st/2009/09/09/jetib-login-tool-v0-2/
#!/bin/sh
#
# Jetib Login Tool (v0.1)
#
# 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
# 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 ""
# Clear cookies file
rm cookies.txt
exit 0
}
status_page() {
# Get status page text
status_text=$(curl -s https://$DOMAIN$STATUS_PAGE -c cookies.txt -b cookies.txt)
# Process status page text
remaining=$(echo "$status_text" | grep remaining)
loggedinas=$(echo "$status_text" | grep "logged in as"|egrep -o '.*'|grep -o '[0-9]*')
quota=$(echo "$status_text" | grep -i quota|egrep -o ':[^<]*' )
thismonth=$(echo "$status_text" | grep -i "this month"|grep -o '[^<]*'|grep 'this')
thissession=$(echo "$status_text" | grep -i "this session"|grep -o '[^<]*'|grep 'this')
# Display status page
clear
echo "$remaining"
echo "Logged in as: $loggedinas"
echo "Monthly Quota$quota"
echo "$thismonth"
echo "$thissession"
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)
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
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
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
September 8th, 2009 | Tags: Bash, client, dash, jet internet billing, jetib, Linux, login, Programming, script, sh, shell, unix | Category: Blog, TechTim | Comments (1)