WIP: use the package botdetection

This commit is contained in:
Alexandre Flament 2024-05-05 17:44:30 +00:00
parent ac430a9eaf
commit e826a71c2b
17 changed files with 98 additions and 1261 deletions

View file

@ -4,7 +4,6 @@
import re
from flask_babel import gettext
from searx.botdetection._helpers import get_real_ip
name = gettext('Self Information')
description = gettext('Displays your IP if the query is "ip" and your user agent if the query contains "user agent".')
@ -17,11 +16,18 @@ query_examples = ''
p = re.compile('.*user[ -]agent.*', re.IGNORECASE)
def get_client_ip(request):
botdetection_context = getattr(request, "botdetection_context", None)
if botdetection_context:
return request.botdetection_request_info.real_ip
return request.remote_addr
def post_search(request, search):
if search.search_query.pageno > 1:
return True
if search.search_query.query == 'ip':
ip = get_real_ip(request)
ip = get_client_ip(request)
search.result_container.answers['ip'] = {'answer': ip}
elif p.match(search.search_query.query):
ua = request.user_agent