6 Commits

4 changed files with 163 additions and 319 deletions

View File

@ -58,18 +58,26 @@ do
outfile="${dest}/authorized_keys.${appendix}" outfile="${dest}/authorized_keys.${appendix}"
cat ${temp_outfile} |envsubst > ${outfile} cat ${temp_outfile} |envsubst > ${outfile}
# Oben # Oben
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh if [ "$(hostname)" = "foodoor" ]; then
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys 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
fi
# Unten # Unten
#if [ "${action}" = "open" ]; then if [ "$(hostname)" = "kellertuer" ]; then
# owner="unlock" if [ "${action}" = "open" ]; then
#elif [ "${action}" = "close" ]; then owner="unlock"
# owner="lock" elif [ "${action}" = "close" ]; then
#fi owner="lock"
fi
install -d -o ${owner} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
install -b -S .last -o ${owner} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
if [ "${appendix}" = "door" ]; then
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
fi
fi
#install -d -o ${owner} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
#install -b -S .last -o ${owner} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
done done

140
foodoord
View File

@ -1,140 +0,0 @@
#!/usr/bin/env python2
import os
import stat
import time
import pifacedigitalio
import urllib2
import signal
import sys
import grp
from ConfigParser import SafeConfigParser
#Read config
parser = SafeConfigParser()
parser.read('/etc/foodoord.conf')
url = parser.get('door_firstlevel', 'status_url')
old_api = parser.get('door_firstlevel_old', 'status_url')
#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
if __name__ == "__main__":
def doorbell(event):
if (STATUS):
pifacedigital.relays[RELAYS_UNLOCK].toggle()
time.sleep(2)
pifacedigital.relays[RELAYS_UNLOCK].toggle()
#print 'got doorbell'
def close_button(event):
global STATUS
STATUS = False
try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except:
pass
set_led(RED)
listener = pifacedigitalio.InputEventListener()
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, close_button, settle_time=5)
listener.activate()
def signal_handler(signal, frame):
listener.deactivate()
os.remove("/var/run/foodoord.pipe")
try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except:
pass
set_led(RED)
sys.exit(0)
def set_led(color):
if (color==RED):
pifacedigital.leds[LED_RED].turn_on()
pifacedigital.leds[LED_GREEN].turn_off()
elif (color==GREEN):
pifacedigital.leds[LED_GREEN].turn_on()
pifacedigital.leds[LED_RED].turn_off()
elif (color==ORANGE):
pifacedigital.leds[LED_RED].turn_on()
pifacedigital.leds[LED_GREEN].turn_on()
pifacedigital = pifacedigitalio.PiFaceDigital()
signal.signal(signal.SIGTERM, signal_handler)
#Startsettings
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
try:
urllib2.urlopen(url+'&door=aerie&locked=1', timeout=2)
urllib2.urlopen(old_api+'&status=closed', timeout=2)
except:
pass
set_led(RED)
elif (Pipe == "open"):
pifacedigital.relays[RELAYS_UNLOCK].toggle()
time.sleep(2)
pifacedigital.relays[RELAYS_UNLOCK].toggle()
if (STATUS==False):
try:
urllib2.urlopen(url+'&door=aerie&locked=0', timeout=2)
urllib2.urlopen(old_api+'&status=open', timeout=2)
except:
pass
STATUS = True
set_led(GREEN)
time.sleep(0.1)

View File

@ -1,23 +1,24 @@
#! /usr/bin/python #!/usr/bin/env python3
# vim: ts=2 sw=2 et
import os import os
import stat import stat
import time import time
import pifacedigitalio import pifacedigitalio
import requests
import signal import signal
import sys import sys
import grp import grp
from ConfigParser import SafeConfigParser from configparser import ConfigParser
#Read config #Read config
parser = SafeConfigParser() 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 #Definitions for output
LED_RED=6 LED_RED=6
LED_GREEN=7 LED_GREEN=7
@ -33,135 +34,110 @@ RED=1
GREEN=2 GREEN=2
ORANGE=3 ORANGE=3
def update_api(locked):
try:
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"aerie\": " + str(locked).lower() + " }' '" + doorapi + "' ")
except:
pass
if __name__ == "__main__": if __name__ == "__main__":
def doorbell(event):
if (STATUS):
pifacedigital.relays[RELAYS_UNLOCK].toggle()
time.sleep(2)
pifacedigital.relays[RELAYS_UNLOCK].toggle()
#print 'got doorbell'
def doorbell(event): def close_button(event):
if (STATUS): global STATUS
pifacedigital.relays[RELAYS_UNLOCK].toggle() STATUS = False
time.sleep(1.5) try:
pifacedigital.relays[RELAYS_UNLOCK].toggle() update_api(True)
def close_button(event):
global STATUS
STATUS = False
write_state("closed")
update_api(True)
set_led(RED)
listener = pifacedigitalio.InputEventListener()
listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, close_button, settle_time=5)
listener.activate()
def signal_handler(signal, frame):
listener.deactivate()
os.remove("/var/run/foodoord.pipe")
write_state("closed")
update_api(True)
set_led(RED)
sys.exit(0)
def set_led(color):
if (color==RED):
pifacedigital.leds[LED_RED].turn_on()
pifacedigital.leds[LED_GREEN].turn_off()
elif (color==GREEN):
pifacedigital.leds[LED_GREEN].turn_on()
pifacedigital.leds[LED_RED].turn_off()
elif (color==ORANGE):
pifacedigital.leds[LED_RED].turn_on()
pifacedigital.leds[LED_GREEN].turn_on()
pifacedigital = pifacedigitalio.PiFaceDigital()
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
def write_state(state):
try:
handle = open("/tmp/door_state", "w")
handle.write(state)
handle.close()
except: except:
pass pass
def update_api(locked): set_led(RED)
#if locked:
#
# try:
# os.system("/usr/bin/mosquitto_pub -h mqtt.chaospott.de -t foobar/aerie/licht -m 'zentral-aus'")
# except:
# pass
try:
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"aerie\": " + str(locked).lower() + " }' '" + doorapi + "' ")
except:
pass
#Startsettings listener = pifacedigitalio.InputEventListener()
STATUS = False listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10)
pifacedigital.leds[LED_RED].turn_on() listener.register(1, pifacedigitalio.IODIR_RISING_EDGE, close_button, settle_time=5)
listener.activate()
#Setting up FiFo to get sshd-output def signal_handler(signal, frame):
try: listener.deactivate()
os.mkfifo("/var/run/foodoord.pipe") os.remove("/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: try:
while 1: update_api(True)
#Read sshd-output from pipe except:
Pipe = ssh_input.readline()[:-1] pass
if (Pipe == "close" and STATUS):
pifacedigital.relays[RELAYS_LOCK].toggle()
time.sleep(1)
pifacedigital.relays[RELAYS_LOCK].toggle()
STATUS = False
write_state("closed")
update_api(True) set_led(RED)
sys.exit(0)
try: def set_led(color):
r = requests.get(url+'&door=aerie&locked=1', timeout=2) if (color==RED):
#print (r.status_code) pifacedigital.leds[LED_RED].turn_on()
r = requests.get(old_api+'&status=closed', timeout=2) pifacedigital.leds[LED_GREEN].turn_off()
#print (r.status_code)
except:
pass
set_led(RED)
elif (Pipe == "open"): elif (color==GREEN):
pifacedigital.relays[RELAYS_UNLOCK].toggle() pifacedigital.leds[LED_GREEN].turn_on()
time.sleep(1.5) pifacedigital.leds[LED_RED].turn_off()
pifacedigital.relays[RELAYS_UNLOCK].toggle()
if (STATUS==False): elif (color==ORANGE):
pifacedigital.leds[LED_RED].turn_on()
try: pifacedigital.leds[LED_GREEN].turn_on()
r = requests.get(url+"&door=aerie&locked=0", timeout=2)
#print (r.status_code)
r = requests.get(old_api+'&status=open', timeout=2)
#print (r.status_code)
except:
pass
update_api(False)
write_state("open")
STATUS = True pifacedigital = pifacedigitalio.PiFaceDigital()
signal.signal(signal.SIGTERM, signal_handler)
set_led(GREEN)
time.sleep(0.1)
#Startsettings
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
try:
update_api(True)
except:
pass
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
STATUS = True
set_led(GREEN)
time.sleep(0.1)

View File

@ -1,17 +1,17 @@
#! /usr/bin/python #! /usr/bin/python3
# vim: ts=2 sw=2 et
import os import os
import stat import stat
import time import time
import urllib2
import signal import signal
import sys import sys
import RPi.GPIO as gpio import RPi.GPIO as gpio
import grp import grp
from ConfigParser import SafeConfigParser from configparser import ConfigParser
#Read config #Read config
parser = SafeConfigParser() parser = ConfigParser()
parser.read('/etc/foodoord.conf') parser.read('/etc/foodoord.conf')
doorapi = parser.get('doorstatus', 'status_url') doorapi = parser.get('doorstatus', 'status_url')
@ -37,61 +37,61 @@ ORANGE=3
def write_state(state): def write_state(state):
try: try:
handle = open("/tmp/door_state", "w") handle = open("/tmp/door_state", "w")
handle.write(state) handle.write(state)
handle.close() handle.close()
except: except:
pass pass
def update_api(locked): def update_api(locked):
try: try:
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"cellar\": " + str(locked).lower() + " }' '" + doorapi + "' ") os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"cellar\": " + str(locked).lower() + " }' '" + doorapi + "' ")
except: except:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
#Startsettings #Startsettings
STATUS=False STATUS=False
gpio.setmode(gpio.BCM) gpio.setmode(gpio.BCM)
gpio.setup(PIN_OPEN, gpio.OUT) gpio.setup(PIN_OPEN, gpio.OUT)
gpio.setup(PIN_CLOSE, gpio.OUT) gpio.setup(PIN_CLOSE, gpio.OUT)
#Setting up FiFo to get sshd-output #Setting up FiFo to get sshd-output
try: try:
os.mkfifo("/var/run/foodoord.pipe") os.mkfifo("/var/run/foodoord.pipe")
os.chown("/var/run/foodoord.pipe", -1, grp.getgrnam('foodoor')[2]) 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) os.chmod("/var/run/foodoord.pipe", stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
except OSError: except OSError:
pass pass
with open("/var/run/foodoord.pipe", "r") as ssh_input: with open("/var/run/foodoord.pipe", "r") as ssh_input:
while 1: while 1:
#Read sshd-output from pipe #Read sshd-output from pipe
Pipe = ssh_input.readline()[:-1] Pipe = ssh_input.readline()[:-1]
if (Pipe == "close"): if (Pipe == "close"):
gpio.output(PIN_CLOSE,1) gpio.output(PIN_CLOSE,1)
time.sleep(1) time.sleep(1)
gpio.output(PIN_CLOSE,0) gpio.output(PIN_CLOSE,0)
write_state("closed") write_state("closed")
update_api(True) update_api(True)
elif (Pipe == "open"): elif (Pipe == "open"):
#Locking #Locking
gpio.output(PIN_OPEN,1) gpio.output(PIN_OPEN,1)
time.sleep(1) time.sleep(1)
gpio.output(PIN_OPEN,0) gpio.output(PIN_OPEN,0)
#Save State
write_state("open")
#Status Update
update_api(False)
#Save State time.sleep(0.2)
write_state("open")
#Status Update
update_api(False)
time.sleep(0.2)