Exemplo n.º 1
0
def ratelimit_handler(e):
    user_agent = request.headers.get('User-Agent')
    remote_ip = get_remote_address()
    evaluation = crawlers.evaluate(remote_ip, user_agent)
    if evaluation == crawlers.VERIFIED_BOT:
        app.logger.info("Rate limited a request classified as 'VERIFIED_BOT'")
    elif evaluation == crawlers.UNVERIFIABLE_BOT:
        app.logger.info(
            "Rate limited a request classified as 'UNVERIFIABLE_BOT'")
    elif evaluation == crawlers.POTENTIAL_MALICIOUS_BOT:
        app.logger.info(
            "Rate limited a request classified as 'POTENTIAL_MALICIOUS_BOT'")
    elif evaluation == crawlers.POTENTIAL_USER:
        app.logger.info(
            "Rate limited a request classified as 'POTENTIAL_USER'")
    else:
        # None
        app.logger.info("Rate limited a request not classified: '%s' - '%s'",
                        remote_ip, user_agent)
    form = ModernForm()
    return render_template('429.html',
                           environment=current_app.config['ENVIRONMENT'],
                           base_url=app.config['SERVER_BASE_URL'],
                           request_path=request.path[1:],
                           form=form,
                           code=429), 429
Exemplo n.º 2
0
def ratelimit_handler(e):
    if e.description.endswith('per 1 day'):
        # ADS Core limit hit (to limit too many bootstraps)
        remote_ip = get_remote_address()
        description = "We have received too many requests from your IP ({}).".format(
            remote_ip)
    else:
        # API ratelimit hit
        description = e.description
    user_agent = request.headers.get('User-Agent')
    remote_ip = get_remote_address()
    evaluation = crawlers.evaluate(remote_ip, user_agent)
    if evaluation == crawlers.VERIFIED_BOT:
        app.logger.info("Rate limited a request classified as 'VERIFIED_BOT'")
    elif evaluation == crawlers.UNVERIFIABLE_BOT:
        app.logger.info(
            "Rate limited a request classified as 'UNVERIFIABLE_BOT'")
    elif evaluation == crawlers.POTENTIAL_MALICIOUS_BOT:
        app.logger.info(
            "Rate limited a request classified as 'POTENTIAL_MALICIOUS_BOT'")
    elif evaluation == crawlers.POTENTIAL_USER:
        app.logger.info(
            "Rate limited a request classified as 'POTENTIAL_USER'")
    else:
        # None
        app.logger.info("Rate limited a request not classified: '%s' - '%s'",
                        remote_ip, user_agent)
    form = ModernForm()
    return render_template('429.html',
                           environment=current_app.config['ENVIRONMENT'],
                           base_url=app.config['SERVER_BASE_URL'],
                           request_path=request.path[1:],
                           form=form,
                           code=429,
                           description=description), 429
Exemplo n.º 3
0
def internal_error(e):
    form = ModernForm()
    return render_template('500.html',
                           environment=current_app.config['ENVIRONMENT'],
                           base_url=app.config['SERVER_BASE_URL'],
                           request_path=request.path[1:],
                           form=form,
                           code=500), 500
Exemplo n.º 4
0
def page_not_found(e):
    form = ModernForm()
    return render_template('404.html',
                           environment=current_app.config['ENVIRONMENT'],
                           base_url=app.config['SERVER_BASE_URL'],
                           request_path=request.path[1:],
                           form=form,
                           code=404), 404
Exemplo n.º 5
0
def index():
    """
    Modern form if no search parameters are sent, otherwise show search results
    """
    form = ModernForm(request.args)
    return render_template('modern-form.html',
                           base_url=SERVER_BASE_URL,
                           auth=session['auth'],
                           form=form)
Exemplo n.º 6
0
def index():
    """
    Modern form if no search parameters are sent, otherwise show search results
    """
    form = ModernForm(request.args)
    return render_template('modern-form.html',
                           environment=current_app.config['ENVIRONMENT'],
                           base_url=app.config['SERVER_BASE_URL'],
                           form=form)
Exemplo n.º 7
0
def search(params=None):
    """
    Modern form if no search parameters are sent, otherwise show search results
    """
    form = ModernForm.parse(params or request.args)
    if form.p_.data > 0:
        # Redirect to correct the start parameter to match the requested page
        computed_start = (form.p_.data - 1) * form.rows.data
        if form.start.data != computed_start:
            return redirect(
                url_for('search',
                        q=form.q.data,
                        sort=form.sort.data,
                        rows=form.rows.data,
                        start=computed_start))
    elif form.q.data and len(form.q.data) > 0:
        if not form.sort.raw_data:
            # There was not previous sorting specified
            if "similar(" in form.q.data or "trending(" in form.q.data:
                form.sort.data = "score desc"
            elif "references(" in form.q.data:
                form.sort.data = "first_author asc"
        results = api.Search(form.q.data,
                             rows=form.rows.data,
                             start=form.start.data,
                             sort=form.sort.data)
        qtime = "{:.3f}s".format(
            float(results.get('responseHeader', {}).get('QTime', 0)) / 1000)
        return render_template('search-results.html',
                               environment=current_app.config['ENVIRONMENT'],
                               base_url=app.config['SERVER_BASE_URL'],
                               auth=session['auth'],
                               form=form,
                               results=results.get('response'),
                               stats=results.get('stats'),
                               error=results.get('error'),
                               qtime=qtime,
                               sort_options=current_app.config['SORT_OPTIONS'])
    else:
        return redirect(url_for('index'))
Exemplo n.º 8
0
def search():
    """
    Modern form if no search parameters are sent, otherwise show search results
    """
    form = ModernForm(request.args)
    if len(form.q.data) > 0:
        results = api.search(form.q.data,
                             rows=form.rows.data,
                             start=form.start.data,
                             sort=form.sort.data)
        qtime = "{:.3f}s".format(
            float(results.get('responseHeader', {}).get('QTime', 0)) / 1000)
        return render_template('search-results.html',
                               base_url=SERVER_BASE_URL,
                               auth=session['auth'],
                               form=form,
                               results=results.get('response'),
                               stats=results.get('stats'),
                               error=results.get('error'),
                               qtime=qtime,
                               sort_options=SORT_OPTIONS)
    return redirect(url_for('index'))
Exemplo n.º 9
0
def index():
    """
    Modern form if no search parameters are sent, otherwise show search results
    """
    form = ModernForm(request.args)
    return _render_template('modern-form.html', form=form)
Exemplo n.º 10
0
def unavailable(endpoint=None):
    """
    Endpoint to be used when the site needs to go into maintenance mode
    """
    form = ModernForm()
    return _render_template('503.html', request_path=request.path[1:], form=form, code=503), 503
Exemplo n.º 11
0
def internal_error(e):
    form = ModernForm()
    return _render_template('500.html', request_path=request.path[1:], form=form, code=500), 500
Exemplo n.º 12
0
def page_not_found(e):
    form = ModernForm()
    return _render_template('404.html', request_path=request.path[1:], form=form, code=404), 404