Skip to content

Commit

Permalink
print a warning when locking/unlocking via SSH when door is already l…
Browse files Browse the repository at this point in the history
…ocked/unlocked
  • Loading branch information
binaryDiv committed Jul 3, 2019
1 parent fad1a9c commit c0a4718
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 7 additions & 1 deletion opt/afra_door/close.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
shared_secret = f.read()

print("Locking door...")
requests.get("http://127.0.0.1:8001/lock?shared_secret={}".format(shared_secret))

# Try to lock door
response = requests.get("http://127.0.0.1:8001/lock?shared_secret={}".format(shared_secret))

if response.status_code != 200:
print(response.text)

20 changes: 17 additions & 3 deletions opt/afra_door/lock_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,29 @@ http.createServer(function (req, res) {

if (q.searchParams.get("shared_secret") === shared_secret){
if (q.pathname === "/unlock"){
res.write("Opening lock")
if (status_door() === "UNLOCKED") {
// Status code 409 CONFLICT
res.statusCode = 409;
res.write("Door is already UNLOCKED! Try to unlock anyway...");
}
else {
res.write("Opening lock...")
}
unlock_door()
}
else if (q.pathname === "/lock"){
res.write("Closing lock")
if (status_door() === "LOCKED") {
// Status code 409 CONFLICT
res.statusCode = 409;
res.write("Door is already LOCKED! Try to lock anyway...");
}
else {
res.write("Closing lock...")
}
lock_door()
}
else if (q.pathname === "/toggle"){
res.write("Toggling lock (old status: " + status_door() + ")");
res.write("Toggling lock (current status: " + status_door() + ")");
toggle_door();
}
}
Expand Down
8 changes: 7 additions & 1 deletion opt/afra_door/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
shared_secret = f.read()

print("Welcome to AfRA, opening door...")
requests.get("http://127.0.0.1:8001/unlock?shared_secret={}".format(shared_secret))

# Try to unlock door
response = requests.get("http://127.0.0.1:8001/unlock?shared_secret={}".format(shared_secret))

if response.status_code != 200:
print(response.text)

0 comments on commit c0a4718

Please sign in to comment.