Compare commits
16 Commits
LukasLenCP
...
v2
Author | SHA1 | Date | |
---|---|---|---|
aadce7fb1a
|
|||
5d475701e6
|
|||
ce451daef1
|
|||
72b2276603 | |||
b3e57e3b57 | |||
a104fbf913 | |||
897c3a442a | |||
3583fddb7b | |||
3995b4b289 | |||
ec75fc14e3 | |||
3f59acbfb0 | |||
98f31f6965 | |||
deed2c6764 | |||
30b027014e | |||
8bb7f10d84
|
|||
116ff5eba0
|
28
foodoor
28
foodoor
@ -9,15 +9,29 @@ if [ ! -e $PIPE_PATH ]
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
close)
|
||||
echo close > $PIPE_PATH
|
||||
action="$1"
|
||||
isTriggerActivated="0"
|
||||
|
||||
if [ -z "$action" ]
|
||||
then
|
||||
action="$SSH_ORIGINAL_COMMAND"
|
||||
isTriggerActivated="1"
|
||||
fi
|
||||
|
||||
case $action in
|
||||
close|open)
|
||||
echo $action | tee $PIPE_PATH |sed 's/open/UNLOCKED/;s/close/LOCKED/' > /state
|
||||
;;
|
||||
open)
|
||||
echo open > $PIPE_PATH
|
||||
status)
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $(basename $0) { close, open}"
|
||||
echo "Usage: $(basename $0) { close, open, status }"
|
||||
exit 1
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $isTriggerActivated -eq 1 ]
|
||||
then
|
||||
cat /state
|
||||
sleep 2
|
||||
fi
|
||||
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
ssh -i /root/.ssh/id_rsa_gitlab_deploy $1 $2
|
@ -2,38 +2,82 @@
|
||||
set -e
|
||||
|
||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||
export GIT_SSH="/usr/sbin/foodoor-ssh-wrapper"
|
||||
|
||||
dest=/var/run/foodoor-keys
|
||||
temp_outfile="$dest.tmp"
|
||||
|
||||
|
||||
if [ ! -e "${dest}/.git/config" ]
|
||||
then
|
||||
#echo "Repo does not exist, trying to clone..."
|
||||
( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Chaospott/foodoor-keys.git "${dest}" )
|
||||
#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
|
||||
#echo "Repo exists, updating..."
|
||||
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
|
||||
#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
|
||||
rm -f ${temp_outfile}
|
||||
find "${dest}/keys" -name '*.pub' | sort | \
|
||||
while read keyfile
|
||||
do
|
||||
ssh-keygen -l -f ${keyfile} &> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
key_length=`ssh-keygen -l -f ${keyfile} | cut -d" " -f1`
|
||||
if [ ${key_length} -lt 4096 ]; then
|
||||
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
printf "command=\"/usr/sbin/foodoor ${action}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding " >> ${outfile}
|
||||
cat "${keyfile}" >> ${outfile}
|
||||
echo >> ${outfile}
|
||||
done
|
||||
install -d -o ${action} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
|
||||
install -b -S .last -o ${action} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
|
||||
valid=false
|
||||
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
|
||||
crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)"
|
||||
key_length=$(echo "${keyinfo}" | cut -d" " -f1)
|
||||
|
||||
if [ "${crypto}" == "(RSA)" ]; then
|
||||
|
||||
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
|
||||
|
||||
if [ "$valid" = true ]; then
|
||||
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile}
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for appendix in open close door
|
||||
do
|
||||
action="$appendix"
|
||||
if [ "$action" = "door" ]
|
||||
then
|
||||
action=""
|
||||
fi
|
||||
|
||||
export action
|
||||
outfile="${dest}/authorized_keys.${appendix}"
|
||||
cat ${temp_outfile} |envsubst > ${outfile}
|
||||
|
||||
# Oben
|
||||
if [ "$(hostname)" = "foodoor" ]; 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
|
||||
|
||||
# Unten
|
||||
if [ "$(hostname)" = "kellertuer" ]; then
|
||||
if [ "${action}" = "open" ]; then
|
||||
owner="unlock"
|
||||
elif [ "${action}" = "close" ]; then
|
||||
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
|
||||
|
||||
done
|
||||
|
140
foodoord
140
foodoord
@ -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)
|
@ -1,5 +1,4 @@
|
||||
[door_firstlevel_old]
|
||||
[doorstatus]
|
||||
status_url =
|
||||
|
||||
[door_firstlevel]
|
||||
status_url =
|
||||
key =
|
||||
secret =
|
||||
|
0
foodoord_initd
Normal file → Executable file
0
foodoord_initd
Normal file → Executable file
143
foodoord_oben
Executable file
143
foodoord_oben
Executable file
@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim: ts=2 sw=2 et
|
||||
|
||||
import os
|
||||
import stat
|
||||
import time
|
||||
import pifacedigitalio
|
||||
import signal
|
||||
import sys
|
||||
import grp
|
||||
from configparser import ConfigParser
|
||||
|
||||
#Read config
|
||||
parser = ConfigParser()
|
||||
parser.read('/etc/foodoord.conf')
|
||||
|
||||
doorapi = parser.get('doorstatus', 'status_url')
|
||||
consumerkey = parser.get('doorstatus', 'key')
|
||||
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):
|
||||
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__":
|
||||
|
||||
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:
|
||||
update_api(True)
|
||||
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:
|
||||
update_api(True)
|
||||
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:
|
||||
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)
|
97
foodoord_unten
Executable file
97
foodoord_unten
Executable file
@ -0,0 +1,97 @@
|
||||
#! /usr/bin/python3
|
||||
# vim: ts=2 sw=2 et
|
||||
|
||||
import os
|
||||
import stat
|
||||
import time
|
||||
import signal
|
||||
import sys
|
||||
import RPi.GPIO as gpio
|
||||
import grp
|
||||
from configparser import ConfigParser
|
||||
|
||||
#Read config
|
||||
parser = ConfigParser()
|
||||
parser.read('/etc/foodoord.conf')
|
||||
|
||||
doorapi = parser.get('doorstatus', 'status_url')
|
||||
consumerkey = parser.get('doorstatus', 'key')
|
||||
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):
|
||||
try:
|
||||
handle = open("/tmp/door_state", "w")
|
||||
handle.write(state)
|
||||
handle.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def update_api(locked):
|
||||
try:
|
||||
os.system("/usr/bin/curl -XPOST --header 'Content-Type: application/json' --data '{ \"consumer_key\": \"" + consumerkey + "\", \"consumer_secret\": \"" + consumersecret + "\", \"cellar\": " + str(locked).lower() + " }' '" + doorapi + "' ")
|
||||
except:
|
||||
pass
|
||||
|
||||
if __name__ == "__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)
|
||||
|
Reference in New Issue
Block a user