Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Proxy and Redirects in Updater-Script #5

Open
wazilla opened this issue Jan 7, 2025 · 5 comments
Open

Add Support for Proxy and Redirects in Updater-Script #5

wazilla opened this issue Jan 7, 2025 · 5 comments

Comments

@wazilla
Copy link

wazilla commented Jan 7, 2025

Hi,

i've had some problems getting this to work behind a corporate proxy. Maybe you could switch to cURL (instead of wget) in the Updater-Script to fix these issues for others in the future?

  • First i had to set an EnvVar for wget to use the proxy: set http_proxy=http://#host#:#port#
  • Then i ran into a problem, because github sends a 302 Redirect, which isn't followed by wget
  • Other Versions of wget seems to have a parameter for this (--max-redirect=20), but your version (thru busybox) doenst support this parameter
  • The solution in the end was to use curl instead of wget for the download.

Here are my changes to the Updater.bat - Script:

set http_proxy=http://localhost:3128
set CURL="%HERE%App\Utils\curl.exe"
%CURL% --insecure --location --proxy %http_proxy% %OBSIDIAN% -o TMP\Obsidian-%LATEST%.exe

@Numstr
Copy link
Owner

Numstr commented Jan 7, 2025

Hi, thanks for the info, yeah maybe i should go back to CURL.
But also need to add some checks for the presence of proxy, or leave it to manual edit.

What proxy are you using?
Is this a standard WinHTTP proxy or something else?
Is authorization required?
Can you show me the CMD output of this command:

  1. netsh winhttp show proxy

Do you use WGET with -Y or -e use_proxy=on / -e use_proxy=yes (for newer versions) flag after URL?

Change line 97 of the updater.bat

%BUSYBOX% wget %OBSIDIAN% -O TMP\Obsidian-%LATEST%.exe

to this

:Your proxy without http / https
set http_proxy=localhost:3128
%BUSYBOX% wget %OBSIDIAN% -Y -O TMP\Obsidian-%LATEST%.exe

@wazilla
Copy link
Author

wazilla commented Jan 8, 2025

I'm not really sure which proxy-software is used, i think it's squid-cache. For development i've added https://github.com/genotrance/px as "ntlm-proxy" running on my local machine. Because our corporate proxy needs NTLM-authentifaction (Microsoft AD) and we need to regularly change ours password. And in a lot of tools (e.g. IDEA IntelliJ) you need to manually configure the proxy (including user/pw)... And then i change my pwd, forgot to update my IntelliJ-Settings and after 3 wrong attempt my AD-Domain accout is locked and i need to submit a ticket :-(.
So PX to the rescue ;-) App -> PX -> Squid -> Web

C:>netsh winhttp show proxy
Aktuelle WinHTTP-Proxyeinstellungen:
DirectAccess (kein Proxyserver).

The -Y switch for wget is working, you have to add the "on" parameter

%BUSYBOX% wget %OBSIDIAN% -Y on -O TMP\Obsidian-%LATEST%.exe

But then i still get a Textfile with the "HTTP/1.1 302 Found" Response instead of the Obsidian.exe

There seems to be a "--max-redirect=20"-Parameter which could help, but unfortunately it isn't supported by your version of busybox :-(.

I would suggest...

  • to use cURL
  • the user has to manually set the EnvVar "http_proxy" (or "https_proxy")
  • your script checks if this var is set and build the commandline for cURL accordingly
  • maybe some hint / documentation at the top of the script
  • and maybe some more "exists" checks in the following steps. In my case 7-Zip failed, because the Textfile could not be extracted. After that, the next 7-Zip (for "ARCH") fails, because the file doesnt exists.

@Numstr
Copy link
Owner

Numstr commented Jan 8, 2025

I forgot that Windows 10/11 has CURL by default, so no additions are required. CURL can only be used if PROXY is set to true. I changed the bat file, can you check?

@wazilla
Copy link
Author

wazilla commented Jan 9, 2025

Almost ;-)

You're still using wget for obtaining the latest version. So wget needs to pick up the proxy too. For this, the variable needs to have the name "HTTP_PROXY" (with underscore).

Here's my modifications...

At the start:

:::::: PROXY
rem uncomment and modify the following line to use a proxy for internet access
rem set HTTP_PROXY=http://127.0.0.1:3128

And later on

set OBSIDIAN="https://github.com/obsidianmd/obsidian-releases/releases/download/v%LATEST%/Obsidian-%LATEST%.exe"
if "%HTTP_PROXY" NEQ "" (
set CURL_OPTS=-x %HTTP_PROXY%
)
%CURL% -k -L %CURL_OPTS% %OBSIDIAN% -o TMP\Obsidian-%LATEST%.exe

In the default case (no proxy) the variable CURL_OPTS is empty, so it should work like before (can't test this here). In case of a proxy, the commandline is expanded, so that curl uses the proxy.
And the EnvVar itself is used by wget for the other downloads though a proxy ;-)

@Numstr
Copy link
Owner

Numstr commented Jan 9, 2025

Back to cURL, because busybox wget only supports http proxy. The http_proxy, HTTP_PROXY variables used by many apps, so I don't set it yet. In the future they can be used to separate proxies. Everything should work now, if not, try adding --insecure to cURL or set http_proxy variable again to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants