Example #1
0
    def get_sending_emails(self, notif_rules, conn=None):
        try:
            email_sender_list = []
            for notif in notif_rules:
                if notif[NotificationKeys.Group]:
                    users_list = (r.table(Collection.Groups).filter({
                        'name':
                        notif['group']
                    }).filter(lambda x: x['customer']['name'] == notif[
                        'customer_name']).map(lambda x: x['users']).run(conn))
                    if users_list:
                        users = map(lambda x: x['name'], user_list[0])
                        email_sender_list += (r.expr(users).map(
                            lambda user: r.table('users').get(user)).map(
                                lambda x: x['email']).run(conn))

                elif notif[NotificationKeys.User]:
                    email = (r.table(Collection.Users).get(
                        notif[NotificationKeys.User]).pluck(
                            UserKey.Email).run(conn))
                    if email:
                        email_sender_list.append(email[UserKey.Email])

        except Exception as e:
            logger.exception(e)

        return (email_sender_list)
Example #2
0
def move_agents_to_customer(agent_ids, new_customer, conn=None):
    """Move a list of agents into another customer
    Args:
        agent_ids (list): List of agent ids
        new_customer (str): Name of the new customer.

    Basic Usage:
        >>> from vFense.agent._db import move_agents_to_customer
        >>> new_customer = 'test'
        >>> agent_ids = ['7f242ab8-a9d7-418f-9ce2-7bcba6c2d9dc']
        >>> move_agents_to_customer(agent_ids, new_customer)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        data = (
            r.expr(agent_ids)
            .for_each(
                lambda agent_id: r.table(AgentCollections.Agents)
                .get(agent_id)
                .update({AgentKey.CustomerName: new_customer})
            )
            .run(conn)
        )

    except Exception as e:
        logger.exception(e)

    return data
Example #3
0
File: _db.py Project: vFense/vFense
def delete_users_in_group(usernames, group_id, conn=None):
    """Remove a group from a user or remove all groups for a user.
    Args:
        usernames (list): Name of the users.
        group_id (str): 36 character group UUID

    Basic Usage::
        >>> from vFense.group._db delete_users_from_group
        >>> usernames = ['agent_api']
        >>> delete_users_from_group(usernames, group_id)

    Return:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        data = (r.expr(usernames).for_each(
            lambda username: r.table(GroupCollections.GroupsPerUser).filter(
                {
                    GroupsPerUserKeys.UserName: username,
                    GroupsPerUserKeys.GroupId: group_id
                }).delete()).run(conn))

    except Exception as e:
        logger.exception(e)

    return (data)
Example #4
0
def update_cve_categories(conn=None):
    """Update CVE Categories in the CVE Collection
    Args:
        cve_data (list|dict): List or dictionary of cve data

    Basic Usage:
        >>> from vFense.plugins.vuln.cve._db update_cve_categories
        >>> update_cve_categories([{"cve_data goes in here"}])

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2004, 6730, None, [])
    """
    data = {}
    try:
        data = (r.expr(CVECategories.CATEGORIES).for_each(
            lambda category: r.table(CVECollections.CVE).filter(lambda x: x[
                CveKey.CveDescriptions].contains(lambda y: y[
                    CVEStrings.DESCRIPTION].match('(?i)' + category))).update(
                        lambda y: {
                            CveKey.CveCategories:
                            y[CveKey.CveCategories].set_insert(category)
                        })).run(conn))

    except Exception as e:
        logger.exception(e)

    return (data)
Example #5
0
File: _db.py Project: vFense/vFense
def move_agents_to_customer(agent_ids, new_customer, conn=None):
    """Move a list of agents into another customer
    Args:
        agent_ids (list): List of agent ids
        new_customer (str): Name of the new customer.

    Basic Usage:
        >>> from vFense.agent._db import move_agents_to_customer
        >>> new_customer = 'test'
        >>> agent_ids = ['7f242ab8-a9d7-418f-9ce2-7bcba6c2d9dc']
        >>> move_agents_to_customer(agent_ids, new_customer)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        data = (r.expr(agent_ids).for_each(
            lambda agent_id: r.table(AgentCollections.Agents).get(agent_id).
            update({AgentKey.CustomerName: new_customer})).run(conn))

    except Exception as e:
        logger.exception(e)

    return data
Example #6
0
File: _db.py Project: vFense/vFense
def delete_users(usernames, conn=None):
    """ Delete a user and all of its properties
    Args:
        usernames (list): username of the user you are deleteing.

    Basic Usage:
        >>> from vFense.user._db import delete_users
        >>> usernames = ['admin', 'foo', 'bar']
        >>> delete_users(usernames)

    Returns:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        data = (r.expr(usernames).for_each(lambda username: r.table(
            UserCollections.Users).get(username).delete()).run(conn))

    except Exception as e:
        logger.exception(e)

    return (data)
Example #7
0
File: _db.py Project: vFense/vFense
def delete_groups_from_user(username, group_ids=None, conn=None):
    """Remove a group from a user or remove all groups for a user.
    Args:
        username (str): Name of the user.

    Kwargs:
        group_ids(list): List of group_ids

    Basic Usage::
        >>> from vFense.group._db delete_groups_from_user
        >>> username = '******'
        >>> delete_groups_from_user(username)

    Return:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:
        if group_ids:
            data = (r.expr(group_ids).for_each(
                lambda group_id: r.table(GroupCollections.GroupsPerUser).
                filter({
                    GroupsPerUserKeys.UserName: username,
                    GroupsPerUserKeys.GroupId: group_id
                }).delete()).run(conn))

        else:
            data = (r.table(GroupCollections.GroupsPerUser).filter({
                GroupsPerUserKeys.UserName:
                username,
            }).delete().run(conn))

    except Exception as e:
        logger.exception(e)

    return (data)
Example #8
0
File: _db.py Project: vFense/vFense
def delete_groups(group_ids, conn=None):
    """Delete a group from the database.
    Args:
        group_ids (list): group ids of the group you are deleteing

    Basic Usage::
        >>> from vFense.group._db import delete_groups
        >>> group_ids = ['d081a343-cc6c-4f08-81d9-62a116fda025']
        >>> delete_groups(group_ids)

    Return:
        Tuple (status_code, count, error, generated ids)
        >>> (2001, 1, None, [])
    """
    data = {}
    try:

        data = (r.expr(group_ids).for_each(lambda group_id: r.table(
            GroupCollections.Groups).get(group_id).delete()).run(conn))

    except Exception as e:
        logger.exception(e)

    return (data)