diff --git a/m/fichier/conf b/m/fichier/conf index 130b420..8f36451 100644 --- a/m/fichier/conf +++ b/m/fichier/conf @@ -1 +1,3 @@ -handicap=1 +blind=1 +camera=192.168.1.13 +port=80 diff --git a/m/loadConf.py b/m/loadConf.py index 2ae4748..6f0d687 100644 --- a/m/loadConf.py +++ b/m/loadConf.py @@ -1,16 +1,25 @@ class LoadConf(object): - def loadHand(self): + def loadValue(self, key): with open("m/fichier/conf", "r") as source : for ligne in source: data = ligne.rstrip('\n\r').split('=') - if data[0] in 'handicap' : + if data[0] in key : source.close() return data[1] source.close() - return 0 + return "error" - def estAveugle(self): - if self.loadHand() == "1" : + def isBlind(self): + rep = self.loadValue("blind") + if rep == "1" : return True - else : + else if rep == "0": return False + else : + return rep + + def ipCamera(self) + return self.loadValue("camera") + + def portServ(self) + return self.loadValue("port") diff --git a/m/log.py b/m/log.py new file mode 100644 index 0000000..a0fa16d --- /dev/null +++ b/m/log.py @@ -0,0 +1,8 @@ +import time +from datetime import datetime + +class Log(object): + def enregDansLog(self,pLog,pMsg,pIP): + with open("m/fichier/log", "a") as dest : + d = datetime.now().strftime("%c") + dest.write("%s,%s,%s,%s\n" % (d,pLog,pMsg,pIP)) diff --git a/m/login.py b/m/login.py index e364e20..a1208c6 100644 --- a/m/login.py +++ b/m/login.py @@ -1,7 +1,6 @@ -import time import hashlib import httplib -from datetime import datetime + class Login(object): def verifLogin(self,pLog,pMdp): @@ -16,11 +15,6 @@ class Login(object): source.close() return False - def enregDansLog(self,pLog,pMsg,pIP): - with open("m/fichier/log", "a") as dest : - d = datetime.now().strftime("%c") - dest.write("%s,%s,%s,%s\n" % (d,pLog,pMsg,pIP)) - def connexion(self,pLog,pMdp): if self.verifLogin(pLog,pMdp) == True : return True diff --git a/superTornado.py b/superTornado.py index 1e4b2bd..6d0d490 100644 --- a/superTornado.py +++ b/superTornado.py @@ -14,11 +14,12 @@ from tornado.ioloop import PeriodicCallback from m.loadConf import * from m.login import * +from m.log import * import os -confAveug = LoadConf().estAveugle() -ficLog = Login() +config = LoadConf() +ficLog = Log() class BaseHandler(tornado.web.RequestHandler): def get_current_user(self): @@ -43,7 +44,7 @@ class MainHandler(BaseHandler): self.set_secure_cookie("auth", "yes") self.redirect("/video") else: - print "->An unauthorized user try to access" + print "->An unauthorized user try to access : " + self.request.remote_ip self.redirect("/unauthorized") class VideoHandler(BaseHandler): @@ -99,7 +100,7 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler): 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 + print "->Unauthorized user access : " + self.request.remote_ip self.send_image() def on_message(self,mesg): @@ -120,7 +121,7 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler): else: print '->Send visual alarm deconnection user' print 'maison.request("GET", "micom/lamp.php?room=salon1&order=0")' - print"->"+iden+" Deconnection" + self.request.remote_ip + print"->"+iden+" Deconnection : " + self.request.remote_ip def send_image(self) : @@ -147,12 +148,31 @@ application = tornado.web.Application([ cookie_secret="1213215656") if __name__ == "__main__": + print "->Loading configuration ... " + try : + confAveug = config.estAveugle + ipCamera = config.ipCamera + portServ = config.portServ + if confAveug == "error" + raise "Failed Load Blind Configuration" + if ipCamera == "error" + raise "Failed Load IP Camera Configuration" + if portServ == "error" + raise "Failed Load Port Server Configuration" + except Exception, e : + print "Configuration Loading Failed ! Check Conf File !" + print e + return 1 + print "->Configuraion Server Load Successfully:" if confAveug == True: - print "->Blind unhabitant system configuration" + print " ->Blind unhabitant" else : - print "->Not blind unhabitant system configuration" + print " ->Not blind unhabitant" + print " ->Ip camera : " + ipCamera + print " ->Port Server : " + portServ tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(application) http_server.listen(80) + tornado.ioloop.IOLoop.instance().start()