-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.py
85 lines (78 loc) · 2.92 KB
/
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
77
78
79
80
81
82
83
84
85
from kivy.logger import Logger
class Status:
def __init__(self,success,reason):
self.success=success
self.reason=reason
def login(username,password):
from requests import post
try:
creds={}
creds['username']=username
creds['password']=password
creds['mode']=191
#print(creds)
response=post("http://172.16.0.30:8090/httpclient.html",data=creds,timeout=8)
Logger.info(response.text)
return login_status(response.text)
except Exception as e:
Logger.error(e)
return Status(False,"cannot connect to cyberoam. is the ethernet/wifi working ?")
def getCreds():
return {'username':'lol','password':'$as'}
def login_status(response):
try:
from lxml import etree
status=etree.fromstring(response)
Logger.info(status[1].text)
if(status[1].text=='You have successfully logged in'):
#print("logged in")
return Status(True,"Logged In")
elif(status[1].text=='The system could not log you on. Make sure your password is correct'):
#print("invalid Password")
return Status(False,"invalid Password")
elif(status[1].text=='Your data transfer has been exceeded, Please contact the administrator'):
return Status(False,"Data Limit exceeded")
elif(status[1].text=='You have reached Maximum Login Limit.'):
return Status(False,"Login Limit exceeded")
else:
Logger.error("Something wierd happened")
return Status(False,"Oops.Something wierd happened !!")
except Exception as e:
Logger.error("error parsing Response")
Logger.error(e)
return Status(False,"Error Parsing response.")
def logout(username):
from requests import post
try:
creds={}
creds['username']=username
creds['mode']=193
response=post("http://172.16.0.30:8090/httpclient.html",data=creds,timeout=8)
Logger.info(response.text)
return logout_status(response.text)
except Exception as e:
Logger.error(e)
return Status(False,"No Internet. So don't bother trying ")
def logout_status(response):
try:
from lxml import etree
status=etree.fromstring(response)
Logger.info(status[1].text)
if(status[1].text=='You have successfully logged off'):
#print("logged out")
return Status(True,"Logged out")
else:
Logger.error("Something wierd happened")
return Status(False,"Oops.Something wierd happened !!")
except Exception as e:
Logger.error("error parsing Response")
Logger.error(e)
return Status(False,"Error Parsing response.")
def save(self,creds):
with open('cred.bin','wb') as f:
from pickle import dump
dump(creds,f)
def load(self):
with open('creds.bin','rb') as f:
from pickle import load
return load(f)