-
Notifications
You must be signed in to change notification settings - Fork 0
/
crous-login.py
executable file
·77 lines (56 loc) · 1.88 KB
/
crous-login.py
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
#!/usr/bin/env python
"""
crous-login: Fill the forms needed to login to the crous osiris network.
Rodrigo Campos <[email protected]>
"""
import requests
import time
import subprocess
USER="XXX"
PASS="YYY"
def login(user, password):
#subprocess.check_call("killall dhclient ; dhclient -v eth0", shell=True)
time.sleep(1)
r = requests.get("http://google.com")
if not "/webauth/loginprocess" in r.text:
print "Not the expected form. Already conected ?"
return
print "Got the form..."
# Do the POST to: <the same site we connected>/webauth/loginprocess
payload = { "user": user, "pass": password }
r = requests.post("http://google.com/webauth/loginprocess", data=payload)
# Print just in case it says some wierd error
print r.text
# Wait till the access is granted
while 'granted' not in r.text.lower():
# Two seconds is the time used in the META header to refresh, so we wait
# the same (and if they change it, fuck it :D)
time.sleep(2)
r = requests.get("http://google.com/webauth/statusprocess")
print "granted! Waiting to activate..."
time.sleep(10)
#subprocess.check_call("killall dhclient ; dhclient -v eth0", shell=True)
def connect(use, password):
while True:
try:
login(USER, PASS)
except:
print "Error while trying to login, trying again"
time.sleep(2)
continue
break
def are_connected():
try:
subprocess.check_call("ping -c 2 8.8.8.8 > /dev/null", shell=True)
return True
except:
return False
if __name__ == "__main__":
while True:
if not are_connected():
print "Not connected! Trying to connect..."
connect(USER, PASS)
try:
time.sleep(60)
except KeyboardInterrupt:
print "Checking connection again..."