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