2014-02-27 15:43:58 +01:00
|
|
|
import tornado.ioloop
|
2014-02-27 15:55:16 +01:00
|
|
|
import tornado.web
|
2014-02-27 16:55:33 +01:00
|
|
|
import tornado.httpserver
|
2014-02-27 21:22:02 +01:00
|
|
|
import tornado.websocket
|
|
|
|
|
2014-02-27 22:34:28 +01:00
|
|
|
from tornado.ioloop import PeriodicCallback
|
2014-02-27 21:22:02 +01:00
|
|
|
|
2014-02-27 22:34:28 +01:00
|
|
|
from session import *
|
2014-02-27 19:57:53 +01:00
|
|
|
from loadConf import *
|
2014-02-27 20:06:37 +01:00
|
|
|
from login import *
|
2014-02-27 15:43:58 +01:00
|
|
|
|
2014-02-27 19:55:43 +01:00
|
|
|
confAveug = False
|
2014-02-27 20:06:37 +01:00
|
|
|
ficLog = Login()
|
2014-02-27 22:34:28 +01:00
|
|
|
settings["session_secret"] = 'some secret password!!'
|
|
|
|
settings["session_dir"] = 'sessions' # the directory to store sessions in
|
|
|
|
application.session_manager = session.TornadoSessionManager(settings["session_secret"], settings["session_dir"])
|
2014-02-27 19:55:43 +01:00
|
|
|
|
2014-02-27 16:06:38 +01:00
|
|
|
class MainHandler(tornado.web.RequestHandler):
|
2014-02-27 22:34:28 +01:00
|
|
|
def __init__ (self) :
|
|
|
|
self.session = session.TornadoSession(self.application.session_manager, self)
|
2014-02-27 16:06:38 +01:00
|
|
|
def get(self):
|
2014-02-27 16:28:49 +01:00
|
|
|
self.render("index.html")
|
2014-02-27 17:51:13 +01:00
|
|
|
def post(self):
|
2014-02-27 18:43:55 +01:00
|
|
|
iden = self.get_argument("id","")
|
|
|
|
mdp = self.get_argument("mdp","")
|
2014-02-27 20:06:37 +01:00
|
|
|
|
|
|
|
login = Login()
|
|
|
|
autorise = login.connexion(iden, mdp)
|
2014-02-27 20:09:53 +01:00
|
|
|
#maison = httplib.HTTPConnection("192.168.16.150", 80)
|
2014-02-27 20:06:37 +01:00
|
|
|
if autorise == True:
|
2014-02-27 20:15:11 +01:00
|
|
|
ficLog.enregDansLog(iden,"Authorized user connection","IP TO DO")
|
2014-02-27 20:06:37 +01:00
|
|
|
if confAveug == True:
|
|
|
|
print '->Send audio alarm authorized user'
|
|
|
|
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")'
|
|
|
|
else:
|
|
|
|
print '->Send visual alarm authorized user'
|
|
|
|
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
|
|
|
print "->Send to client authorized user access"
|
2014-02-27 22:34:28 +01:00
|
|
|
self.session['blah'] = 1234
|
|
|
|
self.save()
|
|
|
|
blah = self.session['blah']
|
|
|
|
self.write(blah)
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2014-02-27 20:10:46 +01:00
|
|
|
else:
|
2014-02-27 20:15:11 +01:00
|
|
|
ficLog.enregDansLog(iden,"Unauthorized user connection","IP TO DO")
|
2014-02-27 20:06:37 +01:00
|
|
|
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 "->Send to client unauthorized user access"
|
2014-02-27 20:53:48 +01:00
|
|
|
self.write("Unauthorized user access")
|
2014-02-27 17:56:39 +01:00
|
|
|
|
2014-02-27 20:53:48 +01:00
|
|
|
class VideoHandler(tornado.web.RequestHandler):
|
|
|
|
def get(self):
|
2014-02-27 21:22:02 +01:00
|
|
|
self.render("test.html")
|
|
|
|
|
2014-02-27 21:39:39 +01:00
|
|
|
class WSHandler(tornado.websocket.WebSocketHandler):
|
2014-02-27 21:38:17 +01:00
|
|
|
def open(self, *args):
|
|
|
|
self.id = self.get_argument("Id")
|
|
|
|
self.stream.set_nodelay(True)
|
|
|
|
clients[self.id] = {"id": self.id, "object": self}
|
2014-02-27 21:22:02 +01:00
|
|
|
|
|
|
|
def on_message(self, message):
|
2014-02-27 21:38:17 +01:00
|
|
|
"""
|
|
|
|
when we receive some message we want some message handler..
|
|
|
|
for this example i will just print message to console
|
|
|
|
"""
|
|
|
|
print "Client %s received a message : %s" % (self.id, message)
|
2014-02-27 21:22:02 +01:00
|
|
|
|
|
|
|
def on_close(self):
|
2014-02-27 21:38:17 +01:00
|
|
|
if self.id in clients:
|
|
|
|
del clients[self.id]
|
2014-02-27 17:56:39 +01:00
|
|
|
|
2014-02-27 15:43:58 +01:00
|
|
|
|
2014-02-27 16:06:38 +01:00
|
|
|
application = tornado.web.Application([
|
|
|
|
(r"/", MainHandler),
|
2014-02-27 20:54:51 +01:00
|
|
|
(r"/video", VideoHandler),
|
2014-02-27 21:22:02 +01:00
|
|
|
(r"/test", WSHandler),
|
2014-02-27 16:06:38 +01:00
|
|
|
])
|
2014-02-27 15:43:58 +01:00
|
|
|
|
2014-02-27 15:51:19 +01:00
|
|
|
if __name__ == "__main__":
|
2014-02-27 19:57:53 +01:00
|
|
|
hand = LoadConf()
|
2014-02-27 19:55:43 +01:00
|
|
|
confAveug = hand.estAveugle()
|
2014-02-27 19:56:31 +01:00
|
|
|
if confAveug == True:
|
|
|
|
print "->Blind unhabitant system configuration"
|
|
|
|
else :
|
|
|
|
print "->Not blind unhabitant system configuration"
|
2014-02-27 19:57:53 +01:00
|
|
|
|
2014-02-27 16:56:43 +01:00
|
|
|
http_server = tornado.httpserver.HTTPServer(application)
|
2014-02-27 16:53:58 +01:00
|
|
|
http_server.listen(80)
|
2014-02-27 16:06:38 +01:00
|
|
|
tornado.ioloop.IOLoop.instance().start()
|
2014-02-27 21:22:02 +01:00
|
|
|
|