[digicode] On confie la gestion de digicode à l'intranet 2
* digicode.py appelle désormais la fonction create de l'intranet 2. * digicode_server2.py est renommé en digicode_server.py. * Edition de gen_code.py pour le rendre compatible avec le nouveau digicode.py.
This commit is contained in:
parent
dbf4496b78
commit
7122f040e6
4 changed files with 21 additions and 127 deletions
|
@ -1,13 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
#!/bin/bash /usr/scripts/python.sh
|
||||
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import SocketServer
|
||||
import requests
|
||||
|
||||
import gestion.secrets_new
|
||||
digicode_pass = gestion.secrets_new.get('digicode_pass')
|
||||
|
||||
CODES = "/var/impression/codes"
|
||||
PIDFILE = "/var/run/digicode.pid"
|
||||
HOST, PORT = "zamok.adm.crans.org", 1200
|
||||
DIGICODE_LINK = "https://intranet2.crans.org/digicode/delete/"
|
||||
CERTIFICATE = "/etc/ssl/certs/cacert.org.pem"
|
||||
|
||||
def log(message = "", logfile = "/var/log/crans/digicode.log"):
|
||||
"""Log a message to the default logfile"""
|
||||
|
@ -41,19 +47,11 @@ class VigileHandler(SocketServer.BaseRequestHandler):
|
|||
# if data starts with o, opened door validation, else should
|
||||
# be a code
|
||||
if not data.startswith("o"):
|
||||
valide, contents = self.check_code(data)
|
||||
if valide:
|
||||
response = requests.post(DIGICODE_LINK, data = {'password' : digicode_pass, 'code' : data}, verify = CERTIFICATE, timeout=0.5)
|
||||
if response.content == u'Code Successfully Deleted':
|
||||
socket.sendto("passoir,o=1", self.client_address)
|
||||
log("valid code! (%s)" % contents.strip())
|
||||
|
||||
def check_code(self, data):
|
||||
"""Check the given code against the available codes list."""
|
||||
path = os.path.join(CODES, data)
|
||||
if os.path.exists(path):
|
||||
contents = open(path).read()
|
||||
os.remove(path)
|
||||
return True, contents
|
||||
return False, ""
|
||||
log("%s -- %s" % (data, response.content))
|
||||
|
||||
if __name__ == "__main__":
|
||||
# do the UNIX double-fork magic, see Stevens' "Advanced
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue