From: Frank Brehm Date: Tue, 7 Dec 2021 14:25:59 +0000 (+0100) Subject: Starting with method get_named_keys() of class PpDeployZonesApp X-Git-Tag: 0.4.1~5^2~11 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=be33d981bf71c2f666f178954facf36433320725;p=pixelpark%2Fpp-admin-tools.git Starting with method get_named_keys() of class PpDeployZonesApp --- diff --git a/lib/pp_admintools/deploy_zones_from_pdns.py b/lib/pp_admintools/deploy_zones_from_pdns.py index b985194..8d6afa9 100644 --- a/lib/pp_admintools/deploy_zones_from_pdns.py +++ b/lib/pp_admintools/deploy_zones_from_pdns.py @@ -130,6 +130,8 @@ class PpDeployZonesApp(PpPDNSApplication): self.cmd_start = self.default_cmd_start self.cmd_restart = self.default_cmd_restart + self.named_keys = {} + self.zone_tsig_key = None self.files2replace = {} @@ -354,6 +356,11 @@ class PpDeployZonesApp(PpPDNSApplication): "please use 'local' or 'public'")) self.exit(1) + cmd_namedcheckconf = self.get_command('named-checkconf') + if not cmd_namedcheckconf: + self.exit(1) + self.cmd_checkconf = cmd_namedcheckconf + # ------------------------------------------------------------------------- def _run(self): @@ -369,6 +376,8 @@ class PpDeployZonesApp(PpPDNSApplication): LOG.info(_("Starting: {}").format( datetime.datetime.now(local_tz).strftime('%Y-%m-%d %H:%M:%S %Z'))) + self.get_named_keys() + try: self.pidfile.create() except PidFileError as e: @@ -447,6 +456,39 @@ class PpDeployZonesApp(PpPDNSApplication): if self.verbose > 1: LOG.debug(_("Temporary zones conf: {!r}").format(self.temp_zones_cfg_file)) + # ------------------------------------------------------------------------- + def get_named_keys(self): + + LOG.info(_("Trying to get all keys from named.conf ...")) + + LOG.info(_("Checking syntax correctness of named.conf ...")) + cmd = shlex.split(self.cmd_checkconf) + cmd.append('-p') + + cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd)) + LOG.debug(_("Executing: {}").format(cmd_str)) + + result = self.run( + cmd, stdout=PIPE, stderr=PIPE, timeout=10, check=True, may_simulate=False) + if self.verbose > 1: + LOG.debug(_("Result:") + '\n' + str(result)) + + config = result.stdout + + key_pattern = r'^\s*key\s+("[^"]+"|\S+)\s+\{([^\}]+\}\s*;' + re_quotes = re.compile(r'^\s*"([^"]+)"\s*$') + re_key = re.compile(key_pattern, re.IGNORECASE | re.MULTILINE | re.DOTALL) + + for match in re_key.finditer(config): + match_quotes = re_quotes.match(match[1]) + if match_quotes: + key_name = match_quotes[1] + else: + key_name = match[1] + key_data = match[2].strip() + if self.verbose > 1: + LOG.debug("Found key {!r}:".format(key_name) + '\n' + key_data) + # ------------------------------------------------------------------------- def generate_slave_cfg_file(self):