Initial commit

master
root 2014-10-01 16:31:55 +02:00
commit 5b6963ade4
24 changed files with 831 additions and 0 deletions

146
433send/433send.c Normal file
View File

@ -0,0 +1,146 @@
/*
Usage: ./send <command>
SystemCodeType is 1 for default and 2 for switches with 10 Bits 123456ABCD
Command is 0 for OFF and 1 for ON
*/
#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
/*
output PIN is hardcoded for testing purposes
see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
for pin mapping of the raspberry pi GPIO connector
*/
int PIN = 0; // GPIO-PIN 17
int systemCodeType = atoi(argv[1]);
int systemCode = atoi(argv[2]);
int unitCode = atoi(argv[3]);
int command = atoi(argv[4]);
char pSystemCode[14];
if (wiringPiSetup () == -1) return 1;
printf("sending systemCodeType[%i] systemCode[%i] unitCode[%i] command[%i] ...\n", systemCodeType, systemCode, unitCode, command);
RCSwitch mySwitch = RCSwitch();
printf("defining transmit PIN[%i] ... ",PIN);
mySwitch.enableTransmit(PIN);
printf("success\n");
printf("computing system Code Type ...\n");
switch(systemCodeType)
{
case 1:
{
printf("Switching \"default\" system[%i] unit[%i] ... ", systemCode, unitCode);
switch(command)
{
case 0:
{
printf("off\n");
mySwitch.switchOff(systemCode, unitCode);
break;
}
case 1:
{
printf("on\n");
mySwitch.switchOn(systemCode, unitCode);
break;
}
default:
{
printf("command[%i] is unsupported\n", command);
return -1;
}
}
break;
}
case 2:
{
printf("computing systemcode for Intertechno Type B house[%i] unit[%i] ... ",systemCode, unitCode);
switch(systemCode)
{
// house/family code A=1 - P=16
case 1: { printf("1/A ... "); strcpy(pSystemCode,"0000"); break; }
case 2: { printf("2/B ... "); strcpy(pSystemCode,"F000"); break; }
case 3: { printf("3/C ... "); strcpy(pSystemCode,"0F00"); break; }
case 4: { printf("4/D ... "); strcpy(pSystemCode,"FF00"); break; }
case 5: { printf("5/E ... "); strcpy(pSystemCode,"00F0"); break; }
case 6: { printf("6/F ... "); strcpy(pSystemCode,"F0F0"); break; }
case 7: { printf("7/G ... "); strcpy(pSystemCode,"0FF0"); break; }
case 8: { printf("8/H ... "); strcpy(pSystemCode,"FFF0"); break; }
case 9: { printf("9/I ... "); strcpy(pSystemCode,"000F"); break; }
case 10: { printf("10/J ... "); strcpy(pSystemCode,"F00F"); break; }
case 11: { printf("11/K ... "); strcpy(pSystemCode,"0F0F"); break; }
case 12: { printf("12/L ... "); strcpy(pSystemCode,"FF0F"); break; }
case 13: { printf("13/M ... "); strcpy(pSystemCode,"00FF"); break; }
case 14: { printf("14/N ... "); strcpy(pSystemCode,"F0FF"); break; }
case 15: { printf("15/O ... "); strcpy(pSystemCode,"0FFF"); break; }
case 16: { printf("16/P ... "); strcpy(pSystemCode,"FFFF"); break; }
default:
{
printf("systemCode[%s] is unsupported\n", systemCode);
return -1;
}
}
printf("got systemCode\n");
switch(unitCode)
{
// unit/group code 01-16
case 1: { printf("1 ... "); strcat(pSystemCode,"0000"); break; }
case 2: { printf("2 ... "); strcat(pSystemCode,"F000"); break; }
case 3: { printf("3 ... "); strcat(pSystemCode,"0F00"); break; }
case 4: { printf("4 ... "); strcat(pSystemCode,"FF00"); break; }
case 5: { printf("5 ... "); strcat(pSystemCode,"00F0"); break; }
case 6: { printf("6 ... "); strcat(pSystemCode,"F0F0"); break; }
case 7: { printf("7 ... "); strcat(pSystemCode,"0FF0"); break; }
case 8: { printf("8 ... "); strcat(pSystemCode,"FFF0"); break; }
case 9: { printf("9 ... "); strcat(pSystemCode,"000F"); break; }
case 10: { printf("10 ... "); strcat(pSystemCode,"F00F"); break; }
case 11: { printf("11 ... "); strcat(pSystemCode,"0F0F"); break; }
case 12: { printf("12 ... "); strcat(pSystemCode,"FF0F"); break; }
case 13: { printf("13 ... "); strcat(pSystemCode,"00FF"); break; }
case 14: { printf("14 ... "); strcat(pSystemCode,"F0FF"); break; }
case 15: { printf("15 ... "); strcat(pSystemCode,"0FFF"); break; }
case 16: { printf("16 ... "); strcat(pSystemCode,"FFFF"); break; }
default:
{
printf("unitCode[%i] is unsupported\n", unitCode);
return -1;
}
}
strcat(pSystemCode,"0F"); // mandatory bits
switch(command)
{
case 0:
{
strcat(pSystemCode,"F0");
mySwitch.sendTriState(pSystemCode);
printf("sent TriState signal: pSystemCode[%s]\n",pSystemCode);
break;
}
case 1:
{
strcat(pSystemCode,"FF");
mySwitch.sendTriState(pSystemCode);
printf("sent TriState signal: pSystemCode[%s]\n",pSystemCode);
break;
}
default:
{
printf("command[%i] is unsupported\n", command);
return -1;
}
}
break;
}
default:
{
printf("command sequence unknown, aborting!\n");
return -1;
}
}
return 0;
}

16
doc/FHEMinstall.txt Normal file
View File

@ -0,0 +1,16 @@
http://www.fhemwiki.de/wiki/Raspberry_Pi
sudo apt-get install perl libdevice-serialport-perl
sudo apt-get install libio-socket-ssl-perl libwww-perl
wget http://fhem.de/fhem-5.5.deb
dpkg -i fhem-5.5.deb
apt-get install -f
go to interface:
http://pidor:8083/fhem
how to make a button:
https://groups.google.com/forum/#!topic/fhem-users/1eQJ_Q4Evo4
define MyBtn FS20 9999 99
attr MyBtn dummy
define MyNotify notify MyBtn "/local/bin/mypgm %"

Binary file not shown.

4
scripts/close.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
/usr/local/bin/gpio mode 7 out
/usr/local/bin/gpio write 7 1

5
scripts/closetrigger.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
logger -t $(basename $0) adding upd_status.sh to at
#echo "$(dirname "$0")/upd_status.sh" | at -t $(date --date "2 seconds" +%Y%m%d%H%M%S)
"$(dirname "$0")/upd_status.sh" </dev/null >/dev/null 2>&1 &
logger -t $(basename $0) added $(dirname "$0")/upd_status.sh as at job with ret=$?

18
scripts/dhcp2presency.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
n=0
for i in $(ls /run/dhcp-leases/)
do
if ping -qc 1 -W 1 "$i" >/dev/null
then
touch "/run/dhcp-leases/$ip"
n=$((n+1))
else
logger -t $(basename $0) "dhcp $i is not pingable anymore"
if [ $(stat -c %Y /run/dhcp-leases/$i) -lt $(date --date "1 hour ago" +%s) ]
then
logger -t $(basename $0) "removing dhcp $i after one hour"
rm /run/dhcp-leases/$i
fi
fi
done
echo "$n" > /run/presency

38
scripts/lockbutton.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
# add this to /etc/inittab
# P1:2345:respawn:/root/lockbutton.sh
PATH=/bin:/usr/bin:/usr/local/bin
logger -t $(basename $0) "starting..."
gpio -g mode 11 in # this is usually SCLK as ALT0
# transform into GPIO11 as IN
gpio -g mode 11 up # set internal pullup
while true
do
logger -t $(basename $0) "change detected (was $state)"
if [ $(gpio -g read 11) -eq 1 ] && [ "$state" != "pushed" ]
then
for plugin in "$0".d/*
do
"$plugin" pushed
logger -t $(basename $0) "called '$plugin pushed' with ret=$?"
done
state="pushed"
else
if [ "$state" != "released" ]
then
for plugin in "$0".d/*
do
"$plugin" released
logger -t $(basename $0) "called '$plugin released' with ret=$?"
done
state="released"
fi
fi
if ( [ $(gpio -g read 11) -eq 1 ] && [ "$state" = "released" ] ) ||
( [ $(gpio -g read 11) -eq 0 ] && [ "$state" = "pushed" ] )
then
logger -t $(basename $0) "inconsistent state $state, aborting"
break
fi
gpio -g wfi 11 both # wait for change (uses no cpu, but interrupt)
done

View File

@ -0,0 +1,6 @@
#!/bin/bash
if [ "$1" = "pushed" ] || [ "$1" = "released" ]
then
logger -t $(basename $0) "writing $1 to doorlockbutton"
echo "$1" > /run/doorlockbutton
fi

View File

@ -0,0 +1,8 @@
#!/bin/bash
if [ "$1" = "released" ] && # if switch was released (the door opened, or someone is playing with the switch)
[ "$(cat /run/spacestatus)" = "closed" ] && # the status was closed
[ $(stat -c "%Y" /run/spacestatus) -lt $(date --date "1 hour ago" +%s) ] # since at least one hour
then
echo "intrusion detected: space was closed since some time and locked, but now is still closed but unlocked" | wall
logger -t $(basename $0) "INTRUSION ALARM. door was opened while status is closed"
fi

33
scripts/lockbutton.sh.d/lights Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# called by upd_status and lockbutton, so that whatever
# sequence is used, the lights go off
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
[ "$(cat /run/spacestatus)" = "closed" ] &&
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
then
logger -t $(basename $0) "switching all lights off"
for i in {1..16}
do
/usr/local/bin/433send 2 1A $i 0 #off
done
logger -t $(basename $0) "all lights should be off now"
fi
if [ "$1" = "released" ] && # the door has been opened
[ "$(cat /run/spacestatus)" = "open" ] && # status is open
[ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
then
logger -t $(basename $0) "switching some lights on"
/usr/local/bin/433send 2 1A 1 1 #on
fi
# type (2=10bit)
# | house 1-16 (always 1 in our case)
# | |group A-P (the dial thingie)
# | || unit (1-16) (the button, usually 1-4)
# | || | on/off
# | || | |
#/usr/local/bin/433send 2 1A 1 1 #on
#/usr/local/bin/433send 2 1A 1 0 #off

4
scripts/open.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
/usr/local/bin/gpio mode 7 out
/usr/local/bin/gpio write 7 0

24
scripts/rsyslog-mikrotik.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
exec 2>/tmp/out.log
set -x
PATH=/bin:/usr/bin
mkdir /run/dhcp-leases 2>/dev/null
while read l
do
ip="$(echo "$l" |
fgrep Address-Request|
fgrep "10.2.113" |
sed 's/^.* //')"
if [ "$ip" != "" ]
then
t=$(date +%s)
if [ -f "/run/dhcp-leases/$ip" ]
then
touch "/run/dhcp-leases/$ip"
else
logget -t $(basename $0) "new dhcp for $ip"
echo "$t" > "/run/dhcp-leases/$ip"
fi
echo "========== $t $ip" >> /tmp/out.log
fi
done

25
scripts/semaphore.sh Normal file
View File

@ -0,0 +1,25 @@
#!/bin/bash
LockDir="/run/$(basename "$0").run"
P() {
while ! mkdir "$LockDir" 2>/dev/null
do
echo "cannot lock $LockDir, waiting"
LockDirStamp=$(stat -c %Y "$LockDir")
if [ "$LockDirStamp" != "" ] && [ "$LockDirStamp" -lt $(date --date "15 seconds ago" +%s) ]
then
echo lock is old, deleting
rmdir "$LockDir"
fi
sleep 1
done
echo got lock
}
V() {
echo "releasing $LockDir"
rmdir "$LockDir"
}
P
echo "running protected code"
sleep 10
V
echo "end protected code"

46
scripts/upd_arps.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
if [ "$(awk -W version 2>/dev/null|awk '{print $1;exit}')" != "GNU" ]
then
echo "do 'apt-get install gawk' for this to work"
exit 1
fi
export PATH=/bin:/usr/bin:/usr/sbin
arps="$( (cat /root/arps.txt # get old list
arp -an| # get current values
awk -F'[().: ]' '/10.2.113/ && $6 > 100 && !/incomplete/'| # only our subnet and only addresses above 100
awk -v now=$(date +%s) '{print $4 " " now}') | # write them with current timestamp
awk '{arps[$1]=arps[$1]" "$2}
END {
for(i in arps) {
split(arps[i],a)
asort(a)
print i " " a[1] " " a[length(a)] # write out mac, oldest seen and newest seen
}
}'|
sort -k2 | # sort by timestamp, newest first
sort -u -k1,1 )" # remove duplicate arp (keeps the most recent entry by timestamp)
# echo "$arps" | sort -n -k2| awk -v onehour=$(date --date="1 hour ago" +%s) '{print $0 " " $3-onehour};c==1 && (($3 - $2)<3600*24) && ($3 > onehour) {n+=1;print "->"$0}
Current="$(
(date --date="1 hour ago" +"CURRENT: %s"
echo "$arps" )|
sort -n -k2|
awk 'c==1 && (($3 - $2)<3600*10) && ($3 > c) {n+=1}
/CURRENT:/{c=1}
END{print n}'
)"
Current="$(
echo "$arps" |
sort -n -k2|
awk -v onehour=$(date --date="1 hour ago" +%s) '
$3 > onehour {print $0 " " $3-$2}
' |
awk '$3-$2 < 24*3600' |
wc -l
)"
echo "$arps" > /root/arps.txt
oldCurrent="$(cat /run/presency)"
echo "$Current" > /run/presency
if [ "$Current" != "$oldCurrent" ]
then
logger -t $(basename $0) "there are now $Current people in Level2"
fi

72
scripts/upd_status.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
IGNORE_DOORLOCKBUTTON="no"
LockDir="/run/$(basename "$0").run"
P() {
while ! mkdir "$LockDir" 2>/dev/null
do
LockDirStamp=$(stat -c %Y "$LockDir" 2>/dev/null)
if [ "$LockDirStamp" != "" ] && [ "$LockDirStamp" -lt $(date --date "90 seconds ago" +%s) ]
then
rmdir "$LockDir"
logger -t $(basename $0) "deleting stale semaphore dir $LockDir"
fi
sleep 1
done
}
V() {
rmdir "$LockDir" 2>/dev/null
if [ $? -ne 0 ]
then
logger -t $(basename $0) "semaphore dir $LockDir disappeared while running"
fi
}
P
if [ ! -f /run/spacestatus ] # self initilizing on new install or boot
then
if [ -f /root/var/spacestatus ]
then # we could also get it from spaceapi, so that could should go here:
logger -t $(basename $0) "boot detected, restoring spacestatus to $(cat /root/var/spacestatus)"
cp -p /root/var/spacestatus /run/spacestatus # restore from backup
else
logger -t $(basename $0) "never run before (new install?) setting spacestatus to closed"
echo "closed" > /run/spacestatus
fi
chown www-data /run/spacestatus
fi
status=$(cat /run/spacestatus)
doorlockbutton=$(cat /run/doorlockbutton)
nai=$(stat -c "%Y" /run/spacestatus) # get mtime as status change time
if [ "$status" = "open" ]
then
/usr/bin/curl --max-time 1 --silent --data key=96f7896f97asdf89u0a9s7d7fdasgsda88af --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set
#logger -t $(basename $0) "sending status $status to spacapi ret=$?"
fi
for plugin in $(ls "$0".d)
do
"$0".d/"$plugin" "$status"
# logger -t $(basename $0) "called $plugin '$status'. ret=$?"
done
if [ "$status" = "closed" ] && (
[ "$IGNORE_DOORLOCKBUTTON" = "yes" ] || [ "$doorlockbutton" = "pushed" ] )
then
# problem: if closing state but not actually shuting door for a longer time, the status in spaceapi
# will be the time of closing but not that of actually shutting the door
# but the status will only be updated once the door is shut
/usr/bin/curl --max-time 1 --silent --data key=96f7896f97asdf89u0a9s7d7fdasgsda88af --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set
#logger -t $(basename $0) "sending status $status to spacapi ret=$?"
fi
if [ $nai -ne $(stat -c "%Y" /root/var/spacestatus) ] # backup file in case it changed
then
cp -p /run/spacestatus /root/var/spacestatus
logger -t $(basename $0) "spacestatus changed, saving to SD. ret=$?"
fi
presency=$(cat /run/presency)
if [ "$status" = "closed" ]
then
presency=0
fi
/usr/bin/curl --max-time 1 --silent --data key=96f7896f97asdf89u0a9s7d7fdasgsda88af --data-urlencode sensors='{"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' http://spaceapi.syn2cat.lu/sensor/set
V

33
scripts/upd_status.sh.d/lights Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# called by upd_status and lockbutton, so that whatever
# sequence is used, the lights go off
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
[ "$(cat /run/spacestatus)" = "closed" ] &&
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
then
logger -t $(basename $0) "switching all lights off"
for i in {1..16}
do
/usr/local/bin/433send 2 1A $i 0 #off
done
logger -t $(basename $0) "all lights should be off now"
fi
if [ "$1" = "released" ] && # the door has been opened
[ "$(cat /run/spacestatus)" = "open" ] && # status is open
[ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
then
logger -t $(basename $0) "switching some lights on"
/usr/local/bin/433send 2 1A 1 1 #on
fi
# type (2=10bit)
# | house 1-16 (always 1 in our case)
# | |group A-P (the dial thingie)
# | || unit (1-16) (the button, usually 1-4)
# | || | on/off
# | || | |
#/usr/local/bin/433send 2 1A 1 1 #on
#/usr/local/bin/433send 2 1A 1 0 #off

27
systemfiles/crontab-l Normal file
View File

@ -0,0 +1,27 @@
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
#* * * * * curl -XPOST "http://localhost:80/GPIO/0/value/1"
#* * * * * /root/upd_arps.sh
* * * * * /root/dhcp2presency.sh
* * * * * /root/upd_status.sh > /run/spacestatus.out 2>&1

75
systemfiles/inittab Normal file
View File

@ -0,0 +1,75 @@
# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
# The default runlevel.
id:2:initdefault:
# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."
# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
# <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty --noclear 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6
# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
# Example how to put a getty on a modem line.
#
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
# pidor
P0:2345:respawn:/root/lockbutton.sh

126
systemfiles/rsyslog.conf Normal file
View File

@ -0,0 +1,126 @@
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#################
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
$ModLoad omprog
$ActionOMProgBinary /root/rsyslog-mikrotik.sh
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
$RepeatedMsgReduction on # suppress repeating messages (gunstick: does not work. wtf)
###############
#### RULES ####
###############
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info -/var/log/mail.info
mail.warn -/var/log/mail.warn
mail.err /var/log/mail.err
#
# Logging for INN news system.
#
news.crit /var/log/news/news.crit
news.err /var/log/news/news.err
news.notice -/var/log/news/news.notice
#
# Some "catch-all" log files.
#
*.=debug;\
auth,authpriv.none;\
news.none;mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
# news.=crit;news.=err;news.=notice;\
# *.=debug;*.=info;\
# *.=notice;*.=warn /dev/tty8
# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
# you must invoke `xconsole' with the `-file' option:
#
# $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
:hostname, isequal, "MikroTik" :omprog:;RSYSLOG_TraditionalFileFormat

View File

@ -0,0 +1 @@
www-data ALL=(root) NOPASSWD: /root/pidor/scripts/closetrigger.sh

View File

@ -0,0 +1,54 @@
#!/bin/bash
#parse-query
# Copyright 2007 Chris F.A. Johnson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# rebuilt by gunstick 2012 (http://cfajohnson.com/shell/articles/parse-query/ is non working version)
parse_query() #@ USAGE: parse_query var ...
{
local var val
local IFS='&'
vars="&$*&"
[ "$REQUEST_METHOD" = "POST" ] && read QUERY_STRING
set -f
for item in $QUERY_STRING
do
var=${item%%=*}
val=${item#*=}
val=${val//+/ }
# case $vars in
# *"&$var&"* )
case $val in
*%[0-9a-fA-F][0-9a-fA-F]*)
val=$( printf "%b" "${val//\%/\\x}." )
val=${val%.}
#printf -v val "%b" "${val//\%/\\x}"
;;
esac
val="$(echo "$val"|tr -d '\r')"
eval "FORM_$var=\$val"
# create var for use in form fields
val="$(echo "$val"|sed 's/&/\&#38/g;s/"/\&#34;/g;s/</\&#60;/g')"
eval "FORM_f_$var=\$val"
# ;;
# esac
done
set +f
}

39
webserver/cgi-bin/pidor.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
# TODO use functions
nai=`date +%s`;
echo "Content-type: text/html"
echo
echo "<html><body><pre>"
exec 2>&1
. "$(dirname "$0")"/parse_query
parse_query
logger -t $(basename $0) got $FORM_action from $REMOTE_USER
logger -t $(basename $0) spacestatus was $(cat /run/spacestatus)
if [ "$FORM_action" = "open" ]
then
/usr/local/bin/gpio mode 7 out
/usr/local/bin/gpio write 7 0
if [ "$(cat /run/spacestatus)" != "open" ] # do not modify timestamp on multiple clicks
then
echo "open" > /run/spacestatus
fi
# is now handled in cron Gunstick20140904 # /usr/bin/curl --max-time 1 --silent --data key=96f7896f97asdf89u0a9s7d7fdasgsda88af --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set
fi
if [ "$FORM_action" = "close" ]
then
/usr/local/bin/gpio mode 7 out
/usr/local/bin/gpio write 7 1
if [ "$(cat /run/spacestatus)" != "closed" ] # do not modify timestamp on multiple clicks
then
echo "closed" > /run/spacestatus
fi
# is now handled in cron Gunstick20140904 # /usr/bin/curl --max-time 1 --silent --data key=96f7896f97asdf89u0a9s7d7fdasgsda88af --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set
sudo /root/pidor/scripts/closetrigger.sh
logger -t $(basename $0) closetrigger ret=$?
fi
logger -t $(basename $0) spacestatus is now $(cat /run/spacestatus)
echo "</pre>"
echo "<script>history.back()</script>"

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,31 @@
<html>
<title>Level2</title>
<style>
* {
padding: 0;
margin: 0
}
.open {
background-color: #00ff00;
}
.close {
background-color: #ff0000;
}
.button {
height: 50%;
color: #ffffff;
border: 0;
font-size: 10em;
width: 100%;
}
</style>
<form action="/cgi-bin/pidor.sh" method="get">
<input type=hidden name="action" value="open">
<input class="button open" type="submit" value="Open">
</form>
<form action="/cgi-bin/pidor.sh" method="get">
<input type=hidden name="action" value="close">
<input class="button close" type="submit" value="Close">
</form>