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 @@
diff --git a/app/version.py b/app/version.py index 58b4367..cbe105e 100644 --- a/app/version.py +++ b/app/version.py @@ -4,4 +4,4 @@ optional_dev_tag = '' if os.getenv('DEV_BUILD'): optional_dev_tag = '.dev' + os.getenv('DEV_BUILD') -__version__ = '0.9.3' + optional_dev_tag +__version__ = '0.9.4' + optional_dev_tag diff --git a/charts/whoogle/Chart.yaml b/charts/whoogle/Chart.yaml index 17085db..074e907 100644 --- a/charts/whoogle/Chart.yaml +++ b/charts/whoogle/Chart.yaml @@ -3,7 +3,7 @@ name: whoogle description: A self hosted search engine on Kubernetes type: application version: 0.1.0 -appVersion: 0.9.3 +appVersion: 0.9.4 icon: https://github.com/benbusby/whoogle-search/raw/main/app/static/img/favicon/favicon-96x96.png