##############################################################################
#define variables
tput clear
srv_ip=""
username=""
password=""
connected=0
lastcheck_ts=0
first_time=1
interface="eth0"
#check whether curl is installed or not
#
which curl &> /dev/null
if [ $? -ne 0 ]
then
tput setaf 1 && tput bold
echo "This script heavily depends on curl for proper execution.Please install curl and try again"
exit
tput sgr0
fi
logout_session()
# logout function
{
get_tstamp
tput setaf 6
echo "$tstamp: Disconnecting now.. pls wait"
tput sgr0
#disconnect client
url="http://$srv_ip/24online/servlet/CyberoamHTTPClient"
post_data="mode=193&isAccessDenied=null&url=null&message=&checkClose=1&sessionTimeout=-1.0&guestmsgreq=false&logintype=2&username=$username&username1=$username&password=****&logout=Logout&saveinfo="
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie --data $post_data $url > /dev/null 2>&1
trap: 180: SIGINT: bad trap
url="http://$srv_ip/24online/webpages/clientlogin.jsp?loginstatus=null&logoutstatus=true&liverequesttime=null&livemessage=null&url=null&isAccessDenied=false&fromlogout=null&sessionTimeout=-1.0"
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url > /dev/null 2>&1
get_tstamp
#wait for 5 seconds
tput setaf 6
echo "$tstamp: Please wait for 5 seconds for connection to stabilise"
tput sgr0
sleep 5
#test net connection
chk_connection
rm -f /tmp/24onlinecookie
end_rxbyte_count=$(printrxbytes);
end_txbyte_count=$(printtxbytes);
rx_count=$((end_rxbyte_count - start_rxbyte_count))
tx_count=$((end_txbyte_count - start_txbyte_count))
echo "Session Stats"
echo "Rx=" $rx_count "Bytes|"$((rx_count/1024)) "KB|"$((rx_count/1048756)) "MB|"$(($rx_count/1073741824)) "GB"
echo "Tx=" $rx_count "Bytes|"$((tx_count/1024)) "KB|"$((tx_count/1048756)) "MB|"$(($tx_count/1073741824)) "GB"
return $?
}
init_login()
{
get_tstamp
#attempt connection to cyberoam server to get the session cookie. save cookie locally
curl -c /tmp/24onlinecookie http://$srv_ip/24online/webpages/client.jsp > /dev/null 2>&1
session_id=$(sed -n -e 's/.*JSESSIONID\(.*\).*/\1/p' /tmp/24onlinecookie | sed -e 's/^[ \t]*//')
tput setaf 6
echo "$tstamp: Session id is $session_id"
tput sgr0
#attempt reverse session registration
url="http://$srv_ip/24online/webpages/clientlogin.jsp?loginstatus=null&logoutstatus=null&message=null&liverequesttime=null&livemessage=null&url=null&isAccessDenied=null&fromlogout=null&sessionTimeout=null"
referrer="http://$srv_ip/24online/webpages/client.jsp"
curl -b /tmp/24onlinecookie $url > /dev/null 2>&1
#attempt initial login
url="http://$srv_ip/24online/servlet/CyberoamHTTPClient"
post_data="mode=191&isAccessDenied=null&url=null&message=&checkClose=1&sessionTimeout=0.0&guestmsgreq=false&logintype=2&username=$username&password=$password&login=Login&saveinfo="
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie --data $post_data $url > /dev/null 2>&1
url="http://$srv_ip/24online/webpages/clientlogin.jsp?loginstatus=true&logoutstatus=null&liverequesttime=180&livemessage=null&url=null&isAccessDenied=null&fromlogout=null&sessionTimeout=-1"
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url > /dev/null 2>&1
url2="http://$srv_ip/24online/webpages/liverequest.jsp?isfirsttime=true"
curl --referrer $url -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url2 > /dev/null 2>&1
get_tstamp
#wait for 5 seconds
tput setaf 6
echo "$tstamp: Please wait for 5 seconds for connection to stabilise"
tput sgr0
sleep 5
chk_connection
if [ $connected -eq 1 ]
then first_time=0
keep_alive_check_ts=$lastcheck_ts # to prevent premature keepalive packet being sent
fi
}
keep_alive()
{
get_tstamp
url="http://$srv_ip/24online/webpages/liverequest.jsp?isfirsttime=false"
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url > /dev/null 2>&1
url="http://$srv_ip/24online/servlet/CyberoamHTTPClient?mode=192&username=$username"
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url > /dev/null 2>&1
url="http://$srv_ip/24online/webpages/liverequest.jsp"
curl -b /tmp/24onlinecookie -c /tmp/24onlinecookie $url > /dev/null 2>&1
chk_connection
keep_alive_check_ts=$lastcheck_ts
}
chk_connection()
{
get_tstamp
#test net connection
if ping -c1 google.com > /dev/null
then
connected=1
if [ $first_time -eq 1 ] #display prompt only initially
then
tput setaf 2 && tput bold
echo "$tstamp: Yipee You are connected to Internet"
tput sgr0
fi
else
tput setaf 1 && tput bold
echo "$tstamp: You are not connected to Internet"
connected=0
tput sgr0
fi
lastcheck_ts=`date "+%s"` # set to current unix timestamp
}
get_tstamp()
{
tstamp=`date "+%Y-%m-%d %H:%M:%S"`
}
control_c()
# run if user hits control-c to exit the code
{
get_tstamp
tput setaf 3 && tput bold
echo -en "\n$tstamp: *** Ouch! Logging out ***\n"
tput sgr0
logout_session
exit $?
}
#byte counter
#source http://meinit.nl/shell-script-measure-network-throughput-linux-machines
printrxbytes()
{
/sbin/ifconfig "$interface" | grep "RX bytes" | cut -d: -f2 | awk '{ print $1 }'
}
printtxbytes()
{
/sbin/ifconfig "$interface" | grep "TX bytes" | cut -d: -f3 | awk '{ print $1 }'
}
#--------------------------------------------
start_rxbyte_count=$(printrxbytes);
start_txbyte_count=$(printtxbytes);
#--------------------------------------------
# trap keyboard control-c interrup for graceful exit
#trap control_c SIGINT
#main loop
#check if connection is alive every 5s
#if yes do nothing
#if not connected then relogin
#if connection is alive for more than 3m then keep alive connection
while true
do
current_ts=`date "+%s"`
#check if connection is alive every 5s
if [ $((current_ts - lastcheck_ts)) -ge 600 ]
then chk_connection #lastcheck_ts is automatically set in this loop
fi
#if session is terminated by server then logout gracefully
if [ $connected -eq 0 -a $first_time -eq 0 ]
then
tput setaf 4
echo "$tstamp: It appears that the server terminated your session"
tput sgr0
logout_session
first_time=1
fi
#if not logged in initially then login
if [ $connected -eq 0 -a $first_time -eq 1 ]
then init_login
fi
#if connection is alive for more than 3m then keep alive connection
if [ $((current_ts - keep_alive_check_ts)) -ge 600 ]
then
tput setaf 6
echo -n "$tstamp: Refreshing Connection State"
keep_alive
if [ $connected -eq 1 ]
then
tput setaf 2 && tput bold
echo " [OK]"
tput sgr0
fi
fi
sleep 0.5 # sleep for half a second to prevent loop
done
import urllib
import urllib2
import time
import sys
try:
login=sys.argv[1] # 0 -> logout 1->login
except IndexError:
login = 1
submitVars={}
if(login==0): # LOGOUT
submitVars['mode'] = "192"
submitVars['isAccessDenied'] = "false"
submitVars['url'] = "www.alliancekolkata.co.in/weblink.php"
submitVars['message'] = ""
submitVars['checkClose'] = "0"
submitVars['sessionTimeout'] = "-1.0"
submitVars['guestmsgreq'] = "false"
submitVars['isfirsttime'] = "false"
submitVars['username'] = ""
referer = "http://10.10.0.1/24online/servlet/CyberoamHTTPClient" # URL of referring web page goes here
else: # LOGIN
time.sleep(3)
submitVars['mode'] = "191"
submitVars['isAccessDenied'] = "null"
submitVars['url'] = "www.indiabroadband.net/other-cable-internet-services/12845-alliance-broadband.html"
submitVars['message'] = ""
submitVars['checkClose'] = "0"
submitVars['sessionTimeout'] = "0.0"
submitVars['guestmsgreq'] = "false"
submitVars['username'] = ""
submitVars['password'] = ""
referer = "http://10.10.0.1/24online/webpages/client.jsp" # URL of referring web page goes here
submitUrl = "http://10.10.0.1/24online/servlet/CyberoamHTTPClient" # URL of form action goes here
submitVarsUrlencoded = urllib.urlencode(submitVars)
req = urllib2.Request(submitUrl, submitVarsUrlencoded)
req.add_header('Referer', referer)
response = urllib2.urlopen(req)
thePage = response.read()
#print thePage