.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, missing-class-docstring
3from __future__ import annotations
4import typing
5
6import re
7from flask_babel import gettext
8
9from searx.botdetection._helpers import get_real_ip
10from searx.result_types import EngineResults
11
12from . import Plugin, PluginInfo
13
14if typing.TYPE_CHECKING:
15 from searx.search import SearchWithPlugins
16 from searx.extended_types import SXNG_Request
17
18
20 """Simple plugin that displays information about user's request, including
21 the IP or HTTP User-Agent. The information is displayed in area for the
22 "answers".
23 """
24
25 id = "self_info"
26 default_on = True
27 keywords = ["ip", "user-agent"]
28
29 def __init__(self):
30 super().__init__()
31
32 self.ip_regex = re.compile(r"^ip", re.IGNORECASE)
33 self.ua_regex = re.compile(r"^user-agent", re.IGNORECASE)
34
36 id=self.id,
37 name=gettext("Self Information"),
38 description=gettext(
39 """Displays your IP if the query is "ip" and your user agent if the query is "user-agent"."""
40 ),
41 preference_section="query",
42 )
43
44 def post_search(self, request: "SXNG_Request", search: "SearchWithPlugins") -> EngineResults:
45 """Returns a result list only for the first page."""
46 results = EngineResults()
47
48 if search.search_query.pageno > 1:
49 return results
50
51 if self.ip_regex.search(search.search_query.query):
52 results.add(results.types.Answer(answer=gettext("Your IP is: ") + get_real_ip(request)))
53
54 if self.ua_regex.match(search.search_query.query):
55 results.add(results.types.Answer(answer=gettext("Your user-agent is: ") + str(request.user_agent)))
56
57 return results
EngineResults post_search(self, "SXNG_Request" request, "SearchWithPlugins" search)
Definition self_info.py:44