2018-03-13 18:26:12 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-03-18 18:25:06 +01:00
|
|
|
"""
|
|
|
|
Doorlockd -- Binary Kitchen's smart door opener
|
|
|
|
|
|
|
|
Copyright (c) Binary Kitchen e.V., 2018
|
|
|
|
|
|
|
|
Author:
|
|
|
|
Ralf Ramsauer <ralf@binary-kitchen.de>
|
|
|
|
|
|
|
|
This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
the LICENSE file in the top-level directory.
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
2018-10-08 02:40:36 +02:00
|
|
|
from configparser import ConfigParser
|
2018-03-13 18:26:12 +01:00
|
|
|
from enum import Enum
|
2018-09-05 21:26:38 +02:00
|
|
|
from os.path import join
|
2018-03-13 18:26:12 +01:00
|
|
|
from serial import Serial
|
2018-03-18 22:03:48 +01:00
|
|
|
from subprocess import Popen
|
2018-03-18 15:48:59 +01:00
|
|
|
from threading import Thread
|
|
|
|
from time import sleep
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-06-29 23:42:13 +02:00
|
|
|
from flask import abort, Flask, jsonify, render_template, request
|
2018-03-13 18:26:12 +01:00
|
|
|
from flask_socketio import SocketIO
|
|
|
|
from flask_wtf import FlaskForm
|
|
|
|
from wtforms import PasswordField, StringField, SubmitField
|
|
|
|
from wtforms.validators import DataRequired, Length
|
|
|
|
|
2018-10-08 01:12:32 +02:00
|
|
|
from pydoorlock.Authenticator import Authenticator, AuthMethod, AuthenticationResult
|
2018-10-08 01:56:59 +02:00
|
|
|
from pydoorlock.WebApp import AuthenticationForm
|
2018-10-08 01:55:42 +02:00
|
|
|
from pydoorlock.Door import DoorState
|
2018-10-08 01:12:32 +02:00
|
|
|
|
2018-09-05 21:26:38 +02:00
|
|
|
SYSCONFDIR = '.'
|
|
|
|
PREFIX = '.'
|
|
|
|
|
2018-09-05 21:29:12 +02:00
|
|
|
root_prefix = join(PREFIX, 'share', 'doorlockd')
|
|
|
|
sounds_prefix = join(root_prefix, 'sounds')
|
2018-09-05 23:14:28 +02:00
|
|
|
static_folder = join(root_prefix, 'static')
|
|
|
|
template_folder = join(root_prefix, 'templates')
|
2018-09-05 23:47:42 +02:00
|
|
|
scripts_prefix = join(root_prefix, 'scripts')
|
2018-09-05 23:14:28 +02:00
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
__author__ = 'Ralf Ramsauer'
|
|
|
|
__copyright = 'Copyright (c) Ralf Ramsauer, 2018'
|
|
|
|
__license__ = 'GPLv2'
|
|
|
|
__email__ = 'ralf@binary-kitchen.de'
|
|
|
|
__status__ = 'Development'
|
|
|
|
__maintainer__ = 'Ralf Ramsauer'
|
2018-10-07 03:48:13 +02:00
|
|
|
__version__ = '2.0-rc2'
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
log_level = logging.DEBUG
|
|
|
|
date_fmt = '%Y-%m-%d %H:%M:%S'
|
|
|
|
log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s'
|
|
|
|
log = logging.getLogger()
|
|
|
|
|
2018-09-05 23:14:28 +02:00
|
|
|
webapp = Flask(__name__,
|
|
|
|
template_folder=template_folder,
|
|
|
|
static_folder=static_folder)
|
2018-04-03 23:29:51 +02:00
|
|
|
socketio = SocketIO(webapp, async_mode='threading')
|
2018-09-17 19:54:33 +02:00
|
|
|
|
2018-10-08 02:40:36 +02:00
|
|
|
class Config:
|
|
|
|
config_topic = 'doorlock'
|
|
|
|
|
|
|
|
def __init__(self, sysconfdir):
|
|
|
|
self.config = ConfigParser()
|
|
|
|
self.config.read([join(sysconfdir, 'doorlockd.default.cfg'),
|
|
|
|
join(sysconfdir, 'doorlockd.cfg')])
|
|
|
|
|
|
|
|
def boolean(self, key):
|
|
|
|
return self.config.getboolean(self.config_topic, key)
|
|
|
|
|
|
|
|
def str(self, key):
|
|
|
|
return self.config.get(self.config_topic, key)
|
|
|
|
|
|
|
|
cfg = Config(SYSCONFDIR)
|
|
|
|
|
|
|
|
# Booleans
|
|
|
|
debug = cfg.boolean('DEBUG')
|
|
|
|
simulate_serial = cfg.boolean('SIMULATE_SERIAL')
|
|
|
|
run_hooks = cfg.boolean('RUN_HOOKS')
|
|
|
|
sounds = cfg.boolean('SOUNDS')
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-10-08 02:40:36 +02:00
|
|
|
serial_port = cfg.str('SERIAL_PORT')
|
|
|
|
room = cfg.str('ROOM')
|
|
|
|
title = cfg.str('TITLE')
|
|
|
|
welcome = cfg.str('WELCOME')
|
|
|
|
|
|
|
|
webapp.config['SECRET_KEY'] = cfg.str('SECRET_KEY')
|
|
|
|
|
|
|
|
|
|
|
|
html_title = '%s (%s - v%s)' % (title, __status__, __version__)
|
2018-03-23 00:32:34 +01:00
|
|
|
|
2018-09-05 21:29:12 +02:00
|
|
|
wave_emergency = 'emergency_unlock.wav'
|
2018-10-07 03:47:05 +02:00
|
|
|
|
2018-09-05 21:29:12 +02:00
|
|
|
wave_lock = 'lock.wav'
|
|
|
|
wave_lock_button = 'lock_button.wav'
|
2018-10-07 03:47:05 +02:00
|
|
|
|
|
|
|
wave_present = 'present.wav'
|
|
|
|
wave_present_button = 'present.wav'
|
|
|
|
|
2018-09-05 21:29:12 +02:00
|
|
|
wave_unlock = 'unlock.wav'
|
|
|
|
wave_unlock_button = 'unlock_button.wav'
|
2018-10-07 03:47:05 +02:00
|
|
|
|
2018-09-05 21:29:12 +02:00
|
|
|
wave_zonk = 'zonk.wav'
|
|
|
|
|
2018-03-23 23:00:25 +01:00
|
|
|
|
2018-09-05 20:23:39 +02:00
|
|
|
host = 'localhost'
|
2018-10-08 02:40:36 +02:00
|
|
|
if debug:
|
2018-09-05 20:23:39 +02:00
|
|
|
host = '0.0.0.0'
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-03-23 23:00:25 +01:00
|
|
|
def playsound(filename):
|
|
|
|
if not sounds:
|
|
|
|
return
|
2018-09-05 21:29:12 +02:00
|
|
|
Popen(['nohup', 'aplay', join(sounds_prefix, filename)])
|
2018-03-23 23:00:25 +01:00
|
|
|
|
|
|
|
|
2018-03-18 22:03:48 +01:00
|
|
|
def start_hook(script):
|
2018-03-21 00:58:16 +01:00
|
|
|
if not run_hooks:
|
|
|
|
log.info('Hooks disabled: not starting %s' % script)
|
2018-03-18 22:03:48 +01:00
|
|
|
return
|
|
|
|
log.info('Starting hook %s' % script)
|
2018-09-05 23:47:42 +02:00
|
|
|
Popen(['nohup', join(scripts_prefix, script)])
|
2018-03-18 22:03:48 +01:00
|
|
|
|
|
|
|
|
2018-10-07 03:47:05 +02:00
|
|
|
def sound_helper(old_state, new_state, button):
|
|
|
|
if old_state == new_state:
|
|
|
|
playsound(wave_zonk)
|
|
|
|
|
|
|
|
if button:
|
|
|
|
if new_state == DoorState.Open:
|
|
|
|
playsound(wave_unlock_button)
|
|
|
|
elif new_state == DoorState.Present:
|
|
|
|
playsound(wave_present_button)
|
|
|
|
elif new_state == DoorState.Closed:
|
|
|
|
playsound(wave_lock_button)
|
|
|
|
else:
|
|
|
|
if new_state == DoorState.Open:
|
|
|
|
playsound(wave_unlock)
|
|
|
|
elif new_state == DoorState.Present:
|
|
|
|
playsound(wave_present)
|
|
|
|
elif new_state == DoorState.Closed:
|
|
|
|
playsound(wave_lock)
|
|
|
|
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
class LogicResponse(Enum):
|
|
|
|
Success = 0
|
|
|
|
Perm = 1
|
2018-09-03 00:29:30 +02:00
|
|
|
AlreadyActive = 2
|
|
|
|
# don't break old apps, value 3 is reserved now
|
|
|
|
RESERVED = 3
|
2018-03-13 18:26:12 +01:00
|
|
|
Inval = 4
|
|
|
|
|
2018-03-19 18:46:33 +01:00
|
|
|
EmergencyUnlock = 10,
|
|
|
|
ButtonLock = 11,
|
|
|
|
ButtonUnlock = 12,
|
2018-09-02 04:11:15 +02:00
|
|
|
ButtonPresent = 13,
|
2018-03-19 18:46:33 +01:00
|
|
|
|
2018-10-08 01:12:32 +02:00
|
|
|
def __str__(self):
|
2018-03-13 18:26:12 +01:00
|
|
|
if self == LogicResponse.Success:
|
|
|
|
return 'Yo, passt.'
|
|
|
|
elif self == LogicResponse.Perm:
|
|
|
|
return choose_insult()
|
2018-09-03 00:29:30 +02:00
|
|
|
elif self == LogicResponse.AlreadyActive:
|
|
|
|
return 'Zustand bereits aktiv'
|
2018-03-13 18:26:12 +01:00
|
|
|
elif self == LogicResponse.Inval:
|
|
|
|
return 'Das was du willst geht nicht.'
|
2018-03-19 18:46:33 +01:00
|
|
|
elif self == LogicResponse.EmergencyUnlock:
|
|
|
|
return '!!! Emergency Unlock !!!'
|
|
|
|
elif self == LogicResponse.ButtonLock:
|
2018-09-02 04:11:15 +02:00
|
|
|
return 'Closed by button'
|
2018-03-19 18:46:33 +01:00
|
|
|
elif self == LogicResponse.ButtonUnlock:
|
2018-09-02 04:11:15 +02:00
|
|
|
return 'Opened by button'
|
|
|
|
elif self == LogicResponse.ButtonPresent:
|
|
|
|
return 'Present by button'
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-10-08 01:12:32 +02:00
|
|
|
return 'Error'
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DoorHandler:
|
2018-09-02 04:11:15 +02:00
|
|
|
state = DoorState.Closed
|
|
|
|
do_close = False
|
|
|
|
|
|
|
|
CMD_PRESENT = b'y'
|
|
|
|
CMD_OPEN = b'g'
|
|
|
|
CMD_CLOSE = b'r'
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-09-02 04:11:15 +02:00
|
|
|
BUTTON_PRESENT = b'Y'
|
|
|
|
BUTTON_OPEN = b'G'
|
|
|
|
BUTTON_CLOSE = b'R'
|
2018-09-04 01:05:46 +02:00
|
|
|
|
|
|
|
CMD_EMERGENCY_SWITCH = b'E'
|
2018-09-02 04:11:15 +02:00
|
|
|
# TBD DOOR NOT CLOSED
|
2018-03-19 18:46:33 +01:00
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
def __init__(self, device):
|
2018-09-02 04:00:03 +02:00
|
|
|
if simulate_serial:
|
2018-03-16 16:52:43 +01:00
|
|
|
return
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
self.serial = Serial(device, baudrate=9600, bytesize=8, parity='N',
|
2018-03-19 18:46:33 +01:00
|
|
|
stopbits=1, timeout=0)
|
2018-03-13 18:26:12 +01:00
|
|
|
self.thread = Thread(target=self.thread_worker)
|
2018-09-06 00:49:23 +02:00
|
|
|
log.debug('Spawning RS232 Thread')
|
2018-03-13 18:26:12 +01:00
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def thread_worker(self):
|
|
|
|
while True:
|
2018-03-19 18:46:33 +01:00
|
|
|
sleep(0.4)
|
|
|
|
while True:
|
2018-09-06 00:49:23 +02:00
|
|
|
rx = self.serial.read(1)
|
|
|
|
if len(rx) == 0:
|
2018-03-19 18:46:33 +01:00
|
|
|
break
|
2018-10-07 03:47:05 +02:00
|
|
|
|
|
|
|
old_state = self.state
|
2018-09-06 00:49:23 +02:00
|
|
|
if rx == DoorHandler.BUTTON_CLOSE:
|
|
|
|
self.close()
|
|
|
|
log.info('Closed due to Button press')
|
|
|
|
logic.emit_status(LogicResponse.ButtonLock)
|
|
|
|
elif rx == DoorHandler.BUTTON_OPEN:
|
|
|
|
self.open()
|
|
|
|
log.info('Opened due to Button press')
|
|
|
|
logic.emit_status(LogicResponse.ButtonUnlock)
|
|
|
|
elif rx == DoorHandler.BUTTON_PRESENT:
|
|
|
|
self.present()
|
|
|
|
log.info('Present due to Button press')
|
|
|
|
logic.emit_status(LogicResponse.ButtonPresent)
|
|
|
|
elif rx == DoorHandler.CMD_EMERGENCY_SWITCH:
|
|
|
|
log.warning('Emergency unlock')
|
|
|
|
logic.emit_status(LogicResponse.EmergencyUnlock)
|
|
|
|
else:
|
|
|
|
log.error('Received unknown message "%s" from AVR' % rx)
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-10-07 03:47:05 +02:00
|
|
|
sound_helper(old_state, self.state, True)
|
|
|
|
|
2018-09-02 04:11:15 +02:00
|
|
|
if self.do_close:
|
2018-09-06 00:49:23 +02:00
|
|
|
tx = DoorHandler.CMD_CLOSE
|
2018-09-02 04:11:15 +02:00
|
|
|
self.do_close = False
|
2018-09-08 00:58:32 +02:00
|
|
|
elif self.state == DoorState.Present:
|
2018-09-06 00:49:23 +02:00
|
|
|
tx = DoorHandler.CMD_PRESENT
|
|
|
|
elif self.state == DoorState.Open:
|
|
|
|
tx = DoorHandler.CMD_OPEN
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
self.serial.write(tx)
|
|
|
|
self.serial.flush()
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
def open(self):
|
|
|
|
if self.state == DoorState.Open:
|
2018-09-03 00:29:30 +02:00
|
|
|
return LogicResponse.AlreadyActive
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
self.state = DoorState.Open
|
2018-09-08 00:37:21 +02:00
|
|
|
start_hook('post_unlock')
|
2018-03-13 18:26:12 +01:00
|
|
|
return LogicResponse.Success
|
|
|
|
|
2018-09-08 00:37:21 +02:00
|
|
|
def present(self):
|
|
|
|
if self.state == DoorState.Present:
|
2018-09-03 00:29:30 +02:00
|
|
|
return LogicResponse.AlreadyActive
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-09-08 00:37:21 +02:00
|
|
|
self.state = DoorState.Present
|
|
|
|
start_hook('post_present')
|
2018-03-13 18:26:12 +01:00
|
|
|
return LogicResponse.Success
|
|
|
|
|
2018-09-08 00:37:21 +02:00
|
|
|
def close(self):
|
|
|
|
if self.state == DoorState.Closed:
|
2018-09-03 00:29:30 +02:00
|
|
|
return LogicResponse.AlreadyActive
|
2018-09-02 04:11:15 +02:00
|
|
|
|
2018-09-08 00:37:21 +02:00
|
|
|
self.do_close = True
|
|
|
|
self.state = DoorState.Closed
|
|
|
|
start_hook('post_lock')
|
2018-09-02 04:11:15 +02:00
|
|
|
return LogicResponse.Success
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
def request(self, state):
|
2018-09-02 04:11:15 +02:00
|
|
|
if state == DoorState.Closed:
|
2018-03-13 18:26:12 +01:00
|
|
|
return self.close()
|
2018-09-02 04:11:15 +02:00
|
|
|
elif state == DoorState.Present:
|
|
|
|
return self.present()
|
2018-03-13 18:26:12 +01:00
|
|
|
elif state == DoorState.Open:
|
|
|
|
return self.open()
|
|
|
|
|
|
|
|
|
|
|
|
class Logic:
|
2018-03-18 16:35:09 +01:00
|
|
|
def __init__(self):
|
2018-10-08 19:47:26 +02:00
|
|
|
self.auth = Authenticator(cfg)
|
2018-10-08 01:12:32 +02:00
|
|
|
self.door_handler = DoorHandler(serial_port)
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
def _request(self, state, credentials):
|
2018-10-08 01:12:32 +02:00
|
|
|
err = self.auth.try_auth(credentials)
|
|
|
|
if err != AuthenticationResult.Success:
|
2018-03-13 18:26:12 +01:00
|
|
|
return err
|
|
|
|
return self.door_handler.request(state)
|
|
|
|
|
|
|
|
def request(self, state, credentials):
|
2018-10-07 03:47:05 +02:00
|
|
|
old_state = self.door_handler.state
|
2018-03-13 18:26:12 +01:00
|
|
|
err = self._request(state, credentials)
|
2018-10-07 03:47:05 +02:00
|
|
|
if err == LogicResponse.Success or err == LogicResponse.AlreadyActive:
|
|
|
|
sound_helper(old_state, self.door_handler.state, False)
|
2018-03-18 17:47:50 +01:00
|
|
|
self.emit_status(err)
|
2018-03-13 18:26:12 +01:00
|
|
|
return err
|
|
|
|
|
2018-03-18 17:47:50 +01:00
|
|
|
def emit_status(self, message=None):
|
|
|
|
led = self.state.to_img()
|
|
|
|
if message is None:
|
|
|
|
message = self.state.to_html()
|
|
|
|
else:
|
2018-10-08 01:12:32 +02:00
|
|
|
message = str(message)
|
2018-03-18 17:47:50 +01:00
|
|
|
|
|
|
|
socketio.emit('status', {'led': led, 'message': message})
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
return self.door_handler.state
|
|
|
|
|
|
|
|
|
2018-03-18 18:21:07 +01:00
|
|
|
@socketio.on('request_status')
|
2018-03-13 18:26:12 +01:00
|
|
|
@socketio.on('connect')
|
|
|
|
def on_connect():
|
2018-03-18 17:47:50 +01:00
|
|
|
logic.emit_status()
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
@webapp.route('/display')
|
|
|
|
def display():
|
2018-09-17 19:54:33 +02:00
|
|
|
return render_template('display.html',
|
|
|
|
room=room,
|
|
|
|
title=title,
|
|
|
|
welcome=welcome)
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
|
2018-06-29 23:42:13 +02:00
|
|
|
@webapp.route('/api', methods=['POST'])
|
|
|
|
def api():
|
|
|
|
def json_response(response, msg=None):
|
|
|
|
json = dict()
|
|
|
|
json['err'] = response.value
|
|
|
|
json['msg'] = response.to_html() if msg is None else msg
|
|
|
|
if response == LogicResponse.Success or \
|
2018-09-03 00:29:30 +02:00
|
|
|
response == LogicResponse.AlreadyActive:
|
2018-09-03 00:19:24 +02:00
|
|
|
# TBD: Remove 'open'. No more users. Still used in App Version 2.1.1!
|
2018-09-02 04:11:15 +02:00
|
|
|
json['open'] = logic.state.is_open()
|
2018-09-03 00:19:24 +02:00
|
|
|
json['status'] = logic.state.value
|
2018-06-29 23:42:13 +02:00
|
|
|
return jsonify(json)
|
|
|
|
|
2018-09-18 00:25:21 +02:00
|
|
|
method = request.form.get('method')
|
2018-06-29 23:42:13 +02:00
|
|
|
user = request.form.get('user')
|
|
|
|
password = request.form.get('pass')
|
|
|
|
command = request.form.get('command')
|
|
|
|
|
2018-09-18 00:25:21 +02:00
|
|
|
if method == 'local':
|
|
|
|
method = AuthMethod.LOCAL_USER_DB
|
|
|
|
else: # 'ldap' or default
|
|
|
|
method = AuthMethod.LDAP_USER_PW
|
|
|
|
|
2018-06-29 23:42:13 +02:00
|
|
|
if any(v is None for v in [user, password, command]):
|
|
|
|
log.warning('Incomplete API request')
|
|
|
|
abort(400)
|
|
|
|
|
|
|
|
if not user or not password:
|
|
|
|
log.warning('Invalid username or password format')
|
|
|
|
return json_response(LogicResponse.Inval,
|
|
|
|
'Invalid username or password format')
|
|
|
|
|
2018-09-18 00:25:21 +02:00
|
|
|
credentials = method, user, password
|
2018-06-29 23:42:13 +02:00
|
|
|
|
|
|
|
if command == 'status':
|
|
|
|
return json_response(logic.try_auth(credentials))
|
|
|
|
|
2018-09-02 23:21:26 +02:00
|
|
|
desired_state = DoorState.from_string(command)
|
2018-06-29 23:42:13 +02:00
|
|
|
if not desired_state:
|
|
|
|
return json_response(LogicResponse.Inval, "Invalid command requested")
|
|
|
|
|
|
|
|
log.info('Incoming API request from %s' % user.encode('utf-8'))
|
|
|
|
log.info(' desired state: %s' % desired_state)
|
|
|
|
log.info(' current state: %s' % logic.state)
|
|
|
|
|
|
|
|
response = logic.request(desired_state, credentials)
|
|
|
|
|
|
|
|
return json_response(response)
|
|
|
|
|
|
|
|
|
2018-03-13 18:26:12 +01:00
|
|
|
@webapp.route('/', methods=['GET', 'POST'])
|
|
|
|
def home():
|
|
|
|
authentication_form = AuthenticationForm()
|
|
|
|
response = None
|
|
|
|
|
|
|
|
if request.method == 'POST' and authentication_form.validate():
|
|
|
|
user = authentication_form.username.data
|
|
|
|
password = authentication_form.password.data
|
2018-09-18 01:02:44 +02:00
|
|
|
method = authentication_form.method
|
|
|
|
credentials = method, user, password
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-03-20 00:54:52 +01:00
|
|
|
log.info('Incoming request from %s' % user.encode('utf-8'))
|
2018-09-18 01:02:44 +02:00
|
|
|
log.info(' authentication method: %s' % method)
|
2018-03-13 18:26:12 +01:00
|
|
|
desired_state = authentication_form.desired_state
|
|
|
|
log.info(' desired state: %s' % desired_state)
|
|
|
|
log.info(' current state: %s' % logic.state)
|
|
|
|
response = logic.request(desired_state, credentials)
|
|
|
|
log.info(' response: %s' % response)
|
|
|
|
|
2018-03-21 00:29:13 +01:00
|
|
|
# Don't trust python, zero credentials
|
|
|
|
user = password = credentials = None
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
return render_template('index.html',
|
|
|
|
authentication_form=authentication_form,
|
2018-10-08 01:12:32 +02:00
|
|
|
auth_backends=logic.auth.backends,
|
2018-03-13 18:26:12 +01:00
|
|
|
response=response,
|
|
|
|
state_text=logic.state.to_html(),
|
2018-03-18 17:22:08 +01:00
|
|
|
led=logic.state.to_img(),
|
2018-09-17 19:54:33 +02:00
|
|
|
banner='%s - %s' % (title, room))
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
logging.basicConfig(level=log_level, stream=sys.stdout,
|
|
|
|
format=log_fmt, datefmt=date_fmt)
|
|
|
|
log.info('Starting doorlockd')
|
2018-10-08 02:40:36 +02:00
|
|
|
log.info('Using serial port: %s' % serial_port)
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-03-18 16:35:09 +01:00
|
|
|
logic = Logic()
|
2018-03-13 18:26:12 +01:00
|
|
|
|
2018-10-08 02:40:36 +02:00
|
|
|
socketio.run(webapp, host=host, port=8080, use_reloader=False, debug=debug)
|
2018-03-13 18:26:12 +01:00
|
|
|
|
|
|
|
sys.exit(0)
|