|
@@ -1,9 +1,12 @@
|
1
|
|
-
|
|
1
|
+from flask.ext.babel import gettext
|
2
|
2
|
name = "Self IP"
|
3
|
|
-description = "Display your source IP address"
|
|
3
|
+description = gettext('Display your source IP address if the query expression is "ip"')
|
4
|
4
|
default_on = True
|
5
|
5
|
|
6
|
6
|
|
|
7
|
+# attach callback to the pre search hook
|
|
8
|
+# request: flask request object
|
|
9
|
+# ctx: the whole local context of the pre search hook
|
7
|
10
|
def pre_search(request, ctx):
|
8
|
11
|
if ctx['search'].query == 'ip':
|
9
|
12
|
x_forwarded_for = request.headers.getlist("X-Forwarded-For")
|
|
@@ -13,5 +16,6 @@ def pre_search(request, ctx):
|
13
|
16
|
ip = request.remote_addr
|
14
|
17
|
ctx['search'].answers.clear()
|
15
|
18
|
ctx['search'].answers.add(ip)
|
|
19
|
+ # return False prevents exeecution of the original block
|
16
|
20
|
return False
|
17
|
21
|
return True
|