Beispiel #1
0
def __create_without_services(abuse_report, filename):
    """
        Create report in Cerberus

        :param `worker.parsing.parser.ParsedEmail` abuse_report: The `worker.parsing.parser.ParsedEmail`
        :param str filename: The filename of the email
        :rtype: `abuse.models.Report`
        :returns: The Cerberus `abuse.models.Report`
    """
    provider = database.get_or_create_provider(abuse_report.provider)
    trusted = True if provider.trusted or abuse_report.trusted else False
    status = 'ToValidate' if trusted else 'New'

    report = Report.objects.create(**{
        'provider': provider,
        'receivedDate': datetime.fromtimestamp(abuse_report.date),
        'subject': abuse_report.subject,
        'body': abuse_report.body,
        'category': database.get_category(abuse_report.category),
        'filename': filename,
        'status': status,
    })

    __add_report_tags(report, abuse_report.recipients)
    autoarchive, _, _ = __get_attributes_based_on_tags(report, abuse_report.recipients)
    database.log_new_report(report)

    # If report is not attached within 30 days -> archived
    if report.status == 'New':
        utils.scheduler.enqueue_in(
            timedelta(days=settings.GENERAL_CONFIG['report_timeout']),
            'report.archive_if_timeout',
            report_id=report.id
        )

    if autoarchive:
        report.status = 'Archived'

    report.save()
    return report
Beispiel #2
0
def __create_contact_tickets(services, campaign_name, ip_address, category, email_subject, email_body, user):

    # Create fake report
    report_subject = 'Campaign %s for ip %s' % (campaign_name, ip_address)
    report_body = 'Campaign: %s\nIP Address: %s\n' % (campaign_name, ip_address)
    filename = hashlib.sha256(report_body.encode('utf-8')).hexdigest()
    __save_email(filename, report_body)

    for data in services:  # For identified (service, defendant, items) tuple

        actions = []

        # Create report
        report = Report.objects.create(**{
            'provider': database.get_or_create_provider('mass_contact'),
            'receivedDate': datetime.now(),
            'subject': report_subject,
            'body': report_body,
            'category': category,
            'filename': filename,
            'status': 'Archived',
            'defendant': database.get_or_create_defendant(data['defendant']),
            'service': database.get_or_create_service(data['service']),
        })
        database.log_new_report(report)

        # Create item
        item_dict = {'itemType': 'IP', 'report_id': report.id, 'rawItem': ip_address}
        item_dict.update(utils.get_reverses_for_item(ip_address, nature='IP'))
        ReportItem.objects.create(**item_dict)

        # Create ticket
        ticket = database.create_ticket(
            report.defendant,
            report.category,
            report.service,
            priority=report.provider.priority,
            attach_new=False,
        )
        database.add_mass_contact_tag(ticket, campaign_name)
        actions.append({'ticket': ticket, 'action': 'create_masscontact', 'campaign_name': campaign_name})
        actions.append({'ticket': ticket, 'action': 'change_treatedby', 'new_value': user.username})
        report.ticket = ticket
        report.save()
        Logger.debug(unicode(
            'ticket %d successfully created for (%s, %s)' % (ticket.id, report.defendant.customerId, report.service.name)
        ))

        # Send email to defendant
        __send_mass_contact_email(ticket, email_subject, email_body)
        actions.append({'ticket': ticket, 'action': 'send_email', 'email': report.defendant.details.email})

        # Close ticket/report
        ticket.resolution = Resolution.objects.get(codename=settings.CODENAMES['fixed_customer'])
        ticket.previousStatus = ticket.status
        ticket.status = 'Closed'
        ticket.save()
        actions.append({
            'ticket': ticket,
            'action': 'change_status',
            'previous_value': ticket.previousStatus,
            'new_value': ticket.status,
            'close_reason': ticket.resolution.codename
        })

        for action in actions:
            database.log_action_on_ticket(**action)