From cae057252ecb28b043b6b7cf376dbb41ab20b170 Mon Sep 17 00:00:00 2001 From: Anya Lin Date: Tue, 1 Oct 2024 17:27:36 +0800 Subject: [PATCH] feat(node/scripts/subscribe): allow use custom UA when updating subscriptions --- htdocs/luci-static/resources/view/homeproxy/node.js | 3 +++ root/etc/homeproxy/scripts/homeproxy.uc | 7 +++++-- root/etc/homeproxy/scripts/update_subscriptions.uc | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/htdocs/luci-static/resources/view/homeproxy/node.js b/htdocs/luci-static/resources/view/homeproxy/node.js index d84e2c8c..88ceb30a 100644 --- a/htdocs/luci-static/resources/view/homeproxy/node.js +++ b/htdocs/luci-static/resources/view/homeproxy/node.js @@ -1331,6 +1331,9 @@ return view.extend({ o.depends({'filter_nodes': 'disabled', '!reverse': true}); o.rmempty = false; + o = s.taboption('subscription', form.Value, 'user_agent', _('User-Agent')); + o.placeholder = 'Wget/1.21 (HomeProxy, like v2rayN)'; + o = s.taboption('subscription', form.Flag, 'allow_insecure', _('Allow insecure'), _('Allow insecure connection by default when add nodes from subscriptions.') + '
' + diff --git a/root/etc/homeproxy/scripts/homeproxy.uc b/root/etc/homeproxy/scripts/homeproxy.uc index b846c434..5623ab0d 100644 --- a/root/etc/homeproxy/scripts/homeproxy.uc +++ b/root/etc/homeproxy/scripts/homeproxy.uc @@ -74,11 +74,14 @@ export function getTime(epoch) { }; -export function wGET(url) { +export function wGET(url, ua) { if (!url || type(url) !== 'string') return null; - const output = executeCommand(`/usr/bin/wget -qO- --user-agent 'Wget/1.21 (HomeProxy, like v2rayN)' --timeout=10 ${shellQuote(url)}`) || {}; + if (!ua) + ua = 'Wget/1.21 (HomeProxy, like v2rayN)'; + + const output = executeCommand(`/usr/bin/wget -qO- --user-agent ${shellQuote(ua)} --timeout=10 ${shellQuote(url)}`) || {}; return trim(output.stdout); }; /* Utilities end */ diff --git a/root/etc/homeproxy/scripts/update_subscriptions.uc b/root/etc/homeproxy/scripts/update_subscriptions.uc index d10639f0..6ed08f3a 100755 --- a/root/etc/homeproxy/scripts/update_subscriptions.uc +++ b/root/etc/homeproxy/scripts/update_subscriptions.uc @@ -31,6 +31,7 @@ const ucimain = 'config', ucisubscription = 'subscription'; const allow_insecure = uci.get(uciconfig, ucisubscription, 'allow_insecure') || '0', + user_agent = uci.get(uciconfig, ucisubscription, 'user_agent'), filter_mode = uci.get(uciconfig, ucisubscription, 'filter_nodes') || 'disabled', filter_keywords = uci.get(uciconfig, ucisubscription, 'filter_keywords') || [], packet_encoding = uci.get(uciconfig, ucisubscription, 'packet_encoding') || 'xudp', @@ -457,7 +458,7 @@ function main() { const groupHash = calcStringMD5(url); node_cache[groupHash] = {}; - const res = wGET(url); + const res = wGET(url, user_agent); if (isEmpty(res)) { log(sprintf('Failed to fetch resources from %s.', url)); continue;