modifié: superTornado.py
This commit is contained in:
parent
154542831d
commit
547879e8f9
@ -24,6 +24,9 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||||||
def get_current_user(self):
|
def get_current_user(self):
|
||||||
return self.get_secure_cookie("user")
|
return self.get_secure_cookie("user")
|
||||||
|
|
||||||
|
def get_autorisation(self):
|
||||||
|
return self.get_secure_cookie("auth")
|
||||||
|
|
||||||
class MainHandler(BaseHandler):
|
class MainHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
self.render("v/index.html")
|
self.render("v/index.html")
|
||||||
@ -35,8 +38,9 @@ class MainHandler(BaseHandler):
|
|||||||
login = Login()
|
login = Login()
|
||||||
autorise = login.connexion(iden, mdp)
|
autorise = login.connexion(iden, mdp)
|
||||||
print 'maison = httplib.HTTPConnection("192.168.16.150", 80)'
|
print 'maison = httplib.HTTPConnection("192.168.16.150", 80)'
|
||||||
|
self.set_secure_cookie("user", iden)
|
||||||
if autorise == True:
|
if autorise == True:
|
||||||
self.set_secure_cookie("user", iden)
|
self.set_secure_cookie("auth", "yes")
|
||||||
self.redirect("/video")
|
self.redirect("/video")
|
||||||
else:
|
else:
|
||||||
print "->An unauthorized user try to access"
|
print "->An unauthorized user try to access"
|
||||||
@ -44,19 +48,22 @@ class MainHandler(BaseHandler):
|
|||||||
|
|
||||||
class VideoHandler(BaseHandler):
|
class VideoHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
if not self.current_user :
|
if not self.get_current_user :
|
||||||
self.redirect("/")
|
self.redirect("/")
|
||||||
return
|
return
|
||||||
self.render("v/video.html")
|
self.render("v/video.html")
|
||||||
|
|
||||||
class UnauthorizedHandler(BaseHandler):
|
class UnauthorizedHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
|
if not self.get_autorisation :
|
||||||
|
self.redirect("/")
|
||||||
|
return
|
||||||
self.render("v/illegal.html")
|
self.render("v/illegal.html")
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
force = self.get_argument("illegalAccess","")
|
force = self.get_argument("illegalAccess","")
|
||||||
if force == "1" :
|
if force == "1" :
|
||||||
self.set_secure_cookie("user", "illegalUser")
|
self.set_secure_cookie("auth", "no")
|
||||||
self.redirect("/video")
|
self.redirect("/video")
|
||||||
else :
|
else :
|
||||||
self.redirect("/")
|
self.redirect("/")
|
||||||
@ -64,30 +71,18 @@ class UnauthorizedHandler(BaseHandler):
|
|||||||
|
|
||||||
class DisconnectionHandler(BaseHandler):
|
class DisconnectionHandler(BaseHandler):
|
||||||
def post(self):
|
def post(self):
|
||||||
if not self.current_user :
|
self.clear_cookie("auth")
|
||||||
self.close()
|
|
||||||
return
|
|
||||||
self.clear_cookie("user")
|
self.clear_cookie("user")
|
||||||
self.redirect("/")
|
self.redirect("/")
|
||||||
|
|
||||||
class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
||||||
def open(self) :
|
def open(self) :
|
||||||
if not self.current_user :
|
if not self.get_autorisation :
|
||||||
self.close()
|
self.close()
|
||||||
return
|
return
|
||||||
print "->Websocket opened : " + self.request.remote_ip
|
print "->Websocket opened : " + self.request.remote_ip
|
||||||
if self.current_user == "illegalUser":
|
iden = self.current_user
|
||||||
iden="IllegalUser"
|
if self.get_autorisation == "yes":
|
||||||
ficLog.enregDansLog(iden,"Unauthorized user connection",self.request.remote_ip)
|
|
||||||
if confAveug == True:
|
|
||||||
print '->Send audio alarm unauthorized user'
|
|
||||||
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")'
|
|
||||||
else:
|
|
||||||
print '->Send visual alarm unauthorized user'
|
|
||||||
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
|
||||||
print "->Unauthorized user access" + self.request.remote_ip
|
|
||||||
else :
|
|
||||||
iden = self.current_user
|
|
||||||
ficLog.enregDansLog(iden,"Authorized user connection",self.request.remote_ip)
|
ficLog.enregDansLog(iden,"Authorized user connection",self.request.remote_ip)
|
||||||
if confAveug == True:
|
if confAveug == True:
|
||||||
print '->Send audio alarm authorized user'
|
print '->Send audio alarm authorized user'
|
||||||
@ -95,21 +90,30 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
else:
|
else:
|
||||||
print '->Send visual alarm authorized user'
|
print '->Send visual alarm authorized user'
|
||||||
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
||||||
print "->Authorized user access" + self.request.remote_ip
|
print "->Authorized user access : " + self.request.remote_ip
|
||||||
|
else :
|
||||||
|
ficLog.enregDansLog(iden + "as IllegalUser","Unauthorized user connection",self.request.remote_ip)
|
||||||
|
if confAveug == True:
|
||||||
|
print '->Send audio alarm unauthorized user'
|
||||||
|
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")'
|
||||||
|
else:
|
||||||
|
print '->Send visual alarm unauthorized user'
|
||||||
|
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
||||||
|
print "->Unauthorized user access" + self.request.remote_ip
|
||||||
self.send_image()
|
self.send_image()
|
||||||
|
|
||||||
def on_message(self,mesg):
|
def on_message(self,mesg):
|
||||||
print "->Data receive"
|
print "->Data receive : " + self.request.remote_ip
|
||||||
self.send_image()
|
self.send_image()
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
print "->Websocket closed : "+self.request.remote_ip
|
print "->Websocket closed : "+self.request.remote_ip
|
||||||
if self.current_user == "illegalUser":
|
if self.get_autorisation == "yes":
|
||||||
iden="IllegalUser"
|
|
||||||
ficLog.enregDansLog(iden,"Unauthorized user deconnection",self.request.remote_ip)
|
|
||||||
else :
|
|
||||||
iden = self.current_user
|
iden = self.current_user
|
||||||
ficLog.enregDansLog(iden,"Authorized user deconnection",self.request.remote_ip)
|
ficLog.enregDansLog(iden,"Authorized user deconnection",self.request.remote_ip)
|
||||||
|
else :
|
||||||
|
iden="IllegalUser"
|
||||||
|
ficLog.enregDansLog(iden + "as IllegalUser","Unauthorized user deconnection",self.request.remote_ip)
|
||||||
|
|
||||||
if confAveug == True:
|
if confAveug == True:
|
||||||
print '->Send audio alarm deconnection user'
|
print '->Send audio alarm deconnection user'
|
||||||
@ -127,7 +131,7 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
data = f.read()
|
data = f.read()
|
||||||
encoded = base64.b64encode(data)
|
encoded = base64.b64encode(data)
|
||||||
self.write_message(encoded)
|
self.write_message(encoded)
|
||||||
print ("->Data send")
|
print "->Data send : " + self.request.remote_ip
|
||||||
except Exception, e :
|
except Exception, e :
|
||||||
print e
|
print e
|
||||||
self.write_message("error")
|
self.write_message("error")
|
||||||
|
Reference in New Issue
Block a user