Beispiel #1
0
    def get_service_site_params(service, force_makecache=False):
        start_time = time.time()
        if force_makecache:
            analyser_cron.create_service_cache(service, force=True)
        site_params = cache.get(service.derive_service_cache_path())
        if site_params is None:
            return None

        # All identities of the service
        identities = Identity.objects.filter(service=service)
        emails = Mail.objects.filter(
            identity__in=identities, identity__approved=True
        ).distinct()
        service_3p_conns = ServiceThirdPartyEmbeds.objects.filter(service=service)
        third_party_conns_setting_cookies = service_3p_conns.filter(sets_cookie=True)
        third_parties = service.thirdparties.distinct()


        site_params["service"] = service
        # site_params["num_different_idents"] = identities.count()
        site_params["num_different_idents"] = identities.filter(approved=True).count()
        site_params["count_mails"] = emails.count()
        # site_params['unconfirmed_idents'] = identities.filter(approved=False)
        site_params["sets_cookies"] = third_party_conns_setting_cookies.exists()
        site_params["num_different_thirdparties"] = third_parties.count()
        site_params["leaks_address"] = service_3p_conns.filter(
            leaks_address=True
        ).exists()

        end_time = time.time()
        print("Get service_site_params took: {}s".format(end_time - start_time))
        return site_params
Beispiel #2
0
 def handle(self, *args, **kwargs):
     print("Services")
     t = time.time()
     service1 = Service.objects.filter(id=1)[0]
     #print(service1.mails_not_cached().count()
     create_service_cache(service1, force=True)
     t2 = time.time()
     print(t2 - t)
     print('Done')
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        try:
            url = request.POST["url"]
            url = validate_domain(url)

            # Get or create the service matching this domain
            service, created = Service.get_or_create(url=url, name=url)
            service.save()

            # Select a domain to use for the identity
            # Create a list of possible domains
            domains = [cred["DOMAIN"] for cred in settings.MAILCREDENTIALS]
            # Shuffle it
            shuffle(domains)
            # Iterate through it
            for identityDomain in domains:
                # If the domain has not yet been used, stop the loop, otherwise try the next
                if (Identity.objects.filter(service_id=service.pk).filter(
                        mail__contains=identityDomain).count() == 0):
                    break
            # At this point, we have either selected a domain that has not yet been used for the
            # provided service, or the service already has at least one identity for each domain,
            # in which case we have picked one domain at random (by shuffling the list first).

            # Create an identity and save it
            ident = Identity.create(service, identityDomain)
            ident.save()

            if created:
                create_service_cache(service, force=True)

            # Return the created identity
            r = JsonResponse({
                "site": url,
                "email": ident.mail,
                "first": ident.first_name,
                "last": ident.surname,
                "gender": "Male" if ident.gender else "Female",
            })
        except KeyError:
            logger.warning(
                "BookmarkletApiView.post: Malformed request received, missing url.",
                extra={"request": request},
            )
            r = JsonResponse({"error": "No URL passed"})
        except AssertionError:
            # Invalid URL passed
            logger.warning(
                "BookmarkletApiView.post: Malformed request received, malformed URL.",
                extra={"request": request},
            )
            r = JsonResponse({"error": "Invalid URL passed."})
        r["Access-Control-Allow-Origin"] = "*"
        return r
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        try:
            domain = request.POST['domain']
            # Format domain. Will also ensure that the domain is valid, and return None on invalid domains
            domain = validate_domain(domain)
        except KeyError:
            # Someone is messing with us. Log this.
            logger.warning(
                'IdentityView.post: Malformed POST request received',
                extra={'request': request})
            # Send them back to the homepage with a slap on the wrist
            # TODO: Add code to display a warning on homepage
            return redirect('Home')
        # Check if people are messing with us
        except AssertionError:
            # Someone may be messing with us. Save it, just in case.
            logger.info("IdentityView.post: Invalid URL passed",
                        extra={
                            'request': request,
                            'domain': domain
                        })
            # Send them back to the homepage with a slap on the wrist
            # TODO: Add code to display a warning on homepage
            return redirect('Home')

        # Get or create service
        service, created = Service.get_or_create(url=domain, name=domain)
        service.save()

        # Select a domain to use for the identity
        # Create a list of possible domains
        domains = [cred["DOMAIN"] for cred in settings.MAILCREDENTIALS]
        # Shuffle it
        shuffle(domains)
        # Iterate through it
        for identityDomain in domains:
            # If the domain has not yet been used, stop the loop, otherwise try the next
            if Identity.objects.filter(service_id=service.pk).filter(
                    mail__contains=identityDomain).count() == 0:
                break
        # At this point, we have either selected a domain that has not yet been used for the
        # provided service, or the service already has at least one identity for each domain,
        # in which case we have picked one domain at random (by shuffling the list first).

        # Create an identity and save it
        ident = Identity.create(service, identityDomain)
        ident.save()

        if created:
            create_service_cache(service, force=True)

        # Display the result to the user
        return render(request, 'identity/identity.html', {'ident': ident})
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        try:
            # Get service from database
            body_unicode = request.body.decode("utf-8")
            body = json.loads(body_unicode)
            domain = body["domain"]
        except KeyError:
            # No service kwarg is set, warn
            logger.warn(
                "ServiceMetaView.post: Malformed POST request received",
                extra={"request": request},
            )
            # TODO: Add code to display a warning on homepage
            return JsonResponse(convertForJsonResponse({"success": False}))
        try:
            # Format domain. Will also ensure that the domain is valid, and return None on invalid domains
            domain = validate_domain(domain)
        except KeyError:
            # Someone is messing with us. Log this.
            logger.warning(
                "IdentityView.post: Malformed POST request received",
                extra={"request": request},
            )
            # Send them back to the homepage with a slap on the wrist
            # TODO: Add code to display a warning on homepage
            return JsonResponse(convertForJsonResponse({"success": False}))
        # Check if people are messing with us
        except AssertionError:
            # Someone may be messing with us. Save it, just in case.
            logger.info(
                "IdentityView.post: Invalid URL passed",
                extra={"request": request, "domain": domain},
            )
            # Send them back to the homepage with a slap on the wrist
            # TODO: Add code to display a warning on homepage
            return JsonResponse(convertForJsonResponse({"success": False}))

        # Get or create service
        service, created = Service.get_or_create(url=domain, name=domain)
        service.save()

        # Select a domain to use for the identity
        # Create a list of possible domains
        domains = [cred["DOMAIN"] for cred in settings.MAILCREDENTIALS]
        # Shuffle it
        shuffle(domains)
        # Iterate through it
        for identityDomain in domains:
            # If the domain has not yet been used, stop the loop, otherwise try the next
            if (
                Identity.objects.filter(service_id=service.pk)
                .filter(mail__contains=identityDomain)
                .count()
                == 0
            ):
                break
        # At this point, we have either selected a domain that has not yet been used for the
        # provided service, or the service already has at least one identity for each domain,
        # in which case we have picked one domain at random (by shuffling the list first).

        # Create an identity and save it
        ident = Identity.create(service, identityDomain)
        ident.save()

        if created:
            create_service_cache(service, force=True)

        # Display the result to the user
        return JsonResponse(convertForJsonResponse(ident))