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 (#1240)
* Updated UI Config to respect User Agent in ENV file if exists * Updated version number
This commit is contained in:
parent
e4cabe3e5b
commit
69d1ddae0c
7 changed files with 46 additions and 13 deletions
|
|
@ -37,8 +37,12 @@ def get_rule_for_selector(stylesheet: CSSStyleSheet,
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
# User agent configuration
|
# User agent configuration - default to env_conf if environment variables exist, otherwise default
|
||||||
self.user_agent = kwargs.get('user_agent', 'LYNX_UA')
|
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.custom_user_agent = kwargs.get('custom_user_agent', '')
|
||||||
self.use_custom_user_agent = kwargs.get('use_custom_user_agent', False)
|
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:
|
def gen_user_agent(config, is_mobile) -> str:
|
||||||
# Define the Lynx user agent
|
# Define the default PlayStation Portable user agent (replaces Lynx)
|
||||||
LYNX_UA = 'Lynx/2.9.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/3.4.0'
|
DEFAULT_UA = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'
|
||||||
|
|
||||||
# If using custom user agent, return the custom string
|
# If using custom user agent, return the custom string
|
||||||
if config.user_agent == 'custom' and config.custom_user_agent:
|
if config.user_agent == 'custom' and config.custom_user_agent:
|
||||||
return config.custom_user_agent
|
return config.custom_user_agent
|
||||||
|
|
||||||
# If using Lynx user agent
|
# If using environment configuration
|
||||||
if config.user_agent == 'LYNX_UA':
|
if config.user_agent == 'env_conf':
|
||||||
return LYNX_UA
|
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'
|
firefox = random.choice(['Choir', 'Squier', 'Higher', 'Wire']) + 'fox'
|
||||||
linux = random.choice(['Win', 'Sin', 'Gin', 'Fin', 'Kin']) + 'ux'
|
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
|
print(f"Setting custom user agent to: {config_data['custom_user_agent']}") # Debug log
|
||||||
else:
|
else:
|
||||||
config_data['use_custom_user_agent'] = False
|
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
|
# Save config by name to allow a user to easily load later
|
||||||
if name:
|
if name:
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,20 @@ const setupConfigLayout = () => {
|
||||||
|
|
||||||
content.classList.toggle("open");
|
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 => {
|
const loadConfig = event => {
|
||||||
|
|
|
||||||
|
|
@ -231,8 +231,8 @@
|
||||||
<div class="config-div config-div-user-agent">
|
<div class="config-div config-div-user-agent">
|
||||||
<label for="config-user-agent">User Agent: </label>
|
<label for="config-user-agent">User Agent: </label>
|
||||||
<select name="user_agent" id="config-user-agent">
|
<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="env_conf" {% if config.user_agent == 'env_conf' %}selected{% endif %}>Use ENV Conf</option>
|
||||||
<option value="" {% if config.user_agent == '' and config.user_agent != 'LYNX_UA' %}selected{% endif %}>Original (Random)</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>
|
<option value="custom" {% if config.user_agent == 'custom' %}selected{% endif %}>Custom</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@ optional_dev_tag = ''
|
||||||
if os.getenv('DEV_BUILD'):
|
if os.getenv('DEV_BUILD'):
|
||||||
optional_dev_tag = '.dev' + 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
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ name: whoogle
|
||||||
description: A self hosted search engine on Kubernetes
|
description: A self hosted search engine on Kubernetes
|
||||||
type: application
|
type: application
|
||||||
version: 0.1.0
|
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
|
icon: https://github.com/benbusby/whoogle-search/raw/main/app/static/img/favicon/favicon-96x96.png
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue