From dfdb0dca173c7bc2b95bbdefb8525fe5e2601a97 Mon Sep 17 00:00:00 2001 From: Bernward Sanchez <109844019+pneb@users.noreply.github.com> Date: Sat, 10 Dec 2022 10:37:06 +0800 Subject: [PATCH] Update domain.py --- powerdnsadmin/models/domain.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/powerdnsadmin/models/domain.py b/powerdnsadmin/models/domain.py index bbd71e1..09b697e 100644 --- a/powerdnsadmin/models/domain.py +++ b/powerdnsadmin/models/domain.py @@ -110,6 +110,22 @@ class Domain(db.Model): 'Domain does not exist. ERROR: {0}'.format(e)) return None + def search_idn_domains(self, search_string): + """ + Search for IDN domains using the provided search string. + """ + # Compile the regular expression pattern for matching IDN domain names + idn_pattern = re.compile(r'^xn--') + + # Search for domain names that match the IDN pattern + idn_domains = [ + domain for domain in self.get_domains() if idn_pattern.match(domain) + ] + + # Filter the search results based on the provided search string + return [domain for domain in idn_domains if search_string in domain] + + def update(self): """ Fetch zones (domains) from PowerDNS and update into DB @@ -906,4 +922,4 @@ class Domain(db.Model): current_app.logger.error('Domain already exists as a record: {} under domain: {}'.format(r['name'].rstrip('.'), upper_domain_name)) return upper_domain_name upper_domain_name = '.'.join(upper_domain_name.split('.')[1:]) - return None \ No newline at end of file + return None