-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcyberoam.py
More file actions
192 lines (126 loc) · 3.98 KB
/
cyberoam.py
File metadata and controls
192 lines (126 loc) · 3.98 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/python2.7
import sys
from urllib import urlencode
from urllib2 import urlopen
import getpass
import urllib2
from time import sleep
from os import system
from bs4 import BeautifulSoup
import subprocess
import pynotify
import cookielib
''''' this cyberoam working on DA-IICT because i use DA IP
even if you close terminal but process will running'''''
cyberoamIP = "10.100.56.55" #The IP of the Cyberoam site of DA-IICT,
cyberoamPort = "8090" #PORT number
neverQuit=True
sleeptime=10
pynotify.init("Cyberoam")
URL = 'https://'+cyberoamIP+":"+cyberoamPort+'/'+'httpclient.html'
n = pynotify.Notification("Cyberoam Login with valid DA_id and password")
n.show()
DA_id = raw_input("Enter your ID: ")
#passwordd = raw_input("password: ")
passwordd=getpass.getpass('Password:')
def totalnetused(user,passs):
p=subprocess.Popen('ps', stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
print p.communicate()
params = urlencode({'mode': 1, 'username': user, 'password': passs})
res = urlopen(URL, params)
if res != '':
bs = BeautifulSoup(res)
data= bs.html.body
data_info= []
for dt in data.readline():
start = dt.find('')
the_page = dt[start+53:]
end = the_page.find('data_info.append(dt[0:end])')
print data_info
else :
print "did not find data used"
def forprocide():
URLLIVE='https://'+cyberoamIP+":"+cyberoamPort+'/live?'+'mode=192&username='+str(DA_id)
info=urlopen(URLLIVE).read()
bs = BeautifulSoup(info)
data= bs.html.body
ss=1
if "exceeded" in data :
ss=0
elif "login again" in data:
ss=0
else:
ss=1
return ss
def Timerforlogin():
sleep(sleeptime)
def forLogin(user,passs):
params = urlencode({'mode': 191, 'username': user, 'password': passs})
res = urlopen(URL, params)
aa=res.read()
print "login procedure"
return aa
def forLogout(user):
params = urlencode({'mode': 193, 'username': user})
res = urlopen(URL, params)
aa=res.read()
print "logout procedure"
return aa
def logout():
info = forLogout(DA_id)
if 'off' in info:
n = pynotify.Notification("logout")
n.show()
sys.exit()
def loginLogout():
relogin=False
try:
if "login" in sys.argv:
info=forLogin(DA_id,passwordd)
if "could not" in info:
n = pynotify.Notification("id or password incorrect...enter valid DA_id and password and run file")
n.show()
exit()
elif "Maximum" in info:
n = pynotify.Notification("Maximum data limit")
n.show()
exit()
elif "exceeded" in info:
n = pynotify.Notification("data limit exceeded")
n.show()
exit()
elif "successfully logged in" in info :
n = pynotify.Notification("login success")
n.show()
relogin=True
print "Press Ctrl + C to logout"
# totalnetused(DA_id,passwordd)
#print forprocide()
else:
print "this Cyberoam don't recognise your error..please try again"
if relogin:
total=0
while forprocide() != 0:
Timerforlogin()
total +=10
if(total==3600):
break
if total==3600:
total=0
sys.argv="login"
loginLogout()
else :
logout()
totalnetused(DA_id,passwordd)
exit()
if "logout" in sys.argv:
logout()
exit()
except KeyboardInterrupt:
logout()
totalnetused(DA_id,passwordd)
exit()
except Exception as e:
print e
if __name__ == "__main__":
loginLogout()