Esempio n. 1
0
File: plan.py Progetto: jdh6660/fuzz
    def __get_potential_page_links(self, page):
        # Find all the pages href links
        html = BeautifulSoup(page.text, 'html5lib')
        for tag in html.find_all('a'):
            link = tag.get('href').__str__()

            element = None

            # If link appears to be a valid url
            if validators.url(link):
                # Categorize local and external links
                if link.startswith(self.site.base_url):
                    element = PotentialUrlLinkElement(link)
                else:
                    element = ExternalUrlLinkElement(link)

            # Find email address
            elif "mailto:" in link:
                potential_email = re.sub('mailto:', '', link)
                if validators.email(potential_email):
                    element = EmailAddressElement(potential_email)
            elif validators.email(link):
                element = EmailAddressElement(link)

            # Link didn't match anything valid
            else:
                element = MalformedLinkElement(link)

            # Add new link element to list if it does not already exist
            if not self.discovered_links.contains(element) and element is not None:
                self.discovered_links.add_element(element)

            # Will attempt to create valid links with invalid fragments
            self.__build_in_malformed()
Esempio n. 2
0
    def __get_potential_page_links(self, page):
        # Find all the pages href links
        html = BeautifulSoup(page.text, 'html5lib')
        for tag in html.find_all('a'):
            link = tag.get('href').__str__()

            element = None

            # If link appears to be a valid url
            if validators.url(link):
                # Categorize local and external links
                if link.startswith(self.site.base_url):
                    element = PotentialUrlLinkElement(link)
                else:
                    element = ExternalUrlLinkElement(link)

            # Find email address
            elif "mailto:" in link:
                potential_email = re.sub('mailto:', '', link)
                if validators.email(potential_email):
                    element = EmailAddressElement(potential_email)
            elif validators.email(link):
                element = EmailAddressElement(link)

            # Link didn't match anything valid
            else:
                element = MalformedLinkElement(link)

            # Add new link element to list if it does not already exist
            if not self.discovered_links.contains(
                    element) and element is not None:
                self.discovered_links.add_element(element)

            # Will attempt to create valid links with invalid fragments
            self.__build_in_malformed()
Esempio n. 3
0
    def validate(cls, resource):
        temp_username = f"{resource}@thethe.com"

        try:
            if validators.ipv4(resource):
                return ResourceType.IPv4

            elif validators.domain(resource):
                return ResourceType.DOMAIN

            elif validators.url(resource):
                return ResourceType.URL

            elif validators.email(resource):
                return ResourceType.EMAIL

            elif (HashType.hash_detection(resource) in HashType and
                  not HashType.hash_detection(resource) == HashType.UNKNOWN):
                return ResourceType.HASH

            # EYES HERE! We check a username as a contrived email
            # See temp_username
            elif validators.email(temp_username):
                return ResourceType.USERNAME

            print(
                "[!] No resource type has found for your resource: {resource}")
            return ResourceType.UNKNOWN

        except Exception as e:
            raise Exception()
Esempio n. 4
0
def createUser():

    # Start interactive Shell!
    while True:
        username = input("Enter User Name: ")
        if validators.truthy(username):
            break
        else:
            print("Please enter a valid username!")
            continue


    while True:
        email = input("Enter your Email: ")
        if validators.email(email):
            break
        else:
            print("Please enter a valid email!")
            continue

    while True:
        kindlemail = input("Enter your Kindle Email: ")
        if validators.email(kindlemail):
            break
        else:
            print("Please enter a valid Email!")
            continue

    while True:
        sendToKindle = input("Do you want to send Ebooks to this Account? [yes/no] ")
        if sendToKindle == "yes":
            break
        elif sendToKindle == "no":
            break
        else:
            print("Answer with yes or no.")
            continue

    logging.debug([username, email, kindlemail, sendToKindle])

    # switch sendToKindle to 0 or 1
    if sendToKindle == "yes":
        sendToKindle = "1"
    else:
        sendToKindle = "0"

    # Save data now!
    db.connection()
    newuser = User.create(email=email, name=username, sendtokindle=sendToKindle, kindle_mail=kindlemail)

    try:
        newuser.save()
    except IntegrityError as fail:
        db.rollback()
        logging.error(fail)
    finally:
        logging.info("Succesfully added user %s!", username)
    db.close()
Esempio n. 5
0
def read_config(default_conf="config.local.ini", mail=False):
    """ setup configuration

    :param default_conf: filename
    :param type: string

    :param mail: arg flag to mail notification
    :param type: boolean

    :return GITLABSERVER: gitlab server host
    :return type: string

    :return GITLABTOKEN: gitlab private token
    :return type: string

    :return MAILSERVER: mail server host
    :return type: string

    :return MAILPORT: mail server port
    :return type: int

    :return MAILACCOUNT: mail account sender
    :return type: string

    :return MAILPASSWORD: mail password
    :return type: string

    :return DESTINATIONMAIL: mail account destination
    :return type: string
    """
    if not os.path.exists(default_conf):
        LOGGER.error('no local config file founded.')
        sys.exit("Create config.local.ini from config.ini and restart.")
    # load configparser with interpolation to allow dynamic config file
    config = configparser.ConfigParser()
    config._interpolation = configparser.ExtendedInterpolation()
    config.read(default_conf)
    LOGGER.info("Config file loaded %s", default_conf)

    # load gitlab section
    GITLABSERVER = config['GITLAB']['SERVER']
    GITLABTOKEN = config['GITLAB']['TOKEN']

    # load mail section
    if mail == True:
        MAILSERVER = config['MAIL']['SERVER']
        validators.domain(MAILSERVER)
        MAILPORT = config['MAIL']['PORT']
        MAILACCOUNT = config['MAIL']['ACCOUNT']
        validators.email(MAILACCOUNT)
        MAILPASSWORD = config['MAIL']['PASSWORD']
        DESTINATIONMAIL = config['MAIL']['DESTINATION']
        validators.email(DESTINATIONMAIL)
        LOGGER.debug('MAIL - CONFIGURATION LOADED')

        return (GITLABSERVER, GITLABTOKEN, MAILSERVER, MAILPORT, MAILACCOUNT, MAILPASSWORD, DESTINATIONMAIL)
    else:
        return (GITLABSERVER, GITLABTOKEN)
Esempio n. 6
0
def validate_result(current, default, type):
    """
    Validates the data, whether it needs to be url, twitter, linkedin link etc.
    """
    if current is None:
        current = ""
    if default is None:
        default = ""
    if type == "URL" and validators.url(current, require_tld=True) and not validators.url(default, require_tld=True):
        return current
    if type == "EMAIL" and validators.email(current) and not validators.email(default):
        return current
    return default
    def add_email(self, email: str) -> bool:
        """Adds an e-mail address to this objects.

        This method will fail if the email address already exists or
        isn't a valid e-mail address.

        Returns:
            True iff the operation is successful.
        """
        if email is None:
            return False

        if self.emails is None:
            self.emails = []

        email_canonicalized = email.strip().lower()
        if (
            email_canonicalized == ""
            or not validators.email(email)
            or email_canonicalized in map(str.lower, self.emails)
        ):
            return False

        self.emails.append(email)
        return True
Esempio n. 8
0
def actionable_id(identifier_string, return_resolver=True):
    if validators.url(identifier_string
                      ) and "/staff-profiles/" in identifier_string.lower():
        return {
            "url": identifier_string,
            "profile": identifier_string.split("?")[0]
        }

    if validators.email(identifier_string):
        return {"email": identifier_string}

    identifiers = {
        "doi": {
            "pattern": r"10.\d{4,9}\/[\S]+$",
            "resolver": "https://doi.org/"
        },
        "orcid": {
            "pattern": r"\d{4}-\d{4}-\d{4}-\w{4}",
            "resolver": "https://orcid.org/"
        }
    }
    for k, v in identifiers.items():
        search = re.search(v["pattern"], identifier_string)
        if search:
            d_identifier = {k: search.group()}
            if return_resolver and v["resolver"] is not None:
                d_identifier[
                    "url"] = f"{v['resolver']}{search.group().upper()}"

            return d_identifier

    return
Esempio n. 9
0
def main():
    parser = argparse.ArgumentParser(
        description="""
    A tool to catch phishes
    
    Lookup email reputation:
    ------------------------------
    fisherman [email protected]
    """,
        formatter_class=argparse.RawDescriptionHelpFormatter,
        prog="fisherman")

    parser.add_argument("email",
                        type=str,
                        help="Email you want to check the reputation of")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="View detailed results from each service queried")
    args = parser.parse_args()

    if not validators.email(args.email):
        colors.print_pink(
            "Error: {} is not in a valid email address format".format(
                args.email))
        sys.exit()

    banner()

    if args.verbose:
        colors.print_gray("Verbose mode activated")

    emailrep.check_email_rep(args.email, args.verbose)
    apility.check_email_rep(args.email, args.verbose)
Esempio n. 10
0
def configureauth():
    email = None
    password = None
    while email is None:
        em = input('Google Email: ').strip()
        if validators.email(em):
            email = em
        else:
            print(colored('Provided email is invalid.', 'red'))

    while password is None:
        password = getpass('Google Password: '******'en_US', 'America/New York', devicecode)
    try:
        server.login(email, password)
        server.details('com.whatsapp')
        config = {'email': email, 'password': password}
        pickle.dump(config, open(CONFIGFILE, 'wb'))
        print(
            colored(
                'Configuration file created successfully! Try downloading an app now.',
                'green'))
    except Exception as e:
        print(colored(str(e), 'yellow'))
        configureauth()
Esempio n. 11
0
def import_validate_row(key, row, errors):
    # Fix birthday
    birthday = None
    if row['birthday']:
        try:
            birthday = datetime.strptime(row['birthday'], '%Y-%m-%d')
        except ValueError:
            import_report_error(errors, key, {'birthday': ['type']})
    row['birthday'] = birthday
    # Clean iban and bic
    row['iban'] = row['iban'].upper().replace(" ",
                                              "").encode('ascii', 'ignore')
    row['bic'] = row['bic'].upper().replace(" ", "")

    if not validators.email(row['email']):
        import_report_error(errors, key, {'email': ['type']})
    if row['iban'] != current_app.config.get(
            'NO_IBAN_STRING', 'OUTSIDE_SEPA_AREA') and (
                not validators.iban(row['iban']) or len(row['iban']) > 34):
        import_report_error(errors, key, {'iban': ['type']})
    if row['bic'] and not (len(row['bic']) == 8 or len(row['bic']) == 11):
        import_report_error(errors, key, {'bic': ['type']})

    for prop in ['name', 'address', 'city', 'email', 'iban']:
        if not row[prop].strip():
            import_report_error(errors, key, {prop: ['nonblank']})
    return (row, errors)
Esempio n. 12
0
def sign_post():
    email = request.form.get('email')
    name = request.form.get('name')
    password = request.form.get('password')

    valid = validators.email(email)

    if not valid:
        flash('Please provide a valid email')
        return redirect(url_for('auth.signup'))

    user = User.query.filter_by(email=email).first(
    )  # if this returns a user, then the email already exists in db

    if user:
        flash('Email address already exists')
        return redirect(url_for('auth.signup'))

    new_user = User(email=email,
                    name=name,
                    password=generate_password_hash(password, method='sha256'))

    db.session.add(new_user)
    db.session.commit()

    return redirect(url_for('auth.login'))
Esempio n. 13
0
def create_user():
    username=request.json['username']
    email=request.json['email']
    password=request.json['password']
    pw_hash = generate_password_hash(password)

    if len(password)<6:
        return jsonify({'password':['Passwords should be at least 6 charatcers long']}), HTTP_400_BAD_REQUEST

    if len(username)<3:
        return jsonify({'username':['usernames should be at least 3 charatcers long']}),HTTP_400_BAD_REQUEST

    if not validators.email(email):
        return jsonify({'email':['Email is of invalid format']}),HTTP_400_BAD_REQUEST
    
    if not username.isalnum() or " " in username:
        return jsonify({'username':['username should only contain alphanumeric characters,no spaces']}),HTTP_400_BAD_REQUEST

    if User.query.filter_by(email=email).first() is not None:
        return jsonify({'email':['Email is taken']}),HTTP_409_CONFLICT

    if  User.query.filter_by(username=username).first() is not None:
        return jsonify({'username':['username is taken']}),HTTP_409_CONFLICT

    user=User(username=username, email=email,password=pw_hash)
    db.session.add(user)
    db.session.commit()


    return jsonify({'user':{
        'username':username,
        'email':email,
    }}),HTTP_201_CREATED
Esempio n. 14
0
    def __init__(self, schema=None, **kwargs):
        if schema is None:
            schema = TagAnnotationSchema()
        for attr, req, param, default in self.PARAMS:
            if req is True:
                if attr not in kwargs:
                    raise KeyError('{} is a mandatory field'.format(attr))
            setattr(self, attr, kwargs.get(param, default))

        # TACC username or email (lexical check)
        if not tacc.username.validate(self.owner, permissive=True):
            if not validators.email(self.owner):
                raise ValueError(
                    'Owner must be a TACC username or valid email')

        # Tag length (technically redundant with regex validation)
        if len(self.name) >= TAG_NAME_MAX_LEN:
            raise ValueError('Tag name can have a max of {} characters'.format(
                TAG_NAME_MAX_LEN))
        # Validate name with regex
        if not TAG_NAME_REGEX.search(self.name):
            raise ValueError('{} is not a valid tag name'.format(self.name))
        # Max description length (technically redundant with regex validation)
        if len(self.description) > 255:
            raise ValueError(
                'Tag description can have a max of {} characters'.format(
                    TAG_DESC_MAX_LEN))
        # Validate description with regex
        if not TAG_DESC_REGEX.search(self.description):
            raise ValueError('This is not a valid tag description')
Esempio n. 15
0
    async def m_contact(self, data):
        global objects

        antispam(self.getip(), "contact", 20)

        errors = []
        if not validators.email(data['email']):
            errors += ['Email invalid']
        if len(errors) > 0:
            self.send_data({
                "key": "form_contact",
                "success": False,
                "errors": errors
            })
            return None

        antispam(self.getip(), "contact", 5)

        contact = await objects.create(ContactModel,
                                       name=data['name'],
                                       website=data['website'],
                                       email=data['email'],
                                       content=data['content'])

        self.send_data({"key": "form_contact", "success": True})
Esempio n. 16
0
 def connect(self, url, infos):
     try:
         msg = getMessage(self._ctx, g_message, 111, url)
         logMessage(self._ctx, INFO, msg, 'Driver', 'connect()')
         protocols = url.strip().split(':')
         if len(protocols) != 4 or not all(protocols):
             state = getMessage(self._ctx, g_message, 112)
             msg = getMessage(self._ctx, g_message, 1101, url)
             raise getSqlException(state, 1101, msg, self)
         username = protocols[3]
         password = ''
         if not validators.email(username):
             state = getMessage(self._ctx, g_message, 113)
             msg = getMessage(self._ctx, g_message, 1102, username)
             msg += getMessage(self._ctx, g_message, 1103)
             raise getSqlException(state, 1104, msg, self)
         msg = getMessage(self._ctx, g_message, 114, g_host)
         logMessage(self._ctx, INFO, msg, 'Driver', 'connect()')
         self.DataSource.setUser(username, password)
         msg = getMessage(self._ctx, g_message, 118, username)
         logMessage(self._ctx, INFO, msg, 'Driver', 'connect()')
         connection = self.DataSource.getConnection(username, password)
         msg = getMessage(self._ctx, g_message, 119, username)
         logMessage(self._ctx, INFO, msg, 'Driver', 'connect()')
         version = connection.getMetaData().getDriverVersion()
         msg = getMessage(self._ctx, g_message, 120, (version, username))
         logMessage(self._ctx, INFO, msg, 'Driver', 'connect()')
         return connection
     except SQLException as e:
         raise e
     except Exception as e:
         msg = getMessage(self._ctx, g_message, 121,
                          (e, traceback.print_exc()))
         logMessage(self._ctx, SEVERE, msg, 'Driver', 'connect()')
         print(msg)
Esempio n. 17
0
def profile(request):
    vinfo = viewinfo.prepare(request)
    
    user = User.objects.get(
        username=request.user,
        is_active=True
    )
    
    if request.POST.get('email', None) != None:
        email_new = request.POST.get('email').strip()
        if validators.email(email_new):
            user.email = email_new
            user.save()
    
    if request.POST.get('pass1', None) != None and request.POST.get('pass2', None) != None:
        if request.POST.get('pass1') == request.POST.get('pass2'):
            pass_new = request.POST.get('pass1').strip()
            if pass_new != '':
                user.set_password(pass_new)
                user.save()

    context = viewinfo.context(vinfo)    
    localcontext = {
        'user':                 user,
    }
    context.update(localcontext)

    return render(request, 'accounts/profile.html', context)
Esempio n. 18
0
def verify_config(owner, sample_config, config, current_key=None):
    """Verify that config corresponds to sample_config"""
    import validators

    def raise_exception(message):
        raise ValueError('in {} config {}\nsample:   {}\nprovided: {}'.format(owner, message, sorted(sample_config.items()), sorted(config.items())))

    if isinstance(sample_config, list):
        if not len(config):
            raise_exception('empty_list')
        for element in config:
            verify_config(owner=owner, sample_config=sample_config[0], config=element, current_key=current_key)
    elif isinstance(sample_config, dict):
        for sample_key, sample_value in sample_config.items():
            if sample_key not in config:
                raise_exception('key "{}" is not provided'.format(sample_key))
            if config[sample_key] is None:
                raise_exception('Value of "{}" is empty'.format(sample_key))
            verify_config(owner=owner, sample_config=sample_value, config=config[sample_key], current_key=sample_key)
    else:
        # from this point config and sample_config start to be simple values
        if type(sample_config) is str:
            if sample_config.startswith('http') and validators.url(config) is not True:
                raise_exception('Key "{}" do not contain valid url: {}'.format(current_key, config))
            elif sample_config.startswith('email') and not validators.email(config):
                raise_exception('Key "{}" do not contain valid email: {}'.format(current_key, config))
            elif sample_config.startswith('ipv4') and not validators.ipv4(config):
                raise_exception('Key "{}" do not contain valid IPv4: {}'.format(current_key, config))
            elif sample_config.startswith('int'):
                try:
                    int(config)
                except ValueError:
                    raise_exception('Key "{}" do not contain valid int number: {}'.format(current_key, config))
        elif type(sample_config) is bool and type(config) is not bool:
            raise_exception('Key "{}" must be bool: {}'.format(current_key, config))
Esempio n. 19
0
def user_put(user_inst):
    """
    Handles PUT for resource <base>/api/users .
    :return: "{'status': 'Daten wurden geändert'}", 200
    """
    firstname = request.headers.get('firstname', default=None)
    lastname = request.headers.get('lastname', default=None)
    email = request.headers.get('email', default=None)

    if email is not None and not validators.email(email):
        return jsonify({'error': 'email is not valid'}), 400

    if None in [firstname, lastname, email]:
        return jsonify({'error': 'Missing parameter'}), 400

    if "" in [firstname, lastname, email]:
        return jsonify({'error': 'Empty parameter'}), 400

    if re.match("^[a-zA-ZäÄöÖüÜ ,.'-]+$", firstname) is None or re.match(
            "^[a-zA-ZäÄöÖüÜ ,.'-]+$", lastname) is None:
        return jsonify({
            'error':
            'Firstname and/or lastname must contain only alphanumeric characters'
        }), 400

    if firstname is not None:
        user_inst.firstnameUser = firstname
    if lastname is not None:
        user_inst.lastnameUser = lastname
    if email is not None:
        user_inst.emailUser = email

    return jsonify({'status': 'changed'}), 200
Esempio n. 20
0
def validate(keyword, target):
    """
	validation method to reduce malformed querys and unnecessary connection attempts
	:param keyword: used keyword
	:param target: provided target
	:return: true if valid
	"""
    # if keyword in domain_keywords list
    if keyword in StaticAnswers().keys('domain_keywords'):
        # if target is a domain / email return True
        if validators.domain(target) or validators.email(target):
            return True

    # check if keyword is in number_keyword list
    elif keyword in StaticAnswers().keys('number_keywords'):
        # prevent AttributeError if target is NoneType
        if target is not None:
            # if target only consists of digits return True
            return target.isdigit()

    # if keyword is in no_arg_keywords list return True
    elif keyword in StaticAnswers().keys("no_arg_keywords"):
        return True

    # if the target could not be validated until this return False
    return False
Esempio n. 21
0
def process_master(results):
    """Return dictionary containing data returned from the (unofficial) 
    CryberCrime Tracker API."""
    splunk_dict = []

    if results != None:
        provided_iocs = [y for x in results for y in x.values()]
    else:
        provided_iocs = sys.argv[1:]

    for provided_ioc in set(provided_iocs):
        if validators.ipv4(provided_ioc) or validators.domain(provided_ioc):
            threatcrowd_dicts = threatcrowd.process_host(provided_ioc)
        elif validators.email(provided_ioc):
            threatcrowd_dicts = threatcrowd.process_email(provided_ioc)
        else:
            splunk_dict.append({"Invalid": provided_ioc})
            continue

        if len(threatcrowd_dicts) == 0:
            splunk_dict.append({"Invalid": provided_ioc})
            continue

        for threatcrowd_dict in threatcrowd_dicts:
            splunk_dict.append(threatcrowd_dict)

        if len(provided_iocs) > 1:
            sleep(10)

    return splunk_dict
Esempio n. 22
0
 def process_mod(self):
     for email_addr in self.args.newname, self.args.newvalue:
         if email_addr is not None and not validators.email(email_addr):
             print("Invalid email: \"{}\"".format(email_addr))
             sys.exit(1)
     self.process_vars[
         "action_msg_1"] = "Modifying an alias with the attributes:"
     self.process_vars["action_attrs"] = [
         "name", "newname", "fullname", "value", "newvalue", "active",
         "public"
     ]
     if self.args.value is not None:
         self.process_vars[
             "action_msg_1"] = "Modifying an alias value with the attributes:"
         self.process_vars["action_attrs"] = [
             "name", "value", "newvalue", "active"
         ]
     self.process_vars["action_msg_2"] = "Modifying alias... "
     self.process_vars["action_attrs_translations"] = {
         "newname": "New name",
         "fullname": "Full name",
         "newvalue": "New value"
     }
     self.process_vars["action_proc"] = "alias_mod"
     self.process_vars["action_params"] = [
         self.args.name, self.args.newname, self.args.value,
         self.args.newvalue, self.args.fullname, self.args.active,
         self.args.public
     ]
     libemailmgr.BasePlugin.process_action(self)
Esempio n. 23
0
def token_handler(token, auth_data):
    """
    Sets up and returns an Oauth Session that will automatically handle token refreshing
    """
    #validate the url and email
    valid_url = validators.url(auth_data['url'])
    valid_user = validators.email(auth_data['user'])
    if not valid_url:
        raise ValueError('Invalid url: ' + auth_data['url'])
    if not valid_user:
        raise ValueError('Invalid email: ' + auth_data['user'])

    extra = {
        'client_id': auth_data['client_id'],
        'key': auth_data['key'],
        'proxies': auth_data['proxies']
    }

    #attempt to create client session to pass back
    client = OpenlabApplicationClient(client_id=auth_data['client_id'])
    oauth = OAuth2Session(client=client,
                          token=token,
                          auto_refresh_url=auth_data['refresh_url'],
                          auto_refresh_kwargs=extra,
                          token_updater=token_saver)
    oauth.proxies = auth_data['proxies']  # probabily redundant

    return oauth
Esempio n. 24
0
def validate_email(email):
    if User.query.filter_by(email=email).count() > 0:
        # Ensure the email address hasn't already been used
        return errors.email_used()
    elif not validators.email(email):
        # Ensure the email address is valid
        return errors.invalid_email()
Esempio n. 25
0
def user_edit(request, username):
    vinfo = viewinfo.prepare(request)
    if validator_letters_numbers(username):
        user = User.objects.get(username=username)
        if request.POST.get('email', None) != None:
            email_new = request.POST.get('email').strip()

            if validators.email(email_new):
                user.email = email_new
                user.save()

        if request.POST.get('pass1', None) != None and request.POST.get(
                'pass2', None) != None:
            if request.POST.get('pass1') == request.POST.get('pass2'):
                pass_new = request.POST.get('pass1').strip()
                if pass_new != '':
                    user.set_password(pass_new)
                    user.save()
    else:
        return redirect('config:users-list')

    context = viewinfo.context(vinfo)
    localcontext = {
        'user': user,
    }
    context.update(localcontext)

    return render(request, 'config/user_edit.html', context)
Esempio n. 26
0
def register_user(request, user_data):
    _ = request.translate
    user_data.pop("user_password2", None)
    mapped_data = map_to_schema(User, user_data)
    email_valid = validators.email(mapped_data["user_email"])
    if email_valid:
        res = (request.dbsession.query(User).filter(
            User.user_email == mapped_data["user_email"]).first())
        if res is None:
            new_user = User(**mapped_data)
            try:
                request.dbsession.add(new_user)
                request.dbsession.flush()
                return True, ""
            except IntegrityError:
                request.dbsession.rollback()
                log.error("Duplicated user {}".format(mapped_data["user_id"]))
                return False, _("Username is already taken")
            except Exception as e:
                request.dbsession.rollback()
                log.error("Error {} when inserting user {}".format(
                    str(e), mapped_data["user_id"]))
                return False, str(e)
        else:
            log.error("Duplicated user with email {}".format(
                mapped_data["user_email"]))
            return False, _("Email is invalid")
    else:
        log.error("Email {} is not valid".format(mapped_data["user_email"]))
        return False, _("Email is invalid")
Esempio n. 27
0
def configureauth():
    email = None
    password = None
    while email is None:
        em = input("Google Email: ").strip()
        if validators.email(em):
            email = em
        else:
            print(colored("Provided email is invalid.", "red"))

    while password is None:
        password = getpass("Google Password: "******"en_US", "America/New York", devicecode)
    try:
        server.login(email, password)
        server.details("com.whatsapp")
        config = {"email": email, "password": password}
        pickle.dump(config, open(CONFIGFILE, "wb"))
        print(
            colored(
                "Configuration file created successfully! Try downloading an app now.",
                "green"))
    except Exception as e:
        print(colored(str(e), "yellow"))
        configureauth()
Esempio n. 28
0
    def _hyperlink_conversion(self, ignoretext):

        if not self.has_selection:
            self.inline_call('square_brackets', nomove=True, text="Link text")
            return self.inline_call('parentheses', text="http://www.example.com")


        text = self.cursor.selectedText()
        is_email = validators.email(text)
        is_url = validators.url(text)

        if is_url:
            self.inline_call('square_brackets', text=text)
            return self.inline._call('parentheses', text=text)
        elif is_email:
            self.inline_call('square_brackets', text=text)
            return self.inline_call('parentheses', text='mailto:' + text)
        
        url_from_partial = 'http://' + text
        if validators.url(url_from_partial):
            self.inline_call('square_brackets')
            self.inline_call('parentheses', text=url_from_partial)
        else:
            self.inline_call('square_brackets', nomove=True)
            self.inline_call('parentheses', text="http://www.example.com")
Esempio n. 29
0
    def search_managed_devices(self, device):
        if validators.uuid(device):
            return list(
                filter(
                    lambda iter_device: iter_device['userId'] == device or
                    iter_device['id'] == device,
                    self._call_api(
                        "GET", "deviceManagement/managedDevices")["value"]))
        elif validators.email(device):
            param = 'emailAddress'
        else:
            param = 'deviceName'

        value = self._call_api(
            "GET",
            f"deviceManagement/managedDevices?$filter={param} eq '{device}'"
        )["value"]
        if value:
            return value

        device = device.strip().lower()
        return list(
            filter(
                lambda iter_device: iter_device['emailAddress'].lower() ==
                device or iter_device['userPrincipalName'].lower() == device,
                self._call_api("GET",
                               "deviceManagement/managedDevices")["value"]))
Esempio n. 30
0
    def entity_check(self, entity):
        # check if entity is email
        if validators.email(entity):
            return entity

        # check if entity is IP or URL
        return self.url_ip_check(entity)
Esempio n. 31
0
def validate_result(current, default, type):
    """
    Validates the data, whether it needs to be url, twitter, linkedin link etc.
    """
    if current is None:
        current = ""
    if default is None:
        default = ""
    if type == "URL" and validators.url(
            current, require_tld=True) and not validators.url(
                default, require_tld=True):
        return current
    if type == "EMAIL" and validators.email(
            current) and not validators.email(default):
        return current
    return default
Esempio n. 32
0
def get_user_data(user, request):
    email_valid = validators.email(user)
    # Load connected plugins and check if they modify the user authentication
    plugin_result = None
    plugin_result_dict = {}
    for plugin in PluginImplementations(IUserAuthentication):
        plugin_result, plugin_result_dict = plugin.on_authenticate_user(
            request, user, email_valid
        )
        break  # Only one plugging will be called to extend authenticate_user
    if plugin_result is not None:
        if plugin_result:
            # The plugin authenticated the user. Check now that such user exists in {{ cookiecutter.project_name }}.
            internal_user = get_{{ cookiecutter.project_name }}_user_data(request, user, email_valid)
            if internal_user:
                return User(plugin_result_dict)
            else:
                return None
        else:
            return None
    else:
        result = get_{{ cookiecutter.project_name }}_user_data(request, user, email_valid)
        if result:
            result["user_password"] = ""  # Remove the password form the result
            return User(result)
        return None
Esempio n. 33
0
    def lookup_person(self,
                      criteria,
                      unique=True,
                      verifier_operator=None,
                      verifier_criteria=None,
                      attempt_last_name=True):
        if validators.email(criteria):
            q_operator = "email"
        elif re.search(self.orcid_pattern, criteria):
            q_operator = "q"
            verifier_operator = "orcId"
            verifier_criteria = criteria
        else:
            q_operator = "q"
            criteria = f"{criteria.split()[0]} {criteria.split()[-1]}"
            criteria = unidecode.unidecode(criteria)

        if verifier_operator is not None:
            unique = False

        query_url = f"{self.sb_root_url}&{q_operator}={criteria}"

        try:
            if self.authenticated:
                sb_results = self.sb._session.get(query_url).json()
            else:
                sb_results = requests.get(query_url).json()
        except:
            return None

        if len(sb_results["people"]) == 0 and attempt_last_name:
            name_criteria = criteria.split()[-1]
            query_url = f"{self.sb_root_url}&lastName={name_criteria}"
            try:
                if self.authenticated:
                    sb_results = self.sb._session.get(query_url).json()
                else:
                    sb_results = requests.get(query_url).json()
            except:
                return None
        elif len(sb_results["people"]) == 0 and not attempt_last_name:
            return None

        if unique and len(sb_results["people"]) == 1:
            return sb_results["people"][0]

        if not unique and verifier_operator is not None and verifier_criteria is not None:
            return next(
                (i for i in sb_results["people"] if verifier_operator in i
                 and i[verifier_operator] == verifier_criteria), None)

        if unique and len(sb_results["people"]) > 1:
            list_active = [i for i in sb_results["people"] if i["active"]]
            if len(list_active) == 1:
                return list_active[0]

        if not unique and len(sb_results["people"]) > 1:
            return sb_results["people"]

        return None
Esempio n. 34
0
    def validate(self, clean=True):
        if clean:
            self.clean()

        if self.action_name is None or not self.action_name.strip():
            raise ValidationError("Action name cannot be empty")
        if self.smtp_url is None or not self.smtp_url.strip():
            raise ValidationError("URL cannot be empty")
        if not Utility.validate_smtp(self.smtp_url, self.smtp_port):
            raise ValidationError("Invalid SMTP url")
        elif isinstance(email(self.from_email), ValidationFailure):
            raise ValidationError("Invalid From or To email address")
        else:
            for to_email in self.to_email:
                if isinstance(email(to_email), ValidationFailure):
                    raise ValidationError("Invalid From or To email address")
Esempio n. 35
0
def tips_process():
    error = []
    event_name = request.forms.get("event_name")
    if event_name == "":
        error.append("error01")
    category = request.POST.getall("category")
    if len(category) == 0:
        error.append("error02")
    first_day = request.forms.get("first_day")
    try:
        datetime.datetime.strptime(first_day, '%Y-%m-%d')
    except:
        error.append("error03")
    last_day = request.forms.get("last_day")
    try:
        datetime.datetime.strptime(last_day, '%Y-%m-%d')
    except:
        error.append("error04")
    first_time = request.forms.get("first_time")
    try:
        datetime.datetime.strptime(first_time, '%H:%M')
    except:
        error.append("error05")
    last_time = request.forms.get("last_time")
    try:
        datetime.datetime.strptime(last_time, '%H:%M')
    except:
        error.append("error06")
    location = request.forms.get("location")
    if location == "":
        error.append("error07")
    adress = request.forms.get("adress")
    if adress == "":
        error.append("error08")
    organizer = request.forms.get("organizer")
    if organizer == "":
        error.append("error09")
    website = request.forms.get("website")
    if not validators.url(website):
        error.append("error10")
    image = request.files.get("image")
    description = request.forms.get("description")
    if description == "":
        error.append("error12")
    tipster = request.forms.get("tipster")
    if tipster == "":
        error.append("error13")
    tipster_mail = request.forms.get("tipster_mail")
    if not validators.email(tipster_mail):
        error.append("error14")
    
    if len(error) > 0:
        redirect("/tips")
        
    else:    
            query = ("INSERT INTO event (event_name, first_day, last_day, first_time, last_time, location, adress, organizer, website, image, description, tipster, tipster_mail) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
            cur.execute(query, (event_name, first_day, last_day,    first_time, last_time, location, adress, organizer, website, image, description, tipster, tipster_mail))
            db.commit()
            redirect("/tips")
Esempio n. 36
0
def email(email_str):

	if validators.email(email_str):

		return email_str
	else:

	    return False
Esempio n. 37
0
    def remove_special_chars(self, term):
        """
        Removes all illegal characters from the search term. PostgreSQL search
        vector parser notices email addresses hence we need special parsing for
        them.

        :param term: search term to filter
        """
        if self.emails_as_tokens and email(term):
            return term
        else:
            return re.sub(r'[%s]+' % unicode_non_alnum, ' ', term)
Esempio n. 38
0
def filter_term(term):
    """
    Removes all illegal characters from the search term but only if given
    search term is not an email. PostgreSQL search vector parser notices email
    addresses hence we need special parsing for them here also.

    :param term: search term to filter
    """
    if email(term):
        return term
    else:
        return re.sub(r'[%s]+' % unicode_non_alnum, ' ', term)
Esempio n. 39
0
def test_randemail():
    for length in range(0, 6):
        with pytest.raises(ValueError):
            randemail(length)

    def not_so_rand_email(length, char):
        return randemail(length, randomizer=lambda n, *args, **kwargs: char * n)

    assert not_so_rand_email(7, 'a') == '*****@*****.**'
    assert not_so_rand_email(8, 'b') == '*****@*****.**'
    assert not_so_rand_email(9, 'c') == '*****@*****.**'

    # Fuzzy testing for an extra dose of confidence
    for length in range(7, 50):
        email = randemail(length)
        assert len(email) == length
        assert validators.email(email)

    # Get some confidence of randomness
    assert len(set(randemail(50) for _ in range(5))) == 5, \
        'randemail not random (beware non-determinism; try again)'
Esempio n. 40
0
def verify_config(sample_config, config, exception, current_key=None):
    """Verify that config corresponds to sample_config"""
    import validators

    if isinstance(sample_config, list):
        if not len(config):
            exception.message = 'empty list'
            raise exception
        for element in config:
            verify_config(sample_config=sample_config[0], config=element, exception=exception, current_key=current_key)
    elif isinstance(sample_config, dict):
        for sample_key, sample_value in sample_config.iteritems():
            if sample_key not in config:
                exception.message = 'Key "{0}" not in config'.format(sample_key)
                raise exception
            if config[sample_key] is None:
                exception.message = 'Value of "{0}" is empty'.format(sample_key)
                raise exception
            verify_config(sample_config=sample_value, config=config[sample_key], exception=exception, current_key=sample_key)
    else:
        # from this point config and sample_config start to be simple values
        if type(sample_config) is str:
            if sample_config.startswith('http') and validators.url(config) is not True:
                exception.message = 'Key "{0}" do not contain valid url: {1}'.format(current_key, config)
                raise exception
            elif sample_config.startswith('email') and not validators.email(config):
                exception.message = 'Key "{0}" do not contain valid email: {1}'.format(current_key, config)
                raise exception
            elif sample_config.startswith('ipv4') and not validators.ipv4(config):
                exception.message = 'Key "{0}" do not contain valid IPv4: {1}'.format(current_key, config)
                raise exception
            elif sample_config.startswith('int'):
                try:
                    int(config)
                except ValueError:
                    exception.message = 'Key "{0}" do not contain valid int number: {1}'.format(current_key, config)
                    raise exception
        elif type(sample_config) is bool and type(config) is not bool:
            exception.message = 'Key "{0}" must be bool: {1}'.format(current_key, config)
            raise exception
Esempio n. 41
0
def process(data=None, via_api=False):
    """
    Start the generation process when the form is submitted
    :return:
    """
    if not data:
        data = request.form
    email = data.get('email', None)
    data_source = data.get('data-source', None)

    if not email or not data_source or data_source not in VALID_DATA_SOURCES or not validators.email(email):
        return jsonify(status='error', message='invalid data'), 400

    payload = {
        'creator_email': email
    }

    identifier = str(uuid.uuid4())

    if data_source == 'api_endpoint':
        api_endpoint = data.get('api-endpoint', None)
        if not api_endpoint or not validators.url(api_endpoint):
            return jsonify(status='error', message='invalid endpoint url'), 400
        payload['endpoint_url'] = api_endpoint
    elif data_source == 'json_upload':
        if 'json-upload' not in request.files:
            return jsonify(status='error', message='data file is required for the selected source'), 400
        uploaded_file = request.files['json-upload']
        if uploaded_file.filename == '':
            return jsonify(status='error', message='data file is required for the selected source'), 400
        if uploaded_file and allowed_file(uploaded_file.filename, ['zip']):
            filename = secure_filename(identifier)
            file_save_location = os.path.join(app.config['UPLOAD_DIR'], filename)
            uploaded_file.save(file_save_location)
            payload['zip_file'] = file_save_location

    from app.tasks import generate_app_task  # A Local import to avoid circular import
    task = generate_app_task.delay(config=app.config, payload=payload, via_api=via_api, identifier=identifier)
    return jsonify(status='ok', identifier=identifier, started_at=datetime.datetime.now(), task_id=task.id)
Esempio n. 42
0
def app_generate():
    """
    Start the generator via API
    :return:
    """
    json_input = request.get_json(force=True, silent=True)
    if not json_input:
        return jsonify(status='error', message='invalid data'), 400

    if 'email' not in json_input or not validators.email(str(json_input.get('email'))):
        return jsonify(status='error', message='Valid Email is required'), 400

    if 'endpoint' not in json_input or not validators.url(str(json_input.get('endpoint'))):
        return jsonify(status='error', message='Valid endpoint URL is required'), 400

    data = {
        'email': json_input.get('email'),
        'data-source': 'api_endpoint',
        'api-endpoint': json_input.get('endpoint')
    }

    return process(data=data, via_api=True)
Esempio n. 43
0
def post_comment():
  tag = request.headers["Referer"].split("/")[-1]

  if tag == request.form["tag"] and tag == request.form["check"]:
    if not validators.email(request.form["mail"]):
      return render_template("comment.invalid-email.html", email=request.form["mail"])

    site = request.form["site"]
    # if site is not a valid url just leave empty
    if not validators.url(request.form["site"]):
      site = ""

    comment = Comment.create(
        tag=request.form["tag"],
        author=request.form["name"],
        site=site,
        email=request.form["mail"],
        comment=request.form["comment"])

    return redirect("/tag/" + request.form["tag"] + "#comment-" + str(comment.id))

  else:
    return render_template("comment.invalid-captcha.html")
Esempio n. 44
0
def import_validate_row(key, row, errors):
    # Fix birthday
    birthday = None
    if row['birthday']:
        try:
            birthday = datetime.strptime(row['birthday'], "%d-%m-%Y")
        except ValueError:
            import_report_error(errors,key,{'birthday': ['type']})
    row['birthday'] = birthday
    # Clean iban and bic
    row['iban'] = row['iban'].upper().replace(" ", "").encode('ascii', 'ignore')
    row['bic'] = row['bic'].upper().replace(" ", "")

    if not validators.email(row['email']):
        import_report_error(errors,key,{'email': ['type']})
    if not validators.iban(row['iban']) or len(row['iban']) > 34:
        import_report_error(errors,key,{'iban': ['type']})
    if row['bic'] and not ( len(row['bic']) == 8 or len(row['bic']) == 11 ):
        import_report_error(errors,key,{'bic': ['type']})

    for prop in ['name', 'address', 'city', 'email', 'iban']:
        if not row[prop].strip():
            import_report_error(errors,key,{prop: ['nonblank']})
    return (row, errors)
Esempio n. 45
0
def test_returns_failed_validation_on_invalid_email(value):
    assert isinstance(email(value), ValidationFailure)
Esempio n. 46
0
def test_returns_true_on_valid_email(value, whitelist):
    assert email(value, whitelist=whitelist)
def test_valid_maintainer():
    assert python_template.__maintainer__
    assert validators.email(python_template.__maintainer_email__)
def test_valid_author():
    assert python_template.__author__
    assert validators.email(python_template.__author_email__)
Esempio n. 49
0
from validators import email, ValidationFailure
from naval.core import *
from postpone import LazyString as _

__all__ = ['Email', 'Url']

Email = Assert(
    lambda v: not isinstance(email(v, whitelist = ()), ValidationFailure),
    error_message = _("This is not a valid email address.")
)

Email.__doc__ = """
    Email validator.
    This validator uses the email validator from the "validators" library: https://github.com/kvesteri/validators
"""

Url = Do(
    Type(str),
    Length(max=2083),
    # regex stolen from the php Spoon Library: https://github.com/spoon/library/blob/master/spoon/filter/filter.php
    Regex(
        r'(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\xa1-\xff0-9]+-?)*[a-z\xa1-\xff0-9]+)(?:\.(?:[a-z\xa1}-\xff0-9]+-?)*[a-z\xa1-\xff0-9]+)*(?:\.(?:[a-z\xa1-\xff]{2,})))(?::\d{2,5})?(?:/[^\s]*)?'
    ),
    error_message = _("This is not a valid url.")
)
Url.__doc__ = """
    Url validator.
    The regex used is stolen from the php Spoon Library: https://github.com/spoon/library/blob/master/spoon/filter/filter.php    
"""

Esempio n. 50
0
 def _validate_type_email(self, field, value):
     if not validators.email(value):
         self._error(field, errors.ERROR_BAD_TYPE.format('email'))
Esempio n. 51
0
 def validate_email(self, key, email):
     if email and not validators.email(email):
         raise ValueError("'{}' is an invalid email".format(email))
     return email
Esempio n. 52
0
def tips_process():
    error = []
    event_name = request.forms.get("event_name")
    if event_name == "":
        error.append("error01")
    category = request.POST.getall("category")
    if len(category) == 0:
        error.append("error02")
    first_day = request.forms.get("first_day")
    try:
        datetime.datetime.strptime(first_day, '%Y-%m-%d')
    except:
        error.append("error03")
    last_day = request.forms.get("last_day")
    try:
        datetime.datetime.strptime(last_day, '%Y-%m-%d')
    except:
        error.append("error04")
    first_time = request.forms.get("first_time")
    try:
        datetime.datetime.strptime(first_time, '%H:%M')
    except:
        error.append("error05")
    last_time = request.forms.get("last_time")
    try:
        datetime.datetime.strptime(last_time, '%H:%M')
    except:
        error.append("error06")
    location = request.forms.get("location")
    if location == "":
        error.append("error07")
    adress = request.forms.get("adress")
    if adress == "":
        error.append("error08")
    organizer = request.forms.get("organizer")
    if organizer == "":
        error.append("error09")
    website = request.forms.get("website")
    if not validators.url(website):
        error.append("error10")
    image = request.files.get("image")
    file_path = None
    if image:
        name, ext = os.path.splitext(image.filename)
        if ext not in ('.png','.jpg','.jpeg'):
            return 'File extension not allowed.'
        save_path = "static/images/uploaded"
        file_path = "{path}/{file}".format(path=save_path, file=image.filename)
        image.save(file_path)
    else:
        pass
    description = request.forms.get("description")
    if description == "":
        error.append("error12")
    tipster = request.forms.get("tipster")
    if tipster == "":
        error.append("error13")
    tipster_mail = request.forms.get("tipster_mail")
    if not validators.email(tipster_mail):
        error.append("error14")
    status = "new"
    if len(error) > 0:
        return template("tips", error=error, success=False)
        
    else:
        query = ("INSERT INTO event (event_name, first_day, last_day, first_time, last_time, location, adress, organizer, website, image, description, tipster, tipster_mail, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
        cur.execute(query, (event_name, first_day, last_day,    first_time, last_time, location, adress, organizer, website, file_path, description, tipster, tipster_mail, status))
        db.commit()
        new_event_id = cur.lastrowid
        int_category = []
        for i in category:
            i = map(int, i)
            i.append(new_event_id)
            int_category.append(tuple(i))
        query3 = ("INSERT INTO category_event (ID_category, ID_event) VALUES (%s, %s)")
        cur.executemany(query3, int_category)
        db.commit()
        return template("tips", error=error, success=True)
Esempio n. 53
0
 def process(self):
     ret={}
     data=""
     pelib=self._getLibrary(PEFileModule().getName())
     if(pelib==None):data=self.sample.getBinary()
     else:
         for section in pelib.sections:
             data=data+section.get_data()    
     
     regexp='[A-Za-z0-9/\-:.,_$&@=?%()[\]<> ]{4,}'
     strings=re.findall(regexp,data)
     aux={}
     for s in strings:
         aux[repr(s).lower()]=True
     
     unique_strings=[]
     for k in aux:
         unique_strings.append(k)
     
     mdc=self._getLibrary(MetaDataModule().getName())
     if(mdc==None):return ret
     
     
     searchUsed={}
     imports=self.sample.getLastValue("particular_header.imports")
     if(imports!=None ): 
         for i in imports:
             searchUsed[i["lib"]]=True
             for f in i["functions"]:
                 searchUsed[f]=True
     
     exports=self.sample.getLastValue("particular_header.exports.symbols")
     if(exports!=None ):
         #print("No exports")
         for i in exports:
             searchUsed[i["name"]]=True
             if(hasattr(i,"forwarder_dll") and hasattr(i,"forwarder_function")):
                 searchUsed[i["forwarder_dll"]]=True
                 searchUsed[i["forwarder_function"]]=True
             
     version_p=self.sample.getLastValue("particular_header.version.string_file_info")
     if(version_p!=None ):
         for k in version_p.keys():
             searchUsed["'"+str(version_p[k])+"'"]=True
             
     
     
     raw=[]
     hidden=[]
     email=[]
     url=[]
     ip_l=[] 
     
     dll=[]
     domain=[]
     interesting=[]
     
     registry=[]
     for s in unique_strings:
         #viendo si declara el import o no
         #print(s)
         #print(searchUsed.get(repr(s).lower()))
         #raw_input()
         if(searchUsed.get(s)==True): continue           
         raw.append(s)
                     
         #buscando si es un import o no
         r=mdc.searchImportByName(s)
         if(r!=None):
             hidden.append(s)
             continue
         evaluado=eval(s)
             
         #buscando dll
         r=mdc.searchDllByName(s)
         if(r!=None):
             dll.append(s)
             continue
         
         #buscando cosas nombres de archivos
         types=["exe","dll","bat","sys","htm","html","js","jar","jpg",
                 "png","vb","scr","pif","chm","zip","rar","cab","pdf",
                 "doc","docx","ppt","pptx","xls","xlsx","swf","gif","pdb","cpp"]
         salir=False
         for pat in types:
             if(s.find("."+pat)!=-1):
                 interesting.append(s)
                 salir=True
                 break
         if salir: continue
                 
         
         #buscando email
         if(validators.email(evaluado)):
             email.append(s)
             continue
         
         #buscando url
         if(validators.url(evaluado)):
             url.append(s)
             continue
             
         #buscando ip
         if(validators.ipv4(evaluado)): #or validators.ipv6(evaluado)):
             ip_l.append(s)
             continue
         
         #buscando registry
         if(s.find("HKLM\\")!=-1 or s.find("HKCU\\")!=-1 ):
             registry.append(s)
             continue
         
         #buscando dominios
         if(validators.domain(evaluado)):
             domain.append(s)
             continue
         
     ret["raw_strings"]=sorted(raw)
     if(len(hidden)>0):ret["hidden_imports"]=sorted(hidden)  
     if(len(email)>0):ret["emails"]=sorted(email)
     if(len(url)>0):ret["urls"]=sorted(url)
     if(len(ip_l)>0):ret["ips"]=sorted(ip_l)
     if(len(dll)>0):ret["hidden_dll"]=sorted(dll)
     if(len(domain)>0):ret["domains"]=sorted(domain)
     if(len(interesting)>0):ret["interesting"]=sorted(interesting)
     if(len(registry)>0):ret["registry"]=sorted(registry)
     
     return ret
def test_valid_maintainer():
    assert flask_template.__maintainer__
    assert validators.email(flask_template.__maintainer_email__)
def test_valid_author():
    assert flask_template.__author__
    assert validators.email(flask_template.__author_email__)
Esempio n. 56
0
def arg_validator(arg, vlist=None):
    """
    检查数据,可对同一个数据进行多种检查

    arg : 字符串,要验证的参数
    vlist :  列表,验证列表,每个元素包含两项.
            第一个项是检查类型(字符串),第二项是可选参数字典,类似:
            [
                ("检查类型",{"可选参数1":参数值,"可选参数2":参数值...}),
                ("检查类型",{"可选参数1":参数值,"可选参数2":参数值...}),
            ...
            ]
    返回: 双元组,第一项为True 或 False,第二项为验证失败的类型(第一项为True的话第二项就留空)

    注意:
    vlist 列表的第一项可以是字符串 "required",用于表示是必填项:
        如果第一项不是,而且要验证的 arg 为空,会直接返回 True,不是的继续验证。
        如果第一项是,就完全按照 vlist[1:] 的要求验证
    vlist 的元素如果是验证整数/小数/email等不需要附加参数的可以直接传入验证类型字符串即可

    用例(使用args_validator函数的,看这里vdict每个键值对的形式):
    vdict = {
            "token": ["required", "uuid"],
            "username": ["required", ("length", {"min": 4, "max": 30}), "safe_str"],
            "password": ["required", ("length", {"min": 4, "max": 20}), "safe_str"],
            "captcha": ["required", ("length", {"min": 4, "max": 8}), "safe_str"],
        }
    form = args_validator(self.request.arguments, vdict)

    """
    if not any((isinstance(vlist, list), isinstance(vlist, tuple))):
        einfo = "不支持的数据类型!应使用列表或元组,但输入的是{}".format(type(vlist))
        raise ValueError(einfo)

    if vlist[0] == "required":
        # 第一项不是 required 的,把第一项的 "required" 去掉
        vlist = vlist[1:]
    else:
        # 第一项不是 required 的,如果 arg 是空的,直接返回 True,不是的继续验证
        if not arg:
            return True, None

    # 待返回的验证结果
    verification = None
    failed_type = None        # 验证失败的类型

    # 开始检查,有一个不通过就返回 False
    for i in vlist:
        local_verification = None
        if isinstance(i, str):  # 如果是字符串的话就改为元组
            i = (i, {})

        if len(i) == 1:         # 只有一个元素的,添加一个空字典
            i = (i[0], {})

        vtype = i[0]        # 检查类型是第一项
        vdict = i[1]        # 检查类型所需的可选参数字典

        # 在 validators 之外添加的
        # 没有空白
        if vtype == "no_space":
            if not re.search(r"\s", arg):
                local_verification = True
        # 安全字符串,只包含 0-9a-zA-Z-空格和下划线
        elif vtype == "safe_str":
            if re.match(r"^[0-9a-zA-Z-_ ]+$", arg, flags=re.U):
                local_verification = True

        # 是否包含
        elif vtype == "in":
            # 迭代 vdict 的键值(所以键名无所谓)
            for v in vdict.values():
                if arg not in v:
                    local_verification = False
                    break
        elif vtype == "not_in":
            # 迭代 vdict 的键值(所以键名无所谓)
            for v in vdict.values():
                if arg in v:
                    local_verification = False
                    break

        # 字符串形式的数字
        elif vtype == "str_number":
            if re.match(r"[+-]?\d+$", arg, flags=re.U) or \
                    re.match(r"[+-]?\d+\.\d+$", arg, flags=re.U):
                local_verification = True
        elif vtype == "str_int":
            if re.match(r"[+-]?\d+$", arg, flags=re.U):
                local_verification = True
        elif vtype == "str_float":
            if re.match(r"[+-]?\d+\.\d+$", arg, flags=re.U):
                local_verification = True

        # 数字
        elif vtype == "number":     # 整数或浮点数都可以
            local_verification = isinstance(arg, int) or isinstance(arg, float)
        elif vtype == "int":
            local_verification = isinstance(arg, int)
        elif vtype == "float":
            local_verification = isinstance(arg, float)

        # 直接调用 validators的
        elif vtype == "length":
            local_verification = validators.length(arg, **vdict)
        elif vtype == "url":
            local_verification = validators.url(arg, **vdict)
        elif vtype == "email":
            local_verification = validators.email(arg, **vdict)
        elif vtype == "ip":       # ipv4 或 ipv6都可以
            local_verification = any((validators.ipv4(arg, **vdict),
                                      validators.ipv6(arg, **vdict)))
        elif vtype == "between":
            local_verification = validators.between(arg, **vdict)
        elif vtype == "uuid":
            local_verification = validators.uuid(arg, **vdict)
        elif vtype == "ipv4":
            local_verification = validators.ipv4(arg, **vdict)
        elif vtype == "ipv6":
            local_verification = validators.ipv6(arg, **vdict)
        elif vtype == "mac_address":
            local_verification = validators.mac_address(arg, **vdict)
        elif vtype == "iban":
            local_verification = validators.iban(arg, **vdict)
        elif vtype == "slug":
            local_verification = validators.slug(arg, **vdict)
        elif vtype == "truthy":
            local_verification = validators.truthy(arg, **vdict)

        # 对于验证不为真或没有验证的
        # 不为真的时候返回的是: ValidationFailure(......)
        if not local_verification:
            verification = False
            failed_type = vtype
            break                           # 有一条不为 True, 直接返回 False
        else:
            verification = True
    # 处理返回值
    if verification not in(False, True):
        verification = False
    if not verification:
        return verification, failed_type
    else:
        return True, None
Esempio n. 57
0
	def parse_string(value):
		if validators.email(value):
			return ''.join(['email("',value,'")'])
		elif validators.url(value):
			return ''.join(['url("',value,'")'])
		return value
Esempio n. 58
0
 def __call__(self, form, field):
     if not email(field.data, self.domain_whitelist):
         if self.message is None:
             self.message = field.gettext(u'Invalid email address.')
         raise ValidationError(self.message)