2023-05-29 17:46:37 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# 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
|
|
|
|
2024-06-11 14:58:10 +00:00
|
|
|
# "ip" or "my ip" regex
|
|
|
|
ip_regex = re.compile('^ip$|my ip', re.IGNORECASE)
|
|
|
|
|
2015-06-15 08:22:37 +00:00
|
|
|
# Self User Agent regex
|
2024-06-11 14:58:10 +00:00
|
|
|
ua_regex = 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
|
2024-06-11 14:58:10 +00:00
|
|
|
if ip_regex.search(search.search_query.query):
|
2023-05-29 17:46:37 +00:00
|
|
|
ip = get_real_ip(request)
|
2024-06-11 14:58:10 +00:00
|
|
|
search.result_container.answers['ip'] = {'answer': gettext('Your IP is: ') + ip}
|
|
|
|
elif ua_regex.match(search.search_query.query):
|
2015-06-15 08:22:37 +00:00
|
|
|
ua = request.user_agent
|
2024-06-11 14:58:10 +00:00
|
|
|
search.result_container.answers['user-agent'] = {'answer': gettext('Your user-agent is: ') + ua}
|
2015-03-10 18:55:22 +00:00
|
|
|
return True
|