2014-02-27 14:43:58 +00:00
|
|
|
import tornado.ioloop
|
2014-02-27 14:55:16 +00:00
|
|
|
import tornado.web
|
2014-02-27 15:55:33 +00:00
|
|
|
import tornado.httpserver
|
2014-02-27 20:22:02 +00:00
|
|
|
import tornado.websocket
|
2014-02-27 22:39:19 +00:00
|
|
|
import tornado.options
|
2014-02-27 20:22:02 +00:00
|
|
|
|
2014-02-27 21:34:28 +00:00
|
|
|
from tornado.ioloop import PeriodicCallback
|
2014-02-27 20:22:02 +00:00
|
|
|
|
2014-02-27 21:34:28 +00:00
|
|
|
from session import *
|
2014-02-27 18:57:53 +00:00
|
|
|
from loadConf import *
|
2014-02-27 19:06:37 +00:00
|
|
|
from login import *
|
2014-02-27 14:43:58 +00:00
|
|
|
|
2014-02-27 18:55:43 +00:00
|
|
|
confAveug = False
|
2014-02-27 19:06:37 +00:00
|
|
|
ficLog = Login()
|
2014-02-27 21:45:07 +00:00
|
|
|
|
2014-02-27 22:12:23 +00:00
|
|
|
class BaseHandler(tornado.web.RequestHandler):
|
|
|
|
def get_current_user(self):
|
|
|
|
return self.get_secure_cookie("user")
|
2014-02-27 21:46:17 +00:00
|
|
|
|
2014-02-27 22:12:23 +00:00
|
|
|
class MainHandler(BaseHandler):
|
2014-02-27 15:06:38 +00:00
|
|
|
def get(self):
|
2014-02-27 15:28:49 +00:00
|
|
|
self.render("index.html")
|
2014-02-27 16:51:13 +00:00
|
|
|
def post(self):
|
2014-02-27 17:43:55 +00:00
|
|
|
iden = self.get_argument("id","")
|
|
|
|
mdp = self.get_argument("mdp","")
|
2014-02-27 19:06:37 +00:00
|
|
|
|
|
|
|
login = Login()
|
|
|
|
autorise = login.connexion(iden, mdp)
|
2014-02-27 19:09:53 +00:00
|
|
|
#maison = httplib.HTTPConnection("192.168.16.150", 80)
|
2014-02-27 19:06:37 +00:00
|
|
|
if autorise == True:
|
2014-02-27 19:15:11 +00:00
|
|
|
ficLog.enregDansLog(iden,"Authorized user connection","IP TO DO")
|
2014-02-27 19:06:37 +00: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")'
|
2014-02-27 22:33:51 +00:00
|
|
|
print "->Authorized user access"
|
2014-02-27 22:12:23 +00:00
|
|
|
self.set_secure_cookie("user", iden)
|
|
|
|
self.redirect("/video")
|
2014-02-27 19:10:46 +00:00
|
|
|
else:
|
2014-02-27 22:33:51 +00:00
|
|
|
print "->An unauthorized user try to access"
|
2014-02-27 22:42:47 +00:00
|
|
|
self.redirect("/unauthorized")
|
2014-02-27 16:56:39 +00:00
|
|
|
|
2014-02-27 22:12:23 +00:00
|
|
|
class VideoHandler(BaseHandler):
|
2014-02-27 19:53:48 +00:00
|
|
|
def get(self):
|
2014-02-27 22:12:23 +00:00
|
|
|
if not self.current_user :
|
|
|
|
self.redirect("/")
|
|
|
|
return
|
|
|
|
name = tornado.escape.xhtml_escape(self.current_user)
|
2014-02-28 00:41:59 +00:00
|
|
|
with open("image/temp.jpg", 'rb') as f:
|
|
|
|
data = f.read()
|
2014-02-28 00:44:22 +00:00
|
|
|
self.set_header('Content-type', 'image/jpg')
|
|
|
|
self.write(data)
|
2014-02-28 00:41:59 +00:00
|
|
|
self.finish()
|
2014-02-27 20:22:02 +00:00
|
|
|
|
2014-02-27 22:33:51 +00:00
|
|
|
class UnauthorizedHandler(BaseHandler):
|
|
|
|
def get(self):
|
2014-02-27 22:39:19 +00:00
|
|
|
self.render("illegal.html")
|
2014-02-27 22:33:51 +00:00
|
|
|
def post(self):
|
2014-02-27 22:42:47 +00:00
|
|
|
force = self.get_argument("illegalAccess","")
|
2014-02-27 22:44:32 +00:00
|
|
|
if force == "1" :
|
2014-02-27 22:33:51 +00:00
|
|
|
self.set_secure_cookie("user", "illegalUser")
|
2014-02-28 00:13:54 +00:00
|
|
|
ficLog.enregDansLog(iden,"Unauthorized user connection","IP TO DO")
|
|
|
|
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")'
|
2014-02-27 22:46:53 +00:00
|
|
|
self.redirect("/video")
|
2014-02-27 22:33:51 +00:00
|
|
|
else :
|
|
|
|
self.redirect("/")
|
2014-02-27 16:56:39 +00:00
|
|
|
|
2014-02-27 14:43:58 +00:00
|
|
|
|
2014-02-28 00:27:12 +00:00
|
|
|
|
|
|
|
class AJAXHandler(BaseHandler):
|
|
|
|
def get(self):
|
2014-02-28 00:30:08 +00:00
|
|
|
self.write("lol")
|
2014-02-28 00:27:12 +00:00
|
|
|
|
|
|
|
|
2014-02-27 15:06:38 +00:00
|
|
|
application = tornado.web.Application([
|
|
|
|
(r"/", MainHandler),
|
2014-02-27 19:54:51 +00:00
|
|
|
(r"/video", VideoHandler),
|
2014-02-27 22:33:51 +00:00
|
|
|
(r"/unauthorized", UnauthorizedHandler),
|
2014-02-28 00:27:12 +00:00
|
|
|
(r"/ajax", AJAXHandler),
|
2014-02-27 22:12:23 +00:00
|
|
|
], cookie_secret="1213215656")
|
2014-02-27 14:43:58 +00:00
|
|
|
|
2014-02-27 14:51:19 +00:00
|
|
|
if __name__ == "__main__":
|
2014-02-27 18:57:53 +00:00
|
|
|
hand = LoadConf()
|
2014-02-27 18:55:43 +00:00
|
|
|
confAveug = hand.estAveugle()
|
2014-02-27 18:56:31 +00:00
|
|
|
if confAveug == True:
|
|
|
|
print "->Blind unhabitant system configuration"
|
|
|
|
else :
|
|
|
|
print "->Not blind unhabitant system configuration"
|
2014-02-27 18:57:53 +00:00
|
|
|
|
2014-02-27 22:39:19 +00:00
|
|
|
tornado.options.parse_command_line()
|
2014-02-27 15:56:43 +00:00
|
|
|
http_server = tornado.httpserver.HTTPServer(application)
|
2014-02-27 15:53:58 +00:00
|
|
|
http_server.listen(80)
|
2014-02-27 15:06:38 +00:00
|
|
|
tornado.ioloop.IOLoop.instance().start()
|
2014-02-27 20:22:02 +00:00
|
|
|
|