]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Show Lua config converted to YAML in rec_control show-yaml
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 31 Jan 2024 15:25:29 +0000 (16:25 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 25 Apr 2024 09:31:40 +0000 (11:31 +0200)
pdns/recursordist/Makefile.am
pdns/recursordist/rec-lua-conf.cc
pdns/recursordist/rec_control.cc

index 43ac680342ca40cc689d454a09e339230bbddf1a..afc41e9a46727ddcedee2d0089afd7b21d1289ed 100644 (file)
@@ -445,6 +445,7 @@ endif
 
 if LUA
 pdns_recursor_LDADD += $(LUA_LIBS)
+rec_control_LDADD += $(LUA_LIBS)
 testrunner_LDADD += $(LUA_LIBS)
 endif
 
@@ -515,12 +516,15 @@ rec_control_SOURCES = \
        dnsrecords.cc dnsrecords.hh \
        dnswriter.cc dnswriter.hh \
        filterpo.cc filterpo.hh \
+       lua-base4.cc lua-base4.hh \
+       iputils.cc iputils.hh \
        logger.cc \
        logging.cc \
        misc.cc \
        nsecrecords.cc \
        qtype.cc \
        rcpgenerator.cc rcpgenerator.hh \
+       rec-lua-conf.cc rec-lua-conf.hh \
        rec_channel.cc rec_channel.hh \
        rec_control.cc \
        settings/cxxsupport.cc \
index 2ac2026a3e3d56c369035b492fac0cd29bef05be..97d643024598a02eb13ef2700f9b7dabe84bb31a 100644 (file)
@@ -376,7 +376,9 @@ public:
 void loadRecursorLuaConfig(const std::string& fname, ProxyMapping& proxyMapping, LuaConfigItems& newLuaConfig)
 {
   LuaConfigItems lci;
-  lci.d_slog = g_slog->withName("luaconfig");
+  if (g_slog) {
+    lci.d_slog = g_slog->withName("luaconfig");
+  }
 
   RecLuaConfigContext Lua;
 
index fe04c93ed02516dbece71161cbcab979b58b10cc..4ad16e440f7a0bade9ccad9d4aea1c48c0a75d4f 100644 (file)
@@ -111,6 +111,41 @@ static void initArguments(int argc, char** argv, Logr::log_t log)
   }
 }
 
+static std::string showLuaYAML(const ::rust::string rfile)
+{
+  std::string msg;
+  if (rfile.empty()) {
+    return msg;
+  }
+
+  const auto file = string(rfile);
+  ProxyMapping proxyMapping;
+  LuaConfigItems lci;
+
+  try {
+    loadRecursorLuaConfig(file, proxyMapping, lci);
+    auto settings = pdns::rust::settings::rec::parse_yaml_string("");
+    pdns::settings::rec::fromLuaConfigToBridgeStruct(lci, proxyMapping, settings);
+    auto yaml = settings.to_yaml_string();
+    msg += "# Start of converted Lua config .yml based on " + file + "\n";
+    msg += std::string(yaml);
+    msg += "# Validation result: ";
+    try {
+      // Parse back and validate
+      settings.validate();
+      msg += "OK";
+    }
+    catch (const rust::Error& err) {
+      msg += err.what();
+    }
+    msg += "\n# End of converted " + file + "\n#\n";
+  }
+  catch (PDNSException& e) {
+    cerr <<  "Cannot load Lua configuration: " << e.reason << endl;
+  }
+  return msg;
+}
+
 static std::string showIncludeYAML(::rust::String& rdirname)
 {
   std::string msg;
@@ -220,6 +255,7 @@ static RecursorControlChannel::Answer showYAML(const std::string& path)
     }
     msg += "\n# End of converted " + configName + "\n#\n";
 
+    msg += showLuaYAML(mainsettings.recursor.lua_config_file);
     msg += showIncludeYAML(mainsettings.recursor.include_dir);
     msg += showForwardFileYAML(mainsettings.recursor.forward_zones_file);
     msg += showAllowYAML(mainsettings.incoming.allow_from_file, "incoming", "allow_from_file", pdns::rust::settings::rec::validate_allow_from);