diff --git a/doorlockd-new/TODOs b/TODOs similarity index 100% rename from doorlockd-new/TODOs rename to TODOs diff --git a/doorlockd-new/config.cfg b/config.cfg similarity index 100% rename from doorlockd-new/config.cfg rename to config.cfg diff --git a/doorlockd-new/doorlockd.py b/doorlockd.py similarity index 100% rename from doorlockd-new/doorlockd.py rename to doorlockd.py diff --git a/doorlockd-new/doorlockd.service b/doorlockd.service similarity index 100% rename from doorlockd-new/doorlockd.service rename to doorlockd.service diff --git a/doorlockd/CMakeLists.txt b/doorlockd/CMakeLists.txt deleted file mode 100644 index ae5af39..0000000 --- a/doorlockd/CMakeLists.txt +++ /dev/null @@ -1,146 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project(doorlockd) - -option(USE_COLORIZED_LOGS "Colorized logging" ON) -option(DORLOCKD_CMAKE_DEBUG "Add some debug output" Off) - -set(DOORLOCK_VERSION_MAJOR 1) -set(DOORLOCK_VERSION_MINOR 4) -set(DOORLOCK_VERSION_PATCH 0) - -set(DOORLOCK_VERSION "${DOORLOCK_VERSION_MAJOR}.${DOORLOCK_VERSION_MINOR}.${DOORLOCK_VERSION_PATCH}") - -# Instruct CMake to run moc automatically when needed. -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - -if(DORLOCKD_CMAKE_DEBUG) - message(STATUS "[${CMAKE_CURRENT_LIST_DIR}:${CMAKE_CURRENT_LIST_LINE}] " - "doorlockd version: ${DOORLOCK_VERSION}") -endif() - -# Get the current working branch -execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE -) -set(GIT_BRANCH "\"${GIT_BRANCH}\"") - -if(DORLOCKD_CMAKE_DEBUG) - message(STATUS "[${CMAKE_CURRENT_LIST_DIR}:${CMAKE_CURRENT_LIST_LINE}] " - "git branch: ${GIT_BRANCH}") -endif() - -# Get the latest abbreviated commit hash of the working branch -execute_process( - COMMAND git log -1 --format=%h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE -) -set(GIT_COMMIT_HASH "\"${GIT_COMMIT_HASH}\"") - -if(DORLOCKD_CMAKE_DEBUG) - message(STATUS "[${CMAKE_CURRENT_LIST_DIR}:${CMAKE_CURRENT_LIST_LINE}] " - "git commit hash: ${GIT_COMMIT_HASH}") -endif() - -add_definitions(-std=c++11) - -configure_file ( - "${PROJECT_SOURCE_DIR}/config.h.in" - "${PROJECT_BINARY_DIR}/config.h" -) - -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb -Wall -pedantic -Weffc++ -Wextra -Wno-unused-result") -set(CMAKE_CXX_FLAGS "-O2 -Wall -pedantic -Wextra -Weffc++ -Wno-unused-result") -set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb -Wall -pedantic -Wextra -Wno-unused-result") -set(CMAKE_C_FLAGS "-O2 -Wall -pedantic -Wextra -Wno-unused-result") - -find_package(Boost 1.55.0 COMPONENTS filesystem program_options system REQUIRED) - -set(JSON_INCLUDE_DIR "/usr/include/jsoncpp" CACHE PATH "path to jsoncpp includes") - -find_package (Threads) - -find_package(Qt5Widgets) - -include_directories( - ${Boost_INCLUDE_DIRS} - ${PROJECT_BINARY_DIR} - ${JSON_INCLUDE_DIR}) - -set(_LIBDOORLOCK_SRCS - lib/clientmessage.cpp - lib/clientmessage.h - lib/door.cpp - lib/door.h - lib/doormessage.cpp - lib/doormessage.h - lib/logger.cpp - lib/logger.h - lib/logic.cpp - lib/logic.h - lib/request.cpp - lib/request.h - lib/response.cpp - lib/response.h - lib/util.cpp - lib/util.h) - -set(_DOORLOCKD_SRCS - daemon/doorlockd.cpp) - -set(_DOORLOCK_CLIENT_SRCS - client/qrwidget.cpp - client/qrwidget.h - client/doorlock-client.cpp - client/mainwindow.h - client/mainwindow.cpp - client/mainwindow.ui - client/network.cpp - client/network.h - client/wave.h - client/wave.cpp) - -add_library(doorlock STATIC ${_LIBDOORLOCK_SRCS}) -target_link_libraries(doorlock jsoncpp ldap ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(doorlockd ${_DOORLOCKD_SRCS}) -target_link_libraries(doorlockd doorlock) - -add_executable(doorlock-client ${_DOORLOCK_CLIENT_SRCS}) -target_link_libraries(doorlock-client doorlock qrencode Qt5::Widgets) -target_include_directories(doorlock-client PRIVATE ${CMAKE_SOURCE_DIR}) - -mark_as_advanced( - _LIBDOORLOCK_SRCS - _DOORLOCKD_SRCS - _DOORLOCK_CLIENT_SRCS) - -install(TARGETS doorlockd DESTINATION sbin/) -install(TARGETS doorlock-client DESTINATION bin/) - -install(DIRECTORY images/ DESTINATION share/doorlockd/images - FILES_MATCHING PATTERN "images/*.png" - PERMISSIONS WORLD_READ OWNER_READ GROUP_READ) - -install(DIRECTORY sounds/ DESTINATION share/doorlockd/sounds - FILES_MATCHING PATTERN "sounds/*.wav" - PERMISSIONS WORLD_READ OWNER_READ GROUP_READ) - -install(FILES scripts/doorlockd.service DESTINATION /etc/systemd/system/) - -install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ - FILES_MATCHING PATTERN "scripts/pre_*lock" - PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) - -install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ - FILES_MATCHING PATTERN "scripts/post_*lock" - PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) - -install(DIRECTORY scripts/ DESTINATION etc/doorlockd/ - FILES_MATCHING PATTERN "scripts/emergency_unlock" - PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE) diff --git a/doorlockd/client/doorlock-client.cpp b/doorlockd/client/doorlock-client.cpp deleted file mode 100644 index 577d19d..0000000 --- a/doorlockd/client/doorlock-client.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include - -#include - -#include - -#include "config.h" -#include "mainwindow.h" - -// Info about doorlock-client version -const static std::string version = - "doorlock-client-" DOORLOCK_VERSION; -const static std::string gitversion = - DOORLOCK_GIT_BRANCH "-" DOORLOCK_GIT_COMMIT_HASH; - -namespace po = boost::program_options; - -int main(int argc, char** argv) -{ - int retval = 0; - Logger &l = Logger::get(); - l((std::string)"Hello, this is " + version + " built on " + gitversion, - LogLevel::info); - - try { - QApplication app(argc, argv); - std::string hostname; - unsigned short port; - po::variables_map vm; - - qRegisterMetaType("Clientmessage"); - app.setOrganizationName("Binary Kitchen"); - app.setApplicationName("doorlock-client"); - - po::options_description desc("doorlockd (" + version + " built on " + gitversion + ")"); - desc.add_options() - ("help,h", - "print help") - ("port,p", - po::value(&port)->default_value(DEFAULT_PORT), - "Port") - ("host,c", - po::value(&hostname)->default_value("localhost"), - "IP or name of host running doorlockd"); - - po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); - - if (vm.count("help")) - { - std::cout << desc << std::endl; - exit(-1); - } - - po::notify(vm); - l(LogLevel::notice, "Starting doorlock-client"); - - // Start main GUI - MainWindow mainWindow(hostname, port); - mainWindow.showFullScreen(); - - // This routine will never return under normal conditions - retval = app.exec(); - - mainWindow.hide(); - mainWindow.close(); - } - catch(const std::exception &e) - { - l(LogLevel::error, e.what()); - retval = -1; - } - - l(LogLevel::notice, "Stopping doorlock-client"); - return retval; -} diff --git a/doorlockd/client/mainwindow.cpp b/doorlockd/client/mainwindow.cpp deleted file mode 100644 index 38214ef..0000000 --- a/doorlockd/client/mainwindow.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "config.h" - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "network.h" - -MainWindow::MainWindow(const std::string &hostname, - const unsigned short port, - QWidget* parent) : - QWidget(parent), - ui(new Ui::MainWindow), - _soundLock(Wave(SOUND_LOCK)), - _soundUnlock(Wave(SOUND_UNLOCK)), - _soundEmergencyUnlock(Wave(SOUND_EMERGENCY_UNLOCK)), - _soundZonk(Wave(SOUND_ZONK)), - _soundLockButton(Wave(SOUND_LOCK_BUTTON)), - _soundUnlockButton(Wave(SOUND_UNLOCK_BUTTON)) -{ - ui->setupUi(this); - _LED(false); - NetworkThread* nw = new NetworkThread(hostname, port); - connect(nw, SIGNAL(new_clientmessage(Clientmessage)), - SLOT(setClientmessage(Clientmessage))); - connect(nw, SIGNAL(finished()), - nw, SLOT(deleteLater())); - nw->start(); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::setClientmessage(const Clientmessage &msg) -{ - ui->qrwidget->setQRData(msg.web_address()); - ui->address->setText(QString::fromStdString(msg.web_address())); - ui->token->setText(QString::fromStdString(msg.token())); - QString statusMessage(""); - - const auto &doormsg = msg.doormessage(); - - _LED(msg.isOpen()); - - if (_oldMessage.isOpen() - && !msg.isOpen() - && !doormsg.isLockButton) { - // regular close - statusMessage = "Bye bye. See you next time!"; - _soundLock.playAsync(); - } else if (!_oldMessage.isOpen() && msg.isOpen()) { - // regular open - statusMessage = "Come in! Happy hacking!"; - _soundUnlock.playAsync(); - } else { - // no change - } - - if (doormsg.isEmergencyUnlock) { - _soundEmergencyUnlock.playAsync(); - statusMessage = "!! EMERGENCY UNLOCK !!"; - } else if (doormsg.isLockButton) { - _soundLockButton.playAsync(); - statusMessage = "!! LOCK BUTTON !!"; - } else if (doormsg.isUnlockButton) { - statusMessage = "!! UNLOCK BUTTON !!"; - if (msg.isOpen()) { - _soundZonk.playAsync(); - } else { - _soundUnlockButton.playAsync(); - } - } - - ui->message->setText(statusMessage); - - _oldMessage = msg; -} - -void MainWindow::_LED(const bool on) -{ - if (on) - ui->LED->setPixmap(QPixmap(IMAGE_LED_GREEN)); - else - ui->LED->setPixmap(QPixmap(IMAGE_LED_RED)); -} diff --git a/doorlockd/client/mainwindow.h b/doorlockd/client/mainwindow.h deleted file mode 100644 index 437ee8c..0000000 --- a/doorlockd/client/mainwindow.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -#include "../lib/clientmessage.h" -#include "../lib/logger.h" -#include "wave.h" - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QWidget -{ - Q_OBJECT - -public: - explicit MainWindow(const std::string &hostname, - const unsigned short port, - QWidget *parent = 0); - - MainWindow(const MainWindow &rhs); - MainWindow &operator =(const MainWindow &rhs); - - ~MainWindow(); - -public slots: - void setClientmessage(const Clientmessage &msg); - -private: - Ui::MainWindow *ui; - - Clientmessage _oldMessage = { }; - - const Wave _soundLock; - const Wave _soundUnlock; - const Wave _soundEmergencyUnlock; - const Wave _soundZonk; - const Wave _soundLockButton; - const Wave _soundUnlockButton; - - void _LED(const bool on); -}; - -#endif // MAINWINDOW_H diff --git a/doorlockd/client/mainwindow.ui b/doorlockd/client/mainwindow.ui deleted file mode 100644 index 054d8bc..0000000 --- a/doorlockd/client/mainwindow.ui +++ /dev/null @@ -1,168 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 400 - - - - Form - - - - - - - 36 - - - - Willkommen in der Binary Kitchen! - - - - - - - QLayout::SetFixedSize - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - TextLabel - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 28 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 36 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 22 - - - - - - - - - - - - - Qt::Vertical - - - - - - - - - Qt::Horizontal - - - - - - - - QRWidget - QWidget -
client/qrwidget.h
- 1 -
-
- - -
diff --git a/doorlockd/client/network.cpp b/doorlockd/client/network.cpp deleted file mode 100644 index 59db568..0000000 --- a/doorlockd/client/network.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "network.h" - -#include "../lib/response.h" - -namespace ba = boost::asio; -using ba::ip::tcp; - -const std::string NetworkThread::_subscription_command = "{ \"command\": \"subscribe\"}"; - -NetworkThread::NetworkThread(const std::string &hostname, - const unsigned short port) : - QThread(), - _l(Logger::get()), - _hostname(hostname), - _port(port), - _io_service() -{ -} - -void NetworkThread::run() { - do { - try { - tcp::resolver resolver(_io_service); - tcp::socket socket(_io_service); - tcp::resolver::query query(_hostname, std::to_string(_port)); - tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); - tcp::resolver::iterator end; - boost::system::error_code error = ba::error::host_not_found; - std::vector data; - - while (error && endpoint_iterator != end) { - socket.close(); - socket.connect(*endpoint_iterator++, error); - } - if (error) - throw boost::system::system_error(error); - - // After connection is established, send the subscription command - socket.write_some(ba::buffer(_subscription_command), error); - if (error) - throw boost::system::system_error(error); - - data.resize(_SOCKET_BUFFERLENGTH); - - std::function receiveMessage = [&] () { - socket.async_read_some(ba::buffer(data), - [&] (const boost::system::error_code &ec, - const size_t length) - { - if (ec) { - throw boost::system::system_error(ec); - } - - const auto msg = Clientmessage::fromString( - std::string(data.begin(), data.begin()+length)); - - // Received valid Clientmessage - // Log it! - const auto& doormessage = msg.doormessage(); - _l("Received message", LogLevel::info); - _l((std::string)" token: " + msg.web_address(), - LogLevel::info); - _l((std::string)" open: " + std::to_string(msg.isOpen()), - LogLevel::info); - _l((std::string)" button lock: " + std::to_string(doormessage.isLockButton), - LogLevel::info); - _l((std::string)" button unlock: " + std::to_string(doormessage.isUnlockButton), - LogLevel::info); - _l((std::string)" emergency open: " + std::to_string(doormessage.isEmergencyUnlock), - LogLevel::info); - - // Emit the new message - emit new_clientmessage(msg); - - // Wait for new message - receiveMessage(); - }); - }; - - receiveMessage(); - _io_service.run(); - } - catch(const Response &err) { - _l(err.message, LogLevel::error); - } - catch(const std::exception &err) { - _l(LogLevel::error, err.what()); - } - - sleep(1); - } while(1); - - _io_service.reset(); -} diff --git a/doorlockd/client/network.h b/doorlockd/client/network.h deleted file mode 100644 index c4e980b..0000000 --- a/doorlockd/client/network.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef NETWORK_H -#define NETWORK_H - -#include - -#include -#include - -#include "../lib/clientmessage.h" -#include "../lib/logger.h" - -class NetworkThread : public QThread { - Q_OBJECT - -public: - NetworkThread(const std::string &hostname, - const unsigned short port); - -private: - void run(); - - Logger &_l; - const std::string _hostname; - const unsigned short _port; - - boost::asio::io_service _io_service; - - const static std::string _subscription_command; - - // The receive buffer length of the TCP socket - constexpr static int _SOCKET_BUFFERLENGTH = {2048}; - -signals: - void new_clientmessage(Clientmessage msg); -}; - -#endif diff --git a/doorlockd/client/qrwidget.cpp b/doorlockd/client/qrwidget.cpp deleted file mode 100644 index 27b4124..0000000 --- a/doorlockd/client/qrwidget.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -#include -#include - -#include - -#include "qrwidget.h" - -QRWidget::QRWidget(QWidget* parent) : - QWidget(parent), - _data(" ") -{ -} - -void QRWidget::setQRData(const std::string &data) -{ - _data = data; - update(); -} - -void QRWidget::paintEvent(QPaintEvent*) -{ - QPainter painter(this); - - std::unique_ptr qr( - QRcode_encodeString(_data.c_str(), 1, QR_ECLEVEL_L, QR_MODE_8, 1), - [] (QRcode* ptr) { - if (ptr) - QRcode_free(ptr); - }); - - if (!qr) - throw std::runtime_error("Error generating QR Code"); - - QColor fg("black"); - QColor bg("white"); - - painter.setBrush(bg); - painter.setPen(Qt::NoPen); - painter.drawRect(0,0,width(),height()); - painter.setBrush(fg); - - const int s=qr->width>0?qr->width:1; - const double w=width(); - const double h=height(); - const double aspect=w/h; - const double scale=((aspect>1.0)?h:w)/s; - - for(int y=0;ydata[xx]; - if(b &0x01) { - const double rx1=x*scale, ry1=y*scale; - QRectF r(rx1, ry1, scale, scale); - painter.drawRects(&r,1); - } - } - } -} diff --git a/doorlockd/client/qrwidget.h b/doorlockd/client/qrwidget.h deleted file mode 100644 index e1652fb..0000000 --- a/doorlockd/client/qrwidget.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef QRWIDGET_H -#define QRWIDGET_H - -#include - -#include - -class QRWidget : public QWidget -{ - Q_OBJECT - -public: - explicit QRWidget(QWidget *parent = nullptr); - void setQRData(const std::string &data); - -private: - std::string _data; - -protected: - void paintEvent(QPaintEvent *); -}; - -#endif diff --git a/doorlockd/client/wave.cpp b/doorlockd/client/wave.cpp deleted file mode 100644 index 26ee6bf..0000000 --- a/doorlockd/client/wave.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -#include "wave.h" - -std::mutex Wave::_playMutex = {}; - -Wave::Wave(const std::string &filename): - _filename(filename), - _command("aplay " + _filename) -{ -} - -Wave::~Wave() -{ -} - -void Wave::play() const -{ - std::lock_guard l(_playMutex); - system(_command.c_str()); -} - -void Wave::playAsync() const -{ - std::thread([this] () { - play(); - }).detach(); -} diff --git a/doorlockd/client/wave.h b/doorlockd/client/wave.h deleted file mode 100644 index ef6d15e..0000000 --- a/doorlockd/client/wave.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef WAVE_H -#define WAVE_H - -#include -#include - -class Wave { -public: - Wave(const std::string &filename); - Wave(const Wave &rhs); - ~Wave(); - - Wave &operator=(const Wave &rhs); - - void play() const; - void playAsync() const; - -private: - static std::mutex _playMutex; - - const std::string _filename; - const std::string _command; -}; - -#endif diff --git a/doorlockd/config.h.in b/doorlockd/config.h.in deleted file mode 100644 index 296eb00..0000000 --- a/doorlockd/config.h.in +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#cmakedefine USE_COLORIZED_LOGS - -#define DOORLOCK_VERSION_MAJOR "@DOORLOCK_VERSION_MAJOR@" -#define DOORLOCK_VERSION_MINOR "@DOORLOCK_VERSION_MINOR@" -#define DOORLOCK_VERSION_PATCH "@DOORLOCK_VERSION_PATCH@" -#define DOORLOCK_VERSION "@DOORLOCK_VERSION@" - -#define DOORLOCK_GIT_BRANCH @GIT_BRANCH@ -#define DOORLOCK_GIT_COMMIT_HASH @GIT_COMMIT_HASH@ - -#ifdef DEBUG -#define DEFAULT_LOG_LEVEL LogLevel::debug2 -#else -#define DEFAULT_LOG_LEVEL LogLevel::info -#endif - -#define DEFAULT_TOKEN_TIMEOUT (60*5) -#define DEFAULT_PORT 5555 -#define DEFAULT_WEB_PREFIX "https://lock.binary.kitchen/" -#define DEFAULT_LDAP_URI "ldaps://ldap1.binary.kitchen/ ldaps://ldap2.binary.kitchen/ ldaps://ldapm.binary.kitchen/" -#define DEFAULT_BINDDN "cn=%s,ou=people,dc=binary-kitchen,dc=de" -#define DEFAULT_TOKEN_LENGTH 6 -#define DEFAULT_LOG_DIR "/var/log/" -#define DEFAULT_SERIAL_DEVICE "/dev/ttyAMA0" -#define DEFAULT_SERIAL_BAUDRATE 9600UL - -#define LOG_FILENAME "doorlockd.log" -#define LOG_SCRIPTS_FILENAME "doorlockd-scripts.log" - -#define SHARED_LOCATION "@CMAKE_INSTALL_PREFIX@/share/doorlockd/" - -#define IMAGE_LOCATION SHARED_LOCATION "images/" -#define IMAGE_LED_GREEN IMAGE_LOCATION "led-green.png" -#define IMAGE_LED_RED IMAGE_LOCATION "led-red.png" - - -#define SOUNDS_LOCATION SHARED_LOCATION "sounds/" -#define SOUND_LOCK SOUNDS_LOCATION "lock.wav" -#define SOUND_UNLOCK SOUNDS_LOCATION "unlock.wav" -#define SOUND_EMERGENCY_UNLOCK SOUNDS_LOCATION "emergency_unlock.wav" -#define SOUND_ZONK SOUNDS_LOCATION "zonk.wav" -#define SOUND_LOCK_BUTTON SOUNDS_LOCATION "lock_button.wav" -#define SOUND_UNLOCK_BUTTON SOUNDS_LOCATION "unlock_button.wav" - -#define PRE_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_lock" -#define POST_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_lock" -#define PRE_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_unlock" -#define POST_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_unlock" -#define EMERGENCY_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/emergency_unlock" - -#endif diff --git a/doorlockd/daemon/doorlockd.cpp b/doorlockd/daemon/doorlockd.cpp deleted file mode 100644 index ad8e8f9..0000000 --- a/doorlockd/daemon/doorlockd.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include "../lib/logic.h" - -#include "config.h" - -namespace po = boost::program_options; -namespace ba = boost::asio; -namespace fs = boost::filesystem; -using ba::ip::tcp; - -// Info about doorlockd version -const static std::string version = - "doorlockd-" DOORLOCK_VERSION; -const static std::string gitversion = - DOORLOCK_GIT_BRANCH "-" DOORLOCK_GIT_COMMIT_HASH; - -// The receive buffer length of the TCP socket -const int constexpr SOCKET_BUFFERLENGTH = 2048; - -static Logger &l = Logger::get(); - -static std::unique_ptr logic = nullptr; -static ba::io_service io_service; - -static std::mutex mutex; -static std::condition_variable onClientMessage; -static volatile bool run = true; - -static void signal_handler(int signum) -{ - l((std::string)"Received Signal " + std::to_string(signum), - LogLevel::warning); - io_service.stop(); - run = false; - onClientMessage.notify_all(); -} - -static Response subscribe(tcp::socket &sock) -{ - sock.write_some(ba::buffer(logic->getClientMessage().toJson())); - while (run) { - std::unique_lock lock(mutex); - onClientMessage.wait(lock); - if (run) { - sock.write_some(ba::buffer(logic->getClientMessage().toJson())); - } - }; - return Response(Response::Code::Success); -} - -static void session(tcp::socket &&sock) -{ - ba::ip::address remoteAddress; - unsigned short remotePort = 0; - Response response; - - try { - std::vector data; - data.resize(SOCKET_BUFFERLENGTH); - - remoteAddress = sock.remote_endpoint().address(); - remotePort = sock.remote_endpoint().port(); - - l("Incoming TCP connection from " + remoteAddress.to_string() + "(" - + std::to_string(remotePort) + ")", - LogLevel::notice); - - size_t length = sock.read_some(ba::buffer(data)); - - // Get Request - const std::string requestString(data.begin(), data.begin()+length); - l(" Parsing request...", LogLevel::info); - Request request = Request::fromString(requestString); - - switch (request.command) { - case Request::Command::Lock: - case Request::Command::Unlock: - response = logic->request(request); - break; - - case Request::Command::Subscribe: - if (remoteAddress.is_loopback() == false) { - response.code = Response::Code::AccessDenied; - response.message = "Subscriptions are only allowed from localhost"; - } else { - response = subscribe(sock); - } - break; - - case Request::Command::Unknown: - default: - response.code = Response::Code::UnknownCommand; - response.message = "Received unknown command "; - break; - } - - throw response; - } - catch (const Response &err) { - response = err; - } - catch (const std::exception &err) { - response.code = Response::Code::Fail; - response.message = "Exception in session " + remoteAddress.to_string() - + ":" + std::to_string(remotePort) + " : " + err.what(); - } - catch (...) { - response.code = Response::Code::Fail; - response.message = "Unhandled doorlockd error"; - } - - if (!response) { - l(response.message, LogLevel::warning); - } - - if (sock.is_open()) { - boost::system::error_code ec; - sock.write_some(ba::buffer(response.toJson()), ec); - } - - l("Closing TCP connection from " + remoteAddress.to_string(), LogLevel::notice); -} - -static void server(unsigned short port) -{ - l(LogLevel::info, "Starting TCP Server"); - - const auto endpoint = tcp::endpoint(ba::ip::address::from_string("127.0.0.1"), port); - tcp::acceptor a(io_service, endpoint); - - tcp::socket sock(io_service); - - std::function accept_connection = [&] () { - a.async_accept(sock, - [&] (boost::system::error_code ec) { - if (ec) - { - return; - } - std::thread(session, std::move(sock)).detach(); - accept_connection(); - }); - }; - - accept_connection(); - - io_service.run(); - l(LogLevel::info, "Stopped TCP Server"); -} - -int main(int argc, char** argv) -{ - int retval = -1; - short port; - std::chrono::seconds tokenTimeout; - std::string ldapUri; - std::string bindDN; - std::string lockPagePrefix; - fs::path logdir; - std::string logfile; - std::string logfile_scripts; - unsigned int tokenLength; - std::string serDev; - unsigned int baudrate; - - try { - unsigned int timeout; - po::options_description desc("doorlockd (" + version + " built on " + gitversion + ")"); - desc.add_options() - ("help,h", - "print help") - ("tokentimeout,t", - po::value(&timeout)->default_value(DEFAULT_TOKEN_TIMEOUT), - "Token timeout in seconds") - ("port,p", - po::value(&port)->default_value(DEFAULT_PORT), - "Port") - ("ldap,s", - po::value(&ldapUri)->default_value(DEFAULT_LDAP_URI), - "Ldap Server") - ("bidndn,b", - po::value(&bindDN)->default_value(DEFAULT_BINDDN), - "Bind DN, %s means username") - ("web,w", - po::value(&lockPagePrefix)->default_value(DEFAULT_WEB_PREFIX), - "Prefix of the webpage") - ("tokenLength,t", - po::value(&tokenLength)->default_value(DEFAULT_TOKEN_LENGTH), - "Token length") - ("logdir,l", - po::value(&logdir)->default_value(DEFAULT_LOG_DIR), - "Log file") - ("serial,i", - po::value(&serDev)->default_value(DEFAULT_SERIAL_DEVICE), - "Serial port") - ("baud,r", - po::value(&baudrate)->default_value((DEFAULT_SERIAL_BAUDRATE)), - "Serial baudrate"); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); - - if (vm.count("help")) - { - std::cout << desc << std::endl; - retval = 0; - exit(0); - } - - po::notify(vm); - - tokenTimeout = std::chrono::seconds(timeout); - - logfile = (logdir / LOG_FILENAME).string(); - logfile_scripts = (logdir / LOG_SCRIPTS_FILENAME).string(); - - l.setLogFile(logfile); - l.logFile(true); - } - catch(const std::exception &e) - { - std::cerr << "Error: " << e.what() << "\n"; - exit(-1); - } - - l((std::string)"Hello, this is " + version + " built on " + gitversion, - LogLevel::info); - l(LogLevel::notice, "Starting doorlockd"); - - signal(SIGINT, signal_handler); - signal(SIGKILL, signal_handler); - signal(SIGTERM, signal_handler); - signal(SIGUSR1, signal_handler); - signal(SIGUSR2, signal_handler); - - l(LogLevel::info, "Starting Doorlock Logic"); - - retval = 0; - try { - logic = std::unique_ptr(new Logic(tokenTimeout, - ldapUri, - bindDN, - lockPagePrefix, - tokenLength, - serDev, - baudrate, - logfile_scripts, - onClientMessage)); - server(port); - } - catch (const boost::system::system_error &ex) { - l(LogLevel::error, "Fatal error: %s", ex.what()); - retval = -1; - } - catch (const std::exception &ex) { - l(LogLevel::error, "Fatal error: %s", ex.what()); - retval = -1; - } - catch (...) { - l(LogLevel::error, "Fatal error, shutting down"); - retval = -1; - } - - if (logic) { - l(LogLevel::info, "Stopping Doorlock Logic"); - logic.reset(); - } - l(LogLevel::notice, "Doorlockd stopped"); - return retval; -} diff --git a/doorlockd/images/led-green.png b/doorlockd/images/led-green.png deleted file mode 100644 index 34e0080..0000000 Binary files a/doorlockd/images/led-green.png and /dev/null differ diff --git a/doorlockd/images/led-red.png b/doorlockd/images/led-red.png deleted file mode 100644 index 7d6bb6c..0000000 Binary files a/doorlockd/images/led-red.png and /dev/null differ diff --git a/doorlockd/lib/clientmessage.cpp b/doorlockd/lib/clientmessage.cpp deleted file mode 100644 index d303965..0000000 --- a/doorlockd/lib/clientmessage.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "clientmessage.h" -#include "util.h" -#include "response.h" - -const std::string Clientmessage::_tokenKey = "token"; -const std::string Clientmessage::_unlockButtonKey = "unlockButton"; -const std::string Clientmessage::_lockButtonKey = "lockButton"; -const std::string Clientmessage::_emergencyUnlockKey = "emergencyUnlock"; -const std::string Clientmessage::_isOpenKey = "isOpen"; - -const std::regex Clientmessage::_token_regex(".*/([0-9a-fA-F]+)"); - -Clientmessage::Clientmessage(std::string web_address, - bool isOpen, - Doormessage doormessage) : - _web_address(web_address), - _token(), - _isOpen(isOpen), - _doormessage(doormessage) -{ - std::smatch match; - if (std::regex_match(_web_address, match, _token_regex)) { - if (match.size() == 2) { - _token = match[1].str(); - } else { - _token = "ERROR"; - } - } else { - _token = "ERROR"; - } -} - -Clientmessage::Clientmessage() : - _web_address(), - _token(), - _isOpen(false), - _doormessage() -{ -} - -Clientmessage &Clientmessage::operator=(const Clientmessage &rhs) -{ - // Protect against self assignement - if (this == &rhs) { - return *this; - } - - this->_web_address = rhs._web_address; - this->_token = rhs._token; - this->_isOpen = rhs._isOpen; - this->_doormessage = rhs._doormessage; - - return *this; -} - -std::string Clientmessage::toJson() const -{ - Json::StyledWriter writer; - Json::Value message; - - message[_tokenKey] = _web_address; - message[_unlockButtonKey] = _doormessage.isUnlockButton; - message[_lockButtonKey] = _doormessage.isLockButton; - message[_emergencyUnlockKey] = _doormessage.isEmergencyUnlock; - message[_isOpenKey] = _isOpen; - - return writer.write(message); -} - -const std::string& Clientmessage::token() const -{ - return _token; -} - -const std::string& Clientmessage::web_address() const -{ - return _web_address; -} - -const Doormessage& Clientmessage::doormessage() const -{ - return _doormessage; -} - -Clientmessage Clientmessage::fromJson(const Json::Value &root) -{ - std::string token; - bool isOpen; - Doormessage doormessage; - - try { - token = getJsonOrFail(root, _tokenKey); - doormessage.isLockButton = getJsonOrFail(root, _lockButtonKey); - doormessage.isUnlockButton = getJsonOrFail(root, _unlockButtonKey); - doormessage.isEmergencyUnlock = getJsonOrFail(root, _emergencyUnlockKey); - isOpen = getJsonOrFail(root, _isOpenKey); - } - catch (const std::exception &ex) { - throw Response(Response::Code::JsonError, ex.what()); - } - - return Clientmessage(token, isOpen, doormessage); -} - -Clientmessage Clientmessage::fromString(const std::string &string) -{ - Json::Reader reader; - Json::Value root; - - if (reader.parse(string, root) == false) - throw Response(Response::Code::NotJson, - "No valid JSON"); - - return fromJson(root); -} - -bool Clientmessage::isOpen() const -{ - return _isOpen; -} diff --git a/doorlockd/lib/clientmessage.h b/doorlockd/lib/clientmessage.h deleted file mode 100644 index 60ef053..0000000 --- a/doorlockd/lib/clientmessage.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef CLIENTMESSAGE_H -#define CLIENTMESSAGE_H - -#include -#include -#include - -#include "doormessage.h" - -class Clientmessage -{ -public: - - Clientmessage(std::string web_address, - bool isOpen, - Doormessage doormessage); - Clientmessage(); - - Clientmessage &operator=(const Clientmessage& rhs); - - static Clientmessage fromJson(const Json::Value &root); - static Clientmessage fromString(const std::string &json); - std::string toJson() const; - - const std::string& web_address() const; - const std::string& token() const; - bool isOpen() const; - const Doormessage& doormessage() const; - -private: - - std::string _web_address; - std::string _token; - bool _isOpen; - Doormessage _doormessage; - - const static std::string _tokenKey; - const static std::string _unlockButtonKey; - const static std::string _lockButtonKey; - const static std::string _emergencyUnlockKey; - const static std::string _isOpenKey; - - const static std::regex _token_regex; -}; - -#endif diff --git a/doorlockd/lib/door.cpp b/doorlockd/lib/door.cpp deleted file mode 100644 index 2a764ec..0000000 --- a/doorlockd/lib/door.cpp +++ /dev/null @@ -1,208 +0,0 @@ -#include "config.h" -#include "door.h" - -#include "../../doorcmds.h" - -Door::Door(const std::string &serDev, - unsigned int baudrate, - const std::string &logfile_scripts) : - _baudrate(baudrate), - _port(_ioService, serDev), - _logfile_scripts(logfile_scripts), - _logger(Logger::get()) -{ - // Configure serial port - _port.set_option(boost::asio::serial_port_base::baud_rate(baudrate)); - _port.set_option(boost::asio::serial_port_base::character_size(8)); - _port.set_option(boost::asio::serial_port_base::stop_bits(boost::asio::serial_port_base::stop_bits::one)); - _port.set_option(boost::asio::serial_port_base::parity(boost::asio::serial_port_base::parity::none)); - _port.set_option(boost::asio::serial_port_base::flow_control(boost::asio::serial_port_base::flow_control::none)); - - _asyncRead(); - - _ioThread = std::thread([this] () { - _ioService.run(); - }); - - // TODO Ping device -} - -Door::~Door() -{ - lock(); - - _ioService.stop(); - _ioService.reset(); - - _port.cancel(); - _port.close(); - - _ioThread.join(); -} - -bool Door::_readByte(char &byte, std::chrono::milliseconds timeout) -{ - std::unique_lock lock(_receiveLock); - _receivedCondition.wait_for(lock, timeout); - if (_byteReady) { - byte = recvBuf; - _byteReady = false; - return true; - } - return false; -} - -void Door::_asyncRead() -{ - _port.async_read_some( - boost::asio::buffer(&recvBuf, sizeof(recvBuf)), - [this] (const boost::system::error_code &ec, size_t bytes_transferred) { - if (ec) { - // Operation canceled occurs on system shutdown - // So we return without invoking an additional asyncRead() - if (ec == boost::system::errc::operation_canceled) - return; - - _logger(LogLevel::error, "Serialport error: %s", ec.message().c_str()); - goto out; - } - - if (bytes_transferred != 1) { - _logger(LogLevel::error, "Fatal serial error"); - goto out; - } - - if (recvBuf == DOOR_BUTTON_UNLOCK) { - // In case that someone pushed the unlock button - just log it. - // No further actions required - _logger(LogLevel::notice, "Someone pushed the unlock button"); - if (_doorCallback) { - _doorCallback(Doormessage(true, false, false)); - } - goto out; - } else if (recvBuf == DOOR_BUTTON_LOCK) { - _logger(LogLevel::notice, "Someone pushed the lock button"); - _logger(LogLevel::notice, "Locking..."); - lock(); - if (_doorCallback) { - _doorCallback(Doormessage(false, true, false)); - } - goto out; - } else if (recvBuf == DOOR_EMERGENCY_UNLOCK) { - _logger(LogLevel::warning, "Someone did an emergency unlock!"); - _exec_and_log(EMERGENCY_UNLOCK_SCRIPT); - if (_doorCallback) { - _doorCallback(Doormessage(false, false, true)); - } - goto out; - } - - _byteReady = true; - _receivedCondition.notify_one(); - - out: - _asyncRead(); - }); -} - -Door::State Door::state() const -{ - return _state; -} - -void Door::lock() -{ - _stateMutex.lock(); - - - _logger(LogLevel::notice, "Executing Pre Lock Script"); - _exec_and_log(PRE_LOCK_SCRIPT); - - if (_state == State::Locked) { - _stateMutex.unlock(); - _logger(LogLevel::info, "Door already closed"); - goto out; - } - - _state = State::Locked; - _stateMutex.unlock(); - _heartbeatCondition.notify_one(); - _heartbeatThread.join(); - - _logger(LogLevel::notice , "Door closed"); - -out: - _logger(LogLevel::notice, "Executing Post Lock Script"); - _exec_and_log(POST_LOCK_SCRIPT); -} - -void Door::unlock() -{ - _stateMutex.lock(); - _schnapper = true; - - _logger(LogLevel::notice, "Executing Pre Unlock Script"); - _exec_and_log(PRE_UNLOCK_SCRIPT); - - if(_state == State::Unlocked) { - _stateMutex.unlock(); - _logger(LogLevel::info, "Door already opened"); - goto out; - } - - _state = State::Unlocked; - _stateMutex.unlock(); - - _heartbeatThread = std::thread([this] () { - std::unique_lock lock(_heartbeatMutex); - - while (_state == State::Unlocked) { - if (_state == State::Unlocked) { - _writeCMD(DOOR_CMD_UNLOCK); - - if (_schnapper) { - _schnapper = false; - _writeCMD(DOOR_CMD_SCHNAPER); - } - } - - _heartbeatCondition.wait_for(lock, Milliseconds(400)); - } - _writeCMD(DOOR_CMD_LOCK); - }); - - _logger(LogLevel::notice, "Door opened"); - - out: - _logger(LogLevel::notice, "Executing Post Unlock Script"); - _exec_and_log(POST_UNLOCK_SCRIPT); -} - -bool Door::_writeCMD(char c) -{ - std::lock_guard l(_serialMutex); - - _port.write_some(boost::asio::buffer(&c, sizeof(c))); - char response; - if (_readByte(response, Milliseconds(100))) - { - if (c != response) { - _logger(LogLevel::error, "Sent command '%c' but got response '%c'", c, response); - return false; - } - return true; - } - _logger(LogLevel::error, "Sent Serial command, but got no response!"); - return false; -} - -void Door::setDoorCallback(DoorCallback doorCallback) -{ - _doorCallback = doorCallback; -} - -void Door::_exec_and_log(const std::string &filename) -{ - const std::string cmd = "nohup " + filename + " &>> " + _logfile_scripts; - ::system(cmd.c_str()); -} diff --git a/doorlockd/lib/door.h b/doorlockd/lib/door.h deleted file mode 100644 index bb24b6f..0000000 --- a/doorlockd/lib/door.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef DOOR_H -#define DOOR_H - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "logger.h" -#include "doormessage.h" - -class Door final -{ -public: - using DoorCallback = std::function; - enum class State {Unlocked, Locked}; - - Door(const std::string &serDev, - unsigned int baudrate, - const std::string &logfile_scripts); - ~Door(); - - State state() const; - void setDoorCallback(DoorCallback doorCallback); - - void lock(); - void unlock(); - -private: - - using Milliseconds = std::chrono::milliseconds; - - const unsigned int _baudrate; - - // To prevent concurrent writes - std::mutex _serialMutex = { }; - - boost::asio::io_service _ioService = { }; - boost::asio::serial_port _port; - - const std::string _logfile_scripts; - - std::mutex _stateMutex = { }; - volatile State _state = { State::Locked }; - - std::thread _heartbeatThread = { }; - std::mutex _heartbeatMutex = { }; - std::condition_variable _heartbeatCondition = { }; - - std::thread _ioThread = { }; - void _asyncRead(); - - volatile bool _schnapper = { false }; - - // Indicates if recvBuf contains a valid response from AVR Board - volatile bool _byteReady = { false }; - // Actual response - char recvBuf = { }; - - std::condition_variable _receivedCondition = { }; - std::mutex _receiveLock = { }; - - DoorCallback _doorCallback = { }; - - Logger &_logger; - - // Writed command to AVR board - bool _writeCMD(char c); - // Receives one byte and returns true or returns false on timeout - bool _readByte(char &byte, Milliseconds timeout); - - void _exec_and_log(const std::string &filename); -}; - -#endif diff --git a/doorlockd/lib/doormessage.cpp b/doorlockd/lib/doormessage.cpp deleted file mode 100644 index b0f149e..0000000 --- a/doorlockd/lib/doormessage.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "doormessage.h" - -Doormessage::Doormessage() -{ -} - -Doormessage::Doormessage(bool isUnlockButton, bool isLockButton, bool isEmergencyUnlock) : - isUnlockButton(isUnlockButton), - isLockButton(isLockButton), - isEmergencyUnlock(isEmergencyUnlock) -{ -} diff --git a/doorlockd/lib/doormessage.h b/doorlockd/lib/doormessage.h deleted file mode 100644 index d5207b6..0000000 --- a/doorlockd/lib/doormessage.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef DOORMESSAGE_H -#define DOORMESSAGE_H - -struct Doormessage -{ - Doormessage(bool isUnlockButton, - bool isLockButton, - bool isEmergencyUnlock); - - Doormessage(); - - bool isUnlockButton = { false }; - bool isLockButton = { false }; - bool isEmergencyUnlock = { false }; -}; - -#endif diff --git a/doorlockd/lib/logger.cpp b/doorlockd/lib/logger.cpp deleted file mode 100644 index d1776b3..0000000 --- a/doorlockd/lib/logger.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// (c) 2015 Ralf Ramsauer - Logger class from the sdfs project - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#endif - -#include "config.h" -#include "logger.h" - -#ifdef USE_COLORIZED_LOGS -#ifdef _WIN32 // If Windows, Use Windows Terminal coloring -const static map colorAttribute = { - {LogLevel::error, FOREGROUND_RED }, - {LogLevel::warning, FOREGROUND_RED | FOREGROUND_GREEN }, - {LogLevel::notice, FOREGROUND_BLUE }, - {LogLevel::info, FOREGROUND_GREEN }, - {LogLevel::debug, FOREGROUND_BLUE | FOREGROUND_RED }, - {LogLevel::debug2, FOREGROUND_BLUE | FOREGROUND_RED }, -}; -#else // Use ANSI Escape sequences -const static std::map prefix_ansicolor = { - {LogLevel::error, "\x1b[1m\x1b[31m" }, - {LogLevel::warning, "\x1b[1m\x1b[33m" }, - {LogLevel::notice, "\x1b[1m\x1b[34m" }, - {LogLevel::info, "\x1b[1m\x1b[32m" }, - {LogLevel::debug, "\x1b[1m\x1b[35m" }, - {LogLevel::debug2, "\x1b[1m\x1b[36m" }, -}; - -const static std::string suffix_ansireset = "\x1b[0m"; -#endif -#endif - -const static std::map logLevel = { - {LogLevel::error, "ERROR " }, - {LogLevel::warning, "WARNING" }, - {LogLevel::notice, "NOTICE " }, - {LogLevel::info, "INFO " }, - {LogLevel::debug, "DEBUG " }, - {LogLevel::debug2, "DEBUG2 " }, -}; - -Logger::Logger(const LogLevel level) : - _level(level), - _ostreamMutex() -{ -} - -Logger::~Logger() -{ - if (_logFile.is_open()) - _logFile.close(); -} - -Logger &Logger::get() -{ - static Logger l(DEFAULT_LOG_LEVEL); - return l; -} - -void Logger::operator ()(const std::string &message, - const LogLevel level) -{ - if(level > _level) - { - return; - } - - std::ostringstream prefix; - - auto t = std::time(nullptr); - auto tm = *std::localtime(&t); - -#if defined(USE_COLORIZED_LOGS) && !defined(_WIN32) - prefix << prefix_ansicolor.at(level); -#endif - - // GCC does not support put_time :-( - /*stringstream ss; - ss << std::put_time(&tm, "%d-%m-%Y %H-%M-%S"); - prefix = "[" + ss.str() + "] ";*/ - - const size_t BUFFER_SIZE = 80; - char timeBuffer[BUFFER_SIZE]; - std::strftime(timeBuffer, BUFFER_SIZE, "%Y-%m-%d %H:%M:%S", &tm); - prefix << "[" << timeBuffer << "] -- " << logLevel.at(level) << " :: "; - - // Critical section - { - std::lock_guard lock(_ostreamMutex); - -#if defined(USE_COLORIZED_LOGS) && !defined(_WIN32) - if (_consoleActive) { - std::cerr << prefix.str() << message - << suffix_ansireset << std::endl; - std::cerr.flush(); - } - if (_logFileActive && _logFile.is_open()) { - _logFile << prefix.str() << message - << suffix_ansireset << std::endl; - } -#elif defined(USE_COLORIZED_LOGS) && defined(_WIN32) - - if (_consoleActive) { - // taken from GTEST - const HANDLE stdout_handle = GetStdHandle(STD_ERROR_HANDLE); - - // Gets the current text color. - CONSOLE_SCREEN_BUFFER_INFO buffer_info; - GetConsoleScreenBufferInfo(stdout_handle, &buffer_info); - const WORD old_color_attrs = buffer_info.wAttributes; - - // We need to flush the stream buffers into the console before each - // SetConsoleTextAttribute call lest it affect the text that is already - // printed but has not yet reached the console. - std::cerr.flush(); - SetConsoleTextAttribute(stdout_handle, - colorAttribute.at(level) | FOREGROUND_INTENSITY); - - std::cerr << prefix.str() << message << std::endl; - std::cerr.flush(); - - // Restores the text color. - SetConsoleTextAttribute(stdout_handle, old_color_attrs); - } - if (_logFileActive && _logFile.is_open()) { - _logFile << prefix.str() << message << std::endl; - } - -#else - if (_consoleActive) { - std::cerr << prefix.str() << message << std::endl; - std::cerr.flush(); - } - if (_logFileActive && _logFile.is_open()) { - _logFile << prefix.str() << message << std::endl; - } -#endif - } -} - -void Logger::operator ()(const std::ostringstream &message, const LogLevel level) -{ - (*this)(message.str(), level); -} - -void Logger::operator ()(const LogLevel level, const char* format, ...) -{ - if(level > _level) - { - return; - } - - va_list argp; - char* message = nullptr; - - // determine buffer length - va_start(argp, format); - int size = vsnprintf(nullptr, 0, format, argp) + 1; - va_end(argp); - - if (size >= 0) - { - message = (char*)malloc(size); - if (message == nullptr) - { - (*this)("[LOGGER] CRITICAL: MEMORY ALLOCATION ERROR", - LogLevel::error); - } - - va_start(argp,format); - vsnprintf(message, size, format, argp); - va_end(argp); - - (*this)(std::string(message), level); - - free(message); - } else { - (*this)("[LOGGER] CRITICAL: VSNPRINTF ERROR", - LogLevel::error); - } -} - -void Logger::level(const LogLevel level) -{ - _level = level; -} - -LogLevel Logger::level() const -{ - return _level; -} - -bool Logger::console() const -{ - return _consoleActive; -} - -void Logger::console(const bool active) -{ - std::lock_guard lock(_ostreamMutex); - _consoleActive = active; -} - -bool Logger::logFile() const -{ - return _logFileActive; -} - -void Logger::logFile(const bool active) -{ - std::lock_guard lock(_ostreamMutex); - _logFileActive = active; -} - -void Logger::setLogFile(const std::string &logFile) -{ - if (_logFile.is_open()) - _logFile.close(); - - _logFile.open(logFile, std::ofstream::out | std::ofstream::app); - if (!_logFile.is_open()) - throw std::runtime_error("Unable to open " + logFile); -} diff --git a/doorlockd/lib/logger.h b/doorlockd/lib/logger.h deleted file mode 100644 index 0a2dc80..0000000 --- a/doorlockd/lib/logger.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef LOGGER_H -#define LOGGER_H - -#include -#include -#include -#include -#include - -/** - * @brief The LogLevel enum - */ -enum class LogLevel : unsigned char -{ - off, /// disable logging - error, /// error conditions - warning, /// warning conditions - notice, /// normal but significant conditions - info, /// informational messages - debug, /// debug-level messages - debug2 /// more debug-level messages -}; - -/** - * @brief The Logger class - * - * The logger class is a thread-safe class which is used for formatting and forwarding - * log messages. - */ -class Logger final -{ -public: - static Logger &get(); - - /// Log a string - void operator() (const std::string &message, const LogLevel level = LogLevel::debug); - - /// Log a ostringstream - void operator() (const std::ostringstream &message, const LogLevel level = LogLevel::debug); - - /// Log a format string - void operator() (const LogLevel level, const char* format, ...); - - /// Set minimum required log level to generate output - void level(const LogLevel level); - /// Get minimum required log level to generate output - LogLevel level() const; - - /// Getter/Setter for console output - bool console() const; - void console(const bool active); - - /// Getter/Setter for logfile output - bool logFile() const; - void logFile(const bool active); - void setLogFile(const std::string &logFile); - -private: - - /** - * @brief Constructor - * @param level Minimum required log level to generate output - */ - Logger(const LogLevel level); - ~Logger(); - - bool _consoleActive = { true }; - bool _logFileActive = { false }; - - std::ofstream _logFile = {}; - - LogLevel _level; - mutable std::mutex _ostreamMutex; -}; -#endif diff --git a/doorlockd/lib/logic.cpp b/doorlockd/lib/logic.cpp deleted file mode 100644 index 645d1d4..0000000 --- a/doorlockd/lib/logic.cpp +++ /dev/null @@ -1,263 +0,0 @@ -#include -#define LDAP_DEPRECATED 1 -#include - -#include "logic.h" -#include "util.h" - -Logic::Logic(const std::chrono::seconds tokenTimeout, - const std::string &ldapUri, - const std::string &bindDN, - const std::string &webPrefix, - const unsigned int tokenLength, - const std::string &serDev, - const unsigned int baudrate, - const std::string &logfile_scripts, - std::condition_variable &onClientUpdate) : - _logger(Logger::get()), - _door(serDev, baudrate, logfile_scripts), - _tokenTimeout(tokenTimeout), - _onClientUpdate(onClientUpdate), - _ldapUri(ldapUri), - _bindDN(bindDN), - _webPrefix(webPrefix), - _tokenLength(tokenLength) -{ - srand(time(NULL)); - _createNewToken(false); - - _door.setDoorCallback(std::bind(&Logic::_doorCallback, - this, - std::placeholders::_1)); - - _tokenUpdater = std::thread([this] () { - while (_run) - { - std::unique_lock l(_mutex); - _tokenCondition.wait_for(l, _tokenTimeout); - if (_run == false) - { - break; - } else { - _createNewToken(true); - } - } - }); -} - -Logic::~Logic() -{ - _run = false; - _tokenCondition.notify_one(); - _tokenUpdater.join(); -} - -Response Logic::processDoor(const DoorCommand &doorCommand) -{ - Response response; - - switch (doorCommand) { - case DoorCommand::Lock: - response = _lock(); - break; - case DoorCommand::Unlock: - response = _unlock(); - break; - default: - response.code = Response::Code::UnknownCommand; - response.message = "Unknown DoorCommand"; - break; - } - - return response; -} - -Response Logic::request(const Request &request) -{ - std::unique_lock l(_mutex); - Response response; - - DoorCommand doorCommand; - - switch (request.command) { - case Request::Command::Lock: - doorCommand = DoorCommand::Lock; - break; - case Request::Command::Unlock: - doorCommand = DoorCommand::Unlock; - break; - default: - response.code = Response::Code::UnknownCommand; - response.message = "Unknown Command"; - goto out; - } - - response = _checkToken(request.token); - if (!response) { - goto out; - } - _logger(LogLevel::info, " -> Token check successful"); - - response = _checkLDAP(request.user, request.password); - if (!response) { - goto out; - } - _logger(LogLevel::info, " -> LDAP check successful"); - - response = processDoor(doorCommand); - _logger(LogLevel::info, " -> Door Command successful"); - -out: - return response; -} - -Response Logic::_lock() -{ - Response response; - if (_door.state() == Door::State::Locked) - { - response.code = Response::Code::AlreadyLocked; - response.message = "Unable to lock: already closed"; - } else { - _createNewToken(false); - - response.code = Response::Code::Success; - response.message = "Success"; - } - - _door.lock(); - - return response; -} - -Response Logic::_unlock() -{ - Response response; - - const auto oldState = _door.state(); - _door.unlock(); - _createNewToken(false); - - if (oldState == Door::State::Unlocked) - { - response.code = Response::Code::AlreadyUnlocked; - response.message = "Unable to unlock: already unlocked"; - _logger(response.message, LogLevel::info); - } else { - response.code = Response::Code::Success; - response.message = "Success"; - } - - return response; -} - -Response Logic::_checkToken(std::string token) const -{ - std::transform(token.begin(), - token.end(), - token.begin(), - ::toupper); - - if (token == _curToken) - return Response(Response::Code::Success); - - if (_prevValid == true && token == _prevToken) - return Response(Response::Code::Success); - - _logger("Check Token failed: got \"" + token - + "\", expected \"" + _curToken +"\"", - LogLevel::error); - - return Response(Response::InvalidToken, - "User provided invalid token"); -} - -Response Logic::_checkLDAP(const std::string &user, - const std::string &password) -{ - constexpr int BUFFERSIZE = 1024; - char buffer[BUFFERSIZE]; - Response retval; - - int rc = -1; - LDAP* ld = nullptr; - unsigned long version = LDAP_VERSION3; - - _logger(LogLevel::info, " Trying to authenticate as user \"%s\"", user.c_str()); - snprintf(buffer, BUFFERSIZE, _bindDN.c_str(), user.c_str()); - - rc = ldap_initialize(&ld, _ldapUri.c_str()); - if(rc != LDAP_SUCCESS) - { - retval.message = (std::string)"LDAP initialize error: " - + ldap_err2string(rc); - retval.code = Response::Code::LDAPInit; - goto out2; - } - - rc = ldap_set_option(ld, - LDAP_OPT_PROTOCOL_VERSION, - (void*)&version); - if (rc != LDAP_SUCCESS) - { - retval.code = Response::Code::LDAPInit; - retval.message = "LDAP set version failed"; - goto out; - } - - rc = ldap_simple_bind_s(ld, buffer, password.c_str()); - if (rc != LDAP_SUCCESS) - { - retval = Response::Code::InvalidCredentials; - retval.message = "Credential check for user \"" + user - + "\" failed: " + ldap_err2string(rc); - goto out; - } - - retval.code = Response::Code::Success; - retval.message = ""; - -out: - ldap_unbind(ld); - ld = nullptr; -out2: - return retval; -} - -void Logic::_createNewToken(const bool stillValid) -{ - // Todo Mutex einführen - - _prevToken = _curToken; - _prevValid = stillValid; - - _curToken = randHexString(_tokenLength); - - std::ostringstream message; - message << "New token: " << _curToken - << " old token: " << _prevToken << " is " - << (_prevValid?"still":"not") << " valid"; - _logger(message, LogLevel::notice); - - _onClientUpdate.notify_all(); -} - -Clientmessage Logic::getClientMessage() -{ - std::lock_guard l(_mutex); - Clientmessage retval(_webPrefix + _curToken, - _door.state() == Door::State::Unlocked, - _doormessage); - - // Reset doormessage - _doormessage = Doormessage(); - - return retval; -} - -void Logic::_doorCallback(Doormessage doormessage) -{ - std::lock_guard l(_mutex); - _doormessage = doormessage; - _onClientUpdate.notify_all(); -} diff --git a/doorlockd/lib/logic.h b/doorlockd/lib/logic.h deleted file mode 100644 index 8399136..0000000 --- a/doorlockd/lib/logic.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef LOGIC_H -#define LOGIC_H - -#include -#include -#include -#include - -#include "config.h" -#include "clientmessage.h" -#include "door.h" -#include "logger.h" -#include "request.h" -#include "response.h" - -/* The "Logic" class - * - * This class is initilized by all settings. - * - * It handles incoming requests and allows modifications of the door - */ -class Logic -{ -public: - - Logic(const std::chrono::seconds tokenTimeout, - const std::string &ldapUri, - const std::string &bindDN, - const std::string &webPrefix, - const unsigned int tokenLength, - const std::string &serDev, - const unsigned int baudrate, - const std::string &logfile_scripts, - std::condition_variable &onClientUpdate); - ~Logic(); - - // Parse incoming JSON Requests - Response request(const Request &request); - - // Send direct command to door without credential checks - enum class DoorCommand { Lock, Unlock }; - Response processDoor(const DoorCommand &doorCommand); - - // Returns the current Token - Clientmessage getClientMessage(); - -private: - - // Internal lock wrapper - Response _lock(); - // Internal unlock wrapper - Response _unlock(); - - // Checks if the incoming token is valid - Response _checkToken(std::string token) const; - - // Checks if incoming credentials against LDAP - Response _checkLDAP(const std::string &user, - const std::string &password); - - // Creates a new random token and draws it on the epaper. - // stillValid indicates whether the old (previous) token is still valid - void _createNewToken(const bool stillValid); - - void _doorCallback(Doormessage doormessage); - - Logger &_logger; - - // The door - Door _door; - - // The current token - std::string _curToken = {}; - // The previous token - std::string _prevToken = {}; - // Indicates whether the previous token is valid - bool _prevValid = { false }; - - // Tokens are refreshed all tokenTimout seconds - const std::chrono::seconds _tokenTimeout; - // Thread for asynchronosly updating tokens - std::thread _tokenUpdater = {}; - // Thread can be force-triggered for updates using the condition variable - std::condition_variable _tokenCondition = {}; - // stop indicator for the thread - bool _run = true; - // General mutex for concurrent data access - mutable std::mutex _mutex = {}; - - Doormessage _doormessage = {}; - - // This variable gets notified on token updates - std::condition_variable &_onClientUpdate; - - // The URI of the ldap server - const std::string _ldapUri; - // LDAP bindDN - const std::string _bindDN; - // Prefix of the website - const std::string _webPrefix; - // Length of the token in bytes - const unsigned int _tokenLength; -}; - -#endif diff --git a/doorlockd/lib/request.cpp b/doorlockd/lib/request.cpp deleted file mode 100644 index 909bc94..0000000 --- a/doorlockd/lib/request.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "request.h" -#include "util.h" -#include "logger.h" - -const std::string Request::_commandKey = "command"; - -Request::Command Request::_commandFromString(const std::string &command) -{ - Command retval = Command::Unknown; - - if (command == "lock") - retval = Command::Lock; - else if (command == "unlock") - retval = Command::Unlock; - else if (command == "subscribe") - retval = Command::Subscribe; - else - retval = Command::Unknown; - - return retval; -} - -Request Request::fromJson(const Json::Value &root) -{ - Request retval; - auto &l = Logger::get(); - - try { - const auto commandStr = - getJsonOrFail(root, _commandKey); - l(" command: " + commandStr, LogLevel::info); - retval.command = _commandFromString(commandStr); - - // Stop parsing, if command is unknown - if (retval.command == Command::Unknown) - return retval; - - if (retval.command == Command::Lock || - retval.command == Command::Unlock) { - retval.user = getJsonOrFail(root, "user"); - l(" user: " + retval.user, LogLevel::info); - retval.password = getJsonOrFail(root, "password"); - l(" password: XXX", LogLevel::info); - retval.token = getJsonOrFail(root, "token"); - l(" token: " + retval.token, LogLevel::info); - } - - if (retval.command == Command::Subscribe) { - // Nothing to do in this case - } - } - catch (const std::exception &ex) { - throw Response(Response::Code::JsonError, ex.what()); - } - - return retval; -} - -Request Request::fromString(const std::string &string) -{ - Json::Reader reader; - Json::Value root; - - if (reader.parse(string, root) == false) - throw Response(Response::Code::NotJson, - "No valid JSON"); - - return fromJson(root); -} diff --git a/doorlockd/lib/request.h b/doorlockd/lib/request.h deleted file mode 100644 index 1120ac6..0000000 --- a/doorlockd/lib/request.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef REQUEST_H -#define REQUEST_H - -#include - -#include - -#include "response.h" - -class Request -{ -public: - static Request fromJson(const Json::Value &root); - static Request fromString(const std::string &string); - - enum class Command { Lock, Unlock, Subscribe, Unknown } - command = { Command::Unknown }; - std::string user = { }; - std::string password = { }; - std::string token = { }; - -private: - static Command _commandFromString(const std::string &command); - - const static std::string _commandKey; -}; - -#endif // REQUEST_H - diff --git a/doorlockd/lib/response.cpp b/doorlockd/lib/response.cpp deleted file mode 100644 index 6e84830..0000000 --- a/doorlockd/lib/response.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include - -#include - -#include "response.h" -#include "util.h" - -const std::string Response::_codeKey = "code"; -const std::string Response::_messageKey = "message"; - -Response::Response(): - code(Fail), - message("General failure") -{ -} - -Response::Response(Response::Code code, const std::string &what) : - code(code), - message(what) -{ -} - -Response::operator bool() const -{ - return code == Response::Code::Success; -} - -std::string Response::toJson() const -{ - Json::Value response; - Json::StyledWriter writer; - - response[_codeKey] = code; - response[_messageKey] = message; - - return writer.write(response); -} - -Response Response::fromJson(const Json::Value &root) -{ - Response retval; - - try { - retval.message = getJsonOrFail(root, _messageKey); - - const auto code = getJsonOrFail(root, _codeKey); - if (code > Code::RESPONSE_NUM_ITEMS) - throw std::runtime_error("Error code out of range"); - - retval.code = static_cast(code); - } - catch (const std::exception &ex) { - throw Response(Response::Code::JsonError, ex.what()); - } - - return retval; -} - -Response Response::fromString(const std::string &json) -{ - Json::Reader reader; - Json::Value root; - - if (reader.parse(json, root) == false) - throw Response(Response::Code::NotJson, - "No valid JSON"); - - return fromJson(root); -} diff --git a/doorlockd/lib/response.h b/doorlockd/lib/response.h deleted file mode 100644 index 036c4cf..0000000 --- a/doorlockd/lib/response.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef RESPONSE_H -#define RESPONSE_H - -#include - -#include - -class Response -{ -public: - enum Code { - Success = 0, // Request successful - Fail, // General non-specified error - AlreadyUnlocked, // Authentication successful, but door is already unlocked - AlreadyLocked, // Authentication successful, but door is already locked - NotJson, // Request is not a valid JSON object - JsonError, // Request is valid JSON, but does not contain necessary material - InvalidToken, // Request contains invalid token - InvalidCredentials, // Invalid LDAP credentials - InvalidIP, // IP check failure - UnknownCommand, // Unknown action - LDAPInit, // Ldap initialization failed - AccessDenied, // Access denied - RESPONSE_NUM_ITEMS - } code; - std::string message; - - Response(); - Response(Response::Code code, const std::string &message = ""); - - static Response fromJson(const Json::Value &root); - static Response fromString(const std::string &json); - std::string toJson() const; - - // Returns true if code is success - operator bool() const; - -private: - - const static std::string _codeKey; - const static std::string _messageKey; -}; - -#endif // RESPONSE_H diff --git a/doorlockd/lib/util.cpp b/doorlockd/lib/util.cpp deleted file mode 100644 index 44a5706..0000000 --- a/doorlockd/lib/util.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "util.h" - -template <> -int getJson(const Json::Value &root, const std::string &key) -{ - auto val = root.get(key, Json::Value()); - if (val.isInt()) - return val.asInt(); - throw std::runtime_error("Json Type error"); -} - -template <> -std::string getJson(const Json::Value &root, const std::string &key) -{ - auto val = root.get(key, Json::Value()); - if (val.isString()) - return val.asString(); - throw std::runtime_error("Json Type error"); -} - -template <> -size_t getJson(const Json::Value &root, const std::string &key) -{ - auto val = root.get(key, Json::Value()); - if (val.isInt()) - return val.asUInt64(); - throw std::runtime_error("Json Type error"); -} - -template <> -bool getJson(const Json::Value &root, const std::string &key) -{ - auto val = root.get(key, Json::Value()); - if (val.isBool()) - return val.asBool(); - throw std::runtime_error("Json Type error"); -} - -template <> -Json::Value getJson(const Json::Value &root, const std::string &key) -{ - auto val = root.get(key, Json::Value()); - return val; -} - -static char nibble2hex(unsigned char input) -{ - input &= 0xf; - - if(input <= 9) - { - return input + '0'; - } - - return input - 0xA + 'A'; -} - -std::string randHexString(unsigned int len) -{ - std::string retval; - while (len--) - retval += nibble2hex(rand() & 0xF); - return retval; -} - -unsigned char hex2uchar(const char input) -{ - if(input >= '0' && input <= '9') { - return input - '0'; - } else if(input >= 'A' && input <= 'F') { - return input - 'A' + 10; - } else if(input >= 'a' && input <= 'f') { - return input - 'a' + 10; - } - throw std::runtime_error("Malformed hexadecimal input"); -} diff --git a/doorlockd/lib/util.h b/doorlockd/lib/util.h deleted file mode 100644 index 80eeee5..0000000 --- a/doorlockd/lib/util.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef UTIL_H -#define UTIL_H - -#include -#include -#include - -template -T getJson(const Json::Value &root, const std::string &key); - -template -static T getJsonOrFail(const Json::Value &root, const std::string &key) -{ - if (root.isObject() == false) - { - throw std::runtime_error("Invalid Json Object"); - } - - if (root.isMember(key) == false) { - throw std::runtime_error("Json key \"" + key + "\" not existing"); - } - - return getJson(root, key); -} - -std::string randHexString(unsigned int len); - -#endif diff --git a/doorlockd/scripts/doorlockd.service b/doorlockd/scripts/doorlockd.service deleted file mode 100644 index ae76b1a..0000000 --- a/doorlockd/scripts/doorlockd.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Binary Kitchen doorlockd service -After=network.target - -[Service] -User=root -Group=root -EnvironmentFile=-/etc/sysconfig/doorlockd -ExecStart=/usr/local/sbin/doorlockd - -[Install] -WantedBy=multi-user.target - diff --git a/doorlockd/scripts/emergency_unlock b/doorlockd/scripts/emergency_unlock deleted file mode 100755 index a9bf588..0000000 --- a/doorlockd/scripts/emergency_unlock +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash diff --git a/doorlockd/scripts/post_lock b/doorlockd/scripts/post_lock deleted file mode 100755 index ac6f825..0000000 --- a/doorlockd/scripts/post_lock +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -mosquitto_pub -t kitchen/frontdoor/status -m "locked" diff --git a/doorlockd/scripts/post_unlock b/doorlockd/scripts/post_unlock deleted file mode 100755 index 0d27616..0000000 --- a/doorlockd/scripts/post_unlock +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -mosquitto_pub -t kitchen/frontdoor/status -m "unlocked" - -# Wakeup cashdesk -wol -i 172.23.2.44 00:0b:ca:94:13:f1 -wol -i 172.23.2.44 00:0b:ca:94:13:f1 -wol -i 172.23.2.44 00:0b:ca:94:13:f1 diff --git a/doorlockd/scripts/pre_lock b/doorlockd/scripts/pre_lock deleted file mode 100755 index a9bf588..0000000 --- a/doorlockd/scripts/pre_lock +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash diff --git a/doorlockd/scripts/pre_unlock b/doorlockd/scripts/pre_unlock deleted file mode 100755 index a9bf588..0000000 --- a/doorlockd/scripts/pre_unlock +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash diff --git a/doorlockd/sounds/emergency_unlock.wav b/doorlockd/sounds/emergency_unlock.wav deleted file mode 100644 index 675bfd3..0000000 Binary files a/doorlockd/sounds/emergency_unlock.wav and /dev/null differ diff --git a/doorlockd/sounds/lock.wav b/doorlockd/sounds/lock.wav deleted file mode 100644 index b04d827..0000000 Binary files a/doorlockd/sounds/lock.wav and /dev/null differ diff --git a/doorlockd/sounds/lock_button.wav b/doorlockd/sounds/lock_button.wav deleted file mode 100644 index a1578d2..0000000 Binary files a/doorlockd/sounds/lock_button.wav and /dev/null differ diff --git a/doorlockd/sounds/unlock.wav b/doorlockd/sounds/unlock.wav deleted file mode 100644 index 36d6e97..0000000 Binary files a/doorlockd/sounds/unlock.wav and /dev/null differ diff --git a/doorlockd/sounds/unlock_button.wav b/doorlockd/sounds/unlock_button.wav deleted file mode 100644 index dd36653..0000000 Binary files a/doorlockd/sounds/unlock_button.wav and /dev/null differ diff --git a/doorlockd/sounds/zonk.wav b/doorlockd/sounds/zonk.wav deleted file mode 100644 index 2c5d3f5..0000000 Binary files a/doorlockd/sounds/zonk.wav and /dev/null differ diff --git a/doorlockd/tools/inject_doorcommand.sh b/doorlockd/tools/inject_doorcommand.sh deleted file mode 100755 index 79ab874..0000000 --- a/doorlockd/tools/inject_doorcommand.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -echo -n "Cmd: " -read CMD - -echo -n "User: " -read USER - -echo -n "Password: " -read -s PW -echo - -echo -n "Token: " -read TOKEN - -cat << EOF | nc localhost 5555 -{ -"command" : "$CMD", -"user" : "$USER", -"password" : "$PW", -"token" : "$TOKEN" -} -EOF diff --git a/doorlockd-new/scripts/post_lock b/scripts/post_lock similarity index 100% rename from doorlockd-new/scripts/post_lock rename to scripts/post_lock diff --git a/doorlockd-new/scripts/post_unlock b/scripts/post_unlock similarity index 100% rename from doorlockd-new/scripts/post_unlock rename to scripts/post_unlock diff --git a/doorlockd-new/sounds/emergency_unlock.wav b/sounds/emergency_unlock.wav similarity index 100% rename from doorlockd-new/sounds/emergency_unlock.wav rename to sounds/emergency_unlock.wav diff --git a/doorlockd-new/sounds/lock.wav b/sounds/lock.wav similarity index 100% rename from doorlockd-new/sounds/lock.wav rename to sounds/lock.wav diff --git a/doorlockd-new/sounds/lock_button.wav b/sounds/lock_button.wav similarity index 100% rename from doorlockd-new/sounds/lock_button.wav rename to sounds/lock_button.wav diff --git a/doorlockd-new/sounds/unlock.wav b/sounds/unlock.wav similarity index 100% rename from doorlockd-new/sounds/unlock.wav rename to sounds/unlock.wav diff --git a/doorlockd-new/sounds/unlock_button.wav b/sounds/unlock_button.wav similarity index 100% rename from doorlockd-new/sounds/unlock_button.wav rename to sounds/unlock_button.wav diff --git a/doorlockd-new/sounds/zonk.wav b/sounds/zonk.wav similarity index 100% rename from doorlockd-new/sounds/zonk.wav rename to sounds/zonk.wav diff --git a/doorlockd-new/ssl/BKCA.crt b/ssl/BKCA.crt similarity index 100% rename from doorlockd-new/ssl/BKCA.crt rename to ssl/BKCA.crt diff --git a/doorlockd-new/static/led-green.png b/static/led-green.png similarity index 100% rename from doorlockd-new/static/led-green.png rename to static/led-green.png diff --git a/doorlockd-new/static/led-red.png b/static/led-red.png similarity index 100% rename from doorlockd-new/static/led-red.png rename to static/led-red.png diff --git a/doorlockd-new/static/logo.svg b/static/logo.svg similarity index 100% rename from doorlockd-new/static/logo.svg rename to static/logo.svg diff --git a/doorlockd-new/static/socket.io.slim.js b/static/socket.io.slim.js similarity index 100% rename from doorlockd-new/static/socket.io.slim.js rename to static/socket.io.slim.js diff --git a/doorlockd-new/static/token.png b/static/token.png similarity index 100% rename from doorlockd-new/static/token.png rename to static/token.png diff --git a/doorlockd-new/templates/display.html b/templates/display.html similarity index 100% rename from doorlockd-new/templates/display.html rename to templates/display.html diff --git a/doorlockd-new/templates/index.html b/templates/index.html similarity index 100% rename from doorlockd-new/templates/index.html rename to templates/index.html diff --git a/doorlockd-new/templates/layout.html b/templates/layout.html similarity index 100% rename from doorlockd-new/templates/layout.html rename to templates/layout.html diff --git a/webfrontend/index.php b/webfrontend/index.php deleted file mode 100644 index 3d14d5a..0000000 --- a/webfrontend/index.php +++ /dev/null @@ -1,171 +0,0 @@ - - - - - -Login - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- -
- - - -

Welcome Cpt. Cook

- - - -

Something went wrong:

- - - - - - - diff --git a/webfrontend/logo.svg b/webfrontend/logo.svg deleted file mode 100644 index a70b25c..0000000 --- a/webfrontend/logo.svg +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - -