mirror of
https://github.com/benbusby/whoogle-search.git
synced 2026-03-11 08:54:34 +00:00
Updated UI Config to respect User Agent in ENV file if exists
This commit is contained in:
parent
e4cabe3e5b
commit
628e3376d0
5 changed files with 44 additions and 11 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue