Implemented the changes requested
This commit is contained in:
parent
85aef82a8a
commit
96a0862f1e
|
@ -3,7 +3,6 @@ import base64
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import pickle
|
import pickle
|
||||||
import re
|
|
||||||
import urllib.parse as urlparse
|
import urllib.parse as urlparse
|
||||||
import uuid
|
import uuid
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
@ -14,6 +13,7 @@ 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
|
||||||
|
from app.utils.results import add_ip
|
||||||
from app.utils.search import *
|
from app.utils.search import *
|
||||||
from app.utils.session import generate_user_key, valid_user_session
|
from app.utils.session import generate_user_key, valid_user_session
|
||||||
from bs4 import BeautifulSoup as bsoup
|
from bs4 import BeautifulSoup as bsoup
|
||||||
|
@ -252,52 +252,9 @@ def search():
|
||||||
resp_code = 503 if has_captcha(str(response)) else 200
|
resp_code = 503 if has_captcha(str(response)) else 200
|
||||||
|
|
||||||
# Feature to display IP address
|
# Feature to display IP address
|
||||||
html_soup = bsoup(response, 'html.parser')
|
if search_util.check_kw_ip():
|
||||||
if (not html_soup.select_one(".EY24We")
|
html_soup = bsoup(response,"html.parser")
|
||||||
and html_soup.select_one(".OXXup").get_text().lower() == "all"):
|
response = add_ip(html_soup, request.remote_addr)
|
||||||
if re.search("([^a-z0-9]|^)my *[^a-z0-9] *(ip|internet protocol)" +
|
|
||||||
"($|( *[^a-z0-9] *(((addres|address|adres|adress)|a)?" +
|
|
||||||
" *$)))", query.lower()):
|
|
||||||
# HTML IP card tag
|
|
||||||
ip_tag = html_soup.new_tag("div")
|
|
||||||
ip_tag["class"] = "ZINbbc xpd O9g5cc uUPGi"
|
|
||||||
|
|
||||||
# What is my IP tag
|
|
||||||
q_tag = html_soup.new_tag("div")
|
|
||||||
q_tag["class"] = "kCrYT"
|
|
||||||
q_tag.string = "What's my IP"
|
|
||||||
|
|
||||||
# Distinction boundary
|
|
||||||
line = html_soup.new_tag("div")
|
|
||||||
line["class"] = "x54gtf"
|
|
||||||
|
|
||||||
# For IP Address html tag
|
|
||||||
ip_address = html_soup.new_tag("div")
|
|
||||||
ip_address["class"] = "kCrYT"
|
|
||||||
ip_address["style"] = "padding-bottom:0;"
|
|
||||||
ip_address.string = request.remote_addr
|
|
||||||
|
|
||||||
# Text below the IP address
|
|
||||||
ip_text = html_soup.new_tag("div")
|
|
||||||
ip_text.string = "Your public IP address"
|
|
||||||
ip_text["class"] = "kCrYT"
|
|
||||||
ip_text["style"] = "padding-top: 0; color: #9e9e9e!important;"
|
|
||||||
|
|
||||||
# Adding all the above html tags to the IP card
|
|
||||||
ip_tag.append(q_tag)
|
|
||||||
ip_tag.append(line)
|
|
||||||
ip_tag.append(ip_address)
|
|
||||||
ip_tag.append(ip_text)
|
|
||||||
|
|
||||||
# Finding the element before which the IP card would be placed
|
|
||||||
f_link = html_soup.select_one(".BNeawe.vvjwJb.AP7Wnd")
|
|
||||||
ref_element = f_link.find_parent(class_="ZINbbc xpd O9g5cc" +
|
|
||||||
" uUPGi")
|
|
||||||
|
|
||||||
# Inserting the element
|
|
||||||
ref_element.insert_before(ip_tag)
|
|
||||||
|
|
||||||
response = html_soup
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'display.html',
|
'display.html',
|
||||||
|
|
|
@ -186,3 +186,7 @@ path {
|
||||||
.search-bar-desktop {
|
.search-bar-desktop {
|
||||||
color: var(--whoogle-dark-text) !important;
|
color: var(--whoogle-dark-text) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ip-text-div{
|
||||||
|
color: var(--whoogle-dark-secondary-text) !important;
|
||||||
|
}
|
|
@ -174,3 +174,7 @@ path {
|
||||||
color: var(--whoogle-text);
|
color: var(--whoogle-text);
|
||||||
border-bottom: 0px;
|
border-bottom: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ip-text-div{
|
||||||
|
color: var(--whoogle-secondary-text) !important;
|
||||||
|
}
|
|
@ -31,3 +31,11 @@ details summary {
|
||||||
height: 650px;
|
height: 650px;
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ip-address-div{
|
||||||
|
padding-bottom:0!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ip-text-div{
|
||||||
|
padding-top:0!important;
|
||||||
|
}
|
|
@ -138,3 +138,45 @@ def append_nojs(result: BeautifulSoup) -> None:
|
||||||
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
|
nojs_link.string = 'NoJS Link: ' + nojs_link['href']
|
||||||
result.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
|
result.append(BeautifulSoup('<br><hr><br>', 'html.parser'))
|
||||||
result.append(nojs_link)
|
result.append(nojs_link)
|
||||||
|
|
||||||
|
|
||||||
|
def add_ip(html_soup: BeautifulSoup, ip: str) -> BeautifulSoup:
|
||||||
|
"""Adds the client's IP address to the search results if query contains keywords
|
||||||
|
|
||||||
|
Args:
|
||||||
|
query: Query of the client
|
||||||
|
response: The search result containing the keywords
|
||||||
|
ip: ip address of the client
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
BeautifulSoup
|
||||||
|
|
||||||
|
"""
|
||||||
|
if (not html_soup.select_one(".EY24We")
|
||||||
|
and html_soup.select_one(".OXXup").get_text().lower() == "all"):
|
||||||
|
# HTML IP card tag
|
||||||
|
ip_tag = html_soup.new_tag("div")
|
||||||
|
ip_tag["class"] = "ZINbbc xpd O9g5cc uUPGi"
|
||||||
|
|
||||||
|
# For IP Address html tag
|
||||||
|
ip_address = html_soup.new_tag("div")
|
||||||
|
ip_address["class"] = "kCrYT ip-address-div"
|
||||||
|
ip_address.string = ip
|
||||||
|
|
||||||
|
# Text below the IP address
|
||||||
|
ip_text = html_soup.new_tag("div")
|
||||||
|
ip_text.string = "Your public IP address"
|
||||||
|
ip_text["class"] = "kCrYT ip-text-div"
|
||||||
|
|
||||||
|
# Adding all the above html tags to the IP card
|
||||||
|
ip_tag.append(ip_address)
|
||||||
|
ip_tag.append(ip_text)
|
||||||
|
|
||||||
|
# Finding the element before which the IP card would be placed
|
||||||
|
f_link = html_soup.select_one(".BNeawe.vvjwJb.AP7Wnd")
|
||||||
|
ref_element = f_link.find_parent(class_="ZINbbc xpd O9g5cc" +
|
||||||
|
" uUPGi")
|
||||||
|
|
||||||
|
# Inserting the element
|
||||||
|
ref_element.insert_before(ip_tag)
|
||||||
|
return html_soup
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
import re
|
||||||
|
|
||||||
from bs4 import BeautifulSoup as bsoup
|
from bs4 import BeautifulSoup as bsoup
|
||||||
from cryptography.fernet import Fernet, InvalidToken
|
from cryptography.fernet import Fernet, InvalidToken
|
||||||
|
@ -161,3 +162,19 @@ class Search:
|
||||||
link['href'] += param_str
|
link['href'] += param_str
|
||||||
|
|
||||||
return str(formatted_results)
|
return str(formatted_results)
|
||||||
|
|
||||||
|
def check_kw_ip(self) -> bool:
|
||||||
|
"""Checks for keywords related to 'my ip' in the query
|
||||||
|
|
||||||
|
Args:
|
||||||
|
query: Query of the client
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool
|
||||||
|
|
||||||
|
"""
|
||||||
|
if re.search("([^a-z0-9]|^)my *[^a-z0-9] *(ip|internet protocol)" +
|
||||||
|
"($|( *[^a-z0-9] *(((addres|address|adres|adress)|a)?" +
|
||||||
|
" *$)))", self.query.lower()):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user