From 69d1ddae0c31391c65b3a516a649a0ec3b47bb19 Mon Sep 17 00:00:00 2001 From: Don <32144818+Don-Swanson@users.noreply.github.com> Date: Fri, 12 Sep 2025 20:24:44 -0500 Subject: [PATCH] Updated UI Config to respect User Agent in ENV file if exists (#1240) * Updated UI Config to respect User Agent in ENV file if exists * Updated version number --- app/models/config.py | 8 ++++++-- app/request.py | 25 +++++++++++++++++++------ app/routes.py | 4 +++- app/static/js/controller.js | 14 ++++++++++++++ app/templates/index.html | 4 ++-- app/version.py | 2 +- charts/whoogle/Chart.yaml | 2 +- 7 files changed, 46 insertions(+), 13 deletions(-) diff --git a/app/models/config.py b/app/models/config.py index 734165c..2e73f6d 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -37,8 +37,12 @@ def get_rule_for_selector(stylesheet: CSSStyleSheet, class Config: def __init__(self, **kwargs): - # User agent configuration - self.user_agent = kwargs.get('user_agent', 'LYNX_UA') + # User agent configuration - default to env_conf if environment variables exist, otherwise default + env_user_agent = os.getenv('WHOOGLE_USER_AGENT', '') + env_mobile_agent = os.getenv('WHOOGLE_USER_AGENT_MOBILE', '') + default_ua_option = 'env_conf' if (env_user_agent or env_mobile_agent) else 'default' + + self.user_agent = kwargs.get('user_agent', default_ua_option) self.custom_user_agent = kwargs.get('custom_user_agent', '') self.use_custom_user_agent = kwargs.get('use_custom_user_agent', False) diff --git a/app/request.py b/app/request.py index defbb93..41523e9 100644 --- a/app/request.py +++ b/app/request.py @@ -73,18 +73,31 @@ def send_tor_signal(signal: Signal) -> bool: def gen_user_agent(config, is_mobile) -> str: - # Define the Lynx user agent - LYNX_UA = 'Lynx/2.9.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/3.4.0' + # Define the default PlayStation Portable user agent (replaces Lynx) + DEFAULT_UA = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)' # If using custom user agent, return the custom string if config.user_agent == 'custom' and config.custom_user_agent: return config.custom_user_agent - # If using Lynx user agent - if config.user_agent == 'LYNX_UA': - return LYNX_UA + # If using environment configuration + if config.user_agent == 'env_conf': + if is_mobile: + env_ua = os.getenv('WHOOGLE_USER_AGENT_MOBILE', '') + if env_ua: + return env_ua + else: + env_ua = os.getenv('WHOOGLE_USER_AGENT', '') + if env_ua: + return env_ua + # If env vars are not set, fall back to default + return DEFAULT_UA - # If no custom user agent is set, generate a random one + # If using default user agent + if config.user_agent == 'default': + return DEFAULT_UA + + # If no custom user agent is set, generate a random one (for backwards compatibility) firefox = random.choice(['Choir', 'Squier', 'Higher', 'Wire']) + 'fox' linux = random.choice(['Win', 'Sin', 'Gin', 'Fin', 'Kin']) + 'ux' diff --git a/app/routes.py b/app/routes.py index b33e6a5..65ab9d3 100644 --- a/app/routes.py +++ b/app/routes.py @@ -458,7 +458,9 @@ def config(): print(f"Setting custom user agent to: {config_data['custom_user_agent']}") # Debug log else: config_data['use_custom_user_agent'] = False - config_data['custom_user_agent'] = '' + # Only clear custom_user_agent if not using custom option + if config_data['user_agent'] != 'custom': + config_data['custom_user_agent'] = '' # Save config by name to allow a user to easily load later if name: diff --git a/app/static/js/controller.js b/app/static/js/controller.js index 9f05e16..dbf1e9c 100644 --- a/app/static/js/controller.js +++ b/app/static/js/controller.js @@ -34,6 +34,20 @@ const setupConfigLayout = () => { content.classList.toggle("open"); }); + + // Setup user agent dropdown handler + const userAgentSelect = document.getElementById("config-user-agent"); + const customUserAgentDiv = document.querySelector(".config-div-custom-user-agent"); + + if (userAgentSelect && customUserAgentDiv) { + userAgentSelect.addEventListener("change", function() { + if (this.value === "custom") { + customUserAgentDiv.style.display = "block"; + } else { + customUserAgentDiv.style.display = "none"; + } + }); + } }; const loadConfig = event => { diff --git a/app/templates/index.html b/app/templates/index.html index 5693300..bb5e6a9 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -231,8 +231,8 @@