Archived
1
0
Fork 0

Lock system & internet control, WIP yubikey control and fix WIP Core import

This commit is contained in:
Ethanell 2019-04-17 16:57:17 +02:00
parent 60d1529c89
commit 72eecaa20c
3 changed files with 46 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import io, socket, subprocess import io, socket, subprocess, shelve
from requests import post, get from requests import post, get
from flask import request, Flask from flask import request, Flask
#hostapd system #hostapd system
@ -7,9 +7,6 @@ from flask import request, Flask
app = Flask(__name__) app = Flask(__name__)
def ap(switch):
pass
def writeconfig(ssid, password): def writeconfig(ssid, password):
rtline = "\n" rtline = "\n"
with io.open("/etc/wpa_supplicant/wpa_supplicant.conf", "w", encoding="utf8") as note: 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}"]: 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 conf += i
note.write(conf) note.write(conf)
ap(False)
subprocess.check_call(["sudo", "wpa_cli", "-i", "wlan0", "reconfigure"]) subprocess.check_call(["sudo", "wpa_cli", "-i", "wlan0", "reconfigure"])
def testinternet(): def testinternet():
result = True result = True
try: try:
@ -38,11 +33,12 @@ def web_setup():
if testinternet(): if testinternet():
mac = io.open("/sys/class/net/wlan0/address").read() mac = io.open("/sys/class/net/wlan0/address").read()
id = request.args.get("id") 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: else:
ap(True)
return "Cant connect" return "Cant connect"
return "Done" return "Done"
if __name__ == "__main__": 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
View 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
View 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()