fix codestyle, indentation and shellcheck issue
This commit is contained in:
parent
9c6ae81f57
commit
b72f931c26
|
@ -1,31 +1,26 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
header() {
|
header() {
|
||||||
echo -e 'Content-type: text/html\nStrict-Transport-Security: max-age=86400000\n'
|
printf 'Content-type: text/html\nStrict-Transport-Security: max-age=86400000\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
# extract parameters
|
# extract parameters
|
||||||
# tr -dc removes all characters, this prevents things like xss
|
# tr -cd removes all characters, this prevents things like xss
|
||||||
getp() {
|
getp() {
|
||||||
echo "$REQUEST_URI" | sed 's/.*?//' | sed 's/%20/ /g' \
|
echo "$REQUEST_URI" | sed 's/.*?//' | sed 's/%20/ /g' \
|
||||||
| tr "?&" "\n" | tr --complement --delete "0-9a-z_= \n" | egrep "^$1=" | sed "s/^$1=//"
|
| tr '?&' '\n' | tr --complement --delete '0-9a-z_= \n' \
|
||||||
|
| grep --extended-regexp "^$1=" | sed "s/^$1=//"
|
||||||
}
|
}
|
||||||
|
|
||||||
#header
|
secret="$(getp secret)"
|
||||||
#echo "anz $# "
|
secret_length="$(echo "$secret" | wc --chars)"
|
||||||
#echo "alle $@"
|
hashed_secret="$(echo "$secret" | sha512sum | cut -f1 -d\ )"
|
||||||
#printenv
|
|
||||||
#exit
|
|
||||||
|
|
||||||
secret=$(getp secret)
|
|
||||||
secret_length=`echo $secret | wc --chars`
|
|
||||||
hashed_secret=$(echo "$secret" | sha512sum | cut -f1 -d\ )
|
|
||||||
cmd=$(getp cmd)
|
cmd=$(getp cmd)
|
||||||
|
|
||||||
# check secret
|
# check secret
|
||||||
# the secrets file has to contain the hashes on a single line, comments are allowed on seperate lines
|
# the secrets file has to contain the hashes on a single line, comments are allowed on seperate lines
|
||||||
# secrets can only contain the characters that are allowed in getp() with tr -dc
|
# secrets can only contain the characters that are allowed in getp() with tr -cd
|
||||||
if [ -z "$secret" ] || [ $secret_length -lt 30 ] || ! grep -q ";$hashed_secret$" /etc/tuer3.0/door_access_list; then
|
if [ -z "$secret" ] || [ "$secret_length" -lt 30 ] || ! grep -q ";$hashed_secret$" /etc/tuer3.0/door_access_list; then
|
||||||
header
|
header
|
||||||
[ -z "$secret" ] || echo "<html><p>Ich bin mir nicht sicher. Mir scheint, du bist doch ein Kohlkopf oder Anderes!</p>"
|
[ -z "$secret" ] || echo "<html><p>Ich bin mir nicht sicher. Mir scheint, du bist doch ein Kohlkopf oder Anderes!</p>"
|
||||||
# $hashed_secret"
|
# $hashed_secret"
|
||||||
|
@ -36,13 +31,13 @@ fi
|
||||||
# control relais card
|
# control relais card
|
||||||
if [ -n "$cmd" ]; then
|
if [ -n "$cmd" ]; then
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
# indoor_unlock) pin=17; delay1=0; delay2=1;; unused pin
|
#indoor_unlock) pin=17; delay1=0; delay2=1;; unused pin
|
||||||
indoor_lock) pin=4; delay1=0; delay2=1;;
|
indoor_lock) pin=4; delay1=0; delay2=1;;
|
||||||
indoor_open) pin=27; delay1=0; delay2=1;;
|
indoor_open) pin=27; delay1=0; delay2=1;;
|
||||||
outdoor_buzz) pin=22; delay1=15; delay2=5;;
|
outdoor_buzz) pin=22; delay1=15; delay2=5;;
|
||||||
*) header; echo 'Do not hack the hackerspace!'"$cmd"; exit;;
|
*) header; echo 'Do not hack the hackerspace!'"$cmd"; exit;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# execute long-running ppio job in background shell
|
# execute long-running ppio job in background shell
|
||||||
( sleep $delay1
|
( sleep $delay1
|
||||||
/usr/local/bin/gpio -g write $pin on
|
/usr/local/bin/gpio -g write $pin on
|
||||||
|
@ -50,9 +45,11 @@ if [ -n "$cmd" ]; then
|
||||||
/usr/local/bin/gpio -g write $pin off
|
/usr/local/bin/gpio -g write $pin off
|
||||||
) </dev/null >/dev/null 2>/dev/null &
|
) </dev/null >/dev/null 2>/dev/null &
|
||||||
|
|
||||||
|
DATE="$(date +"%F %T")"
|
||||||
|
echo "$DATE $cmd $hashed_secret" >>/var/log/tuer/log &
|
||||||
|
|
||||||
header
|
header
|
||||||
sed 's/XTIMEOUTX/'"$(($delay1 + $delay2))"'/' /var/www/tpl/wait.html | sed 's/XSECRETX/'"$secret"/
|
sed 's/XTIMEOUTX/'"$((delay1 + delay2))"'/' /var/www/tpl/wait.html | sed 's/XSECRETX/'"$secret"/
|
||||||
exit
|
exit
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue