Exemplo n.º 1
0
def modify_configuration(config_form, analyst):
    """
    Modify the configuration with the submitted changes.

    :param config_form: The form data.
    :type config_form: dict
    :param analyst: The user making the modifications.
    :type analyst: str
    :returns: dict with key "message"
    """

    config = CRITsConfig.objects().first()
    if not config:
        config = CRITsConfig()
    data = config_form.cleaned_data
    allowed_hosts_list = data['allowed_hosts'].split(',')
    allowed_hosts = ()
    for allowed_host in allowed_hosts_list:
        allowed_hosts = allowed_hosts + (allowed_host.strip(),)
    data['allowed_hosts'] = allowed_hosts
    service_dirs_list = data['service_dirs'].split(',')
    service_dirs = ()
    for service_dir in service_dirs_list:
        service_dirs = service_dirs + (service_dir.strip(),)
    data['service_dirs'] = service_dirs
    config.merge(data, overwrite=True)
    try:
        config.save(username=analyst)
        return {'message': "Success!"}
    except Exception, e:
        return {'message': "Failure: %s" % e}
Exemplo n.º 2
0
def modify_configuration(config_form, analyst):
    """
    Modify the configuration with the submitted changes.

    :param config_form: The form data.
    :type config_form: dict
    :param analyst: The user making the modifications.
    :type analyst: str
    :returns: dict with key "message"
    """

    config = CRITsConfig.objects().first()
    if not config:
        config = CRITsConfig()
    data = config_form.cleaned_data
    allowed_hosts_list = data['allowed_hosts'].split(',')
    allowed_hosts = ()
    for allowed_host in allowed_hosts_list:
        allowed_hosts = allowed_hosts + (allowed_host.strip(), )
    data['allowed_hosts'] = allowed_hosts
    service_dirs_list = data['service_dirs'].split(',')
    service_dirs = ()
    for service_dir in service_dirs_list:
        service_dirs = service_dirs + (service_dir.strip(), )
    data['service_dirs'] = service_dirs
    config.merge(data, overwrite=True)
    try:
        config.save(username=analyst)
        return {'message': "Success!"}
    except Exception, e:
        return {'message': "Failure: %s" % e}
Exemplo n.º 3
0
def force_reset_config():
    """
    Resets the values for the CRITsConfig class by dropping the
    database collection and then saving a new default CRITsConfig.
    """

    print "Resetting CRITs configuration settings."
    CRITsConfig.drop_collection();

    crits_config = CRITsConfig();
    crits_config.save();
Exemplo n.º 4
0
def get_config():
    """
    Get the CRITs configuration.

    :returns: :class:`crits.config.config.CRITsConfig`
    """

    crits_config = CRITsConfig.objects().first()
    if not crits_config:
        crits_config = CRITsConfig()
        crits_config.save()
    return crits_config
Exemplo n.º 5
0
def get_config():
    """
    Get the CRITs configuration.

    :returns: :class:`crits.config.config.CRITsConfig`
    """

    crits_config = CRITsConfig.objects().first()
    if not crits_config:
        crits_config = CRITsConfig()
        crits_config.save()
    return crits_config
Exemplo n.º 6
0
def create_config_if_not_exist():
    """
    If the CRITsConfig already exists then the CRITsConfig is returned,
    otherwise a new CRITsConfig will be created, saved, and returned.

    Returns:
        Returns the CRITsConfig if it already exists, otherwise a
        default CRITsConfig is returned.
    """

    crits_config = CRITsConfig.objects().first()
    if not crits_config:
        print "Creating a new CRITs configuration."
        crits_config = CRITsConfig()
        crits_config.save()
    else:
        print "A CRITs configuration already exists. Skipping default creation."

    return crits_config
Exemplo n.º 7
0
def prep_db():
    """
    Prep the DB for testing.
    """

    clean_db()
    # Create a new default config
    crits_config = CRITsConfig()
    crits_config.save()
    # Add Source
    handlers.add_new_source(TSRC, TRANDUSER)

    # Add User
    user = CRITsUser.create_user(username=TUSER_NAME,
                                 password=TUSER_PASS,
                                 email=TUSER_EMAIL)
    user.first_name = TUSER_FNAME
    user.last_name = TUSER_LNAME
    user.save()

    # Add test source object
    '''
Exemplo n.º 8
0
def prep_db():
    """
    Prep the DB for testing.
    """

    clean_db()
    # Create a new default config
    crits_config = CRITsConfig()
    crits_config.save()
    # Add Source
    handlers.add_new_source(TSRC, TRANDUSER)

    # Add User
    user = CRITsUser.create_user(username=TUSER_NAME,
                                 password=TUSER_PASS,
                                 email=TUSER_EMAIL
                                 )
    user.first_name = TUSER_FNAME
    user.last_name = TUSER_LNAME
    user.save()

    # Add test source object
    '''
Exemplo n.º 9
0
def prep_db():
    """
    Prep the DB for testing.
    """

    clean_db()
    # Create a new default config
    crits_config = CRITsConfig()
    crits_config.save()
    # Add Source
    handlers.add_new_source(TSRC, TRANDUSER)
    # Add User
    user = CRITsUser.create_user(
        username=TUSER_NAME,
        password=TUSER_PASS,
        email=TUSER_EMAIL,
    )
    user.first_name = TUSER_FNAME
    user.last_name = TUSER_LNAME
    user.save()
    # Add test source object
    obj = TestSourceObject()
    obj.name = TOBJS_NAME
    obj.value = TOBJS_VALUE
    obj.add_source(source=TSRC, analyst=TUSER_NAME)
    obj.save()
    # Add another with Different source
    obj = TestSourceObject()
    obj.name = TOBJS_NAME
    obj.value = TOBJS_VALUE
    obj.add_source(source=TUNKSRC, analyst=TRANDUSER)
    obj.save()
    # Add test non-source object
    obj = TestObject()
    obj.name = TOBJ_NAME
    obj.value = TOBJ_VALUE
    obj.save()
Exemplo n.º 10
0
def prep_db():
    """
    Prep the DB for testing.
    """

    clean_db()
    # Create a new default config
    crits_config = CRITsConfig()
    crits_config.save()
    # Add Source
    handlers.add_new_source(TSRC, TRANDUSER)
    # Add User
    user = CRITsUser.create_user(username=TUSER_NAME,
                                 password=TUSER_PASS,
                                 email=TUSER_EMAIL,
                                 )
    user.first_name = TUSER_FNAME
    user.last_name = TUSER_LNAME
    user.save()
    # Add test source object
    obj = TestSourceObject()
    obj.name = TOBJS_NAME
    obj.value = TOBJS_VALUE
    obj.add_source(source=TSRC, analyst=TUSER_NAME)
    obj.save()
    # Add another with Different source
    obj = TestSourceObject()
    obj.name = TOBJS_NAME
    obj.value = TOBJS_VALUE
    obj.add_source(source=TUNKSRC, analyst=TRANDUSER)
    obj.save()
    # Add test non-source object
    obj = TestObject()
    obj.name = TOBJ_NAME
    obj.value = TOBJ_VALUE
    obj.save()