Skip to content

Commit

Permalink
feat(node/scripts/subscribe): allow use custom UA when updating subsc…
Browse files Browse the repository at this point in the history
…riptions
  • Loading branch information
muink committed Oct 1, 2024
1 parent 6e2ba05 commit cae0572
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions htdocs/luci-static/resources/view/homeproxy/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.') +
'<br/>' +
Expand Down
7 changes: 5 additions & 2 deletions root/etc/homeproxy/scripts/homeproxy.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion root/etc/homeproxy/scripts/update_subscriptions.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cae0572

Please sign in to comment.