From: Remi Gacogne Date: Thu, 18 Nov 2021 15:09:48 +0000 (+0100) Subject: dnsdist: Add 'showWebserverConfig' X-Git-Tag: dnsdist-1.7.0-beta2~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3491311a23014e51d2dbf37a09e5065a4b271d7;p=thirdparty%2Fpdns.git dnsdist: Add 'showWebserverConfig' --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 44e33cc027..c4f1f6cab8 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -660,6 +660,7 @@ const std::vector g_consoleKeywords{ { "showTLSContexts", true, "", "list all the available TLS contexts" }, { "showTLSErrorCounters", true, "", "show metrics about TLS handshake failures" }, { "showVersion", true, "", "show the current version" }, + { "showWebserverConfig", true, "", "Show the current webserver configuration" }, { "shutdown", true, "", "shut down `dnsdist`" }, { "snmpAgent", true, "enableTraps [, daemonSocket]", "enable `SNMP` support. `enableTraps` is a boolean indicating whether traps should be sent and `daemonSocket` an optional string specifying how to connect to the daemon agent"}, { "SetAdditionalProxyProtocolValueAction", true, "type, value", "Add a Proxy Protocol TLV value of this type" }, diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index fde21a9fcc..5633307d14 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -1051,6 +1051,11 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } }); + luaCtx.writeFunction("showWebserverConfig", []() { + setLuaNoSideEffect(); + return getWebServerConfig(); + }); + luaCtx.writeFunction("hashPassword", [](const std::string& password, boost::optional workFactor) { if (workFactor) { return hashPassword(password, *workFactor, CredentialsHolder::s_defaultParallelFactor, CredentialsHolder::s_defaultBlockSize); diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index 5e551076cb..76f772b704 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -64,6 +64,35 @@ static const MetricDefinitionStorage s_metricDefinitions; static ConcurrentConnectionManager s_connManager(100); +std::string getWebServerConfig() +{ + ostringstream out; + + { + auto config = g_webserverConfig.lock(); + out << "Current web server configuration:" << endl; + out << "ACL: " << config->acl.toString() << endl; + out << "Custom headers: "; + if (config->customHeaders) { + for (const auto& header : *config->customHeaders) { + out << " - " << header.first << ": " << header.second << endl; + } + } + else { + out << "None"; + } + out << endl; + out << "Statistics require authentication: " << (config->statsRequireAuthentication ? "yes" : "no") << endl; + out << "Password: " << (config->password ? "set" : "unset") << endl; + out << "API key: " << (config->apiKey ? "set" : "unset") << endl; + } + out << "API writable: " << (g_apiReadWrite ? "yes" : "no") << endl; + out << "API configuration directory: " << g_apiConfigDirectory << endl; + out << "Maximum concurrent connections: " << s_connManager.getMaxConcurrentConnections() << endl; + + return out.str(); +} + class WebClientConnection { public: diff --git a/pdns/dnsdistdist/connection-management.hh b/pdns/dnsdistdist/connection-management.hh index 9796cb60ef..3237f74b98 100644 --- a/pdns/dnsdistdist/connection-management.hh +++ b/pdns/dnsdistdist/connection-management.hh @@ -36,6 +36,11 @@ public: d_data.lock()->d_maxConcurrentConnections = max; } + size_t getMaxConcurrentConnections() + { + return d_data.lock()->d_maxConcurrentConnections; + } + bool registerConnection() { auto data = d_data.lock(); diff --git a/pdns/dnsdistdist/dnsdist-web.hh b/pdns/dnsdistdist/dnsdist-web.hh index fea62bedff..a4f30fc80d 100644 --- a/pdns/dnsdistdist/dnsdist-web.hh +++ b/pdns/dnsdistdist/dnsdist-web.hh @@ -13,3 +13,5 @@ void dnsdistWebserverThread(int sock, const ComboAddress& local); void registerBuiltInWebHandlers(); void clearWebHandlers(); + +std::string getWebServerConfig(); diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index b2386707f0..d900645421 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -398,6 +398,13 @@ Webserver configuration :param str path: Path to register the handler for. :param function handler: The Lua function to register. +.. function:: showWebserverConfig() + + .. versionadded:: 1.7.0 + + Show the current webserver configuration. See :func:`webserver`. + + Access Control Lists ~~~~~~~~~~~~~~~~~~~~