def new_search_query(self) -> str: # Generate a new element key each time a new search is performed self.session['fernet_keys']['element_key'] = generate_user_keys( cookies_disabled=self.cookies_disabled)['element_key'] q = self.request_params.get('q') if q is None or len(q) == 0: return '' else: # Attempt to decrypt if this is an internal link try: q = Fernet(self.session['fernet_keys']['text_key']).decrypt( q.encode()).decode() except InvalidToken: pass # Reset text key self.session['fernet_keys']['text_key'] = generate_user_keys( cookies_disabled=self.cookies_disabled)['text_key'] # Format depending on whether or not the query is a "feeling lucky" query self.feeling_lucky = q.startswith('! ') self.query = q[2:] if self.feeling_lucky else q return self.query
def client(): with app.test_client() as client: with client.session_transaction() as session: session['uuid'] = 'test' session['fernet_keys'] = generate_user_keys() session['config'] = {} yield client
def get_search_results(data): secret_key = generate_user_keys() soup = Filter(user_keys=secret_key).clean(BeautifulSoup(data, 'html.parser')) main_divs = soup.find('div', {'id': 'main'}) assert len(main_divs) > 1 result_divs = [] for div in main_divs: # Result divs should only have 1 inner div if len(list(div.children)) != 1 or not div.findChild() or 'div' not in div.findChild().name: continue result_divs.append(div) return result_divs
from app.request import send_tor_signal from app.utils.session_utils import generate_user_keys from app.utils.gen_ddg_bangs import gen_bangs_json from flask import Flask from flask_session import Session import json import os from stem import Signal app = Flask(__name__, static_folder=os.path.dirname(os.path.abspath(__file__)) + '/static') app.user_elements = {} app.default_key_set = generate_user_keys() app.no_cookie_ips = [] app.config['SECRET_KEY'] = os.urandom(32) app.config['SESSION_TYPE'] = 'filesystem' app.config['VERSION_NUMBER'] = '0.2.1' app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__))) app.config['LANGUAGES'] = json.load( open(os.path.join(app.config['APP_ROOT'], '../misc/languages.json'))) app.config['COUNTRIES'] = json.load( open(os.path.join(app.config['APP_ROOT'], '../misc/countries.json'))) app.config['STATIC_FOLDER'] = os.getenv( 'STATIC_FOLDER', os.path.join(app.config['APP_ROOT'], 'static')) app.config['CONFIG_PATH'] = os.getenv( 'CONFIG_VOLUME', os.path.join(app.config['STATIC_FOLDER'], 'config')) app.config['DEFAULT_CONFIG'] = os.path.join(app.config['CONFIG_PATH'], 'config.json') app.config['SESSION_FILE_DIR'] = os.path.join(app.config['CONFIG_PATH'],
def test_generate_user_keys(): keys = generate_user_keys() assert 'text_key' in keys assert 'element_key' in keys assert keys['text_key'] not in keys['element_key']