JetIB Login Tool v0.2
Second version of JetIB script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #!/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 "<p>"|sed -e :a -e 's/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}' |sed 's/^[ \t]*//;s/[ \t]*$//' # 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|grep -o '[0-9.]*') loggedinas=$(echo "$status_text" | grep "logged in as"|egrep -o '<em>.*</em>'|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 |
September 9th, 2009 at 9:43 am
[...] « Convert HT8200 into HT8000 JetIB Login Tool v0.2 [...]