mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
WIP: use the package botdetection
This commit is contained in:
parent
ac430a9eaf
commit
e826a71c2b
17 changed files with 98 additions and 1261 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue