From 673807b655cc0782fa782da47544be208d00ac03 Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 22 May 2019 15:40:28 +0200 Subject: [PATCH] Lot of little stupid fix --- Core.py | 5 +++++ Setup.py | 3 ++- internet.py | 5 ++++- lock.py | 14 ++++++++++---- yubikey.py | 2 ++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Core.py b/Core.py index a9a3608..c27b4b2 100644 --- a/Core.py +++ b/Core.py @@ -13,3 +13,8 @@ if not isfile("Settings.conf"): with shelve.open("Settings.conf") as settings: settings["keys"] = keys settings["register"] = list() + + +subprocess.check_call(["screen", "-S", "setup", "-d", "-m", "sudo", "python3.7", "Setup.py"]) +subprocess.check_call(["screen", "-S", "internet", "-d", "-m", "sudo", "python3.7", "internet.py"]) +subprocess.check_call(["screen", "-S", "yubikey", "-m", "sudo", "python3.7", "yubikey.py"]) diff --git a/Setup.py b/Setup.py index 36388e6..2baa3bb 100644 --- a/Setup.py +++ b/Setup.py @@ -1,4 +1,4 @@ -import io, socket, subprocess, shelve +import io, socket, subprocess, shelve, time from requests import post, get from flask import request, Flask #hostapd system @@ -32,6 +32,7 @@ def web_setup(): return "Error" else: writeconfig(request.args.get("ssid"), request.args.get("password")) + time.sleep(10) if testinternet(): id = request.args.get("id") with shelve.open("Settings.conf") as settings: diff --git a/internet.py b/internet.py index 7d5f6a8..c03c840 100644 --- a/internet.py +++ b/internet.py @@ -8,7 +8,10 @@ def web_unlock(): return "Error" else: with shelve.open("Settings.conf") as settings: - token = settings["token"] + if "token" in settings: + token = settings["token"] + else: + return "System not setup !" if request.args.get("token") != token: return "Invalid Token" if request.args.get("state") == "open": diff --git a/lock.py b/lock.py index 8324b95..2e55099 100644 --- a/lock.py +++ b/lock.py @@ -1,7 +1,10 @@ -from gpiozero import LED +from gpiozero import LED #OutputDevice import shelve, io, requests +mac = io.open("/sys/class/net/wlan0/address").read() led = LED(17) +#open = OutputDevice(17, initial_value = False) +#close = OutputDevice(27, initial_value = False) def state(current : bool = None): with shelve.open("Settings.conf") as settings: @@ -17,14 +20,17 @@ def state(current : bool = None): def unlock(keyid = None): led.on() + #close.off() + #open.on() 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)}") + r = requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=unlock&id={str(keyid)}") def lock(keyid = None): + #open.off() + #close.on() led.off() state(False) - requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=lock&id={str(keyid)}") + r = requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=lock&id={str(keyid)}") def switch(keyid = None): if state(): diff --git a/yubikey.py b/yubikey.py index 7eec1ee..ab17817 100644 --- a/yubikey.py +++ b/yubikey.py @@ -11,6 +11,8 @@ while True: client = Yubico(id, settings["keys"][id], api_urls=('http://localhost/wsapi/2.0/verify',)) #client = Yubico(1, "QMho+Y4mtsY+KbCYu1gRKtDtwAM=", api_urls=('http://localhost/wsapi/2.0/verify',)) client.verify(inp) + except KeyboardInterrupt: + break except: pass else: