mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Added more cmdline arguments
This commit is contained in:
parent
1b1ffe54f3
commit
14448e01a2
12
config.h.in
12
config.h.in
@ -10,13 +10,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_PORT 5555
|
#define DEFAULT_PORT 5555
|
||||||
|
#define DEFAULT_WEB_PREFIX "https://lock.binary.kitchen/"
|
||||||
#define LOCKPAGE_PREFIX "https://lock.binary.kitchen/"
|
#define DEFAULT_LDAP_SERVER "ldaps://ldap.binary.kitchen"
|
||||||
#define FIFO_LOCATION "/var/run/doorlockd/doorlockd"
|
#define DEFAULT_BINDDN "cn=%s,ou=Users,dc=binary-kitchen,dc=de"
|
||||||
|
#define DEFAULT_ALLOWED_IP_PREFIX "172.23.3."
|
||||||
#define LDAP_SERVER "ldaps://ldap.binary.kitchen"
|
|
||||||
#define BINDDN "cn=%s,ou=Users,dc=binary-kitchen,dc=de"
|
|
||||||
|
|
||||||
#define ALLOWEDIPPREFIX "172.23.3."
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
20
logic.cpp
20
logic.cpp
@ -13,17 +13,19 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const string Logic::_lockPagePrefix = LOCKPAGE_PREFIX;
|
Logic::Logic(const chrono::seconds tokenTimeout,
|
||||||
|
const string &ldapServer,
|
||||||
const string Logic::_ldapServer = LDAP_SERVER;
|
const string &bindDN,
|
||||||
const string Logic::_bindDN = BINDDN;
|
const string &webPrefix,
|
||||||
const string Logic::_allowedIpPrefix = ALLOWEDIPPREFIX;
|
const string &allowedIpPrefix) :
|
||||||
|
|
||||||
Logic::Logic(const chrono::seconds tokenTimeout) :
|
|
||||||
_logger(Logger::get()),
|
_logger(Logger::get()),
|
||||||
_door(Door::get()),
|
_door(Door::get()),
|
||||||
_epaper(Epaper::get()),
|
_epaper(Epaper::get()),
|
||||||
_tokenTimeout(tokenTimeout)
|
_tokenTimeout(tokenTimeout),
|
||||||
|
_ldapServer(ldapServer),
|
||||||
|
_bindDN(bindDN),
|
||||||
|
_webPrefix(webPrefix),
|
||||||
|
_allowedIpPrefix(allowedIpPrefix)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
_createNewToken(false);
|
_createNewToken(false);
|
||||||
@ -235,7 +237,7 @@ void Logic::_createNewToken(const bool stillValid)
|
|||||||
|
|
||||||
_curToken = (((uint64_t)rand())<<32) | ((uint64_t)rand());
|
_curToken = (((uint64_t)rand())<<32) | ((uint64_t)rand());
|
||||||
|
|
||||||
_epaper.draw(_lockPagePrefix + toHexString(_curToken));
|
_epaper.draw(_webPrefix + toHexString(_curToken));
|
||||||
|
|
||||||
ostringstream message;
|
ostringstream message;
|
||||||
message << "New Token generated: " << toHexString(_curToken) << " old Token: " << toHexString(_prevToken) << " is " << (_prevValid?"still":"not") << " valid";
|
message << "New Token generated: " << toHexString(_curToken) << " old Token: " << toHexString(_prevToken) << " is " << (_prevValid?"still":"not") << " valid";
|
||||||
|
18
logic.h
18
logic.h
@ -16,7 +16,11 @@ class Logic
|
|||||||
{
|
{
|
||||||
public:
|
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();
|
~Logic();
|
||||||
|
|
||||||
enum Response {
|
enum Response {
|
||||||
@ -41,7 +45,8 @@ private:
|
|||||||
Response _unlock();
|
Response _unlock();
|
||||||
|
|
||||||
bool _checkToken(const std::string &token);
|
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);
|
bool _checkIP(const std::string &ip);
|
||||||
|
|
||||||
void _createNewToken(const bool stillValid);
|
void _createNewToken(const bool stillValid);
|
||||||
@ -57,11 +62,10 @@ private:
|
|||||||
Token _prevToken = { 0x0000000000000000 };
|
Token _prevToken = { 0x0000000000000000 };
|
||||||
|
|
||||||
const std::chrono::seconds _tokenTimeout;
|
const std::chrono::seconds _tokenTimeout;
|
||||||
|
const std::string _ldapServer;
|
||||||
const static std::string _lockPagePrefix;
|
const std::string _bindDN;
|
||||||
const static std::string _bindDN;
|
const std::string _webPrefix;
|
||||||
const static std::string _ldapServer;
|
const std::string _allowedIpPrefix;
|
||||||
const static std::string _allowedIpPrefix;
|
|
||||||
|
|
||||||
std::thread _tokenUpdater = {};
|
std::thread _tokenUpdater = {};
|
||||||
std::condition_variable _c = {};
|
std::condition_variable _c = {};
|
||||||
|
16
main.cpp
16
main.cpp
@ -92,6 +92,10 @@ int main(int argc, char** argv)
|
|||||||
int retval = -1;
|
int retval = -1;
|
||||||
short port;
|
short port;
|
||||||
std::chrono::seconds tokenTimeout;
|
std::chrono::seconds tokenTimeout;
|
||||||
|
string ldapServer;
|
||||||
|
string bindDN;
|
||||||
|
string lockPagePrefix;
|
||||||
|
string allowedIpPrefix;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
unsigned int timeout;
|
unsigned int timeout;
|
||||||
@ -99,7 +103,11 @@ int main(int argc, char** argv)
|
|||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help,h", "print help")
|
("help,h", "print help")
|
||||||
("tokentimeout,t", po::value<unsigned int>(&timeout)->required(), "tokentimeout in seconds")
|
("tokentimeout,t", po::value<unsigned int>(&timeout)->required(), "tokentimeout in seconds")
|
||||||
("port,p", po::value<short>(&port)->default_value(DEFAULT_PORT), "Port");
|
("port,p", po::value<short>(&port)->default_value(DEFAULT_PORT), "Port")
|
||||||
|
("ldap,l", po::value<string>(&ldapServer)->default_value(DEFAULT_LDAP_SERVER), "Ldap Server")
|
||||||
|
("bidndn,b", po::value<string>(&bindDN)->default_value(DEFAULT_BINDDN), "Bind DN %s means username")
|
||||||
|
("web,w", po::value<string>(&lockPagePrefix)->default_value(DEFAULT_WEB_PREFIX), "Prefix of the webpage")
|
||||||
|
("ip,i", po::value<string>(&allowedIpPrefix)->default_value(DEFAULT_ALLOWED_IP_PREFIX), "Default allowed IP Prefix");
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
po::store(po::command_line_parser(argc, argv).options(desc).run(), 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;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
logic = unique_ptr<Logic>(new Logic(tokenTimeout));
|
logic = unique_ptr<Logic>(new Logic(tokenTimeout,
|
||||||
|
ldapServer,
|
||||||
|
bindDN,
|
||||||
|
lockPagePrefix,
|
||||||
|
allowedIpPrefix));
|
||||||
|
|
||||||
l(LogLevel::notice, "Starting doorlockd");
|
l(LogLevel::notice, "Starting doorlockd");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user