.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
self_info.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=missing-module-docstring,invalid-name
3
4import re
5from flask_babel import gettext
6
7from searx.botdetection._helpers import get_real_ip
8
9name = gettext('Self Information')
10description = gettext('Displays your IP if the query is "ip" and your user agent if the query contains "user agent".')
11default_on = True
12preference_section = 'query'
13query_keywords = ['user-agent']
14query_examples = ''
15
16# "ip" or "my ip" regex
17ip_regex = re.compile('^ip$|my ip', re.IGNORECASE)
18
19# Self User Agent regex
20ua_regex = re.compile('.*user[ -]agent.*', re.IGNORECASE)
21
22
23def post_search(request, search):
24 if search.search_query.pageno > 1:
25 return True
26 if ip_regex.search(search.search_query.query):
27 ip = get_real_ip(request)
28 search.result_container.answers['ip'] = {'answer': gettext('Your IP is: ') + ip}
29 elif ua_regex.match(search.search_query.query):
30 ua = request.user_agent
31 search.result_container.answers['user-agent'] = {'answer': gettext('Your user-agent is: ') + ua.string}
32 return True
post_search(request, search)
Definition self_info.py:23