Ejemplo n.º 1
0
 def get_input(field, required):
     "Get user input"
     prompt = "Please enter the %s:" % field
     while 1:
         if field in ['password1', 'password2']:
             value = getpass.getpass(prompt=prompt)
         else:
             value = raw_input(prompt)
         if not required:
             break
         if required and value.strip() != "":
             if not field in ['email', 'password1', 'password2']:
                 break
             if field == 'email':
                 if not ADDRESS_RE.match(value):
                     print "Please provide a valid email address."
                 else:
                     break
             if field == 'password1':
                 try:
                     cracklib.VeryFascistCheck(value)
                 except ValueError, message:
                     print str(message)
                 else:
                     break
             if field == 'password2':
                 if values['password1'] == value:
                     break
                 else:
                     print 'password2 does not match password1'
Ejemplo n.º 2
0
 def get_input(field, required):
     "Get user input"
     prompt = "Please enter the %s:" % field
     while 1:
         if field in ['password1', 'password2']:
             value = getpass.getpass(prompt=prompt)
         else:
             value = raw_input(prompt)
         if not required:
             break
         if required and value.strip() != "":
             if not field in ['email', 'password1', 'password2']:
                 break
             if field == 'email':
                 if not ADDRESS_RE.match(value):
                     print "Please provide a valid email address."
                 else:
                     break
             if field == 'password1':
                 try:
                     cracklib.VeryFascistCheck(value)
                 except ValueError, message:
                     print str(message)
                 else:
                     break
             if field == 'password2':
                 if values['password1'] == value:
                     break
                 else:
                     print 'password2 does not match password1'
Ejemplo n.º 3
0
    def validate_altrecipients(self, field):
        if self.usealt.data and not field.data and self.release.data:
            raise validators.ValidationError(
            _('Provide atleast one alternative recipient'))

        if self.usealt.data and field.data and self.release.data:
            emails = field.data.split(',')
            for email in emails:
                if not ADDRESS_RE.match(email.strip()):
                    raise validators.ValidationError(
                    _('Invalid email address'))
Ejemplo n.º 4
0
def check_form(form, field):
    filteredby = dict(FILTER_BY)
    filteritems = dict(FILTER_ITEMS)
    # field <-> filter checks
    if ((field.data in BOOL_FIELDS and int(form.filtered_by.data)
        not in BOOL_FILTER) or (field.data in TEXT_FIELDS and
        int(form.filtered_by.data) not in TEXT_FILTER) or
        (field.data in TIME_FIELDS and int(form.filtered_by.data)
        not in TIME_FILTER) or (field.data in NUM_FIELDS and
        int(form.filtered_by.data) not in NUM_FILTER)):
        raise validators.ValidationError(
        _('%(field)s does not support the "%(filt)s" filter') %
        dict(field=filteritems[field.data],
        filt=filteredby[form.filtered_by.data]))
    # time
    if ((field.data in TEXT_FIELDS or field.data in TIME_FIELDS
        or field.data in NUM_FIELDS) and form.filtered_value.data in
        EMPTY_VALUES):
        raise validators.ValidationError(_('Please supply a value to query'))
    # numerics
    if field.data in NUM_FIELDS and not isnumeric(form.filtered_value.data):
        raise validators.ValidationError(_('The value has to be numeric'))
    # emails
    if (field.data in TEXT_FIELDS and int(form.filtered_by.data) in [1, 2]
        and field.data in EMAIL_FIELDS):
        if not ADDRESS_RE.match(form.filtered_value.data):
            raise validators.ValidationError(
            _('%(email)s is not a valid e-mail address.') %
            dict(email=escape(form.filtered_value.data)))
    # domains
    if (field.data in TEXT_FIELDS and int(form.filtered_by.data) in [1, 2]
        and field.data in DOMAIN_FIELDS):
        if not DOM_RE.match(form.filtered_value.data):
            raise validators.ValidationError(
            _('%(dom)s is not a valid domain address.') %
            dict(dom=escape(form.filtered_value.data)))
    # regex on text fields
    if field.data in TEXT_FIELDS and int(form.filtered_by.data) in [7, 8]:
        try:
            re.compile(form.filtered_value.data)
        except re.error:
            raise validators.ValidationError(_('Invalid regex supplied'))
    if field.data in TEXT_FIELDS:
        # ip
        if field.data == 'clientip':
            if not IPV4_RE.match(form.filtered_value.data):
                raise validators.ValidationError(
                _('Please provide a valid ipv4 address'))
        # hostname
        if field.data == 'hostname':
            if (not IPV4_RE.match(form.filtered_value.data) and
                not DOM_RE.match(form.filtered_value.data)):
                raise validators.ValidationError(
                _("Please provide a valid hostname or ipv4 address"))
    if field.data in TIME_FIELDS:
        if field.data == 'date':
            try:
                datetime.date(
                *time.strptime(form.filtered_value.data, '%Y-%m-%d')[:3])
            except ValueError:
                raise validators.ValidationError(
                    _('Please provide a valid date in YYYY-MM-DD format'))
        if field.data == 'time':
            try:
                datetime.time(
                *time.strptime(form.filtered_value.data, '%H:%M')[3:6])
            except ValueError:
                raise validators.ValidationError(
                    _('Please provide valid time in HH:MM format'))
Ejemplo n.º 5
0
def check_form(form, field):
    filteredby = dict(FILTER_BY)
    filteritems = dict(FILTER_ITEMS)
    # field <-> filter checks
    if ((field.data in BOOL_FIELDS and int(form.filtered_by.data)
        not in BOOL_FILTER) or (field.data in TEXT_FIELDS and
        int(form.filtered_by.data) not in TEXT_FILTER) or
        (field.data in TIME_FIELDS and int(form.filtered_by.data)
        not in TIME_FILTER) or (field.data in NUM_FIELDS and
        int(form.filtered_by.data) not in NUM_FILTER)):
        raise validators.ValidationError(
        _('%(field)s does not support the "%(filt)s" filter') %
        dict(field=filteritems[field.data],
        filt=filteredby[form.filtered_by.data]))
    # time
    if ((field.data in TEXT_FIELDS or field.data in TIME_FIELDS
        or field.data in NUM_FIELDS) and form.filtered_value.data in
        EMPTY_VALUES):
        raise validators.ValidationError(_('Please supply a value to query'))
    # numerics
    if field.data in NUM_FIELDS and not isnumeric(form.filtered_value.data):
        raise validators.ValidationError(_('The value has to be numeric'))
    # emails
    if (field.data in TEXT_FIELDS and int(form.filtered_by.data) in [1, 2]
        and field.data in EMAIL_FIELDS):
        if not ADDRESS_RE.match(form.filtered_value.data):
            raise validators.ValidationError(
            _('%(email)s is not a valid e-mail address.') %
            dict(email=escape(form.filtered_value.data)))
    # domains
    if (field.data in TEXT_FIELDS and int(form.filtered_by.data) in [1, 2]
        and field.data in DOMAIN_FIELDS):
        if not DOM_RE.match(form.filtered_value.data):
            raise validators.ValidationError(
            _('%(dom)s is not a valid domain address.') %
            dict(dom=escape(form.filtered_value.data)))
    # regex on text fields
    if field.data in TEXT_FIELDS and int(form.filtered_by.data) in [7, 8]:
        try:
            re.compile(form.filtered_value.data)
        except re.error:
            raise validators.ValidationError(_('Invalid regex supplied'))
    if field.data in TEXT_FIELDS:
        # ip
        if field.data == 'clientip':
            if not IPV4_RE.match(form.filtered_value.data):
                raise validators.ValidationError(
                _('Please provide a valid ipv4 address'))
        # hostname
        if field.data == 'hostname':
            if (not IPV4_RE.match(form.filtered_value.data) and
                not DOM_RE.match(form.filtered_value.data)):
                raise validators.ValidationError(
                _("Please provide a valid hostname or ipv4 address"))
    if field.data in TIME_FIELDS:
        if field.data == 'date':
            try:
                datetime.date(
                *time.strptime(form.filtered_value.data, '%Y-%m-%d')[:3])
            except ValueError:
                raise validators.ValidationError(
                    _('Please provide a valid date in YYYY-MM-DD format'))
        if field.data == 'time':
            try:
                datetime.time(
                *time.strptime(form.filtered_value.data, '%H:%M')[3:6])
            except ValueError:
                raise validators.ValidationError(
                    _('Please provide valid time in HH:MM format'))