Lock system & internet control, WIP yubikey control and fix WIP Core import
This commit is contained in:
parent
60d1529c89
commit
72eecaa20c
3 changed files with 46 additions and 9 deletions
14
Setup.py
14
Setup.py
|
@ -1,4 +1,4 @@
|
|||
import io, socket, subprocess
|
||||
import io, socket, subprocess, shelve
|
||||
from requests import post, get
|
||||
from flask import request, Flask
|
||||
#hostapd system
|
||||
|
@ -7,9 +7,6 @@ from flask import request, Flask
|
|||
|
||||
app = Flask(__name__)
|
||||
|
||||
def ap(switch):
|
||||
pass
|
||||
|
||||
def writeconfig(ssid, password):
|
||||
rtline = "\n"
|
||||
with io.open("/etc/wpa_supplicant/wpa_supplicant.conf", "w", encoding="utf8") as note:
|
||||
|
@ -17,10 +14,8 @@ def writeconfig(ssid, password):
|
|||
for i in ["ctrl_interface=/var/run/wpa_supplicant\nupdate_config=1\ncountry=FR\nnetwork={\nssid=\"", ssid, "\"\nscan_ssid=1\npsk=\"", password, "\"\n}"]:
|
||||
conf += i
|
||||
note.write(conf)
|
||||
ap(False)
|
||||
subprocess.check_call(["sudo", "wpa_cli", "-i", "wlan0", "reconfigure"])
|
||||
|
||||
|
||||
def testinternet():
|
||||
result = True
|
||||
try:
|
||||
|
@ -38,11 +33,12 @@ def web_setup():
|
|||
if testinternet():
|
||||
mac = io.open("/sys/class/net/wlan0/address").read()
|
||||
id = request.args.get("id")
|
||||
r = get(f"http://flifloo.ddns.net:5000/locksetup?mac={mac}&id={id}")
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
settings["token"] = id
|
||||
r = get(f"http://vps.flifloo.fr:5000/locksetup?mac={mac}&id={id}")
|
||||
else:
|
||||
ap(True)
|
||||
return "Cant connect"
|
||||
return "Done"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, port=5000, host="0.0.0.0")
|
||||
app.run(debug=True, port=6000, host="0.0.0.0")
|
||||
|
|
29
internet.py
Normal file
29
internet.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from flask import request, Flask
|
||||
import lock, shelve
|
||||
|
||||
app = Flask(__name__)
|
||||
@app.route("/unlock")
|
||||
def web_unlock():
|
||||
if not (request.args.get("token") and request.args.get("state")):
|
||||
return "Error"
|
||||
else:
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
token = settings["token"]
|
||||
if request.args.get("token") != token:
|
||||
return "Invalid Token"
|
||||
if request.args.get("state") == "open":
|
||||
lock.unlock()
|
||||
elif request.args.get("state") == "close":
|
||||
lock.lock()
|
||||
elif request.args.get("state") == "switch":
|
||||
lock.switch()
|
||||
else:
|
||||
return "Invalid State"
|
||||
return "Done"
|
||||
|
||||
@app.route("/state")
|
||||
def web_state():
|
||||
return str(lock.state())
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, port=5000, host="0.0.0.0")
|
12
yubikey.py
Normal file
12
yubikey.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from yubico_client import Yubico
|
||||
import lock, shelve
|
||||
|
||||
with shelve.open("Settings.conf") as settings:
|
||||
client = Yubico(settings["id"], settings["secret"], api_urls=('http://localhost/wsapi/2.0/verify',))
|
||||
while True:
|
||||
try:
|
||||
client.verify(input())
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
lock.switch()
|
Reference in a new issue