Expand 'my ip' to work for proxied requests
Adds a check for the HTTP_X_FORWARDED_FOR header, and uses the value from the request if found.main
parent
26b560da1d
commit
0a78c524fa
|
@ -13,7 +13,7 @@ from app import app
|
||||||
from app.models.config import Config
|
from app.models.config import Config
|
||||||
from app.request import Request, TorError
|
from app.request import Request, TorError
|
||||||
from app.utils.bangs import resolve_bang
|
from app.utils.bangs import resolve_bang
|
||||||
from app.utils.misc import read_config_bool
|
from app.utils.misc import read_config_bool, get_client_ip
|
||||||
from app.utils.results import add_ip_card
|
from app.utils.results import add_ip_card
|
||||||
from app.utils.results import bold_search_terms
|
from app.utils.results import bold_search_terms
|
||||||
from app.utils.search import *
|
from app.utils.search import *
|
||||||
|
@ -257,7 +257,7 @@ def search():
|
||||||
# Feature to display IP address
|
# Feature to display IP address
|
||||||
if search_util.check_kw_ip():
|
if search_util.check_kw_ip():
|
||||||
html_soup = bsoup(str(response), 'html.parser')
|
html_soup = bsoup(str(response), 'html.parser')
|
||||||
response = add_ip_card(html_soup, request.remote_addr)
|
response = add_ip_card(html_soup, get_client_ip(request))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'display.html',
|
'display.html',
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from flask import Request
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -15,3 +16,10 @@ def read_config_bool(var: str) -> bool:
|
||||||
if val.isdigit():
|
if val.isdigit():
|
||||||
return bool(int(val))
|
return bool(int(val))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_client_ip(r: Request) -> str:
|
||||||
|
if r.environ.get('HTTP_X_FORWARDED_FOR') is None:
|
||||||
|
return r.environ['REMOTE_ADDR']
|
||||||
|
else:
|
||||||
|
return r.environ['HTTP_X_FORWARDED_FOR']
|
||||||
|
|
Loading…
Reference in New Issue