コード例 #1
0
ファイル: forms.py プロジェクト: sandroden/baruwa
    def clean_from_address(self):
        from_address = self.cleaned_data['from_address']
        from_address = from_address.strip()

        if (not email_re.match(from_address) and not DOM_RE.match(from_address)
                and not IPV4_RE.match(from_address) and not
                IPV4_NET_OR_RANGE_RE.match(from_address)):
            raise forms.ValidationError(_("Provide either a valid IPv4, email,"
            " Domain address, or IPv4 network or range"))
        return from_address
コード例 #2
0
ファイル: forms.py プロジェクト: ajendoubi/baruwa
    def clean_from_address(self):
        from_address = self.cleaned_data['from_address']
        from_address = from_address.strip()

        if (not email_re.match(from_address) and not DOM_RE.match(from_address)
                and not IPV4_RE.match(from_address) and not
                IPV4_NET_OR_RANGE_RE.match(from_address) and not
                ipaddr_is_valid(from_address)):
            raise forms.ValidationError(_("Provide either a valid IPv4/IPv6, email,"
            " Domain address, or IPv4/IPv6 network or range"))
        return from_address
コード例 #3
0
ファイル: forms.py プロジェクト: heartshare/baruwa
    def clean_to_address(self):
        """clean_to_address"""
        to_address = self.cleaned_data['to_address']
        try:
            to_address = to_address.strip()
        except AttributeError:
            pass
        if not self.request.user.is_superuser:
            addresses = self.request.session['user_filter']['addresses']
            if to_address not in addresses:
                raise forms.ValidationError(
                _("The address: %(addr)s does not belong to you.")
                % {'addr': force_escape(to_address)})

        if to_address != "" and not to_address is None:
            if not DOM_RE.match(to_address):
                raise forms.ValidationError(_("Provide either a valid domain"))
        else:
            to_address = 'any'

        return to_address
コード例 #4
0
ファイル: forms.py プロジェクト: ajendoubi/baruwa
    def clean_to_address(self):
        """clean_to_address"""
        to_address = self.cleaned_data['to_address']
        try:
            to_address = to_address.strip()
        except AttributeError:
            pass
        if not self.request.user.is_superuser:
            addresses = self.request.session['user_filter']['addresses']
            if to_address not in addresses:
                raise forms.ValidationError(
                _("The address: %(addr)s does not belong to you.")
                % {'addr': force_escape(to_address)})

        if to_address != "" and not to_address is None:
            if not DOM_RE.match(to_address):
                raise forms.ValidationError(_("Provide either a valid domain"))
        else:
            to_address = 'any'

        return to_address
コード例 #5
0
ファイル: forms.py プロジェクト: ajendoubi/baruwa
    def clean(self):
        """clean_address"""
        if self._errors:
            return self.cleaned_data

        cleaned_data = self.cleaned_data
        address = cleaned_data['address']
        user = cleaned_data['user']
        if user.is_superuser:
            error_msg = _('Super users do not use addresses')
            self._errors["address"] = ErrorList([error_msg])
            del cleaned_data['address']
        account = UserProfile.objects.get(user=user)
        if account.account_type == 2:
            if not DOM_RE.match(address):
                error_msg = _('provide a valid domain address')
                self._errors["address"] = ErrorList([error_msg])
                del cleaned_data['address']
        else:
            if not email_re.match(address):
                error_msg = _('provide a valid email address')
                self._errors["address"] = ErrorList([error_msg])
                del cleaned_data['address']
        return cleaned_data
コード例 #6
0
ファイル: forms.py プロジェクト: haugvald/baruwa
    def clean(self):
        """clean_address"""
        if self._errors:
            return self.cleaned_data

        cleaned_data = self.cleaned_data
        address = cleaned_data['address']
        user = cleaned_data['user']
        if user.is_superuser:
            error_msg = _('Super users do not use addresses')
            self._errors["address"] = ErrorList([error_msg])
            del cleaned_data['address']
        account = UserProfile.objects.get(user=user)
        if account.account_type == 2:
            if not DOM_RE.match(address):
                error_msg = _('provide a valid domain address')
                self._errors["address"] = ErrorList([error_msg])
                del cleaned_data['address']
        else:
            if not email_re.match(address):
                error_msg = _('provide a valid email address')
                self._errors["address"] = ErrorList([error_msg])
                del cleaned_data['address']
        return cleaned_data
コード例 #7
0
ファイル: forms.py プロジェクト: paulojc32/baruwa
def validate_host(value):
    if not ipaddr_is_valid(value) and not DOM_RE.match(value):
        raise ValidationError(
        _(u'%s is not a valid hostname or IPv4/IPv6 address') % value)
コード例 #8
0
    def clean(self):
        "validate the form"
        cleaned_data = self.cleaned_data
        submited_field = cleaned_data.get('filtered_field')
        submited_by = int(cleaned_data.get('filtered_by'))
        submited_value = cleaned_data.get('filtered_value')
        if submited_by != 0:
            sbi = (submited_by - 1)
        else:
            sbi = submited_by

        if submited_field in BOOL_FIELDS:
            if not submited_by in BOOL_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _(
                    "%(field)s does not support the %(filt)s filter") % {
                        'field': filter_items[submited_field],
                        'filt': FILTER_BY[sbi][1]
                    }
                raise forms.ValidationError(error_msg)
        if submited_field in NUM_FIELDS:
            if not submited_by in NUM_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _(
                    "%(field)s does not support the %(filt)s filter") % {
                        'field': filter_items[submited_field],
                        'filt': FILTER_BY[sbi][1]
                    }
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError(
                    _("Please supply a value to query"))
            if not isnumeric(submited_value):
                raise forms.ValidationError(_("The value has to be numeric"))
        if submited_field in TEXT_FIELDS:
            if not submited_by in TEXT_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _(
                    "%(field)s does not support the %(filt)s filter") % {
                        'field': filter_items[submited_field],
                        'filt': FILTER_BY[sbi][1]
                    }
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES and submited_by not in [9, 10]:
                raise forms.ValidationError(
                    _("Please supply a value to query"))
            if ((submited_field == 'from_address'
                 or submited_field == 'to_address') and submited_by in [1, 2]):
                if not email_re.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('%(email)s is not a valid e-mail address.') %
                        {'email': force_escape(submited_value)})
            else:
                if submited_by in [7, 8]:
                    try:
                        re.compile(submited_value)
                    except re.error:
                        raise forms.ValidationError(
                            _("Please provide a valid regex"))
            if ((submited_field == 'from_domain'
                 or submited_field == 'to_domain') and submited_by in [1, 2]):
                if not DOM_RE.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('Please provide a valid domain name'))
            else:
                if submited_by in [7, 8]:
                    try:
                        re.compile(submited_value)
                    except re.error:
                        raise forms.ValidationError(
                            _("Please provide a valid regex"))
            if submited_field == 'clientip':
                if not ipv4_re.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('Please provide a valid ipv4 address'))
            if submited_field == 'hostname':
                if ((not ipv4_re.match(submited_value.strip()))
                        and (not DOM_RE.match(submited_value.strip()))):
                    raise forms.ValidationError(
                        _("Please provide a valid hostname or ipv4 address"))
        if submited_field in TIME_FIELDS:
            if not submited_by in TIME_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _(
                    "%(field)s does not support the %(filt)s filter") % {
                        'field': filter_items[submited_field],
                        'filt': FILTER_BY[sbi][1]
                    }
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError(
                    _("Please supply a value to query"))
            if submited_field == 'date':
                try:
                    datetime.date(
                        *time.strptime(submited_value, '%Y-%m-%d')[:3])
                except ValueError:
                    raise forms.ValidationError(
                        _('Please provide a valid date in YYYY-MM-DD format'))
            if submited_field == 'time':
                try:
                    datetime.time(*time.strptime(submited_value, '%H:%M')[3:6])
                except ValueError:
                    raise forms.ValidationError(
                        _('Please provide valid time in HH:MM format'))

        return cleaned_data
コード例 #9
0
ファイル: forms.py プロジェクト: haugvald/baruwa
    def clean(self):
        "validate the form"
        cleaned_data = self.cleaned_data
        submited_field = cleaned_data.get('filtered_field')
        submited_by = int(cleaned_data.get('filtered_by'))
        submited_value = cleaned_data.get('filtered_value')
        if submited_by != 0:
            sbi = (submited_by - 1)
        else:
            sbi = submited_by

        if submited_field in BOOL_FIELDS:
            if not submited_by in BOOL_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _("%(field)s does not support the %(filt)s filter") % {
                'field': filter_items[submited_field], 'filt': FILTER_BY[sbi][1]}
                raise forms.ValidationError(error_msg)
        if submited_field in NUM_FIELDS:
            if not submited_by in NUM_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _("%(field)s does not support the %(filt)s filter") % {
                'field': filter_items[submited_field], 'filt': FILTER_BY[sbi][1]}
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError(_("Please supply a value to query"))
            if not isnumeric(submited_value):
                raise forms.ValidationError(_("The value has to be numeric"))
        if submited_field in TEXT_FIELDS:
            if not submited_by in TEXT_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _("%(field)s does not support the %(filt)s filter") % {
                'field': filter_items[submited_field], 'filt': FILTER_BY[sbi][1]}
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES and submited_by not in [9, 10]:
                raise forms.ValidationError(_("Please supply a value to query"))
            if ((submited_field == 'from_address' or
                submited_field == 'to_address') and
                submited_by in [1, 2]):
                if not email_re.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('%(email)s is not a valid e-mail address.')
                        % {'email': force_escape(submited_value)})
            else:
                if submited_by in [7, 8]:
                    try:
                        re.compile(submited_value)
                    except re.error:
                        raise forms.ValidationError(
                            _("Please provide a valid regex")
                        )
            if ((submited_field == 'from_domain' or
                submited_field == 'to_domain') and
                submited_by in [1, 2]):
                if not DOM_RE.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('Please provide a valid domain name'))
            else:
                if submited_by in [7, 8]:
                    try:
                        re.compile(submited_value)
                    except re.error:
                        raise forms.ValidationError(
                            _("Please provide a valid regex")
                        )
            if submited_field == 'clientip':
                if not ipv4_re.match(submited_value.strip()):
                    raise forms.ValidationError(
                        _('Please provide a valid ipv4 address'))
            if submited_field == 'hostname':
                if ((not ipv4_re.match(submited_value.strip())) and
                (not DOM_RE.match(submited_value.strip()))):
                    raise forms.ValidationError(
                    _("Please provide a valid hostname or ipv4 address")
                    )
        if submited_field in TIME_FIELDS:
            if not submited_by in TIME_FILTER:
                filter_items = dict(FILTER_ITEMS)
                error_msg = _("%(field)s does not support the %(filt)s filter") % {
                'field': filter_items[submited_field], 'filt': FILTER_BY[sbi][1]}
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError(_("Please supply a value to query"))
            if submited_field == 'date':
                try:
                    datetime.date(
                        *time.strptime(submited_value, '%Y-%m-%d')[:3])
                except ValueError:
                    raise forms.ValidationError(
                        _('Please provide a valid date in YYYY-MM-DD format'))
            if submited_field == 'time':
                try:
                    datetime.time(*time.strptime(submited_value, '%H:%M')[3:6])
                except ValueError:
                    raise forms.ValidationError(
                        _('Please provide valid time in HH:MM format'))

        return cleaned_data
コード例 #10
0
def validate_host(value):
    if not ipaddr_is_valid(value) and not DOM_RE.match(value):
        raise ValidationError(
            _(u'%s is not a valid hostname or IPv4/IPv6 address') % value)
コード例 #11
0
ファイル: forms.py プロジェクト: antineutron/baruwa
    def clean(self):
        "validate the form"
        cleaned_data = self.cleaned_data
        submited_field = cleaned_data.get('filtered_field')
        submited_by = int(cleaned_data.get('filtered_by'))
        submited_value = cleaned_data.get('filtered_value')
        if submited_by != 0:
            sbi = (submited_by - 1)
        else:
            sbi = submited_by

        if submited_field in BOOL_FIELDS:
            if not submited_by in BOOL_FILTER:
                filter_items = to_dict(list(FILTER_ITEMS))
                error_msg = "%s does not support the %s filter" % (
                    filter_items[submited_field],FILTER_BY[sbi][1])
                raise forms.ValidationError(error_msg)
        if submited_field in NUM_FIELDS:
            if not submited_by in NUM_FILTER:
                filter_items = to_dict(list(FILTER_ITEMS))
                error_msg = "%s does not support the %s filter" % (
                    filter_items[submited_field],FILTER_BY[sbi][1])
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError("Please supply a value to query")
            if not isnumeric(submited_value):
                raise forms.ValidationError("The value has to be numeric")
        if submited_field in TEXT_FIELDS:
            if not submited_by in TEXT_FILTER:
                filter_items = to_dict(list(FILTER_ITEMS))
                error_msg = "%s does not support the %s filter" % (
                    filter_items[submited_field],FILTER_BY[sbi][1])
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError("Please supply a value to query")
            if ( FILTER_BY[sbi][1] == 'is equal to' or FILTER_BY[sbi][1] == 'is not equal to' ):
                if (submited_field == 'from_address') or (
                    submited_field == 'to_address'):
                    if not email_re.match(submited_value.strip()):
                        raise forms.ValidationError(
                            '%s is not a valid e-mail address.'
                            % force_escape(submited_value))
                if (submited_field == 'from_domain') or (
                    submited_field == 'to_domain'):
                    if not DOM_RE.match(submited_value.strip()):
                        raise forms.ValidationError(
                            'Please provide a valid domain name')
                if submited_field == 'clientip':
                    if not ipv4_re.match(submited_value.strip()):
                        raise forms.ValidationError(
                            'Please provide a valid ipv4 address')
        if submited_field in TIME_FIELDS:
            if not submited_by in TIME_FILTER:
                filter_items = to_dict(list(FILTER_ITEMS))
                error_msg = "%s does not support the %s filter" % (
                    filter_items[submited_field],FILTER_BY[sbi][1])
                raise forms.ValidationError(error_msg)
            if submited_value in EMPTY_VALUES:
                raise forms.ValidationError("Please supply a value to query")
            if submited_field == 'date':
                try:
                    datetime.date(
                        *time.strptime(submited_value, '%Y-%m-%d')[:3])
                except ValueError:
                    raise forms.ValidationError(
                        'Please provide a valid date in YYYY-MM-DD format')
            if submited_field == 'time':
                try:
                    datetime.time(*time.strptime(submited_value, '%H:%M')[3:6])
                except ValueError:
                    raise forms.ValidationError(
                        'Please provide valid time in HH:MM format')

        return cleaned_data