-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.sh
78 lines (67 loc) · 1.62 KB
/
proxy.sh
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
#!/bin/bash
# proxy_add=https://proxy61.iitd.ac.in/cgi-bin/proxy.cgi
#For mtech
proxy_add=https://proxy62.iitd.ac.in/cgi-bin/proxy.cgi
#FILL THIS
username="";
password="";
unsetProxy()
{
unset http_proxy
unset https_proxy
unset ftp_proxy
}
getsessionid()
{
session_id=`curl $proxy_add -s -k --no-progress-bar --connect-timeout 15| grep -m 1 sessionid[\"=[:alpha:]\ ]*[[:digit:]]* | grep -oh "\"[[:digit:]][[:alnum:]]*\"" | sed 's|"||' | sed 's|"||' `
#echo "Session ID: $session_id"
}
logout()
{
curl -d "sessionid=$session_id&action=logout" $proxy_add -k -s >/dev/null
if [ ${#ifAlreadyLoggedIn} = 0 ]; then
echo -e "Enjoy!"
else
echo -e "proxy logout!!" ;
fi
exit 0
}
login()
{
logintext=`curl -d "sessionid=$session_id&action=Validate&userid=$username&pass=$password" $proxy_add -k -s`
#echo $logintext
ifAlreadyLoggedIn=`echo $logintext | grep -v "already logged in"`
if [ ${#ifAlreadyLoggedIn} = 0 ]; then
echo "Already logged in"
exit 0
fi
}
#trap logout SIGINT
retries=1000
islogout=1;
mainloop()
{
unsetProxy
getsessionid
login
iflogin=`echo $logintext | grep "logged in successfully"`
if [ ${#iflogin} = 0 ] ;then
echo "error in login"
sleep 10
mainloop
else
echo "proxy login "
while true; do
sleep 120
refreshtext=`curl -d "sessionid=$session_id&action=Refresh" $proxy_add -k -s`
ifrefresh=`echo $refreshtext | grep "logged in successfully"`
if [ ${#ifrefresh} = 0 ] ;
then
curl -d "sessionid=$session_id&action=logout" $proxy_add -k -s >/dev/null
mainloop
fi
done
fi
}
trap logout EXIT
mainloop