2023-05-29 19:46:37 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# pylint: disable=missing-module-docstring,invalid-name
|
2015-04-13 00:08:04 +02:00
|
|
|
|
2015-06-15 10:22:37 +02:00
|
|
|
import re
|
2023-05-29 19:46:37 +02:00
|
|
|
from flask_babel import gettext
|
|
|
|
|
|
|
|
from searx.botdetection._helpers import get_real_ip
|
2021-12-27 09:26:22 +01:00
|
|
|
|
2022-09-27 17:01:00 +02:00
|
|
|
name = gettext('Self Information')
|
2015-06-15 13:36:38 +02:00
|
|
|
description = gettext('Displays your IP if the query is "ip" and your user agent if the query contains "user agent".')
|
2015-03-10 19:55:22 +01:00
|
|
|
default_on = True
|
2021-06-01 16:21:56 +02:00
|
|
|
preference_section = 'query'
|
|
|
|
query_keywords = ['user-agent']
|
|
|
|
query_examples = ''
|
2015-03-10 19:55:22 +01:00
|
|
|
|
2015-06-15 10:22:37 +02:00
|
|
|
# Self User Agent regex
|
2020-08-11 16:25:03 +02:00
|
|
|
p = re.compile('.*user[ -]agent.*', re.IGNORECASE)
|
2015-06-15 10:22:37 +02:00
|
|
|
|
|
|
|
|
2016-10-22 14:01:53 +02:00
|
|
|
def post_search(request, search):
|
|
|
|
if search.search_query.pageno > 1:
|
2016-08-27 16:45:25 +02:00
|
|
|
return True
|
2020-08-11 16:25:03 +02:00
|
|
|
if search.search_query.query == 'ip':
|
2023-05-29 19:46:37 +02:00
|
|
|
ip = get_real_ip(request)
|
2020-06-09 17:01:59 +02:00
|
|
|
search.result_container.answers['ip'] = {'answer': ip}
|
2016-10-22 14:01:53 +02:00
|
|
|
elif p.match(search.search_query.query):
|
2015-06-15 10:22:37 +02:00
|
|
|
ua = request.user_agent
|
2020-06-09 17:01:59 +02:00
|
|
|
search.result_container.answers['user-agent'] = {'answer': ua}
|
2015-03-10 19:55:22 +01:00
|
|
|
return True
|