initial commit

master
Bryan 2020-12-18 23:56:03 -06:00
commit 3e98e31466
9 changed files with 203 additions and 0 deletions

55
doorcontrol-main.cgi Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
# Initialize
PASSWD_FILE="/usr/local/www/cgi-bin/passwd"
QUERY_STRING=$1
LOCKFILE="./doorcontrol-main.lock"
. parse_query_string.sh
#
# Exit if instance already running
if [ -e "$LOCKFILE" ]; then
exit 1
else
touch "$LOCKFILE"
fi
#echo "Content-type: text/html"
#echo
# Check password
read passwd <"${PASSWD_FILE}"
if [ "${param[passwd]}" != "${passwd}" ]; then
echo "Password Incorrect: ${param[passwd]}"
echo "$QUERY_STRING"
rm "$LOCKFILE"
exit 1
fi
LABEL_FILE=$(grep -l pcf8574a /sys/class/gpio/*/*label)
BASE_FILE="$(dirname $LABEL_FILE)/base"
BASE=$(cat $BASE_FILE)
for (( i=0; i<=7; i=i+1 )); do
PIN[$i]=$(($BASE+$i))
done
if [ ! -e "/sys/class/gpio/gpio${PIN[7]}/value" ]; then
echo "${PIN[7]}" > /sys/class/gpio/export
fi
#echo "Waiting ..."
sleep ${param[delay]}
echo "out" > /sys/class/gpio/gpio${PIN[7]}/direction
echo "0" > /sys/class/gpio/gpio${PIN[7]}/value
#echo "UNLOCKED"
sleep 2
echo "1" > /sys/class/gpio/gpio${PIN[7]}/value
#echo "<p>Unlocked</p>"
rm "$LOCKFILE"

57
doorcontrol-main.test Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# Initialize
PASSWD_FILE="/usr/local/www/cgi-bin/passwd"
QUERY_STRING=$1
LOCKFILE="./doorcontrol-main.lock"
. parse_query_string.sh
#
# Exit if instance already running
if [ -e "$LOCKFILE" ]; then
exit 1
else
touch "$LOCKFILE"
fi
#echo "Content-type: text/html"
#echo
#echo "<html>"
# Check password
read passwd <"${PASSWD_FILE}"
if [ "${param[passwd]}" != "${passwd}" ]; then
echo "Password Incorrect: ${param[passwd]}"
echo "$QUERY_STRING"
rm "$LOCKFILE"
exit 1
fi
LABEL_FILE=$(grep -l pcf8574a /sys/class/gpio/*/*label)
BASE_FILE="$(dirname $LABEL_FILE)/base"
BASE=$(cat $BASE_FILE)
for (( i=0; i<=7; i=i+1 )); do
PIN[$i]=$(($BASE+$i))
done
if [ ! -e "/sys/class/gpio/gpio${PIN[7]}/value" ]; then
echo "${PIN[7]}" > /sys/class/gpio/export
fi
#echo "<p>Waiting ...</p>"
#sleep ${param[delay]}
#echo "out" > /sys/class/gpio/gpio${PIN[7]}/direction
#echo "0" > /sys/class/gpio/gpio${PIN[7]}/value
sleep 2
#echo "1" > /sys/class/gpio/gpio${PIN[7]}/value
#echo "<p>Unlocked</p>"
#echo "</html>"
rm "$LOCKFILE"

6
doorstatus-main.cgi Executable file
View File

@ -0,0 +1,6 @@
#! /bin/bash
echo "Content-type: text/html"
echo
echo "LOCKED"

10
env.cgi Executable file
View File

@ -0,0 +1,10 @@
#! /bin/bash
echo "Content-type: html"
echo
echo "<html>"
echo "<pre>"
echo "$(env)"
echo "</pre>"
echo "</html>"

17
parse_query_string.sh Normal file
View File

@ -0,0 +1,17 @@
#! /bin/bash
# This will parse the variable $QUERY_STRING.
# The values will be stored in an associative array.
# The value for a key will be stored in the array element `${param[<KEY>]}`
saveIFS=$IFS
IFS='=&'
XXQuery_string=($QUERY_STRING)
IFS=$saveIFS
declare -A param
for ((i=0; i<${#XXQuery_string[@]}; i+=2))
do
param[${XXQuery_string[i]}]=${XXQuery_string[i+1]}
done

1
passwd Executable file
View File

@ -0,0 +1 @@
c5S8De2TTPkDhkXREzSP

20
reset-gpio Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
LABEL_FILE=$(grep -l pcf8574a /sys/class/gpio/*/*label)
BASE_FILE="$(dirname $LABEL_FILE)/base"
BASE=$(cat $BASE_FILE)
for (( i=0; i<=7; i=i+1 )); do
PIN[$i]=$(($BASE+$i))
echo "${PIN[$i]}"
echo "${PIN[$i]}" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio${PIN[$i]}/direction
echo "1" > /sys/class/gpio/gpio${PIN[$i]}/value
done
#if [ ! -e "/sys/class/gpio/gpio${PIN[7]}/value" ]; then
# echo "${PIN[7]}" > /sys/class/gpio/unexport
#fi

29
test.cgi Executable file
View File

@ -0,0 +1,29 @@
#! /bin/bash
saveIFS=$IFS
IFS='=&'
XXQuery_string=($QUERY_STRING)
IFS=$saveIFS
declare -A param
for ((i=0; i<${#XXQuery_string[@]}; i+=2))
do
param[${XXQuery_string[i]}]=${XXQuery_string[i+1]}
done
echo "Content-type: text/html"
echo
echo "<html>"
#echo "$REQUEST_METHOD"
#echo "$QUERY_STRING"
echo "<body>"
echo "<pre>"
env
echo "</pre>"
echo "<pre>"
echo "delay: ${param[delay]}"
echo "password: ${param[passwd]}"
echo "</pre>"
echo "</body>"
echo "</html>"

8
unlock-main.cgi Executable file
View File

@ -0,0 +1,8 @@
#! /bin/bash
echo "Content-type: text/html"
echo
#echo "<title>Unlock</title>"
sudo /usr/local/www/cgi-bin/doorcontrol-main.cgi "$QUERY_STRING"