Exemplo n.º 1
0
 def update(self):
     """
     更新证书
     """
     status = self.exec_task("create")
     self.db_operation(status, "update")
     https_list, http_list = self.get_subdomain_list(status)
     content = email_table(status, self.domain, self.dns, https_list, http_list)  # 格式化成html table作为邮件内容发送
     subject = F"{self.domain} 证书更新成功" if status else F"{self.domain} 证书更新失败"
     to_email = to(self.domain)
     send_email(subject, content, self.domain, to_email)
Exemplo n.º 2
0
def custom_domain_expired_alarms():
    """
    执行计划 执行函数
    自定义域名SSL证书过期提醒
    """
    days = 5
    queryset = custom_domain_filter(days)
    log.info(F"custom domain expire alarms: {queryset.values()}")
    for obj in queryset:
        custom_domain = obj.domain
        expire_date = obj.expire_date
        content = custom_domain_alarm_email(custom_domain, expire_date)
        subject = F"{custom_domain} SSL证书过期提醒"
        email = custom_domain_to_email(custom_domain)
        send_email(subject, content, custom_domain, email)
Exemplo n.º 3
0
    def alarms(self):
        # acme创建的免费证书有效期最多90天,这里过滤有效期100天之内的域名,即所有域名
        queryset = domain_filter(1000)
        for obj in queryset:
            main_domain_result = self.main_domain(obj.domain, obj.source_ip)
            https_sub_domain = self.https_sub_domain_filter(
                obj.domain, obj.dns, eval(obj.dns_account))

            # 域名与证书不匹配、主域名即将过期、子域名即将过期 发送邮件通知
            if "verify_https_msg" in main_domain_result \
                    or main_domain_result["expire"] or https_sub_domain:
                log.info(F"expire alarm main domain: {obj.domain}")
                log.info(F"expire alarm sub domain: {https_sub_domain}")
                sld = SLD(obj.domain)
                new_domain = "@." + obj.domain if sld.is_sld(
                ) else obj.domain  # 如果是个二级域名,在发送邮件时,前面加上@
                email_content = email_table(new_domain, obj.dns,
                                            main_domain_result,
                                            https_sub_domain)
                subject = F"{new_domain} SSL证书过期提醒"
                email = to_email(obj.domain)
                send_email(subject, email_content, obj.domain, email)
Exemplo n.º 4
0
    def post(self, request):
        domain = request.POST.get("domain")
        domain_obj = Domain.objects.get(domain=domain)
        if domain_obj.status != "valid":
            return JsonResponse({"status": "failed", "msg": F"域名状态为: {domain_obj.get_status_display()}, 不能执行此操作"})
        queryset = ToEmail.objects.filter(domain=domain_obj).values("email")
        if not queryset:
            return JsonResponse({"status": "failed", "msg": "请添加接收邮箱"})
        email_list = [item["email"] for item in queryset]

        domain = domain_obj.domain
        dns = domain_obj.dns
        account = eval(domain_obj.dns_account)
        expire_date = domain_obj.expire_date

        domain_classify = DomainClassify(domain, dns, account)
        https_list, http_list = domain_classify.https_http_list()

        content = email_table(domain, dns, expire_date, https_list, http_list)  # 格式化成html table作为邮件内容发送
        subject = F"{domain} SSL证书"
        to_email = email_list
        send_email(subject, content, domain, to_email)

        return JsonResponse({"status": "success"})