modifié: m/fichier/conf

modifié:         m/loadConf.py
	modifié:         m/log.py
	modifié:         m/login.py
	modifié:         superTornado.py
	nouveau fichier: test/AllowTest
	nouveau fichier: test/ConfTest
	nouveau fichier: test/MiEmulator.py
	nouveau fichier: test/a
	nouveau fichier: test/botTest.py
	nouveau fichier: test/mfp.cookies
	nouveau fichier: test/testFichier.py
	nouveau fichier: test/testMISignaux.py
	modifié:         v/illegal.html
	modifié:         v/index.html
This commit is contained in:
sidya82
2014-03-30 22:11:36 +02:00
parent 160ab41dfe
commit 73a1d1e3e4
18 changed files with 2876 additions and 74 deletions

View File

@@ -26,7 +26,8 @@ class GlobalVars :
"""
Global vars for server
"""
config = LoadConf()
config = LoadConf("m/fichier/conf")
log = Log()
blind = False
ipCamera = ""
portCamera = ""
@@ -34,13 +35,15 @@ class GlobalVars :
idCamera = ""
urlCamera = ""
portServ = ""
log = Log()
urlSocket = ""
ipDomo=""
portDomo=""
authorized = 0
unauthorized = 0
class BaseHandler(tornado.web.RequestHandler):
"""
Define BaseHandler for create the basis for session connection
@@ -71,7 +74,7 @@ class MainHandler(BaseHandler):
iden = self.get_argument("id","")
paswd = self.get_argument("paswd","")
login = Login()
login = Login("m/fichier/allow")
autorise = login.checkLogin(iden, paswd)
self.set_secure_cookie("user", iden)
if autorise == True:
@@ -161,34 +164,36 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
if GlobalVars.blind == True:
GlobalVars.authorized + 1
GlobalVars.log.printL('->Send audio alarm authorized user',lvl.INFO)
self.send_signal_house('maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")')
self.send_signal_house('maison.request("GET", "/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")')
else:
GlobalVars.authorized + 1
GlobalVars.log.printL('->Send visual alarm authorized user',lvl.INFO)
self.send_signal_house('maison.request("GET", "micom/lamp.php?room=salon1&order=1")')
self.send_signal_house('maison.request("GET", "/micom/lamp.php?room=salon1&order=1")')
else :
GlobalVars.log.printL("->"+iden + ": Unauthorized user connection : " + self.request.remote_ip,lvl.WARNING)
if GlobalVars.blind == True:
GlobalVars.unauthorized + 1
GlobalVars.log.printL('->Send audio alarm unauthorized user',lvl.WARNING)
self.send_signal_house('maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")')
self.send_signal_house('maison.request("GET", "/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")')
else:
GlobalVars.unauthorized + 1
GlobalVars.log.printL('->Send visual alarm unauthorized user',lvl.WARNING)
self.send_signal_house('maison.request("GET", "micom/lamp.php?room=salon1&order=1")')
self.send_signal_house('maison.request("GET", "/micom/lamp.php?room=salon1&order=1")')
self.send_image()
def on_message(self,mesg):
def on_message(self,msg):
"""
Client Ask For Image
"""
GlobalVars.log.printL("->Demand Data Receive : " + self.request.remote_ip,lvl.INFO)
self.send_image()
try:
self.send_image()
except Exception, e :
GlobalVars.log.printL("->Failed Send data : Socket Close ",lvl.FAIL)
def on_close(self):
"""
Socket connection Connection->
Socket connection Connection
Alert unhabitant with the good signal
"""
GlobalVars.log.printL("->Websocket Closed : "+self.request.remote_ip,lvl.SUCCESS)
@@ -203,24 +208,24 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
if GlobalVars.blind == True:
if (GlobalVars.unauthorized == 0) and (GlobalVars.authorized == 0):
GlobalVars.log.printL('->Send Audio Alarm Deconnection User', lvl.INFO)
self.send_signal_house('maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20rompue")')
self.send_signal_house('maison.request("GET", "/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20rompue")')
else:
if (GlobalVars.unauthorized == 0) and (GlobalVars.authorized == 0):
GlobalVars.log.printL('->Send Visual Alarm Deconnection User ...',lvl.INFO)
self.send_signal_house('maison.request("GET", "micom/lamp.php?room=salon1&order=0")')
self.send_signal_house('maison.request("GET", "/micom/lamp.php?room=salon1&order=0")')
def send_signal_house(self, pRq) :
"""
Allow send pRq request to the house
"""
GlobalVars.log.printL('maison = httplib.HTTPConnection("192.168.16.150", 80)',lvl.DEBUG)
"""maison = httplib.HTTPConnection("192.168.16.150")"""
GlobalVars.log.printL('maison = httplib.HTTPConnection("'+GlobalVars.ipDomo+'",'+ GlobalVars.portDomo+')',lvl.DEBUG)
"""maison = httplib.HTTPConnection(GlobalVars.ipDomo,GlobalVars.portDomo)"""
try :
GlobalVars.log.printL(pRq,lvl.DEBUG)
"""maison.request("GET",pRq)"""
GlobalVars.log.printL("->Signal To House Send Successfully", lvl.SUCCESS)
except Exception, e :
GlobalVars.log.printL(e, lvl.FAIL)
GlobalVars.log.printL(e.value, lvl.FAIL)
GlobalVars.log.printL("->Signal To House Send Failed", lvl.FAIL)
def send_image(self) :
@@ -262,6 +267,8 @@ if __name__ == "__main__":
GlobalVars.endUrlCamera = GlobalVars.config.endUrlCamera()
GlobalVars.ipServ = GlobalVars.config.ipServ()
GlobalVars.portServ = GlobalVars.config.portServ()
GlobalVars.ipDomo = GlobalVars.config.ipDomo()
GlobalVars.portDomo = GlobalVars.config.portDomo()
if GlobalVars.blind == "error" :
raise ConfigError("Failed Load Blind Configuration")
@@ -277,6 +284,10 @@ if __name__ == "__main__":
raise ConfigError("Failed Load IP Server Configuration")
if GlobalVars.portServ == "error" :
raise ConfigError("Failed Load Port Server Configuration")
if GlobalVars.ipDomo == "error" :
raise ConfigError("Failed Load IP Domotic Configuration")
if GlobalVars.portDomo == "error" :
raise ConfigError("Failed Load Port Domotic Configuration")
except ConfigError as e :
GlobalVars.log.printL(e.value,lvl.FAIL)
GlobalVars.log.printL("Configuration Loading Failed ! Check Configuration File !",lvl.FAIL)
@@ -292,9 +303,11 @@ if __name__ == "__main__":
GlobalVars.log.printL(" +End url Camera : " + GlobalVars.endUrlCamera,lvl.INFO)
GlobalVars.log.printL(" +Ip Server : " + GlobalVars.ipServ,lvl.INFO)
GlobalVars.log.printL(" +Port Server : " + GlobalVars.portServ,lvl.INFO)
GlobalVars.log.printL(" +IP Domotic : " + GlobalVars.ipDomo,lvl.INFO)
GlobalVars.log.printL(" +Port Domotic : " + GlobalVars.portDomo,lvl.INFO)
print ""
GlobalVars.urlSocket = 'ws://'+GlobalVars.ipServ+':'+GlobalVars.portCamera+'/socket'
GlobalVars.urlSocket = 'ws://'+GlobalVars.ipServ+':'+GlobalVars.portServ+'/socket'
GlobalVars.urlCamera = 'http://'+GlobalVars.idUrlCamera+'@'+GlobalVars.ipCamera+':'+GlobalVars.portCamera+GlobalVars.endUrlCamera
GlobalVars.log.printL("->Ping camera ...",lvl.INFO)