1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +01:00

added rest of the software

This commit is contained in:
Ralf Ramsauer 2015-05-14 22:03:00 +02:00
parent f04b45e3eb
commit 4f2625525f
31 changed files with 1013 additions and 0 deletions

608
avr-code/Makefile Normal file
View File

@ -0,0 +1,608 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = attiny2313
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
# Typical values are:
# F_CPU = 1000000
# F_CPU = 1843200
# F_CPU = 2000000
# F_CPU = 3686400
# F_CPU = 4000000
# F_CPU = 7372800
# F_CPU = 8000000
# F_CPU = 11059200
# F_CPU = 14745600
# F_CPU = 16000000
# F_CPU = 18432000
# F_CPU = 20000000
F_CPU = 14745600
#F_CPU = 8000000
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = main
# Object files directory
OBJDIR = obj
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG =
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=c11
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
#CPPDEFS += -D__STDC_LIMIT_MACROS
#CPPDEFS += -D__STDC_CONSTANT_MACROS
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
#CFLAGS += -mint8
#CFLAGS += -mshort-calls
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
#CFLAGS += -fno-unit-at-a-time
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wsign-compare
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
#CPPFLAGS += -mint8
#CPPFLAGS += -mshort-calls
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions
#CPPFLAGS += -fno-unit-at-a-time
CPPFLAGS += -Wall
#CPPFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
#CPPFLAGS += -Wunreachable-code
#CPPFLAGS += -Wsign-compare
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
#---------------- Programming Options (avrdude) ----------------
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = avr910
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = /dev/ttyUSB0 # programmer connected to serial device
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
$(AVRMEM) 2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
$(AVRMEM) 2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
@$(REMOVE) $(GDBINIT_FILE)
@echo define reset >> $(GDBINIT_FILE)
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
@echo end >> $(GDBINIT_FILE)
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
@$(WINSHELL) /c pause
else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVEDIR) $(OBJDIR)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVEDIR) .dep
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config

142
avr-code/main.c Normal file
View File

@ -0,0 +1,142 @@
/* 2015, Ralf Ramsauer
* ralf@binary-kitchen.de
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <string.h>
#define GREEN_ON (PORTB &= ~(1<<PB1))
#define GREEN_OFF (PORTB |= (1<<PB1))
#define RED_ON (PORTB &= ~(1<<PB0))
#define RED_OFF (PORTB |= (1<<PB0))
#define OPEN_BOLZEN (PORTD &= ~(1<<PD4))
#define CLOSE_BOLZEN (PORTD |= (1<<PD4))
#define OPEN_SCHNAPPER (PORTD |= (1<<PD5))
#define CLOSE_SCHNAPPER (PORTD &= ~(1<<PD5))
#define IS_RESCUE (!(PIND & (1<<PD3)))
#define IS_SWITCH (!(PIND & (1<<PD2)))
#define DE_RX (PORTD &= ~(1<<PD2))
#define DE_TX (PORTD |= (1<<PD2))
#define IS_SCK (!(PINB & (1<<PB7)))
uint8_t open = 0;
void open_door()
{
RED_OFF;
GREEN_ON;
OPEN_BOLZEN;
_delay_ms(200);
}
void schnapper(unsigned int i)
{
while(i--)
{
OPEN_SCHNAPPER;
_delay_ms(125);
CLOSE_SCHNAPPER;
_delay_ms(125);
}
}
void close_door()
{
RED_ON;
GREEN_OFF;
CLOSE_SCHNAPPER;
CLOSE_BOLZEN;
RED_ON;
}
uint8_t klacker = 0;
ISR(USI_OVERFLOW_vect)
{
USISR = (1<<USIOIF);
open = 1;
TCNT1 = 0;
klacker = USIDR ? 0 : 1;
}
ISR(TIMER1_OVF_vect)
{
open = 0;
}
int main(void) {
// disable all interrupts
cli();
// PD5, PD4 Output
DDRD = (1<<PD5)|(1<<PD4);
DDRB = (1<<PB0)|(1<<PB1);
PORTB |= (1<<PB7)|(1<<PB5);
// PD2,3 as input + pull up
DDRD &= ~((1<<PD2)|(1<<PD3));
PORTD |= (1<<PD3)|(1<<PD3);
USICR = (1<<USICS1) | (1<<USIOIE) | (1<<USIWM0);
TIMSK |= (1<<TOIE1);
TIFR |= (1<<TOV1);
TCNT1 = 0;
TCCR1A = 0;
TCCR1B = (1<<CS01)|(1<<CS00);
_delay_ms(1000);
CLOSE_BOLZEN;
CLOSE_SCHNAPPER;
GREEN_OFF;
RED_ON;
_delay_ms(1000);
sei();
for(;;) {
if (open == 0) {
close_door();
} else if (open == 1) {
open_door();
}
if (open == 1 && klacker == 1)
{
schnapper(20);
klacker = 0;
}
if (IS_RESCUE) {
cli();
open_door();
schnapper(30);
_delay_ms(2000);
sei();
} else if (IS_SWITCH && open == 0) {
_delay_ms(300);
if(IS_SWITCH && open == 0) {
cli();
open_door();
schnapper(20);
_delay_ms(3000);
sei();
}
}
_delay_ms(50);
}
return 0;
}

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

182
webfrontend/index.php Normal file
View File

@ -0,0 +1,182 @@
<!DOCTYPE html>
<?php
function tellLock( $pAction, $pUser, $pPass, $pToken, $pIp ){
$pAuthenticated = true;
$json = '{
"user":' . json_encode( $pUser ) . ',
"password":' . json_encode( $pPass ) . ',
"action":' . json_encode( $pAction ) . ',
"token":' . json_encode( $pToken ) . ',
"ip":' . json_encode( $pIp ) . ',
"authenticate":' . json_encode( $pAuthenticated ) . '
}'."\n";
$address = "127.0.0.1";
$port = "5555";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: " . socket_strerror(socket_last_error()) . "\n";
}
$result = socket_connect($socket, $address, $port);
if ($result === false) {
echo "socket_connect() failed: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_write($socket, $json, strlen($json));
$result = socket_read($socket, 1024);
socket_close($socket);
return $result;
}
function err2str( $code ) {
switch ( $code ) {
case 0:
return "Success";
break;
case 1:
return "Fail";
break;
case 2:
return "Already Unlocked"; // Authentication successful, but door is already unlocked
break;
case 3:
return "Already Locked"; // Authentication successful, but door is already locked
break;
case 4:
return "NotJson"; // Request is not a valid JSON object
break;
case 5:
return "Json Error"; // Request is valid JSON, but does not contain necessary material
break;
case 6:
return "Invalid Token"; // Request contains invalid token
break;
case 7:
return "Invalid Credentials"; // Invalid LDAP credentials
break;
case 8:
return "Invalid IP";
break;
case 9:
return "Unknown Action"; // Unknown action
break;
case 10:
return "LDAP Init error"; // Ldap initialization failed
break;
default:
return "Unknown error";
break;
}
}
$showLoginForm = false;
$showSuccess = false;
$showFailure = false;
$pIp = $_SERVER[ 'REMOTE_ADDR' ];
if( $_SERVER[ 'REQUEST_METHOD' ] == "POST" ) {
$pUser = $_POST[ 'user' ];
$pPass = $_POST[ 'pass' ];
$pToken = $_POST[ 'token' ];
$pAction = $_POST[ 'action' ];
$lSuccess = tellLock( $pAction, $pUser, $pPass, $pToken, $pIp );
if ($lSuccess == 0) {
$showSuccess = true;
} else {
http_response_code( 401 );
$failureMsg = err2str($lSuccess);
$showFailure = true;
}
} else {
// This is done by apache mod_rewrite
$pToken = $_GET[ 'token' ];
$lToken = preg_replace( '/[^0-9a-f]/i', "", $pToken );
if(strlen($lToken) != 16) {
http_response_code( 404 );
$showFailure = true;
}
$showLoginForm = true;
}
?>
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>
<body>
<style>
* {
font: normal 30px Arial,sans-serif;
}
body {
background-color: #037;
color: white;
background-image: url('logo.svg' );
background-repeat: repeat;
background-size: 300%;
background-position: -200px -100px;
}
form {
position: relative;
display: block;
width: auto;
text-align: center;
}
input {
position: relative;
display: block;
width: auto;
width: 100%;
}
button {
width: 100%;
margin-top: 40px;
}
</style>
<?php if( $showLoginForm ): ?>
<form name="login" method="post" action="/">
<label for="user">User</label>
<input id="user" type="text" name="user">
<label for="pass">Pass</label>
<input id="pass" type="password" name="pass">
<input type="hidden" name="token" value="<?php echo $lToken;?>">
<button name="action" value="unlock">Open</button>
<hr/>
<button name="action" value="lock">Lock</button>
</form>
<?php elseif( $showSuccess ): ?>
<h1>Welcome Cpt. Cook</h1>
<?php elseif( $showFailure ): ?>
<h1>Something went wrong: <?php echo $failureMsg; ?></h1>
<?php endif; ?>
</body>
</html>

81
webfrontend/logo.svg Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="180"
id="svg4662"
version="1.1"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="New document 4">
<defs
id="defs4664" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="150.41655"
inkscape:cy="115.14291"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="1031"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata4667">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-872.36218)">
<g
id="g5022"
transform="matrix(1.2255371,0,0,1.2255371,-230.84023,1130.0139)">
<path
inkscape:connector-curvature="0"
id="path3021"
d="m 244.28546,-205.07285 c -13.55524,0.0103 -24.54012,7.56438 -24.53305,16.88361 0.006,7.85919 7.80317,14.5031 18.40741,16.23346 2.21111,0.3608 3.4598,0.3416 4.77455,0.40635 0.27656,0.0138 0.50974,0.29954 0.49777,0.54856 -0.012,0.24902 -0.272,0.52169 -0.54857,0.50793 -1.96704,-0.0979 -2.21207,-0.0854 -3.67741,-0.22349 l 0,4.96757 -2.48886,0.0101 c -0.96509,0.004 -1.80211,0.7736 -1.74729,1.73712 l 2.05204,36.06308 c 0.0548,0.96352 0.78464,1.66853 1.74728,1.73712 16.97546,1.20947 34.16131,1.28134 51.56512,-0.0406 0.96231,-0.0731 1.68392,-0.7735 1.73713,-1.73712 l 1.99108,-36.06307 c 0.0532,-0.96362 -0.77204,-1.73713 -1.73712,-1.73713 l -1.99109,0 -0.0101,-6.41008 c -0.59278,0.0685 -1.30174,0.1021 -2.28569,0.10158 -0.28484,-1.4e-4 -0.55101,-0.28356 -0.54856,-0.5384 0.003,-0.25484 0.27393,-0.52379 0.55872,-0.51809 1.08555,0.0217 1.80456,0.0155 2.37712,-0.1219 7.72295,-1.8535 13.20034,-6.75436 13.19604,-12.43415 -0.006,-7.34241 -9.17359,-13.28587 -20.46961,-13.2773 -5.9236,0.004 -11.26017,1.64843 -14.99411,4.26661 0.71202,0.9635 1.31636,1.69784 1.99109,2.19426 0.68758,0.50589 1.45609,0.794 2.65139,0.85333 0.27658,0.0137 0.50975,0.29955 0.49778,0.54856 -0.012,0.24902 -0.272,0.52167 -0.54857,0.50793 -1.35281,-0.0672 -2.42214,-0.38317 -3.23044,-1.05649 -0.98588,-0.82125 -1.47763,-1.14899 -2.34664,-2.6514 -3.62458,-6.26641 -12.45917,-10.76586 -22.88737,-10.75795 z m 9.38656,47.75563 3.62662,0.0406 c 0.8264,0.01 1.48105,0.67707 1.473,1.50347 l -0.21333,22.39974 c -0.008,0.82641 -0.68724,1.49312 -1.51363,1.48316 l -3.61647,-0.0406 c -0.82639,-0.01 -1.48104,-0.67707 -1.473,-1.50348 l 0.21334,-22.39974 c 0.008,-0.82641 0.67708,-1.49311 1.50347,-1.48316 z m 19.08803,0.19302 c 4.59464,0.0456 8.26648,5.6641 8.198,12.55604 -0.0685,6.89195 -3.83701,12.43916 -8.43164,12.39351 -4.59463,-0.0456 -8.26648,-5.6641 -8.19801,-12.55604 0.0685,-6.89195 3.83702,-12.43916 8.43165,-12.39351 z"
style="fill:#ccbbbb;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<path
inkscape:connector-curvature="0"
id="use3078"
d="m 200.30883,-134.33843 c -1.39853,0.0404 -3.12049,0.56027 -3.67742,1.91997 l -3.37266,8.22848 c -0.84129,2.05396 1.37784,4.43092 2.53965,4.90661 l 35.56531,14.55729 c 0.38962,-0.3884 0.93039,-0.63562 1.52379,-0.65015 1.22875,-0.0301 2.2556,0.96549 2.28569,2.19426 0.15008,0.0661 0.30962,0.14098 0.43682,0.19302 1.16194,0.47535 2.48075,-0.0876 2.95615,-1.24951 l 1.43237,-3.50473 16.57885,6.78596 4.97772,-2.1841 -20.06326,-8.21832 1.43237,-3.50472 c 0.4754,-1.16193 -0.0761,-2.49428 -1.23935,-2.96632 l -0.43682,-0.17269 c -0.39626,0.46577 -0.98624,0.76607 -1.6457,0.78221 -1.22876,0.0301 -2.29115,-1.05984 -2.26537,-2.39743 -12.25687,-5.07793 -24.37983,-9.98145 -35.46372,-14.5065 -0.36093,-0.14735 -0.92873,-0.23168 -1.56442,-0.21333 z m -0.0813,4.15487 c 0.68786,-0.0126 1.39645,0.0653 1.94029,0.28444 11.52178,4.64268 22.39838,9.14152 33.89929,13.83603 0.33307,0.14692 0.49168,0.61064 0.36571,0.91428 -0.12597,0.30363 -0.56708,0.52359 -0.90411,0.38602 l -33.76723,-13.77508 -0.0101,0 c -1.42005,-0.57618 -2.57387,-0.25535 -3.23044,0.57905 -0.2481,0.31529 -0.77308,0.39811 -1.04634,0.17269 -0.27326,-0.22541 -0.2957,-0.76564 -0.0305,-1.06665 0.83707,-0.94999 1.88567,-1.31433 2.78346,-1.33078 z m -1.09713,6.70468 c 0.0935,-0.006 0.18575,0.0105 0.28444,0.0508 11.49444,4.69486 22.39412,9.17072 33.88913,13.87666 0.34309,0.14046 0.52212,0.61406 0.39619,0.92444 -0.12594,0.31037 -0.58137,0.52653 -0.92444,0.38602 l -33.82818,-13.85635 c -0.38694,-0.15848 -0.54846,-0.61414 -0.42666,-0.93459 0.087,-0.22894 0.32917,-0.42985 0.60952,-0.44698 z m 82.01048,28.36285 -5.31296,2.041882 32.64979,13.368734 c 0.25004,1.079745 3.14683,3.021327 5.22152,3.972018 1.30859,0.599644 2.67177,1.086854 4.0025,1.635536 0.91278,-2.256918 1.83518,-4.51491 2.76314,-6.765636 -1.33528,-0.537581 -2.63001,-1.16066 -3.99234,-1.625378 -1.73375,-0.59141 -5.10658,-1.391879 -6.52183,-0.833006 l -28.80982,-11.79415 z"
style="fill:#ccbbbb;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<g
transform="matrix(0.32303566,-0.14109669,0.14109669,0.32303566,99.129267,-226.69717)"
id="use3083">
<path
style="fill:#ccbbbb;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 900.1875,443.75 -10.0625,0.0312 c -2.06742,0.006 -3.71875,1.65132 -3.71875,3.71875 l 0,6.25 -14.875,9.1875 C 822.66476,464.22979 769.15433,465.92087 718,467.4687 c -3.86018,0.1168 -6.954,3.13809 -6.9375,7 l 0.0312,7.3125 c -4.39379,0.1562 -8.77864,0.31969 -13.125,0.40625 0.97303,-5.55653 -0.58392,-11.07117 -3.84375,-15.125 -3.90015,-4.85012 -9.63745,-7.59553 -16.6875,-8.375 -1.77081,-0.19579 -3.69096,-0.27617 -5.65625,-0.15625 -1.96529,0.11992 -3.96613,0.45055 -5.90625,1.0625 -3.88023,1.22388 -7.73646,3.96623 -9.0625,8.53125 -1.13246,3.89857 -1.08251,8.27896 1.21875,12 2.30126,3.72104 6.66466,6.31703 12.8125,7.25 5.20014,0.78916 10.38378,1.20262 15.5625,1.375 -0.42767,0.29707 -0.71554,0.66894 -1.1875,0.9375 -3.16064,1.79846 -7.2586,2.82575 -11.21875,3 -16.17998,0.71196 -33.27007,1.52537 -49.75,0.90625 l -0.21875,6.5 c 16.86139,0.63344 34.08845,-0.19511 50.25,-0.90625 4.85233,-0.21352 9.86708,-1.40312 14.15625,-3.84375 2.80877,-1.59825 5.26565,-3.83995 7.0625,-6.625 5.2263,-0.0543 10.41482,-0.22176 15.59375,-0.40625 l 0.0312,4.875 c 0.0248,3.86187 3.07592,6.91592 6.9375,6.96875 50.79894,0.69498 105.04842,1.35105 153.5625,3.96875 l 14.875,9.125 0.0312,6.25 c 0.0103,2.06745 1.65133,3.72517 3.71875,3.71875 l 10.0625,-0.0312 c 2.06742,-0.006 3.75283,-1.65128 3.75,-3.71875 l -0.0312,-22.84375 127.21875,-0.25 c 2.4965,-0.005 4.5,-2.00347 4.5,-4.5 l 0,-4.78125 31.7188,-0.0625 c 2.1455,-0.004 8.1914,-1.72948 8.1874,-3.875 0,-2.14552 -6.0732,-3.84798 -8.2187,-3.84375 l -31.7187,0.0625 0,-4.78125 c 0,-2.49653 -2.0348,-4.50429 -4.5313,-4.5 L 904,470.3125 903.9375,447.46875 c -0.006,-2.06743 -1.68258,-3.72517 -3.75,-3.71875 z M 674.5,465.03125 c 0.76399,0.0155 1.53642,0.0461 2.25,0.125 5.62398,0.62179 9.55318,2.43804 12.375,6.0625 2.29548,2.94841 3.4456,6.73828 2.3125,10.96875 -6.61366,-0.0371 -13.17428,-0.27106 -19.625,-1.25 -4.90375,-0.74418 -7.17641,-2.43226 -8.28125,-4.21875 -1.10484,-1.78649 -1.24006,-4.12594 -0.46875,-6.78125 0.62042,-2.13582 2.1484,-3.33567 4.75,-4.15625 1.3008,-0.41029 2.83201,-0.6234 4.375,-0.71875 0.77149,-0.0477 1.54851,-0.0468 2.3125,-0.0312 z"
transform="matrix(0.92218368,0.00169429,-0.00169429,0.92218368,-452.50678,78.944729)"
id="path3858"
inkscape:connector-curvature="0"
sodipodi:nodetypes="sssccssccasssssscssccssccssccsssscsscscscsscssssacssssss" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.2 KiB