예제 #1
0
 def _get_object(self, handle: str) -> Any:
     objects = {}
     with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE):
         objects['contact'] = WHOIS.get_contact_by_handle(handle)
     with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE):
         objects['nsset'] = WHOIS.get_nsset_by_handle(handle)
     with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE):
         objects['keyset'] = WHOIS.get_keyset_by_handle(handle)
     with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE):
         objects['registrar'] = WHOIS.get_registrar_by_handle(handle)
     if not handle.startswith("."):
         with suppress(OBJECT_NOT_FOUND, UNMANAGED_ZONE, INVALID_LABEL,
                       TOO_MANY_LABELS, idna.IDNAError):
             idna_handle = idna.encode(handle).decode()
             try:
                 objects['domain'] = WHOIS.get_domain_by_handle(idna_handle)
             except OBJECT_DELETE_CANDIDATE:
                 objects['domain'] = None
     if not objects:
         raise WebwhoisError(
             code="OBJECT_NOT_FOUND",
             title=_("Record not found"),
             message=self.message_with_handle_in_html(
                 _("%s does not match any record."), handle),
             object_not_found=True,
         )
     return objects
예제 #2
0
    def load_related_objects(self, context):
        """Load objects related to the contact and append them into the context."""
        descriptions = self._get_status_descriptions(
            "contact", WHOIS.get_contact_status_descriptions)
        data = context[self._registry_objects_key][
            "contact"]  # detail, type, label, href
        registry_object = data["detail"]

        ver_status = [{
            "code":
            key,
            "label":
            descriptions[key],
            "icon":
            self.VERIFICATION_STATUS_ICON.get(
                key, self.VERIFICATION_STATUS_ICON["DEFAULT"])
        } for key in registry_object.statuses
                      if key in self.CONTACT_VERIFICATION_STATUS]
        data.update({
            "status_descriptions": [
                descriptions[key] for key in registry_object.statuses
                if key not in self.CONTACT_VERIFICATION_STATUS
            ],
            "verification_status":
            ver_status,
            "is_linked":
            STATUS_LINKED in registry_object.statuses
        })
        if registry_object.creating_registrar_handle:
            data["creating_registrar"] = WHOIS.get_registrar_by_handle(
                registry_object.creating_registrar_handle)
        if registry_object.sponsoring_registrar_handle:
            data["sponsoring_registrar"] = WHOIS.get_registrar_by_handle(
                registry_object.sponsoring_registrar_handle)
예제 #3
0
    def load_registry_object(cls, context, handle):
        """Load domain of the handle and append it into the context."""
        if handle.startswith("."):
            context["server_exception"] = cls.message_invalid_handle(handle)
            return

        try:
            idna_handle = idna.encode(handle).decode()
        except idna.IDNAError:
            context["server_exception"] = cls.message_invalid_handle(
                handle, "IDNAError")
            return

        try:
            context[cls._registry_objects_key]["domain"] = {
                "detail": WHOIS.get_domain_by_handle(idna_handle),
                "label": _("Domain"),
            }
        except OBJECT_DELETE_CANDIDATE:
            context['object_delete_candidate'] = True
            # Add fake domain into context for ResolveHandleTypeMixin.
            context[cls._registry_objects_key]['domain'] = None
        except OBJECT_NOT_FOUND:
            # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND.
            context["server_exception"] = cls.make_message_not_found(handle)
            context["server_exception"]["handle_is_in_zone"] = True
        except UNMANAGED_ZONE:
            context["managed_zone_list"] = WHOIS.get_managed_zone_list()
            context["server_exception"] = {
                "code":
                "UNMANAGED_ZONE",
                "title":
                _("Unmanaged zone"),
                "message":
                cls.message_with_handle_in_html(
                    _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:"
                      ), handle),
                "unmanaged_zone":
                True,
            }
        except INVALID_LABEL:
            # Pattern for the handle is more vague than the pattern of domain name format.
            context["server_exception"] = cls.message_invalid_handle(
                handle, "INVALID_LABEL")
        except TOO_MANY_LABELS:
            # Caution! Domain name can have more than one fullstop character and it is still valid.
            # for example: '0.2.4.e164.arpa'
            # remove subdomain names: 'www.sub.domain.cz' -> 'domain.cz'
            domain_match = re.search(r"([^.]+\.\w+)\.?$", handle,
                                     re.IGNORECASE)
            assert domain_match is not None
            context["example_domain_name"] = domain_match.group(1)
            context["server_exception"] = {
                "code": "TOO_MANY_LABELS",
                "title": _("Incorrect input"),
                "too_many_parts_in_domain_name": True,
            }
예제 #4
0
 def append_nsset_related(cls, data):
     """Load objects related to the nsset and append them into the data context."""
     descriptions = cls._get_status_descriptions(
         "nsset", WHOIS.get_nsset_status_descriptions)
     registry_object = data["detail"]
     data.update({
         "admins": [
             WHOIS.get_contact_by_handle(handle)
             for handle in registry_object.tech_contact_handles
         ],
         "registrar":
         WHOIS.get_registrar_by_handle(registry_object.registrar_handle),
         "status_descriptions":
         [descriptions[key] for key in registry_object.statuses],
     })
예제 #5
0
 def load_registry_object(cls, context, handle):
     """Load contact of the handle and append it into the context."""
     try:
         contact = WHOIS.get_contact_by_handle(handle)
         birthday = None
         if contact.identification.value.identification_type == "BIRTHDAY":
             try:
                 birthday = datetime.datetime.strptime(
                     contact.identification.value.identification_data,
                     '%Y-%m-%d').date()
             except ValueError:
                 birthday = contact.identification.value.identification_data
         context[cls._registry_objects_key]["contact"] = {
             "detail": contact,
             "birthday": birthday,
             "label": _("Contact"),
         }
     except OBJECT_NOT_FOUND as error:
         raise WebwhoisError(
             'OBJECT_NOT_FOUND',
             title=_("Contact not found"),
             message=cls.message_with_handle_in_html(
                 _("No contact matches %s handle."), handle),
         ) from error
     except INVALID_HANDLE as error:
         raise WebwhoisError(
             **cls.message_invalid_handle(handle)) from error
예제 #6
0
 def get_certifications(self):
     """Return dictionary of registrar certifications."""
     if self._certifications is None:
         self._certifications = {
             cert.registrar_handle: cert
             for cert in WHOIS.get_registrar_certification_list()
         }
     return self._certifications
예제 #7
0
 def get_groups(self):
     """Return dictionary of registrar groups."""
     if self._groups is None:
         self._groups = {
             group.name: group
             for group in WHOIS.get_registrar_groups()
         }
     return self._groups
예제 #8
0
    def load_registry_object(cls, context, handle):
        """Load domain of the handle and append it into the context."""
        if handle.startswith("."):
            raise WebwhoisError(**cls.message_invalid_handle(handle))

        try:
            idna_handle = idna.encode(handle).decode()
        except idna.IDNAError:
            raise WebwhoisError(
                **cls.message_invalid_handle(handle, "IDNAError"))

        try:
            context[cls._registry_objects_key]["domain"] = {
                "detail": WHOIS.get_domain_by_handle(idna_handle),
                "label": _("Domain"),
            }
        except OBJECT_DELETE_CANDIDATE:
            context['object_delete_candidate'] = True
            # Add fake domain into context for ResolveHandleTypeMixin.
            context[cls._registry_objects_key]['domain'] = None
        except OBJECT_NOT_FOUND as error:
            # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND.
            raise WebwhoisError('OBJECT_NOT_FOUND',
                                **cls.make_message_not_found(handle),
                                handle_is_in_zone=True) from error
        except UNMANAGED_ZONE as error:
            context["managed_zone_list"] = deprecated_context(
                _get_managed_zones(),
                "Context variable 'managed_zone_list' is deprecated. Use 'managed_zones' context processor instead."
            )
            message = cls.message_with_handle_in_html(
                _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:"
                  ), handle)
            raise WebwhoisError('UNMANAGED_ZONE',
                                title=_("Unmanaged zone"),
                                message=message,
                                unmanaged_zone=True) from error
        except INVALID_LABEL:
            # Pattern for the handle is more vague than the pattern of domain name format.
            raise WebwhoisError(
                **cls.message_invalid_handle(handle, "INVALID_LABEL"))
        except TOO_MANY_LABELS as error:
            # Caution! Domain name can have more than one fullstop character and it is still valid.
            # for example: '0.2.4.e164.arpa'
            # remove subdomain names: 'www.sub.domain.cz' -> 'domain.cz'
            domain_match = re.search(r"([^.]+\.\w+)\.?$", handle,
                                     re.IGNORECASE)
            assert domain_match is not None
            context["example_domain_name"] = domain_match.group(1)
            raise WebwhoisError(
                'TOO_MANY_LABELS',
                title=_("Incorrect input"),
                # Templates in webwhois <=1.20 didn't expect message to be `None`.
                message='',
                too_many_parts_in_domain_name=True) from error
예제 #9
0
    def get_domain_registered(self, handle: str) -> Optional[datetime]:
        """Return domain registration datetime."""
        try:
            idna_handle = idna.encode(handle).decode()
        except idna.IDNAError:
            return None

        try:
            domain = WHOIS.get_domain_by_handle(idna_handle)
        except CORBA.Exception:
            return None
        return cast(datetime, domain.registered)
예제 #10
0
 def _get_object(self, handle: str) -> Any:
     try:
         return WHOIS.get_contact_by_handle(handle)
     except OBJECT_NOT_FOUND as error:
         raise WebwhoisError(
             'OBJECT_NOT_FOUND',
             title=_("Contact not found"),
             message=self.message_with_handle_in_html(
                 _("No contact matches %s handle."), handle),
         ) from error
     except INVALID_HANDLE as error:
         raise WebwhoisError(
             **self.message_invalid_handle(handle)) from error
예제 #11
0
    def get_registrars(self):
        """Return a list of registrars to be displayed.

        Results are filtered according to `group_name` attribute.
        """
        registrars = WHOIS.get_registrars()
        if self.group_name:
            groups = self.get_groups()
            if self.group_name not in groups:
                raise Http404('Registrar group {} not found.'.format(
                    self.group_name))
            members = groups[self.group_name].members  # type: Iterable[str]
            registrars = [r for r in registrars if r.handle in members]
        return registrars
예제 #12
0
 def load_related_objects(self, context):
     """Load objects related to the domain and append them into the context."""
     descriptions = self._get_status_descriptions(
         "domain", WHOIS.get_domain_status_descriptions)
     data = context[self._registry_objects_key][
         "domain"]  # detail, type, label, href
     if data is None:
         # Domain is a delete candidate
         return
     registry_object = data["detail"]
     data["status_descriptions"] = [
         descriptions[key] for key in registry_object.statuses
     ]
     if STATUS_DELETE_CANDIDATE in registry_object.statuses:
         return
     data.update({
         "registrant":
         WHOIS.get_contact_by_handle(registry_object.registrant_handle),
         "registrar":
         WHOIS.get_registrar_by_handle(registry_object.registrar_handle),
         "admins": [
             WHOIS.get_contact_by_handle(handle)
             for handle in registry_object.admin_contact_handles
         ],
     })
     if registry_object.nsset_handle:
         data["nsset"] = {
             "detail":
             WHOIS.get_nsset_by_handle(registry_object.nsset_handle)
         }
         NssetDetailMixin.append_nsset_related(data["nsset"])
     if registry_object.keyset_handle:
         data["keyset"] = {
             "detail":
             WHOIS.get_keyset_by_handle(registry_object.keyset_handle)
         }
         KeysetDetailMixin.append_keyset_related(data["keyset"])
예제 #13
0
 def load_registry_object(cls, context, handle):
     """Load nsset of the handle and append it into the context."""
     try:
         context[cls._registry_objects_key]["nsset"] = {
             "detail": WHOIS.get_nsset_by_handle(handle),
             "label": _("Nsset"),
         }
     except OBJECT_NOT_FOUND:
         context["server_exception"] = {
             "title":
             _("Name server set not found"),
             "message":
             cls.message_with_handle_in_html(
                 _("No name server set matches %s handle."), handle),
         }
     except INVALID_HANDLE:
         context["server_exception"] = cls.message_invalid_handle(handle)
예제 #14
0
 def load_registry_object(cls, context, handle):
     """Load keyset of the handle and append it into the context."""
     try:
         context[cls._registry_objects_key]["keyset"] = {
             "detail": WHOIS.get_keyset_by_handle(handle),
             "label": _("Keyset"),
         }
     except OBJECT_NOT_FOUND as error:
         raise WebwhoisError(
             'OBJECT_NOT_FOUND',
             title=_("Key server set not found"),
             message=cls.message_with_handle_in_html(
                 _("No key set matches %s handle."), handle),
         ) from error
     except INVALID_HANDLE as error:
         raise WebwhoisError(
             **cls.message_invalid_handle(handle)) from error
예제 #15
0
    def _get_object(self, handle: str) -> Domain:
        if handle.startswith("."):
            raise WebwhoisError(**self.message_invalid_handle(handle))

        try:
            idna_handle = idna.encode(handle).decode()
        except idna.IDNAError:
            raise WebwhoisError(
                **self.message_invalid_handle(handle, "IDNAError"))

        try:
            return WHOIS.get_domain_by_handle(idna_handle)
        except OBJECT_DELETE_CANDIDATE:
            return Domain(handle, None, (), None, None, None,
                          ['deleteCandidate'], None, None, None, None, None,
                          None, None, None, None)
        except OBJECT_NOT_FOUND as error:
            # Only handle with format of valid domain name and in managed zone raises OBJECT_NOT_FOUND.
            raise WebwhoisError('OBJECT_NOT_FOUND',
                                **self.make_message_not_found(handle),
                                handle_is_in_zone=True) from error
        except UNMANAGED_ZONE as error:
            message = self.message_with_handle_in_html(
                _("Domain %s cannot be found in the registry. You can search for domains in the these zones only:"
                  ), handle)
            raise WebwhoisError('UNMANAGED_ZONE',
                                title=_("Unmanaged zone"),
                                message=message,
                                unmanaged_zone=True) from error
        except INVALID_LABEL as error:
            # Pattern for the handle is more vague than the pattern of domain name format.
            raise WebwhoisError(**self.message_invalid_handle(
                handle, "INVALID_LABEL")) from error
        except TOO_MANY_LABELS as error:
            raise WebwhoisError(
                'TOO_MANY_LABELS',
                title=_("Incorrect input"),
                # Templates in webwhois <=1.20 didn't expect message to be `None`.
                message='',
                too_many_parts_in_domain_name=True) from error
예제 #16
0
    def load_registry_object(cls, context, handle):
        """Load all registry objects of the handle and append it into the context."""
        ContactDetailMixin.load_registry_object(context, handle)
        NssetDetailMixin.load_registry_object(context, handle)
        KeysetDetailMixin.load_registry_object(context, handle)
        RegistrarDetailMixin.load_registry_object(context, handle)
        DomainDetailMixin.load_registry_object(context, handle)

        if not context[cls._registry_objects_key]:
            # No object was found. Create a virtual server exception to render its template.
            # TODO: This solution is hopefully temporary and should be removed very soon.
            context["server_exception"] = {
                "code":
                "OBJECT_NOT_FOUND",
                "title":
                _("Record not found"),
                "message":
                cls.message_with_handle_in_html(
                    _("%s does not match any record."), handle),
                "object_not_found":
                True,
            }
            context["managed_zone_list"] = WHOIS.get_managed_zone_list()
예제 #17
0
 def get(self, request, handle):
     for cert in WHOIS.get_registrar_certification_list():
         # cert: Registry.Whois.RegistrarCertification(registrar_handle='REG-FRED_A', score=2, evaluation_file_id=1L)
         if cert.registrar_handle == handle:
             return self._serve_file(cert.evaluation_file_id)
     raise Http404