From 14448e01a27cbbfc26e2a29eb97057e0f551809a Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Wed, 13 May 2015 14:40:30 +0000 Subject: [PATCH] Added more cmdline arguments --- config.h.in | 12 ++++-------- logic.cpp | 20 +++++++++++--------- logic.h | 18 +++++++++++------- main.cpp | 16 ++++++++++++++-- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/config.h.in b/config.h.in index f3820f1..fbe643c 100755 --- a/config.h.in +++ b/config.h.in @@ -10,13 +10,9 @@ #endif #define DEFAULT_PORT 5555 - -#define LOCKPAGE_PREFIX "https://lock.binary.kitchen/" -#define FIFO_LOCATION "/var/run/doorlockd/doorlockd" - -#define LDAP_SERVER "ldaps://ldap.binary.kitchen" -#define BINDDN "cn=%s,ou=Users,dc=binary-kitchen,dc=de" - -#define ALLOWEDIPPREFIX "172.23.3." +#define DEFAULT_WEB_PREFIX "https://lock.binary.kitchen/" +#define DEFAULT_LDAP_SERVER "ldaps://ldap.binary.kitchen" +#define DEFAULT_BINDDN "cn=%s,ou=Users,dc=binary-kitchen,dc=de" +#define DEFAULT_ALLOWED_IP_PREFIX "172.23.3." #endif diff --git a/logic.cpp b/logic.cpp index d84d5c7..9a8d691 100755 --- a/logic.cpp +++ b/logic.cpp @@ -13,17 +13,19 @@ using namespace std; -const string Logic::_lockPagePrefix = LOCKPAGE_PREFIX; - -const string Logic::_ldapServer = LDAP_SERVER; -const string Logic::_bindDN = BINDDN; -const string Logic::_allowedIpPrefix = ALLOWEDIPPREFIX; - -Logic::Logic(const chrono::seconds tokenTimeout) : +Logic::Logic(const chrono::seconds tokenTimeout, + const string &ldapServer, + const string &bindDN, + const string &webPrefix, + const string &allowedIpPrefix) : _logger(Logger::get()), _door(Door::get()), _epaper(Epaper::get()), - _tokenTimeout(tokenTimeout) + _tokenTimeout(tokenTimeout), + _ldapServer(ldapServer), + _bindDN(bindDN), + _webPrefix(webPrefix), + _allowedIpPrefix(allowedIpPrefix) { srand(time(NULL)); _createNewToken(false); @@ -235,7 +237,7 @@ void Logic::_createNewToken(const bool stillValid) _curToken = (((uint64_t)rand())<<32) | ((uint64_t)rand()); - _epaper.draw(_lockPagePrefix + toHexString(_curToken)); + _epaper.draw(_webPrefix + toHexString(_curToken)); ostringstream message; message << "New Token generated: " << toHexString(_curToken) << " old Token: " << toHexString(_prevToken) << " is " << (_prevValid?"still":"not") << " valid"; diff --git a/logic.h b/logic.h index 3c87d47..7ed7149 100755 --- a/logic.h +++ b/logic.h @@ -16,7 +16,11 @@ class Logic { public: - Logic(const std::chrono::seconds tokenTimeout); + Logic(const std::chrono::seconds tokenTimeout, + const std::string &ldapServer, + const std::string &bindDN, + const std::string &webPrefix, + const std::string &allowedIpPrefix); ~Logic(); enum Response { @@ -41,7 +45,8 @@ private: Response _unlock(); bool _checkToken(const std::string &token); - Response _checkLDAP(const std::string &user, const std::string &password); + Response _checkLDAP(const std::string &user, + const std::string &password); bool _checkIP(const std::string &ip); void _createNewToken(const bool stillValid); @@ -57,11 +62,10 @@ private: Token _prevToken = { 0x0000000000000000 }; const std::chrono::seconds _tokenTimeout; - - const static std::string _lockPagePrefix; - const static std::string _bindDN; - const static std::string _ldapServer; - const static std::string _allowedIpPrefix; + const std::string _ldapServer; + const std::string _bindDN; + const std::string _webPrefix; + const std::string _allowedIpPrefix; std::thread _tokenUpdater = {}; std::condition_variable _c = {}; diff --git a/main.cpp b/main.cpp index b079dd5..58640fa 100755 --- a/main.cpp +++ b/main.cpp @@ -92,6 +92,10 @@ int main(int argc, char** argv) int retval = -1; short port; std::chrono::seconds tokenTimeout; + string ldapServer; + string bindDN; + string lockPagePrefix; + string allowedIpPrefix; try { unsigned int timeout; @@ -99,7 +103,11 @@ int main(int argc, char** argv) desc.add_options() ("help,h", "print help") ("tokentimeout,t", po::value(&timeout)->required(), "tokentimeout in seconds") - ("port,p", po::value(&port)->default_value(DEFAULT_PORT), "Port"); + ("port,p", po::value(&port)->default_value(DEFAULT_PORT), "Port") + ("ldap,l", po::value(&ldapServer)->default_value(DEFAULT_LDAP_SERVER), "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") + ("ip,i", po::value(&allowedIpPrefix)->default_value(DEFAULT_ALLOWED_IP_PREFIX), "Default allowed IP Prefix"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).run(), vm); @@ -121,7 +129,11 @@ int main(int argc, char** argv) goto out; } - logic = unique_ptr(new Logic(tokenTimeout)); + logic = unique_ptr(new Logic(tokenTimeout, + ldapServer, + bindDN, + lockPagePrefix, + allowedIpPrefix)); l(LogLevel::notice, "Starting doorlockd");