Exemplo n.º 1
0
    def filedump(self, ext='tmp'):
        """Dumps parsed configurations into files.

        :param str ext: The file extension to use for the dumped files. If
            empty, this overrides the existing conf files.

        """
        for filename in self.parsed:
            tree = self.parsed[filename]
            if ext:
                filename = filename + os.path.extsep + ext
            try:
                with open(filename, 'w') as _file:
                    nginxparser.dump(tree, _file)
            except IOError:
                logging.error("Could not open file for writing: %s", filename)
Exemplo n.º 2
0
    def filedump(self, ext='tmp'):
        """Dumps parsed configurations into files.

        :param str ext: The file extension to use for the dumped files. If
            empty, this overrides the existing conf files.

        """
        for filename in self.parsed:
            tree = self.parsed[filename]
            if ext:
                filename = filename + os.path.extsep + ext
            try:
                with open(filename, 'w') as _file:
                    nginxparser.dump(tree, _file)
            except IOError:
                logger.error("Could not open file for writing: %s", filename)
    def _mod_config(self, ll_addrs):
        """Modifies Nginx config to include challenge server blocks.

        :param list ll_addrs: list of lists of
            :class:`letsencrypt_nginx.obj.Addr` to apply

        :raises .MisconfigurationError:
            Unable to find a suitable HTTP block in which to include
            authenticator hosts.

        """
        # Add the 'include' statement for the challenges if it doesn't exist
        # already in the main config
        included = False
        include_directive = ['include', self.challenge_conf]
        root = self.configurator.parser.loc["root"]

        bucket_directive = ['server_names_hash_bucket_size', '128']

        main = self.configurator.parser.parsed[root]
        for key, body in main:
            if key == ['http']:
                found_bucket = False
                for k, _ in body:
                    if k == bucket_directive[0]:
                        found_bucket = True
                if not found_bucket:
                    body.insert(0, bucket_directive)
                if include_directive not in body:
                    body.insert(0, include_directive)
                included = True
                break
        if not included:
            raise errors.MisconfigurationError(
                'LetsEncrypt could not find an HTTP block to include '
                'TLS-SNI-01 challenges in %s.' % root)

        config = [
            self._make_server_block(pair[0], pair[1])
            for pair in itertools.izip(self.achalls, ll_addrs)
        ]

        self.configurator.reverter.register_file_creation(
            True, self.challenge_conf)

        with open(self.challenge_conf, "w") as new_conf:
            nginxparser.dump(config, new_conf)
Exemplo n.º 4
0
    def _mod_config(self, ll_addrs):
        """Modifies Nginx config to include challenge server blocks.

        :param list ll_addrs: list of lists of
            :class:`letsencrypt_nginx.obj.Addr` to apply

        :raises .MisconfigurationError:
            Unable to find a suitable HTTP block in which to include
            authenticator hosts.

        """
        # Add the 'include' statement for the challenges if it doesn't exist
        # already in the main config
        included = False
        include_directive = ['include', self.challenge_conf]
        root = self.configurator.parser.loc["root"]

        bucket_directive = ['server_names_hash_bucket_size', '128']

        main = self.configurator.parser.parsed[root]
        for key, body in main:
            if key == ['http']:
                found_bucket = False
                for k, _ in body:
                    if k == bucket_directive[0]:
                        found_bucket = True
                if not found_bucket:
                    body.insert(0, bucket_directive)
                if include_directive not in body:
                    body.insert(0, include_directive)
                included = True
                break
        if not included:
            raise errors.MisconfigurationError(
                'LetsEncrypt could not find an HTTP block to include '
                'TLS-SNI-01 challenges in %s.' % root)

        config = [self._make_server_block(pair[0], pair[1])
                  for pair in itertools.izip(self.achalls, ll_addrs)]

        self.configurator.reverter.register_file_creation(
            True, self.challenge_conf)

        with open(self.challenge_conf, "w") as new_conf:
            nginxparser.dump(config, new_conf)
Exemplo n.º 5
0
 def test_dump_as_file(self):
     parsed = load(open(util.get_data_filename('nginx.conf')))
     parsed[-1][-1].append([['server'],
                            [['listen', '443 ssl'],
                             ['server_name', 'localhost'],
                             ['ssl_certificate', 'cert.pem'],
                             ['ssl_certificate_key', 'cert.key'],
                             ['ssl_session_cache', 'shared:SSL:1m'],
                             ['ssl_session_timeout', '5m'],
                             ['ssl_ciphers', 'HIGH:!aNULL:!MD5'],
                             [['location', '/'],
                              [['root', 'html'],
                               ['index', 'index.html index.htm']]]]])
     _file = open(util.get_data_filename('nginx.new.conf'), 'w')
     dump(parsed, _file)
     _file.close()
     parsed_new = load(open(util.get_data_filename('nginx.new.conf')))
     self.assertEquals(parsed, parsed_new)
 def test_dump_as_file(self):
     parsed = load(open(util.get_data_filename('nginx.conf')))
     parsed[-1][-1].append([['server'],
                            [['listen', '443 ssl'],
                             ['server_name', 'localhost'],
                             ['ssl_certificate', 'cert.pem'],
                             ['ssl_certificate_key', 'cert.key'],
                             ['ssl_session_cache', 'shared:SSL:1m'],
                             ['ssl_session_timeout', '5m'],
                             ['ssl_ciphers', 'HIGH:!aNULL:!MD5'],
                             [['location', '/'],
                              [['root', 'html'],
                               ['index', 'index.html index.htm']]]]])
     _file = open(util.get_data_filename('nginx.new.conf'), 'w')
     dump(parsed, _file)
     _file.close()
     parsed_new = load(open(util.get_data_filename('nginx.new.conf')))
     self.assertEquals(parsed, parsed_new)
Exemplo n.º 7
0
    def _mod_config(self, ll_addrs):
        """Modifies Nginx config to include challenge server blocks.

        :param list ll_addrs: list of lists of
            :class:`letsencrypt_nginx.obj.Addr` to apply

        :raises .MisconfigurationError:
            Unable to find a suitable HTTP block to include DVSNI hosts.

        """
        # Add the 'include' statement for the challenges if it doesn't exist
        # already in the main config
        included = False
        directive = ['include', self.challenge_conf]
        root = self.configurator.parser.loc["root"]
        main = self.configurator.parser.parsed[root]
        for entry in main:
            if entry[0] == ['http']:
                body = entry[1]
                if directive not in body:
                    body.append(directive)
                included = True
                break
        if not included:
            raise errors.MisconfigurationError(
                'LetsEncrypt could not find an HTTP block to include DVSNI '
                'challenges in %s.' % root)

        config = [
            self._make_server_block(pair[0], pair[1])
            for pair in itertools.izip(self.achalls, ll_addrs)
        ]

        self.configurator.reverter.register_file_creation(
            True, self.challenge_conf)

        with open(self.challenge_conf, "w") as new_conf:
            nginxparser.dump(config, new_conf)
Exemplo n.º 8
0
    def _mod_config(self, ll_addrs):
        """Modifies Nginx config to include challenge server blocks.

        :param list ll_addrs: list of lists of
            :class:`letsencrypt_nginx.obj.Addr` to apply

        :raises .MisconfigurationError:
            Unable to find a suitable HTTP block to include DVSNI hosts.

        """
        # Add the 'include' statement for the challenges if it doesn't exist
        # already in the main config
        included = False
        directive = ['include', self.challenge_conf]
        root = self.configurator.parser.loc["root"]
        main = self.configurator.parser.parsed[root]
        for entry in main:
            if entry[0] == ['http']:
                body = entry[1]
                if directive not in body:
                    body.append(directive)
                included = True
                break
        if not included:
            raise errors.MisconfigurationError(
                'LetsEncrypt could not find an HTTP block to include DVSNI '
                'challenges in %s.' % root)

        config = [self._make_server_block(pair[0], pair[1])
                  for pair in itertools.izip(self.achalls, ll_addrs)]

        self.configurator.reverter.register_file_creation(
            True, self.challenge_conf)

        with open(self.challenge_conf, "w") as new_conf:
            nginxparser.dump(config, new_conf)
    def test_comments(self):
        with open(util.get_data_filename('minimalistic_comments.conf')) as handle:
            parsed = load(handle)

        with open(util.get_data_filename('minimalistic_comments.new.conf'), 'w') as handle:
            dump(parsed, handle)

        with open(util.get_data_filename('minimalistic_comments.new.conf')) as handle:
            parsed_new = load(handle)

        self.assertEquals(parsed, parsed_new)

        self.assertEqual(parsed_new, [
            ['#', " Use bar.conf when it's a full moon!"],
            ['include', 'foo.conf'],
            ['#', ' Kilroy was here'],
            ['check_status', None],
            [['server'],
             [['#', ''],
              ['#', " Don't forget to open up your firewall!"],
              ['#', ''],
              ['listen', '1234'],
              ['#', ' listen 80;']]],
        ])
Exemplo n.º 10
0
    def test_comments(self):
        with open(util.get_data_filename(
                'minimalistic_comments.conf')) as handle:
            parsed = load(handle)

        with open(util.get_data_filename('minimalistic_comments.new.conf'),
                  'w') as handle:
            dump(parsed, handle)

        with open(util.get_data_filename(
                'minimalistic_comments.new.conf')) as handle:
            parsed_new = load(handle)

        self.assertEquals(parsed, parsed_new)

        self.assertEqual(parsed_new, [
            ['#', " Use bar.conf when it's a full moon!"],
            ['include', 'foo.conf'],
            ['#', ' Kilroy was here'],
            ['check_status', None],
            [['server'],
             [['#', ''], ['#', " Don't forget to open up your firewall!"],
              ['#', ''], ['listen', '1234'], ['#', ' listen 80;']]],
        ])