]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add 'showWebserverConfig'
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 18 Nov 2021 15:09:48 +0000 (16:09 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 18 Nov 2021 15:09:48 +0000 (16:09 +0100)
pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist-web.cc
pdns/dnsdistdist/connection-management.hh
pdns/dnsdistdist/dnsdist-web.hh
pdns/dnsdistdist/docs/reference/config.rst

index 44e33cc027dc6ad5996f8ad01992c78f415ef39d..c4f1f6cab85fdb6635a05c33b643abbac65444e2 100644 (file)
@@ -660,6 +660,7 @@ const std::vector<ConsoleKeyword> 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" },
index fde21a9fccb47b5f95b6d308d060f91e487e40bb..5633307d14d52f53051b379c8749399f88306da8 100644 (file)
@@ -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<uint64_t> workFactor) {
     if (workFactor) {
       return hashPassword(password, *workFactor, CredentialsHolder::s_defaultParallelFactor, CredentialsHolder::s_defaultBlockSize);
index 5e551076cbcce2c7c72edab4f2b0758a15c751b4..76f772b7047de148117cb656f8652a1c4a0b043f 100644 (file)
@@ -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:
index 9796cb60efd26cad031e72beae37a1f696f15898..3237f74b9811a5af5705e588e817dd5e57aa6683 100644 (file)
@@ -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();
index fea62bedffe506e596ed303e296b0d8de6c8d12b..a4f30fc80d4079bc1c924c35ea2415f26b4e4eb3 100644 (file)
@@ -13,3 +13,5 @@ void dnsdistWebserverThread(int sock, const ComboAddress& local);
 
 void registerBuiltInWebHandlers();
 void clearWebHandlers();
+
+std::string getWebServerConfig();
index b2386707f029cfa1a40cfbe6ab88736dd232dee6..d900645421fd17b4669c4abb0c746414f1e92186 100644 (file)
@@ -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
 ~~~~~~~~~~~~~~~~~~~~