From: Otto Moerbeek Date: Wed, 31 Jan 2024 15:25:29 +0000 (+0100) Subject: Show Lua config converted to YAML in rec_control show-yaml X-Git-Tag: rec-5.1.0-alpha1~9^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9746988f5c1e16ec18da41648136940f91103b68;p=thirdparty%2Fpdns.git Show Lua config converted to YAML in rec_control show-yaml --- diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index 43ac680342..afc41e9a46 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -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 \ diff --git a/pdns/recursordist/rec-lua-conf.cc b/pdns/recursordist/rec-lua-conf.cc index 2ac2026a3e..97d6430245 100644 --- a/pdns/recursordist/rec-lua-conf.cc +++ b/pdns/recursordist/rec-lua-conf.cc @@ -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; diff --git a/pdns/recursordist/rec_control.cc b/pdns/recursordist/rec_control.cc index fe04c93ed0..4ad16e440f 100644 --- a/pdns/recursordist/rec_control.cc +++ b/pdns/recursordist/rec_control.cc @@ -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);