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