Added more cmdline arguments

This commit is contained in:
Ralf Ramsauer 2015-05-13 14:40:30 +00:00
parent 1b1ffe54f3
commit 14448e01a2
4 changed files with 40 additions and 26 deletions

View File

@ -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

View File

@ -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";

18
logic.h
View File

@ -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 = {};

View File

@ -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<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::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<Logic>(new Logic(tokenTimeout));
logic = unique_ptr<Logic>(new Logic(tokenTimeout,
ldapServer,
bindDN,
lockPagePrefix,
allowedIpPrefix));
l(LogLevel::notice, "Starting doorlockd");