コード例 #1
0
    async def letsencrypt_fork(self, instance: Domain):
        domain: str = instance.domain

        command = [
            'letsencrypt',
            'certonly',
            f'--cert-name "{domain}"',
            '--manual',
            # f'--manual-auth-hook {self.dns_acme_auth}',
            f'--manual-auth-hook ./dns_acme_auth.py',
            # f'--deploy-hook {self.dns_acme_deploy}',
            f'--deploy-hook ./dns_acme_deploy.py',
            '--force-renewal',
            '--preferred-challenges=dns',
            '--register-unsafely-without-email',
            '--manual-public-ip-logging-ok',
            '--server https://acme-v02.api.letsencrypt.org/directory',
            '--agree-tos',
            '--quiet',
            f'-d "{domain}"',
            f'-d "*.{domain}"',
        ]

        shell_command = " ".join(command)

        process = await asyncio.create_subprocess_shell(
            shell_command,
            stdout=asyncio.subprocess.PIPE,
            stderr=asyncio.subprocess.PIPE)
        # if success process.returncode = 0
        # if error process.returncode = 1
        stdout, stderr = await process.communicate()

        instance: Domain = self.store.get_cache(domain)

        instance.on_success = stdout.decode().replace("\n", " ").strip()
        instance.on_error = stderr.decode().replace("\n", " ").strip()

        logger.debug(
            f"process.communicate: {process.returncode} {instance.serialize()}"
        )
        if process.returncode == 0:
            instance.status = SUCCESS
        else:
            instance.status = FAILED
        self.store.set_cache(domain, instance, instance.cache_time_out)
コード例 #2
0
    async def periodical_check(self, instance: Domain):
        try:
            domain: str = instance.domain
            while instance.status in [PENDING]:
                await asyncio.sleep(5)
                # we need get fresh cache object

                instance = self.store.get_cache(domain)
                # now we need check dns propagation status
                instance.check_acme()

                if instance.continue_check:
                    acme_time = int(instance.current_time -
                                    instance.start_time)
                    if acme_time >= 60 * 11:
                        instance.status = FAILED
                        instance.on_error = "Session and confirmation timeout."

                self.store.set_cache(domain, instance, instance.cache_time_out)
                await self.store.producer_queue.put({
                    "consumer":
                    "remote.vps.agent",
                    "type":
                    "receive.json",
                    "action":
                    f"acme_{PENDING}",
                    "message":
                    instance.serialize()
                })

            # this mean domains challenge Error or Success
            # TODO add logic for this challenge
            if instance.status == SUCCESS:
                await self.store.producer_queue.put({
                    "consumer":
                    "remote.vps.agent",
                    "type":
                    "receive.json",
                    "action":
                    f"acme_{SUCCESS}",
                    "error": [],
                    "message":
                    instance.serialize()
                })
                self.store.cache.delete(domain)
            else:
                await self.store.producer_queue.put({
                    "consumer":
                    "remote.vps.agent",
                    "type":
                    "receive.json",
                    "action":
                    f"acme_{FAILED}",
                    "error": [],
                    "message":
                    instance.serialize()
                })
                self.store.cache.delete(domain)

        except Exception as exc:
            logger.exception(exc)