Beispiel #1
0
def main_function():
    # pandas options for terminal development. Not needed in production mode
    pd.set_option('display.width', None)
    pd.set_option('display.max_colwidth', 500)
    pd.set_option('display.show_dimensions', True)

    with lock:
        if not get_settings().count() > 0:
            save_settings(default_settings)

        feeds_collection = get_feeds()

        m_data = feeds_collection.find()

        if m_data.count() > 0:
            normal_data_dictionary = normalize_dict(m_data)
            if len(normal_data_dictionary) > 0:
                data_frame = pd.DataFrame.from_dict(
                    normal_data_dictionary, orient='index').drop([
                        'raw', '_id', 'feed_url', 'feed_name', 'feed_provider',
                        'event_description_url', 'extra'
                    ],
                                                                 axis=1)

                prepared = prepare_data_fill_na(data_frame)

                categorical_data_frame = convert_series_to_categorical(
                    prepared)

                generate_plots(categorical_data_frame)

                threading.Thread(
                    filter_for_blocking(categorical_data_frame,
                                        ip_max_attempts_to_block(),
                                        minutes_before_ip_is_blocked(),
                                        "block")).start()
                threading.Thread(
                    filter_for_blocking(categorical_data_frame,
                                        ip_max_attempts_to_warn(),
                                        minutes_before_ip_is_blocked(),
                                        "warn")).start()
                threading.Thread(filter_dns(categorical_data_frame)).start()

            else:
                print("No data found. Set is empty")
        else:
            print("Data query is empty. No records found")
Beispiel #2
0
def fetch_settings(user_id, token):
    """
    :param: category of analysis ie blocked/(unblocked/warned)
    :parameter: user_id: the user making the request
    :parameter: token: the user token for each request
    :rtype: object
    """
    f = do_get_auth(user_id, token)
    if not isinstance(f, bool):
        return f
    else:
        if f is not True:
            return make_response(jsonify({"error": 'Invalid User id or token', "data": False}), 200)

    ips = get_settings()
    data = []
    for d in ips:
        data.append(d)
    return make_response(jsonify({"error": False, "token": get_request_token(user_id),
                                  "data": json.dumps(data, cls=JSONEncoder)}), 200)
Beispiel #3
0
def minutes_before_ip_is_blocked():
    return get_settings(KEY_MINUTES_BEFORE_IP_IS_BLOCKED)
Beispiel #4
0
def ip_max_attempts_to_warn():
    return get_settings(KEY_MAX_ATTEMPTS_TO_WARN_IP)
Beispiel #5
0
def ip_max_attempts_to_block():
    return get_settings(KEY_MAX_ATTEMPTS_TO_BLOCK_IP)
Beispiel #6
0
def is_auto_redirection_enabled():
    v = get_settings(KEY_AUTO_DNS_REDIRECTION_ENABLED)
    if not isinstance(v, bool):
        return False
    return v
Beispiel #7
0
def get_redirection_address():
    return get_settings(KEY_DNS_REDIRECT_TO_ADDRESS)
Beispiel #8
0
def is_auto_clear_old_records_enabled():
    v = get_settings(KEY_AUTO_CLEAR_OLD_RECORDS_ENABLED)
    if not isinstance(v, bool):
        return False
    return v
Beispiel #9
0
def is_auto_blocking_enabled():
    v = get_settings(KEY_AUTO_BLOCKING_ENABLED)
    if not isinstance(v, bool):
        return False
    return v
Beispiel #10
0
def redirection_count():
    return get_settings(KEY_DNS_RECORD_REDIRECTION_COUNT)
Beispiel #11
0
def minutes_to_keep_feed():
    return get_settings(KEY_MAX_MINUTES_TO_KEEP_A_FEED)
Beispiel #12
0
def minutes_a_record_remains_new():
    return get_settings(KEY_MINUTES_A_RECORD_REMAINS_NEW)