]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add GeoIPQueryAttribute to LUA
authorBozhan Liang <lbz@rivensbane.com>
Fri, 13 Dec 2024 09:13:46 +0000 (17:13 +0800)
committerJames <lbz@rivensbane.com>
Thu, 23 Jan 2025 22:13:01 +0000 (11:13 +1300)
pdns/lua-record.cc
regression-tests.auth-py/test_LuaRecords.py

index 53709db61dca635c5861c56032695cec0122c877..f450cc0a0c5985f91821c35ba063cd48fc88e8e9 100644 (file)
@@ -1370,6 +1370,7 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn
   lua.writeFunction("geoiplookup", [](const string &ip, const GeoIPInterface::GeoIPQueryAttribute attr) {
     return getGeo(ip, attr);
   });
+  lua.writeVariable("GeoIPQueryAttribute", std::unordered_map<std::string, int>{{"ASn", GeoIPInterface::GeoIPQueryAttribute::ASn}, {"City", GeoIPInterface::GeoIPQueryAttribute::City}, {"Continent", GeoIPInterface::GeoIPQueryAttribute::Continent}, {"Country", GeoIPInterface::GeoIPQueryAttribute::Country}, {"Country2", GeoIPInterface::GeoIPQueryAttribute::Country2}, {"Name", GeoIPInterface::GeoIPQueryAttribute::Name}, {"Region", GeoIPInterface::GeoIPQueryAttribute::Region}, {"Location", GeoIPInterface::GeoIPQueryAttribute::Location}});
 
   typedef const boost::variant<string,vector<pair<int,string> > > combovar_t;
 
index 6e08b957d4d54d9fc6fba31dc0b0f46e38c5d4a9..3448f22eefa3f330c2c541ecf029258c7f83b831 100644 (file)
@@ -175,6 +175,10 @@ lookmeup         IN           A  192.0.2.5
 dblookup         IN    LUA    A  "dblookup('lookmeup.example.org', pdns.A)[1]"
 
 whitespace       IN    LUA    TXT "'foo" "bar'"
+geoipqueryattribute IN LUA    TXT ("string.format('%d %d %d %d %d %d %d',"
+                                   "GeoIPQueryAttribute.ASn, GeoIPQueryAttribute.City, GeoIPQueryAttribute.Continent,"
+                                   "GeoIPQueryAttribute.Country, GeoIPQueryAttribute.Country2, GeoIPQueryAttribute.Name,"
+                                   "GeoIPQueryAttribute.Region, GeoIPQueryAttribute.Location)")
         """
     }
     _web_rrsets = []
@@ -1177,6 +1181,22 @@ class TestLuaRecords(BaseLuaTest):
         self.assertRcodeEqual(res, dns.rcode.NOERROR)
         self.assertEqual(res.answer, response.answer)
 
+    def testGeoIPQueryAttribute(self):
+        """
+        Test GeoIPQueryAttribute enum
+        """
+        name = 'geoipqueryattribute.example.org.'
+
+        query = dns.message.make_query(name, 'TXT')
+
+        response = dns.message.make_response(query)
+
+        response.answer.append(dns.rrset.from_text(name, 0, dns.rdataclass.IN, dns.rdatatype.TXT, '"0 1 2 3 4 5 6"'))
+
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.NOERROR)
+        self.assertEqual(res.answer, response.answer)
+
 
 class TestLuaRecordsShared(TestLuaRecords):
     _config_template = """