Ejemplo n.º 1
0
class IndicatorActivityForm(forms.Form):
    """
    Django form for adding activity.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    description = forms.CharField(
        widget=forms.TextInput(attrs={'size': '50'}),
        required=False)
    start_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={'class': 'datetimeclass',
                                'size': '25',
                                'id': 'id_activity_start_date'}),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False)
    end_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={'class': 'datetimeclass',
                                'size': '25',
                                'id': 'id_activity_end_date'}),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False)
    date = forms.CharField(
        widget=forms.HiddenInput(attrs={'size': '50',
                                        'readonly': 'readonly',
                                        'id': 'id_activity_date'}))
Ejemplo n.º 2
0
class ActionsForm(forms.Form):
    """
    Django form for adding actions.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    action_type = forms.ChoiceField(widget=forms.Select,
                                    label=ActionConsts.ACTION_TYPE,
                                    required=True)
    begin_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_begin_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        label=ActionConsts.BEGIN_DATE,
        required=False)
    end_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_end_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        label=ActionConsts.END_DATE,
        required=False)
    performed_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_performed_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        label=ActionConsts.PERFORMED_DATE,
        required=False)
    active = forms.ChoiceField(widget=RadioSelect,
                               choices=(('on', 'on'), ('off', 'off')),
                               label=ActionConsts.ACTIVE)
    reason = forms.CharField(widget=forms.TextInput(attrs={'size': '50'}),
                             required=False)
    date = forms.CharField(
        widget=forms.HiddenInput(attrs={
            'size': '50',
            'readonly': 'readonly',
            'id': 'id_action_date'
        }),
        label=ActionConsts.DATE)

    def __init__(self, *args, **kwargs):
        super(ActionsForm, self).__init__(*args, **kwargs)
Ejemplo n.º 3
0
class IndicatorActionsForm(forms.Form):
    """
    Django form for adding actions.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    action_type = forms.ChoiceField(widget=forms.Select, required=True)
    begin_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_begin_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False)
    end_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_end_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False)
    performed_date = forms.DateTimeField(
        widget=CalWidget(format='%Y-%m-%d %H:%M:%S',
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'id_action_performed_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False)
    active = forms.ChoiceField(widget=RadioSelect,
                               choices=(('on', 'on'), ('off', 'off')))
    reason = forms.CharField(widget=forms.TextInput(attrs={'size': '50'}),
                             required=False)
    date = forms.CharField(widget=forms.HiddenInput(
        attrs={
            'size': '50',
            'readonly': 'readonly',
            'id': 'id_action_date'
        }))

    def __init__(self, *args, **kwargs):
        super(IndicatorActionsForm, self).__init__(*args, **kwargs)
        self.fields['action_type'].choices = [
            (c.name, c.name) for c in get_item_names(IndicatorAction, True)
        ]
Ejemplo n.º 4
0
class EventForm(forms.Form):
    """
    Django form for creating a new Event.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    title = forms.CharField(widget=forms.TextInput, required=True)
    event_type = forms.ChoiceField(required=True, widget=forms.Select)
    description = forms.CharField(widget=forms.Textarea(attrs={'cols': '30',
                                                               'rows': '3'}),
                                  required=False)
    occurrence_date = forms.DateTimeField(widget=CalWidget(format=settings.PY_DATETIME_FORMAT,
                                                           attrs={'class':'datetimeclass',
                                                                  'size':'25',
                                                                  'id':'id_occurrence_ip_date'}),
                                          input_formats=settings.PY_FORM_DATETIME_FORMATS)
    source = forms.ChoiceField(required=True, widget=forms.Select(attrs={'class': 'no_clear'}))
    method = forms.CharField(widget=forms.TextInput, required=False)
    reference = forms.CharField(widget=forms.TextInput, required=False)

    def __init__(self, username, *args, **kwargs):
        super(EventForm, self).__init__(*args, **kwargs)
        self.fields['source'].choices = [(c.name,
                                          c.name) for c in get_source_names(True,
                                                                               True,
                                                                               username)]
        self.fields['source'].initial = get_user_organization(username)
        self.fields['event_type'].choices = [(c.name,
                                              c.name) for c in get_item_names(EventType,
                                                                                 True)]

        add_bucketlist_to_form(self)
        add_ticket_to_form(self)
Ejemplo n.º 5
0
class ForgeRelationshipForm(forms.Form):
    """
    Django form for forging relationships between two top-level objects.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    forward_type = forms.CharField(
        required=True,
        label="Source Type",
        widget=forms.TextInput(attrs={'readonly': 'readonly'}))
    forward_value = forms.CharField(
        required=True,
        label="Source ID",
        widget=forms.TextInput(attrs={'readonly': 'readonly'}))
    forward_relationship = forms.ChoiceField(
        required=True,
        widget=forms.Select(attrs={'class': 'relationship-types'}),
        label="Relationship")
    reverse_type = forms.ChoiceField(required=True,
                                     widget=forms.Select,
                                     label="Dest Type")
    dest_id = forms.CharField(required=True, label="Dest ID")
    relationship_date = forms.DateTimeField(
        widget=CalWidget(format=settings.PY_DATETIME_FORMAT,
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False,
        label="Relationship Date")

    def __init__(self, *args, **kwargs):
        super(ForgeRelationshipForm, self).__init__(*args, **kwargs)
        self.fields['forward_type'].choices = self.fields[
            'reverse_type'].choices = [
                (c, c) for c in sorted(settings.CRITS_TYPES.iterkeys())
            ]
        self.fields['forward_relationship'].choices = [
            (c, c) for c in get_relationship_types(True)
        ]

    def clean(self):
        cleaned_data = super(ForgeRelationshipForm, self).clean()

        if 'forward_value' in cleaned_data:
            try:
                cleaned_data['forward_value'] = cleaned_data[
                    'forward_value'].strip()
            except:
                pass

        if 'dest_id' in cleaned_data:
            try:
                cleaned_data['dest_id'] = cleaned_data['dest_id'].strip()
            except:
                pass

        return cleaned_data
Ejemplo n.º 6
0
class JumpToDateForm(forms.Form):
    """
    Django form for finding comments on a specific date.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    date = forms.DateTimeField(widget=CalWidget(
        format=settings.PY_DATETIME_FORMAT,
        attrs={
            'class': 'datetimeclass',
            'size': '25',
            'id': 'id_comment_jump_to_date'
        }),
                               input_formats=settings.PY_FORM_DATETIME_FORMATS)
Ejemplo n.º 7
0
class EventForm(SourceInForm):
    """
    Django form for creating a new Event.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    title = forms.CharField(widget=forms.TextInput, required=True)
    event_type = forms.ChoiceField(required=True, widget=forms.Select)
    description = forms.CharField(widget=forms.Textarea(attrs={'cols': '30',
                                                               'rows': '3'}),
                                  required=False)
    occurrence_date = forms.DateTimeField(
        widget=CalWidget(format=settings.PY_DATETIME_FORMAT,
                         attrs={'class':'datetimeclass',
                                'size':'25',
                                'id':'id_occurrence_date'}),
        input_formats=settings.PY_FORM_DATETIME_FORMATS)
    campaign = forms.ChoiceField(widget=forms.Select, required=False)
    campaign_confidence = forms.ChoiceField(widget=forms.Select, required=False)
    related_id = forms.CharField(widget=forms.HiddenInput(), required=False, label=form_consts.Common.RELATED_ID)
    related_type = forms.CharField(widget=forms.HiddenInput(), required=False, label=form_consts.Common.RELATED_TYPE)
    relationship_type = forms.ChoiceField(required=False,
                                          label=form_consts.Common.RELATIONSHIP_TYPE,
                                          widget=forms.Select(attrs={'id':'relationship_type'}))

    def __init__(self, username, *args, **kwargs):
        super(EventForm, self).__init__(username, *args, **kwargs)

        self.fields['event_type'].choices = [
            (c,c) for c in EventTypes.values(sort=True)
        ]
        self.fields['relationship_type'].choices = relationship_choices
        self.fields['relationship_type'].initial = RelationshipTypes.RELATED_TO
        self.fields['campaign'].choices = [("", "")]
        if username.has_access_to(Common.CAMPAIGN_READ):
            self.fields['campaign'].choices = [('', '')] + [
                (c.name, c.name) for c in get_item_names(Campaign, True)]
        self.fields['campaign_confidence'].choices = [
            ("", ""),
            ("low", "low"),
            ("medium", "medium"),
            ("high", "high")]

        add_bucketlist_to_form(self)
        add_ticket_to_form(self)
Ejemplo n.º 8
0
class AddDomainForm(forms.Form):
    """
    Django form for adding a domain.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    domain = forms.CharField(label=form_consts.Domain.DOMAIN_NAME)
    campaign = forms.ChoiceField(widget=forms.Select,
                                 required=False,
                                 label=form_consts.Domain.CAMPAIGN)
    confidence = forms.ChoiceField(
        required=False, label=form_consts.Domain.CAMPAIGN_CONFIDENCE)
    domain_source = forms.ChoiceField(
        required=True,
        widget=forms.Select(attrs={'class': 'bulknoinitial'}),
        label=form_consts.Domain.DOMAIN_SOURCE)
    domain_method = forms.CharField(required=False,
                                    widget=forms.TextInput,
                                    label=form_consts.Domain.DOMAIN_METHOD)
    domain_reference = forms.CharField(
        widget=forms.TextInput(attrs={'size': '90'}),
        required=False,
        label=form_consts.Domain.DOMAIN_REFERENCE)
    add_ip = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'bulkskip'}),
        label=form_consts.Domain.ADD_IP_ADDRESS)
    ip = forms.GenericIPAddressField(
        required=False,
        label=form_consts.Domain.IP_ADDRESS,
        widget=forms.TextInput(attrs={'class': 'togglewithip bulkrequired'}))
    created = forms.DateTimeField(
        widget=CalWidget(format=settings.PY_DATETIME_FORMAT,
                         attrs={
                             'class':
                             'datetimeclass togglewithip bulkrequired',
                             'size': '25',
                             'id': 'id_domain_ip_date'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS,
        required=False,
        label=form_consts.Domain.IP_DATE)
    same_source = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'togglewithip bulkskip'}),
        label=form_consts.Domain.SAME_SOURCE)
    ip_source = forms.ChoiceField(
        required=False,
        widget=forms.Select(attrs={
            'class':
            'togglewithipsource togglewithip bulkrequired bulknoinitial'
        }),
        label=form_consts.Domain.IP_SOURCE)
    ip_method = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={'class': 'togglewithipsource togglewithip'}),
        label=form_consts.Domain.IP_METHOD)
    ip_reference = forms.CharField(
        widget=forms.TextInput(attrs={
            'size': '90',
            'class': 'togglewithipsource togglewithip'
        }),
        required=False,
        label=form_consts.Domain.IP_REFERENCE)
    add_indicators = forms.BooleanField(
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'bulkskip'}),
        label=form_consts.Domain.ADD_INDICATOR)

    def __init__(self, username, *args, **kwargs):
        super(AddDomainForm, self).__init__(*args, **kwargs)
        self.fields['domain_source'].choices = self.fields[
            'ip_source'].choices = [
                (c.name, c.name)
                for c in get_source_names(True, True, username)
            ]
        self.fields['domain_source'].initial = get_user_organization(username)
        self.fields['ip_source'].initial = get_user_organization(username)
        self.fields['campaign'].choices = [('', '')] + [
            (c.name, c.name) for c in get_item_names(Campaign, True)
        ]
        self.fields['confidence'].choices = [('', ''), ('low', 'low'),
                                             ('medium', 'medium'),
                                             ('high', 'high')]

        add_bucketlist_to_form(self)
        add_ticket_to_form(self)

    def clean(self):
        cleaned_data = super(AddDomainForm, self).clean()
        add_ip = cleaned_data.get('add_ip')
        ip = cleaned_data.get('ip')
        date = cleaned_data.get('created')
        same_source = cleaned_data.get('same_source')
        ip_source = cleaned_data.get('ip_source')

        campaign = cleaned_data.get('campaign')

        if campaign:
            confidence = cleaned_data.get('confidence')

            if not confidence or confidence == '':
                self._errors.setdefault('confidence', ErrorList())
                self._errors['confidence'].append(
                    u'This field is required if campaign is specified.')

        if add_ip:
            if not ip:
                self._errors.setdefault('ip', ErrorList())
                self._errors['ip'].append(u'This field is required.')
            if not date:
                self._errors.setdefault('created', ErrorList())
                self._errors['created'].append(
                    u"This field is required.")  #add error to created field
            if not (same_source or ip_source):
                self._errors.setdefault('same_source', ErrorList())
                self._errors['same_source'].append(
                    u"This field is required.")  #add error to IP source field
            if not same_source and not ip_source:
                self._errors.setdefault('ip_source', ErrorList())
                self._errors['ip_source'].append(
                    u"This field is required.")  #add error to IP source field
        return cleaned_data
Ejemplo n.º 9
0
class EmailAttachForm(forms.Form):
    """
    Django form for uploading attachments as Samples.
    """

    error_css_class = 'error'
    required_css_class = 'required'
    upload_type = forms.ChoiceField(
        choices=[('File Upload', 'File Upload'),
                 ('Metadata Upload', 'Metadata Upload')],
        widget=forms.RadioSelect(attrs={'class': 'toggle_upload_type'}))
    filedata = forms.FileField(required=False)
    filedata.widget.attrs = ({'class': 'id_upload_type_0'})

    filename = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'id_upload_type_1'}),
        required=False)
    md5 = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'id_upload_type_1'}),
        required=False,
        label="MD5")
    file_format = forms.ChoiceField(
        widget=RadioSelect(attrs={'class': 'id_upload_type_0'}),
        choices=[("zip", "Zip"), ("rar", "RAR"), ("raw", "raw")],
        initial="zip",
        required=False)
    password = forms.CharField(
        widget=forms.TextInput(attrs={'class': 'id_upload_type_0'}),
        required=False)
    campaign = forms.ChoiceField(widget=forms.Select,
                                 required=False,
                                 label=form_consts.Sample.CAMPAIGN)
    confidence = forms.ChoiceField(
        widget=forms.Select,
        required=False,
        label=form_consts.Sample.CAMPAIGN_CONFIDENCE)
    source = forms.ChoiceField(widget=forms.Select(
        attrs={'class': 'no_clear'}))
    source_method = forms.CharField(
        widget=forms.TextInput(attrs={'size': '90'}), required=False)
    source_reference = forms.CharField(
        widget=forms.TextInput(attrs={'size': '90'}), required=False)
    source_date = forms.DateTimeField(
        required=False,
        widget=CalWidget(format=settings.PY_DATETIME_FORMAT,
                         attrs={
                             'class': 'datetimeclass',
                             'size': '25',
                             'id': 'email_attach_source_id'
                         }),
        input_formats=settings.PY_FORM_DATETIME_FORMATS)

    def __init__(self, username, *args, **kwargs):
        super(EmailAttachForm, self).__init__(*args, **kwargs)
        self.fields['campaign'].choices = [('', '')] + [
            (c.name, c.name) for c in get_item_names(Campaign, True)
        ]
        self.fields['confidence'].choices = [('', ''), ('low', 'low'),
                                             ('medium', 'medium'),
                                             ('high', 'high')]
        self.fields['source'].choices = [
            (c.name, c.name) for c in get_source_names(True, True, username)
        ]
        self.fields['source'].initial = get_user_organization(username)
        self.fields['source_date'].value = datetime.now()

        add_bucketlist_to_form(self)
        add_ticket_to_form(self)

    def clean(self):
        from django.forms.util import ErrorList
        cleaned_data = super(EmailAttachForm, self).clean()
        upload_type = cleaned_data.get('upload_type')
        if 'filedata' in self.files:
            filedata = True
        else:
            filedata = False

        campaign = cleaned_data.get('campaign')

        if campaign:
            confidence = cleaned_data.get('confidence')

            if not confidence or confidence == '':
                self._errors.setdefault('confidence', ErrorList())
                self._errors['confidence'].append(
                    u'This field is required if campaign is specified.')

        # This duplicates a lot of sample's form, can these likely could be merged
        if upload_type == "Metadata Upload":
            md5 = cleaned_data.get('md5')
            filename = cleaned_data.get('filename')
            if not md5:
                self._errors.setdefault('md5', ErrorList())
                self._errors['md5'].append(u'This field is required.')
            if not filename:
                self._errors.setdefault('filename', ErrorList())
                self._errors['filename'].append(u'This field is required.')
        elif upload_type == "File Upload":
            upload_type = cleaned_data.get('upload_type')
            file_format = cleaned_data.get('file_format')
            if not upload_type:
                self._errors.setdefault('upload_type', ErrorList())
                self._errors['upload_type'].append(u'This field is required.')
            if not filedata:
                self._errors.setdefault('filedata', ErrorList())
                self._errors['filedata'].append(u'This field is required.')
            if not file_format:
                self._errors.setdefault('file_format', ErrorList())
                self._errors['file_format'].append(u'This field is required.')
        return cleaned_data