d_registerApiHandlerCalled = true;
}
-static void webWrapper(WebServer::HandlerFunction handler, HttpRequest* req, HttpResponse* resp) {
- const string& web_password = arg()["webserver-password"];
-
- if (!web_password.empty()) {
- bool auth_ok = req->compareAuthorization(web_password);
+static void webWrapper(WebServer::HandlerFunction handler, HttpRequest* req, HttpResponse* resp, const string &password) {
+ if (!password.empty()) {
+ bool auth_ok = req->compareAuthorization(password);
if (!auth_ok) {
g_log<<Logger::Debug<<"HTTP Request \"" << req->url.path << "\": Web Authentication failed" << endl;
throw HttpUnauthorizedException("Basic");
}
void WebServer::registerWebHandler(const string& url, HandlerFunction handler) {
- HandlerFunction f = boost::bind(&webWrapper, handler, _1, _2);
+ HandlerFunction f = boost::bind(&webWrapper, handler, _1, _2, d_webserverPassword);
registerBareHandler(url, f);
}
d_apikey = apikey;
}
+ void setPassword(const string &password) {
+ if (d_registerWebHandlerCalled) {
+ throw PDNSException("registerWebHandler has been called, can not change password");
+ }
+ d_webserverPassword = password;
+ }
+
void bind();
void go();
std::string d_apikey;
bool d_registerApiHandlerCalled{false};
+
+ std::string d_webserverPassword;
+ bool d_registerWebHandlerCalled{false};
};
#endif /* WEBSERVER_HH */
if(arg().mustDo("webserver") || arg().mustDo("api")) {
d_ws = new WebServer(arg()["webserver-address"], arg().asNum("webserver-port"));
d_ws->setApiKey(arg()["api-key"]);
+ d_ws->setPassword(arg()["webserver-password"]);
d_ws->bind();
}
}
d_ws = new AsyncWebServer(fdm, arg()["webserver-address"], arg().asNum("webserver-port"));
d_ws->setApiKey(arg()["api-key"]);
+ d_ws->setPassword(arg()["webserver-password"]);
d_ws->bind();
// legacy dispatch