commit f34461666e275091bf9315a7b421b5a495704b98 Author: Christian Date: Wed Oct 29 19:33:36 2014 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c5b14b --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +#foodoord + +Das Schließsystem läuft auf einem RaspberryPi mit der Erweiterungsplatine "PiFaceDigitalIO". + +### Input: +* ssh-login +* Klingel +* Statustaster + +### Output: +* Status LEDs +* Summer +* Keymatic \ No newline at end of file diff --git a/door.conf b/door.conf new file mode 100644 index 0000000..b926791 --- /dev/null +++ b/door.conf @@ -0,0 +1,6 @@ +[door_firstlevel] +status_url = + +[door_basement] +status_url = + diff --git a/foodoor.sh b/foodoor.sh new file mode 100755 index 0000000..3814ade --- /dev/null +++ b/foodoor.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +PIPE_PATH=/var/run/foodoord.pipe + +if [ ! -e $PIPE_PATH ] + then + echo "Pipe missing. Check daemon status." + exit 1 +fi + +case $1 in + close) + echo close > $PIPE_PATH + cowsay "Ich mach jetzt auf" > /var/run/banner + ;; + open) + echo open > $PIPE_PATH + cowsay "Ich mach jetzt zu" > /var/run/banner + ;; + *) + echo "Usage: $(basename $0) { close, open}" + exit 1 + ;; +esac diff --git a/foodoord b/foodoord new file mode 100755 index 0000000..674421d --- /dev/null +++ b/foodoord @@ -0,0 +1,124 @@ +#!/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/door.conf') + +url = parser.get('door_firstlevel', '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' + + listener = pifacedigitalio.InputEventListener() + listener.register(0, pifacedigitalio.IODIR_RISING_EDGE, doorbell, settle_time=10) + listener.activate() + + def signal_handler(signal, frame): + listener.deactivate() + os.remove("/var/run/foodoord.pipe") + 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+'&status=closed', timeout=2) + except: + pass + try: + urllib2.urlopen("http://10.42.1.73/door/close", 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+'&status=open', timeout=2) + except: + pass + + try: + urllib2.urlopen('http://10.42.1.73/door/open', timeout=2) + except: + pass + + STATUS = True + + set_led(GREEN) + time.sleep(0.1) diff --git a/gitlab-ssh-wrapper b/gitlab-ssh-wrapper new file mode 100755 index 0000000..9ba7971 --- /dev/null +++ b/gitlab-ssh-wrapper @@ -0,0 +1,2 @@ +#!/bin/sh +ssh -i /root/.ssh/id_rsa_gitlab_deploy $1 $2 diff --git a/update-keydb.sh b/update-keydb.sh new file mode 100755 index 0000000..9a84975 --- /dev/null +++ b/update-keydb.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +export PATH="/usr/bin:/bin:/usr/sbin:/sbin" +export GIT_SSH="/usr/sbin/gitlab-ssh-wrapper" + +dest=/var/run/foodoor-keys + +if [ ! -e "${dest}/.git/config" ] +then +#echo "Repo does not exist, trying to clone..." +( cd /var/run && git clone --quiet --single-branch --depth=1 luftschleuse@nordstern.chaospott.de:/home/luftschleuse/foodoor-keys "${dest}" ) +else +#echo "Repo exists, updating..." +( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master ) +fi + +for action in open close +do +outfile="${dest}/authorized_keys.${action}" +rm -f ${outfile} +find "${dest}/keys" -name '*.pub' | sort | \ +while read keyfile +do +printf "command=\"/usr/sbin/foodoor.sh ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile} +cat "${keyfile}" >> ${outfile} +done +install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /home/${action}/.ssh/authorized_keys +done