예제 #1
0
def remove_blacklist_entry(address):
    """Removes an IP address from the blacklist."""
    result = db.blacklist.cancel_blacklist_entry(address, endpoints.get_user_name(), endpoints.get_comment())
    removed_blacklist_entries, overlapping_blacklist_entries = result
    context.logger.info('Removed %s from the blacklist.', address)
    but = ', but the overlapping blacklist entries listed below are still in effect'
    but = but if overlapping_blacklist_entries else ''
    return flask.jsonify({
        'message': 'The IP address {} has been removed from the blacklist{}.'.format(address, but),
        'removed_blacklist_entries': removed_blacklist_entries,
        'overlapping_blacklist_entries': overlapping_blacklist_entries,
    })
예제 #2
0
def add_whitelist_entry(address):
    """Adds an IP address to the whitelist."""
    result = db.whitelist.add_whitelist_entry(address, endpoints.get_user_name(), endpoints.get_comment())
    new_whitelist_entry, overlapping_whitelist_entries = result
    context.logger.info('Added %s to the whitelist.', address)
    response = flask.jsonify({
        'message': 'The IP address {address} has been added to the whitelist.'.format(address=address),
        'new_whitelist_entry': new_whitelist_entry,
        'overlapping_whitelist_entries': overlapping_whitelist_entries,
    })
    response.status_code = 201
    return response
예제 #3
0
def add_blacklist_entry(address):
    """Adds an IP address to the blacklist."""
    duration, duration_type = endpoints.get_duration()
    user_name, comment = endpoints.get_user_name(), endpoints.get_comment()
    results = db.blacklist.add_blacklist_entry(address, (duration, duration_type), user_name, comment)
    new_blacklist_entry, superseded_blacklist_entries, overlapping_blacklist_entries = results
    context.logger.info('Added %s to the blacklist.', address)
    response = flask.jsonify({
        'message': 'The IP address {address} has been added to the blacklist.'.format(address=address),
        'new_blacklist_entry': new_blacklist_entry,
        'superseded_blacklist_entries': superseded_blacklist_entries,
        'overlapping_blacklist_entries': overlapping_blacklist_entries,
    })
    response.status_code = 201
    return response