Add logs system
This commit is contained in:
parent
02d97e540e
commit
d3d29e686f
3 changed files with 36 additions and 13 deletions
32
Setup.py
32
Setup.py
|
@ -5,6 +5,8 @@ from flask import request, Flask
|
||||||
|
|
||||||
#http://192.168.43.155:5000/setup?ssid=cimaphone&password=cimakodu30&id=1
|
#http://192.168.43.155:5000/setup?ssid=cimaphone&password=cimakodu30&id=1
|
||||||
|
|
||||||
|
mac = io.open("/sys/class/net/wlan0/address").read()
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def writeconfig(ssid, password):
|
def writeconfig(ssid, password):
|
||||||
|
@ -31,7 +33,6 @@ def web_setup():
|
||||||
else:
|
else:
|
||||||
writeconfig(request.args.get("ssid"), request.args.get("password"))
|
writeconfig(request.args.get("ssid"), request.args.get("password"))
|
||||||
if testinternet():
|
if testinternet():
|
||||||
mac = io.open("/sys/class/net/wlan0/address").read()
|
|
||||||
id = request.args.get("id")
|
id = request.args.get("id")
|
||||||
with shelve.open("Settings.conf") as settings:
|
with shelve.open("Settings.conf") as settings:
|
||||||
settings["token"] = id
|
settings["token"] = id
|
||||||
|
@ -67,10 +68,13 @@ def add_yubi():
|
||||||
reg[int(i[:id])] = i[wriedid+1:secret]
|
reg[int(i[:id])] = i[wriedid+1:secret]
|
||||||
|
|
||||||
with shelve.open("Settings.conf", writeback = True) as settings:
|
with shelve.open("Settings.conf", writeback = True) as settings:
|
||||||
if len(settings["register"]) != 0:
|
id = None
|
||||||
id = settings["register"][-1] + 1
|
for i in range(1, 10):
|
||||||
else:
|
if i not in settings["register"]:
|
||||||
id = 1
|
id = i
|
||||||
|
break
|
||||||
|
if id == None:
|
||||||
|
return "Too many yubikeys"
|
||||||
|
|
||||||
settings["register"].append(id)
|
settings["register"].append(id)
|
||||||
|
|
||||||
|
@ -81,9 +85,25 @@ def add_yubi():
|
||||||
return "Error, too many yubikeys"
|
return "Error, too many yubikeys"
|
||||||
|
|
||||||
subprocess.check_call(["ykpersonalize", "-1", f"-ofixed={dico[id]['publicid']}", f"-ouid={dico[id]['privateid']}", f"-a{dico[id]['secretkey']}", "-y"])
|
subprocess.check_call(["ykpersonalize", "-1", f"-ofixed={dico[id]['publicid']}", f"-ouid={dico[id]['privateid']}", f"-a{dico[id]['secretkey']}", "-y"])
|
||||||
|
get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&id={str(id)}")
|
||||||
return "Ok"
|
return "Ok"
|
||||||
|
|
||||||
|
@app.route("/delyubi")
|
||||||
|
def del_yubi():
|
||||||
|
if not request.args.get("id"):
|
||||||
|
return "Error"
|
||||||
|
|
||||||
|
try:
|
||||||
|
id = int(request.args.get("id"))
|
||||||
|
except:
|
||||||
|
return "Error"
|
||||||
|
|
||||||
|
with shelve.open("Settings.conf", writeback = True) as settings:
|
||||||
|
if id not in settings["register"]:
|
||||||
|
return "Error"
|
||||||
|
else:
|
||||||
|
del settings["register"][settings["register"].index(id)]
|
||||||
|
return "Ok"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True, port=6000, host="0.0.0.0")
|
app.run(debug=True, port=6000, host="0.0.0.0")
|
||||||
|
|
15
lock.py
15
lock.py
|
@ -1,5 +1,5 @@
|
||||||
from gpiozero import LED
|
from gpiozero import LED
|
||||||
import shelve
|
import shelve, io, requests
|
||||||
|
|
||||||
led = LED(17)
|
led = LED(17)
|
||||||
|
|
||||||
|
@ -15,16 +15,19 @@ def state(current : bool = None):
|
||||||
return settings["state"]
|
return settings["state"]
|
||||||
|
|
||||||
|
|
||||||
def unlock():
|
def unlock(keyid = None):
|
||||||
led.on()
|
led.on()
|
||||||
state(True)
|
state(True)
|
||||||
|
mac = io.open("/sys/class/net/wlan0/address").read()
|
||||||
|
requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=unlock&id={str(keyid)}")
|
||||||
|
|
||||||
def lock():
|
def lock(keyid = None):
|
||||||
led.off()
|
led.off()
|
||||||
state(False)
|
state(False)
|
||||||
|
requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=lock&id={str(keyid)}")
|
||||||
|
|
||||||
def switch():
|
def switch(keyid = None):
|
||||||
if state():
|
if state():
|
||||||
lock()
|
lock(keyid)
|
||||||
else:
|
else:
|
||||||
unlock()
|
unlock(keyid)
|
||||||
|
|
|
@ -14,4 +14,4 @@ while True:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
lock.switch()
|
lock.switch(id)
|
||||||
|
|
Reference in a new issue