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
This commit is contained in:
Don 2025-09-12 20:24:44 -05:00 committed by GitHub
parent e4cabe3e5b
commit 69d1ddae0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 46 additions and 13 deletions

View file

@ -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)

View file

@ -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'

View file

@ -458,6 +458,8 @@ def config():
print(f"Setting custom user agent to: {config_data['custom_user_agent']}") # Debug log
else:
config_data['use_custom_user_agent'] = False
# 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

View file

@ -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 => {

View file

@ -231,8 +231,8 @@
<div class="config-div config-div-user-agent">
<label for="config-user-agent">User Agent: </label>
<select name="user_agent" id="config-user-agent">
<option value="LYNX_UA" {% if not config.user_agent or config.user_agent == 'LYNX_UA' %}selected{% endif %}>Lynx Browser</option>
<option value="" {% if config.user_agent == '' and config.user_agent != 'LYNX_UA' %}selected{% endif %}>Original (Random)</option>
<option value="env_conf" {% if config.user_agent == 'env_conf' %}selected{% endif %}>Use ENV Conf</option>
<option value="default" {% if config.user_agent == 'default' %}selected{% endif %}>Default</option>
<option value="custom" {% if config.user_agent == 'custom' %}selected{% endif %}>Custom</option>
</select>
</div>

View file

@ -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

View file

@ -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