From 12be452e56b8861b684f4c82ba660b6a5f6a90a1 Mon Sep 17 00:00:00 2001 From: anthraxx Date: Fri, 6 Feb 2015 23:34:57 +0100 Subject: [PATCH] adding config support for password via shared file --- .gitignore | 1 + dooris.conf.sample | 1 + lock | 3 ++- shared | 13 +++++++++++++ unlock | 3 ++- 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 dooris.conf.sample create mode 100755 shared diff --git a/.gitignore b/.gitignore index bebb0b7..94db856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /challenge/*.o /doorchallenge +/dooris.conf diff --git a/dooris.conf.sample b/dooris.conf.sample new file mode 100644 index 0000000..256d7a5 --- /dev/null +++ b/dooris.conf.sample @@ -0,0 +1 @@ +password=sesamaenderdich diff --git a/lock b/lock index aab2903..a050e64 100755 --- a/lock +++ b/lock @@ -1,4 +1,5 @@ #!/bin/sh +source shared echo "Initializing Space Systems..." echo "22" > /sys/class/gpio/unexport @@ -9,7 +10,7 @@ echo "out" > /sys/class/gpio/gpio22/direction sleep 0.5 echo "Open Communication Channel..." # Silent, Output to /dev/null, Timeout after 5s and retry 12 times, each doubling the waitingtime until ten minutes. -curl -s -o /dev/null -m 5 --connect-timeout 5 --retry 12 "hamburg.ccc.de/dooris/status.php?apikey=sesamaenderdich&action=close" & +curl -s -o /dev/null -m 5 --connect-timeout 5 --retry 12 "hamburg.ccc.de/dooris/status.php?apikey=${password}&action=close" & echo "Locking Space..." echo "1" > /sys/class/gpio/gpio22/value sleep 0.3 diff --git a/shared b/shared new file mode 100755 index 0000000..449bc67 --- /dev/null +++ b/shared @@ -0,0 +1,13 @@ +#!/bin/sh +config="dooris.conf" + +# warn if local config file is missing +if [ ! -f "${config}" ]; then + echo "WARNING: ${config} is missing!" >&2 +fi + +# get password config value in a safe way +password="$(grep password ${config} 2>/dev/null|cut -d= -f2|tr -d ' \t')" +if [ -z "${password}" ]; then + echo "WARNING: password in ${config} is missing!" >&2 +fi diff --git a/unlock b/unlock index 58d4b22..19f1eae 100755 --- a/unlock +++ b/unlock @@ -1,4 +1,5 @@ #!/bin/sh +source shared echo "Initializing Space Systems..." echo "27" > /sys/class/gpio/unexport @@ -8,7 +9,7 @@ echo "Securing Communication to Space Systems..." echo "out" > /sys/class/gpio/gpio27/direction sleep 0.5 echo "Open Communication Channel..." -curl -s -o /dev/null -m 5 --connect-timeout 5 --retry 12 "hamburg.ccc.de/dooris/status.php?apikey=sesamaenderdich&action=open" & +curl -s -o /dev/null -m 5 --connect-timeout 5 --retry 12 "hamburg.ccc.de/dooris/status.php?apikey=${password}&action=open" & echo "Unlocking Space..." echo "1" > /sys/class/gpio/gpio27/value sleep 0.3