import logging.config
import re
import pwd
-import glob
import copy
import textwrap
import socket
-import pwd
import grp
import tempfile
import time
import datetime
-import textwrap
import ipaddress
import stat
import shutil
-import shlex, subprocess
+import shlex
from subprocess import Popen, TimeoutExpired, PIPE
# Third party modules
import six
-from six import reraise
import requests
from six.moves.urllib.parse import urlunsplit
# Own modules
-from .common import pp, to_bool, to_bytes, to_str
+from .common import pp, to_bool, to_str
from .cfg_app import PpCfgAppError, PpConfigApplication
-from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile
+from .pidfile import PidFileError, PidFile
-__version__ = '0.7.3'
+__version__ = '0.7.4'
LOG = logging.getLogger(__name__)
log_categories = {
'client': ['null'],
- 'config': ['syslog', 'named', 'config',],
- 'database': ['syslog', 'named',],
- 'default': ['syslog', 'named',],
- 'delegation-only': ['syslog', 'named',],
- 'dispatch': ['syslog', 'named',],
- 'dnssec': ['syslog', 'named', 'dnssec',],
- 'general': ['syslog', 'named',],
+ 'config': ['syslog', 'named', 'config'],
+ 'database': ['syslog', 'named'],
+ 'default': ['syslog', 'named'],
+ 'delegation-only': ['syslog', 'named'],
+ 'dispatch': ['syslog', 'named'],
+ 'dnssec': ['syslog', 'named', 'dnssec'],
+ 'general': ['syslog', 'named'],
'lame-servers': ['lame-servers'],
- 'network': ['syslog', 'named', 'network',],
- 'notify': ['syslog', 'named', 'notify',],
- 'queries': ['query', 'query-error',],
- 'resolver': ['syslog', 'named', 'resolver',],
- 'rpz': ['syslog', 'named',],
- 'rate-limit': ['syslog', 'named', 'ratelimit',],
- 'security': ['syslog', 'named', 'security',],
- 'unmatched': ['syslog', 'named', 'unmatched',],
- 'update': ['syslog', 'named', 'update',],
- 'update-security': ['syslog', 'named', 'update', 'security',],
- 'xfer-in': ['syslog', 'named', 'xfer-in',],
- 'xfer-out': ['syslog', 'named', 'xfer-out',],
+ 'network': ['syslog', 'named', 'network'],
+ 'notify': ['syslog', 'named', 'notify'],
+ 'queries': ['query', 'query-error'],
+ 'resolver': ['syslog', 'named', 'resolver'],
+ 'rpz': ['syslog', 'named'],
+ 'rate-limit': ['syslog', 'named', 'ratelimit'],
+ 'security': ['syslog', 'named', 'security'],
+ 'unmatched': ['syslog', 'named', 'unmatched'],
+ 'update': ['syslog', 'named', 'update'],
+ 'update-security': ['syslog', 'named', 'update', 'security'],
+ 'xfer-in': ['syslog', 'named', 'xfer-in'],
+ 'xfer-out': ['syslog', 'named', 'xfer-out'],
}
# -------------------------------------------------------------------------
self._named_zones_cfg_file = self.default_named_zones_cfg_file
# Variable status directories and files
- self.named_basedir = self.default_named_basedir
- self._named_datadir = self.default_named_datadir
- self._named_slavedir = self.default_named_slavedir
- self._named_managed_keysdir = self.default_named_managed_keysdir
- self._named_root_zone_file = self.default_named_root_zone_file
+ self.named_basedir = self.default_named_basedir
+ self._named_datadir = self.default_named_datadir
+ self._named_slavedir = self.default_named_slavedir
+ self._named_managed_keysdir = self.default_named_managed_keysdir
+ self._named_root_zone_file = self.default_named_root_zone_file
# Runtime volatile directories and files
- self.named_rundir = self.default_named_rundir
- self._named_pidfile = self.default_named_pidfile
- self._named_session_keyfile = self.default_named_session_keyfile
+ self.named_rundir = self.default_named_rundir
+ self._named_pidfile = self.default_named_pidfile
+ self._named_session_keyfile = self.default_named_session_keyfile
# Runtime user and group
self.named_user = 'named'
if section_name.lower() in (
'powerdns-api', 'powerdns_api', 'powerdnsapi',
- 'pdns-api', 'pdns_api', 'pdnsapi' ):
+ 'pdns-api', 'pdns_api', 'pdnsapi'):
self.set_api_options(section, section_name)
if section_name.lower() == 'named':
raise ValueError(
"a port must be greater than 0 and less than {}.".format(2**16))
except (TypeError, ValueError) as e:
- LOG.error("Wrong port number {!r} in configuration section {!r}: {}".format(
- section['port'], section_name, e))
+ LOG.error(
+ "Wrong port number {!r} in configuration section {!r}: {}".format(
+ section['port'], section_name, e))
self.config_has_errors = True
else:
self.pdns_api_port = port
if m:
m = m.strip().lower()
try:
- addr_info = socket.getaddrinfo(
- m, 53, proto=socket.IPPROTO_TCP, family=socket.AF_INET)
+ addr_info = socket.getaddrinfo( # noqa
+ m, 53, proto=socket.IPPROTO_TCP, family=socket.AF_INET) # noqa
except socket.gaierror as e:
msg = (
"Invalid hostname or address {!r} found in "
LOG.debug("Generated {!r}:\n{}".format(self.temp_acl_cfg_file, content.strip()))
# -------------------------------------------------------------------------
- def generate_named_conf(self):
+ def generate_named_conf(self): # noqa
LOG.info("Generating {} ...".format(self.default_named_conf))
LOG.debug("Generated {!r}:\n{}".format(self.temp_named_conf, content.strip()))
# -------------------------------------------------------------------------
- def generate_log_cfg_file(self):
+ def generate_log_cfg_file(self): # noqa
LOG.info("Generating {} ...".format(self.default_named_log_cfg_file))
content = header
- content += '\nlogging {\n';
+ content += '\nlogging {\n'
content += '\n\t// -----------------------------------\n'
content += '\t// Channels\n'
channels = ['null']
if cat_name == 'queries':
if self.query_log:
- if not 'query' in channels:
+ if 'query' not in channels:
channels.append('query')
else:
if 'query' in channels:
if self.verbose > 2:
LOG.debug("Generated {!r}:\n{}".format(self.temp_zones_cfg_file, content.strip()))
-
# -------------------------------------------------------------------------
def get_api_zones(self):
for entry in json_response:
-# { 'account': '',
-# 'dnssec': False,
-# 'id': '56.66.217.in-addr.arpa.',
-# 'kind': 'Master',
-# 'last_check': 0,
-# 'masters': [],
-# 'name': '56.66.217.in-addr.arpa.',
-# 'notified_serial': 2017080202,
-# 'serial': 2017080202,
-# 'url': 'api/v1/servers/localhost/zones/56.66.217.in-addr.arpa.'},
+ # { 'account': '',
+ # 'dnssec': False,
+ # 'id': '56.66.217.in-addr.arpa.',
+ # 'kind': 'Master',
+ # 'last_check': 0,
+ # 'masters': [],
+ # 'name': '56.66.217.in-addr.arpa.',
+ # 'notified_serial': 2017080202,
+ # 'serial': 2017080202,
+ # 'url': 'api/v1/servers/localhost/zones/56.66.217.in-addr.arpa.'},
zone_name = entry['name']
zone = {
def check_directories(self):
LOG.info("Checking all necessary directories for existence and ownership.")
- all_ok = True
self.check_directory(self.named_conf_dir)
self.check_directory(self.named_basedir, None, self.named_gid, 0o750)
self.check_directory(self.named_logdir, self.named_uid, self.named_gid, 0o755)
# -------------------------------------------------------------------------
- def check_directory(self, dirname, owner_id=None, group_id=None, mode=None):
+ def check_directory(self, dirname, owner_id=None, group_id=None, mode=None): # noqa
LOG.debug("Checking directory {!r} ...".format(dirname))