Compare commits
No commits in common. "master" and "v3.0.4" have entirely different histories.
28
README.md
28
README.md
|
@ -18,7 +18,7 @@ Falls `/etc/foodoord.conf` nicht vorhanden ist:
|
||||||
|
|
||||||
### Dateiliste
|
### Dateiliste
|
||||||
|
|
||||||
Der Daemon besteht aus folgenden Dateien.
|
Der Deamon besteht aus folgenden Dateien.
|
||||||
|
|
||||||
* foodoor
|
* foodoor
|
||||||
* foodoord
|
* foodoord
|
||||||
|
@ -31,9 +31,9 @@ Zusätzlich sollte für das git-repo eine Config angelegt werden:
|
||||||
/root/.ssh/config
|
/root/.ssh/config
|
||||||
```
|
```
|
||||||
Host git.chaospott.de
|
Host git.chaospott.de
|
||||||
User git
|
User git
|
||||||
Port 2222
|
Port 2222
|
||||||
IdentityFile ~/.ssh/id_chaospott
|
IdentityFile ~/.ssh/id_chaospott
|
||||||
```
|
```
|
||||||
|
|
||||||
Das IdentityFile ist der Deploy-SSH-Key, der im [Repo](https://git.chaospott.de/Chaospott/foodoor-keys) hinterlegt ist.
|
Das IdentityFile ist der Deploy-SSH-Key, der im [Repo](https://git.chaospott.de/Chaospott/foodoor-keys) hinterlegt ist.
|
||||||
|
@ -44,7 +44,7 @@ Das IdentityFile ist der Deploy-SSH-Key, der im [Repo](https://git.chaospott.de/
|
||||||
### Schlüsselupdate
|
### Schlüsselupdate
|
||||||
|
|
||||||
`foodoor-update-keydb`
|
`foodoor-update-keydb`
|
||||||
Aktualisiert die Schlüssel auf der Tür und baut die *Authorized_Keys* für die User *open* und *close*. Keys die nicht dem OpenSSH-Format mit 4096 bit entsprechen, werden ignoriert. Wenn das Script von Hand aufgerufen wird, werden die betroffenen Keys angezeigt. Über einen Cronjob werden die Keys alle **5 Min aktualisiert**.
|
Aktualisiert die die Schlüssel auf der Tür und baut die *Authorized_Keys* für die User *open* und *close*. Keys die nicht dem OpenSSH-Format mit 4096 bit entsprechen, werden ignoriert. Wenn das Script von Hand aufgerufen wird, werden die betroffenen Keys angezeigt. Über einen Cronjob werden die Keys alle **5 Min aktualisiert**.
|
||||||
|
|
||||||
### Schlüsselformate
|
### Schlüsselformate
|
||||||
|
|
||||||
|
@ -56,30 +56,30 @@ Der foodoord akzeptiert nur Pub-Keys im *OpenSSH2-Format*. Keys lassen sich unte
|
||||||
|
|
||||||
* Mit `ssh-keygen -b 4096` lassen sich Keys generieren.
|
* Mit `ssh-keygen -b 4096` lassen sich Keys generieren.
|
||||||
* `ssh-add $Pfad_zum_Key` fügt den Key dem ssh-Agent hinzu. Die Option `ssh-add -l` zeigt geladene Keys an.
|
* `ssh-add $Pfad_zum_Key` fügt den Key dem ssh-Agent hinzu. Die Option `ssh-add -l` zeigt geladene Keys an.
|
||||||
* `ssh-kegen -l -f $Pfad_zum_Key` gibt den Fingerprint und andere Informationen zurück.
|
* `ssh-kegen -l -f $Pfad_zum_Key ` gibt den Fingerprint und andere Informationen zurück.
|
||||||
|
|
||||||
|
|
||||||
#### Keys konvertieren (PuTTy > OpenSSH):
|
####Keys konvertieren(PuTTy>OpenSSH):####
|
||||||
|
|
||||||
* `ssh-keygen -i $Pfad_zum_Key > $Pfad_neuer_Pfad.pub<` liest ssh2-kompatible Keys (RFC 4716) ein und speichert diese im OpenSSH-Format.
|
* `ssh-keygen -i $Pfad_zum_Key > $Pfad_neuer_Pfad.pub<` liest ssh2-kompatible Keys(RFC 4716) ein und speichert diese im OpenSSH-Format.
|
||||||
|
|
||||||
|
|
||||||
### PuTTy
|
###PuTTy###
|
||||||
|
|
||||||
Da die Tür nur Keys im OpenSSH-Format verträgt, dürfen auch mit Putty nur OpenSSH-Keys genutzt werden.
|
Da die Tür nur Keys im OpenSSH-Format verträgt, dürfen auch mit Putty nur OpenSSH-Keys genutzt werden.
|
||||||
|
|
||||||
#### Keys generieren (OpenSSH-Format mit PuttyGen):
|
###Keys generieren (OpenSSH-Format mit PuttyGen):###
|
||||||
|
|
||||||
1. PuTTYgen öffnen
|
1. PuTTYgen öffnen
|
||||||
2. Unten "Number of Bits in a generated Key:" 4096 eintippen
|
2. Unten "Number of Bits in a generated Key:" 4096 eintippen
|
||||||
3. "Generate" klicken um Key zu generieren
|
3. "Generate" klicken um Key zu generieren
|
||||||
4. Nach dem Generieren oben im Menu "Conversions" > "Export OpenSSH-Key"
|
4. Nach dem generieren oben im Menu "Conversions" > "Export OpenSSH-Key"
|
||||||
5. Speichern
|
5. Speichern
|
||||||
|
|
||||||
Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das heißt, falls der generierte Key vor dem Export nicht gespeichert wurde, muss der private Key noch konvertiert werden, siehe nächster Punkt!
|
Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das heißt, falls der generierte Key vor dem Export nicht gespeichert wurde, muss der private Key noch konvertiert werden, siehe nächster Punkt!
|
||||||
|
|
||||||
|
|
||||||
#### Keys konvertieren (OpenSSH > PuTTy):
|
###Keys konvertieren(OpenSSH>PuTTy):###
|
||||||
|
|
||||||
1. PuTTYgen öffnen
|
1. PuTTYgen öffnen
|
||||||
2. "Load" drücken
|
2. "Load" drücken
|
||||||
|
@ -88,7 +88,8 @@ Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das hei
|
||||||
5. Speichern
|
5. Speichern
|
||||||
|
|
||||||
|
|
||||||
## Hardware
|
|
||||||
|
##Hardware
|
||||||
|
|
||||||
### Input:
|
### Input:
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das hei
|
||||||
* Klingel
|
* Klingel
|
||||||
* Statustaster
|
* Statustaster
|
||||||
|
|
||||||
|
|
||||||
### Output:
|
### Output:
|
||||||
|
|
||||||
* Status LEDs
|
* Status LEDs
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
VERSION=3.1.0
|
VERSION=3.0.4
|
||||||
dpkg-deb --root-owner-group -b debian "foodoord_${VERSION}_all.deb"
|
dpkg-deb --root-owner-group -b debian foodoord_${VERSION}_all.deb
|
||||||
|
|
15
debian/DEBIAN/postinst
vendored
15
debian/DEBIAN/postinst
vendored
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Creating group and users.."
|
echo "Creating group and users.."
|
||||||
groupadd foodoor
|
groupadd foodoor
|
||||||
useradd -M -d /var/lib/foodoor/close -G foodoor -s /bin/sh close
|
useradd -M -d /var/lib/foodoor/close -G foodoor -s /bin/sh close
|
||||||
|
@ -8,8 +7,8 @@ useradd -M -d /var/lib/foodoor/door -G foodoor -s /bin/sh door
|
||||||
|
|
||||||
echo "Chown homes"
|
echo "Chown homes"
|
||||||
for u in close open door; do
|
for u in close open door; do
|
||||||
groupadd ${u}
|
groupadd ${u}
|
||||||
chown ${u}:${u} /var/lib/foodoor/${u}
|
chown ${u}:${u} /var/lib/foodoor/${u}
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Chmod foodoor"
|
echo "Chmod foodoor"
|
||||||
|
@ -21,8 +20,8 @@ chown root:foodoor /state
|
||||||
chmod 664 /state
|
chmod 664 /state
|
||||||
|
|
||||||
echo "##################"
|
echo "##################"
|
||||||
while [ "$prompt" != "oben" ] && [ "$prompt" != "unten" ]; do
|
while [ "$prompt" != "oben" -a "$prompt" != "unten" ]; do
|
||||||
read -r -p "Sind wir oben oder unten? (oben, unten): " prompt
|
read -p "Sind wir oben oder unten? (oben, unten): " prompt
|
||||||
done
|
done
|
||||||
echo "##################"
|
echo "##################"
|
||||||
|
|
||||||
|
@ -31,6 +30,6 @@ pip install pifacecommon pifacedigitalio
|
||||||
|
|
||||||
echo "Enabling and starting systemd-Services"
|
echo "Enabling and starting systemd-Services"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable "foodoord@$prompt"
|
systemctl enable foodoord@$prompt
|
||||||
systemctl restart "foodoord@$prompt"
|
systemctl restart foodoord@$prompt
|
||||||
systemctl status "foodoord@$prompt"
|
systemctl status foodoord@$prompt
|
||||||
|
|
2
debian/etc/systemd/system/foodoord@.service
vendored
2
debian/etc/systemd/system/foodoord@.service
vendored
|
@ -9,5 +9,7 @@ ExecStart=/usr/sbin/foodoord_%i
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
45
debian/usr/sbin/foodoor
vendored
45
debian/usr/sbin/foodoor
vendored
|
@ -1,34 +1,37 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
PIPE_PATH=/var/run/foodoord.pipe
|
PIPE_PATH=/var/run/foodoord.pipe
|
||||||
|
|
||||||
if [ ! -e $PIPE_PATH ]; then
|
if [ ! -e $PIPE_PATH ]
|
||||||
echo "Pipe missing. Check daemon status."
|
then
|
||||||
exit 1
|
echo "Pipe missing. Check daemon status."
|
||||||
fi
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
action=$1
|
action="$1"
|
||||||
isTriggerActivated=0
|
isTriggerActivated="0"
|
||||||
|
|
||||||
if [ -z "$action" ]; then
|
if [ -z "$action" ]
|
||||||
action=$SSH_ORIGINAL_COMMAND
|
then
|
||||||
isTriggerActivated=1
|
action="$SSH_ORIGINAL_COMMAND"
|
||||||
fi
|
isTriggerActivated="1"
|
||||||
|
fi
|
||||||
|
|
||||||
case $action in
|
case $action in
|
||||||
close | open)
|
close|open)
|
||||||
echo "$action" | tee "$PIPE_PATH" | sed 's/open/UNLOCKED/;s/close/LOCKED/' > /state
|
echo $action | tee $PIPE_PATH |sed 's/open/UNLOCKED/;s/close/LOCKED/' > /state
|
||||||
;;
|
;;
|
||||||
status) ;;
|
status)
|
||||||
*)
|
;;
|
||||||
echo "Usage: $(basename "$0") { close, open, status }"
|
*)
|
||||||
|
echo "Usage: $(basename $0) { close, open, status }"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ $isTriggerActivated -eq 1 ]; then
|
if [ $isTriggerActivated -eq 1 ]
|
||||||
cat /state
|
then
|
||||||
sleep 2
|
cat /state
|
||||||
|
sleep 2
|
||||||
fi
|
fi
|
||||||
|
|
75
debian/usr/sbin/foodoor-update-keydb
vendored
75
debian/usr/sbin/foodoor-update-keydb
vendored
|
@ -4,51 +4,60 @@ set -e
|
||||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||||
|
|
||||||
dest=/var/run/foodoor-keys
|
dest=/var/run/foodoor-keys
|
||||||
temp_outfile=$dest.tmp
|
temp_outfile="$dest.tmp"
|
||||||
|
|
||||||
if [ ! -e "$dest/.git/config" ]; then
|
|
||||||
#echo "Repo does not exist, trying to clone..."
|
if [ ! -e "${dest}/.git/config" ]
|
||||||
git -C "$dest" clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "$dest"
|
then
|
||||||
|
#echo "Repo does not exist, trying to clone..."
|
||||||
|
( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${dest}" )
|
||||||
else
|
else
|
||||||
#echo "Repo exists, updating..."
|
#echo "Repo exists, updating..."
|
||||||
git -C "$dest" fetch --quiet && git -C "$dest" merge --quiet origin/master master
|
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$temp_outfile"
|
rm -f ${temp_outfile}
|
||||||
find "$dest/keys" -type f -name '*.pub' | sort |
|
find "${dest}/keys" -name '*.pub' | sort | \
|
||||||
while read -r keyfile; do
|
while read keyfile
|
||||||
if ssh-keygen -l -f "$keyfile" &> /dev/null; then
|
do
|
||||||
keyinfo=$(ssh-keygen -l -f "$keyfile") # The whole key information
|
ssh-keygen -l -f ${keyfile} &> /dev/null
|
||||||
crypto=$(echo "$keyinfo" | sed 's/.*(\(.*\))/\1/') # Looks like "RSA" or "ED25519"
|
if [ $? -eq 0 ]; then
|
||||||
key_length=$(echo "$keyinfo" | cut -d" " -f1)
|
valid=false
|
||||||
|
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
|
||||||
|
crypto=$(echo "${keyinfo}" | sed 's/.*(\(.*\))/\1/') # Looks like "RSA" or "ED25519"
|
||||||
|
key_length=$(echo "${keyinfo}" | cut -d" " -f1)
|
||||||
|
|
||||||
if [ "$crypto" == "RSA" ]; then
|
if [ "${crypto}" == "RSA" ]; then
|
||||||
if [ "$key_length" -lt 4096 ]; then
|
|
||||||
echo "Key size of key $keyfile less than 4096. Not adding it to key database." >&2
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# valid
|
|
||||||
elif [ "$crypto" == "ED25519" ]; then
|
|
||||||
: # valid
|
|
||||||
else
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(sed 's/\r//g' "$keyfile") $keyfile" >> $temp_outfile
|
if [ ${key_length} -lt 4096 ]; then
|
||||||
|
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
|
||||||
|
continue
|
||||||
|
else
|
||||||
|
valid=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "${crypto}" == "ED25519" ]; then
|
||||||
|
valid=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$valid" = true ]; then
|
||||||
|
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile} | sed 's/\r//g') ${keyfile}" >> ${temp_outfile}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
for appendix in open close door; do
|
for appendix in open close door
|
||||||
action=$appendix
|
do
|
||||||
|
action="$appendix"
|
||||||
if [ "$appendix" = "door" ]; then
|
if [ "$appendix" = "door" ]; then
|
||||||
action=""
|
action=""
|
||||||
fi
|
fi
|
||||||
export action
|
export action
|
||||||
|
|
||||||
outfile=$dest/authorized_keys.$appendix
|
outfile="${dest}/authorized_keys.${appendix}"
|
||||||
envsubst < "$temp_outfile" > "$outfile"
|
cat ${temp_outfile} |envsubst > ${outfile}
|
||||||
|
|
||||||
# Oben und unten
|
# Oben und unten
|
||||||
install -d -o "$appendix" -g nogroup -m 0700 "/var/lib/foodoor/$appendix/.ssh"
|
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
|
||||||
install -b -S .last -o "$appendix" -g nogroup -m 0600 "$outfile" "/var/lib/foodoor/$appendix/.ssh/authorized_keys"
|
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
|
||||||
done
|
done
|
||||||
|
|
211
debian/usr/sbin/foodoord_oben
vendored
211
debian/usr/sbin/foodoord_oben
vendored
|
@ -1,136 +1,143 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# vim: ts=2 sw=2 et
|
# vim: ts=2 sw=2 et
|
||||||
|
|
||||||
import grp
|
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import signal
|
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
import pifacedigitalio
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import grp
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
import pifacedigitalio
|
#Read config
|
||||||
|
|
||||||
# Definitions for output
|
|
||||||
LED_RED = 6
|
|
||||||
LED_GREEN = 7
|
|
||||||
RELAYS_LOCK = 0
|
|
||||||
RELAYS_UNLOCK = 1
|
|
||||||
|
|
||||||
# Definitions for input
|
|
||||||
DOOR_BELL = 0
|
|
||||||
REED_RELAYS = 1 # not implemented yet
|
|
||||||
|
|
||||||
# Definitions for LED color
|
|
||||||
RED = 1
|
|
||||||
GREEN = 2
|
|
||||||
ORANGE = 3
|
|
||||||
|
|
||||||
# Read config
|
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read('/etc/foodoord.conf')
|
parser.read('/etc/foodoord.conf')
|
||||||
|
|
||||||
DOORAPI = parser.get('doorstatus', 'status_url')
|
doorapi = parser.get('doorstatus', 'status_url')
|
||||||
CONSUMERKEY = parser.get('doorstatus', 'key')
|
consumerkey = parser.get('doorstatus', 'key')
|
||||||
CONSUMERSECRET = parser.get('doorstatus', 'secret')
|
consumersecret = parser.get('doorstatus', 'secret')
|
||||||
|
|
||||||
|
|
||||||
|
#Definitions for output
|
||||||
|
LED_RED=6
|
||||||
|
LED_GREEN=7
|
||||||
|
RELAYS_LOCK=0
|
||||||
|
RELAYS_UNLOCK=1
|
||||||
|
|
||||||
|
#Definitions for input
|
||||||
|
DOOR_BELL=0
|
||||||
|
REED_RELAYS=1 #not implementet yet
|
||||||
|
|
||||||
|
#Definitions for LEDcolor
|
||||||
|
RED=1
|
||||||
|
GREEN=2
|
||||||
|
ORANGE=3
|
||||||
|
|
||||||
|
|
||||||
def update_api(locked):
|
def update_api(locked):
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([
|
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"aerie\": " + str(locked).lower() + " }' '" + doorapi + "' ")
|
||||||
"/usr/bin/curl", "-XPOST",
|
|
||||||
"--header", "Content-Type: application/json",
|
|
||||||
"--data",
|
|
||||||
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "aerie": locked})
|
|
||||||
])
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def set_led(color):
|
if __name__ == "__main__":
|
||||||
if color == RED:
|
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
def doorbell(event):
|
||||||
pifacedigital.leds[LED_GREEN].turn_off()
|
if (STATUS):
|
||||||
elif color == GREEN:
|
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||||
pifacedigital.leds[LED_GREEN].turn_on()
|
time.sleep(2)
|
||||||
pifacedigital.leds[LED_RED].turn_off()
|
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||||
elif color == ORANGE:
|
#print 'got doorbell'
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
|
||||||
pifacedigital.leds[LED_GREEN].turn_on()
|
def close_button(event):
|
||||||
|
global STATUS
|
||||||
|
STATUS = False
|
||||||
|
try:
|
||||||
|
update_api(True)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
set_led(RED)
|
||||||
|
|
||||||
|
|
||||||
class Foodoord:
|
listener = pifacedigitalio.InputEventListener()
|
||||||
def __init__(self):
|
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
|
||||||
self.status_open = False
|
listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, close_button, settle_time=5)
|
||||||
|
listener.activate()
|
||||||
|
|
||||||
self.listener = pifacedigitalio.InputEventListener()
|
def signal_handler(signal, frame):
|
||||||
self.listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, self.doorbell, settle_time=10)
|
listener.deactivate()
|
||||||
self.listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, self.close_button, settle_time=5)
|
os.remove("/var/run/foodoord.pipe")
|
||||||
|
|
||||||
def signal_handler(self, _signal, _frame):
|
try:
|
||||||
self.listener.deactivate()
|
update_api(True)
|
||||||
os.remove("/var/run/foodoord.pipe")
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
update_api(True)
|
set_led(RED)
|
||||||
set_led(RED)
|
sys.exit(0)
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
def doorbell(self, event):
|
def set_led(color):
|
||||||
if self.status_open:
|
if (color==RED):
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
pifacedigital.leds[LED_RED].turn_on()
|
||||||
time.sleep(2)
|
pifacedigital.leds[LED_GREEN].turn_off()
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
|
||||||
|
|
||||||
def close_button(self, _event):
|
elif (color==GREEN):
|
||||||
self.status_open = False
|
pifacedigital.leds[LED_GREEN].turn_on()
|
||||||
update_api(True)
|
pifacedigital.leds[LED_RED].turn_off()
|
||||||
set_led(RED)
|
|
||||||
|
|
||||||
def main(self):
|
elif (color==ORANGE):
|
||||||
self.listener.activate()
|
pifacedigital.leds[LED_RED].turn_on()
|
||||||
|
pifacedigital.leds[LED_GREEN].turn_on()
|
||||||
|
|
||||||
pifacedigital = pifacedigitalio.PiFaceDigital()
|
pifacedigital = pifacedigitalio.PiFaceDigital()
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
|
||||||
# Start settings
|
#Startsettings
|
||||||
pifacedigital.leds[LED_RED].turn_on()
|
STATUS = False
|
||||||
|
pifacedigital.leds[LED_RED].turn_on()
|
||||||
|
|
||||||
|
#Setting up FiFo to get sshd-output
|
||||||
|
try:
|
||||||
|
os.mkfifo("/var/run/foodoord.pipe")
|
||||||
|
os.chown("/var/run/foodoord.pipe", -1, grp.getgrnam('foodoor')[2])
|
||||||
|
os.chmod("/var/run/foodoord.pipe", stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with open("/var/run/foodoord.pipe", "r") as ssh_input:
|
||||||
|
while 1:
|
||||||
|
#Read sshd-output from pipe
|
||||||
|
Pipe = ssh_input.readline()[:-1]
|
||||||
|
|
||||||
|
if (Pipe == "close" and STATUS):
|
||||||
|
pifacedigital.relays[RELAYS_LOCK].toggle()
|
||||||
|
time.sleep(1)
|
||||||
|
pifacedigital.relays[RELAYS_LOCK].toggle()
|
||||||
|
STATUS = False
|
||||||
|
|
||||||
# Setting up FiFo to get sshd-output
|
|
||||||
try:
|
try:
|
||||||
os.mkfifo("/var/run/foodoord.pipe")
|
update_api(True)
|
||||||
os.chown("/var/run/foodoord.pipe", -1, grp.getgrnam('foodoor')[2])
|
except:
|
||||||
os.chmod("/var/run/foodoord.pipe", stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
|
pass
|
||||||
except OSError:
|
|
||||||
|
set_led(RED)
|
||||||
|
|
||||||
|
elif (Pipe == "open"):
|
||||||
|
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||||
|
time.sleep(2)
|
||||||
|
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
||||||
|
|
||||||
|
if (STATUS==False):
|
||||||
|
|
||||||
|
try:
|
||||||
|
update_api(False)
|
||||||
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ssh_input = open("/var/run/foodoord.pipe", "r")
|
STATUS = True
|
||||||
while True:
|
|
||||||
# Read sshd-output from pipe
|
|
||||||
pipe_cmd = ssh_input.readline().strip()
|
|
||||||
|
|
||||||
if pipe_cmd == "close" and self.status_open:
|
set_led(GREEN)
|
||||||
pifacedigital.relays[RELAYS_LOCK].toggle()
|
time.sleep(0.1)
|
||||||
time.sleep(1)
|
|
||||||
pifacedigital.relays[RELAYS_LOCK].toggle()
|
|
||||||
|
|
||||||
self.status_open = False
|
|
||||||
update_api(True)
|
|
||||||
set_led(RED)
|
|
||||||
|
|
||||||
elif pipe_cmd == "open":
|
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
|
||||||
time.sleep(2)
|
|
||||||
pifacedigital.relays[RELAYS_UNLOCK].toggle()
|
|
||||||
|
|
||||||
if not self.status_open:
|
|
||||||
update_api(False)
|
|
||||||
self.status_open = True
|
|
||||||
set_led(GREEN)
|
|
||||||
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
Foodoord().main()
|
|
||||||
|
|
161
debian/usr/sbin/foodoord_unten
vendored
161
debian/usr/sbin/foodoord_unten
vendored
|
@ -1,100 +1,97 @@
|
||||||
#!/usr/bin/env python3
|
#! /usr/bin/python3
|
||||||
# vim: ts=2 sw=2 et
|
# vim: ts=2 sw=2 et
|
||||||
|
|
||||||
import grp
|
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
|
||||||
import time
|
import time
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import RPi.GPIO as gpio
|
||||||
|
import grp
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
import RPi.GPIO as gpio
|
#Read config
|
||||||
|
|
||||||
# Definitions for output
|
|
||||||
LED_RED = 6
|
|
||||||
LED_GREEN = 7
|
|
||||||
RELAYS_LOCK = 0
|
|
||||||
RELAYS_UNLOCK = 1
|
|
||||||
PIN_OPEN = 24
|
|
||||||
PIN_CLOSE = 27
|
|
||||||
# Definitions for input
|
|
||||||
DOOR_BELL = 0
|
|
||||||
REED_RELAYS = 1 # not implemented yet
|
|
||||||
|
|
||||||
# Definitions for LED color
|
|
||||||
RED = 1
|
|
||||||
GREEN = 2
|
|
||||||
ORANGE = 3
|
|
||||||
|
|
||||||
# Read config
|
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read('/etc/foodoord.conf')
|
parser.read('/etc/foodoord.conf')
|
||||||
|
|
||||||
DOORAPI = parser.get('doorstatus', 'status_url')
|
doorapi = parser.get('doorstatus', 'status_url')
|
||||||
CONSUMERKEY = parser.get('doorstatus', 'key')
|
consumerkey = parser.get('doorstatus', 'key')
|
||||||
CONSUMERSECRET = parser.get('doorstatus', 'secret')
|
consumersecret = parser.get('doorstatus', 'secret')
|
||||||
|
|
||||||
|
#Definitions for output
|
||||||
|
LED_RED=6
|
||||||
|
LED_GREEN=7
|
||||||
|
RELAYS_LOCK=0
|
||||||
|
RELAYS_UNLOCK=1
|
||||||
|
PIN_OPEN=24
|
||||||
|
PIN_CLOSE=27
|
||||||
|
#Definitions for input
|
||||||
|
DOOR_BELL=0
|
||||||
|
REED_RELAYS=1 #not implementet yet
|
||||||
|
|
||||||
|
#Definitions for LEDcolor
|
||||||
|
RED=1
|
||||||
|
GREEN=2
|
||||||
|
ORANGE=3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write_state(state):
|
def write_state(state):
|
||||||
try:
|
try:
|
||||||
with open("/tmp/door_state", "w") as handle:
|
handle = open("/tmp/door_state", "w")
|
||||||
handle.write(state)
|
handle.write(state)
|
||||||
except:
|
handle.close()
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_api(locked):
|
def update_api(locked):
|
||||||
try:
|
try:
|
||||||
subprocess.check_call([
|
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"cellar\": " + str(locked).lower() + " }' '" + doorapi + "' ")
|
||||||
"/usr/bin/curl", "-XPOST",
|
except:
|
||||||
"--header", "Content-Type: application/json",
|
pass
|
||||||
"--data",
|
|
||||||
json.dumps({"consumer_key": CONSUMERKEY, "consumer_secret": CONSUMERSECRET, "cellar": locked}),
|
|
||||||
DOORAPI
|
|
||||||
])
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Start settings
|
|
||||||
gpio.setmode(gpio.BCM)
|
|
||||||
gpio.setup(PIN_OPEN, gpio.OUT)
|
|
||||||
gpio.setup(PIN_CLOSE, gpio.OUT)
|
|
||||||
|
|
||||||
# Setting up FiFo to get sshd-output
|
|
||||||
try:
|
|
||||||
os.mkfifo("/var/run/foodoord.pipe")
|
|
||||||
os.chown("/var/run/foodoord.pipe", -1, grp.getgrnam('foodoor')[2])
|
|
||||||
os.chmod("/var/run/foodoord.pipe", stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
ssh_input = open("/var/run/foodoord.pipe", "r")
|
|
||||||
while True:
|
|
||||||
# Read sshd output from pipe
|
|
||||||
pipe_cmd = ssh_input.readline().strip()
|
|
||||||
|
|
||||||
if pipe_cmd == "close":
|
|
||||||
gpio.output(PIN_CLOSE, 1)
|
|
||||||
time.sleep(1)
|
|
||||||
gpio.output(PIN_CLOSE, 0)
|
|
||||||
|
|
||||||
write_state("closed")
|
|
||||||
update_api(True)
|
|
||||||
|
|
||||||
elif pipe_cmd == "open":
|
|
||||||
# Locking
|
|
||||||
gpio.output(PIN_OPEN, 1)
|
|
||||||
time.sleep(1)
|
|
||||||
gpio.output(PIN_OPEN, 0)
|
|
||||||
|
|
||||||
write_state("open") # Save State
|
|
||||||
update_api(False) # Status Update
|
|
||||||
|
|
||||||
time.sleep(0.2)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
|
||||||
|
#Startsettings
|
||||||
|
STATUS=False
|
||||||
|
gpio.setmode(gpio.BCM)
|
||||||
|
gpio.setup(PIN_OPEN, gpio.OUT)
|
||||||
|
gpio.setup(PIN_CLOSE, gpio.OUT)
|
||||||
|
#Setting up FiFo to get sshd-output
|
||||||
|
try:
|
||||||
|
os.mkfifo("/var/run/foodoord.pipe")
|
||||||
|
os.chown("/var/run/foodoord.pipe", -1, grp.getgrnam('foodoor')[2])
|
||||||
|
os.chmod("/var/run/foodoord.pipe", stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with open("/var/run/foodoord.pipe", "r") as ssh_input:
|
||||||
|
while 1:
|
||||||
|
#Read sshd-output from pipe
|
||||||
|
Pipe = ssh_input.readline()[:-1]
|
||||||
|
|
||||||
|
if (Pipe == "close"):
|
||||||
|
gpio.output(PIN_CLOSE,1)
|
||||||
|
time.sleep(1)
|
||||||
|
gpio.output(PIN_CLOSE,0)
|
||||||
|
|
||||||
|
write_state("closed")
|
||||||
|
update_api(True)
|
||||||
|
|
||||||
|
|
||||||
|
elif (Pipe == "open"):
|
||||||
|
|
||||||
|
#Locking
|
||||||
|
gpio.output(PIN_OPEN,1)
|
||||||
|
time.sleep(1)
|
||||||
|
gpio.output(PIN_OPEN,0)
|
||||||
|
|
||||||
|
#Save State
|
||||||
|
write_state("open")
|
||||||
|
|
||||||
|
#Status Update
|
||||||
|
update_api(False)
|
||||||
|
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user