felixhageloh / uebersicht

ˈyːbɐˌzɪçt
GNU General Public License v3.0
4.56k stars 166 forks source link

Not using proxy settings #88

Open shredsonic opened 9 years ago

shredsonic commented 9 years ago

It looks like Übersicht is not using any of my proxy settings. When I connect to a normal network, the widgets seem to work fine. When I connect to a network a proxy setup, my widgets can't connect to the internet. Could this be added or is there a way I can set proxy settings for the app?

felixhageloh commented 9 years ago

I think the issue is that commands are run in a terminal (essentially) and a quick google suggests that the terminal doesn't use OSX' proxy settings. This url has more info an maybe also some solutions: http://apple.stackexchange.com/questions/99671/how-to-connect-to-the-internet-from-terminal-when-using-a-proxy-with-authenticat

deanishe commented 9 years ago

This issue came up with Alfred 2, in that its workflows (which are Python/Ruby/bash scripts) wouldn't use the system proxy for the same reason.

There are a couple of problems with hard-coding http(s)_proxy manually in a script:

  1. It falls apart if you use your computer on different networks.
  2. You'll most likely have to add it to every single widget that uses HTTP(S).

It is possible, but difficult, to get the currently configured proxy server via the command line using networksetup, but it's complicated and something that every widget would probably have to do for itself.

The best solution (which is what Alfred did) was for Alfred to query the system network settings for the configured proxy (which is way easier from a Mac app than from a shell) and set the http_proxy and https_proxy environmental vars for NSTask. Python, Ruby and curl will automatically use the proxy specified in those environmental variables without any user intervention, which is fantastic, as it's then something that widget authors wouldn't even have to think about.

I'm afraid I have no idea precisely how to do that :(

felixhageloh commented 9 years ago

awesome, thanks for the info @deanishe! I will see what i can do ... problem is that commands aren't run using NSTask, but via the nodejs backend (child_process), so I'll see if there is an easy way to accomplish the same in node

deanishe commented 9 years ago

I've likely read the code wrong (I'm not good with Objective-C, and may be looking in the wrong place), but isn't the nodejs backend launched via NSTask?

felixhageloh commented 9 years ago

you are right! But the nodejs process then launches a bash process to run the command and I am not sure whether that process will also inherit the proxy settings. Worth trying tho!

deanishe commented 9 years ago

Should do. It's just another environmental variable and will be inherited by subprocesses. erlaubt

felixhageloh commented 7 years ago

In v1.2.48, you can now load your bash env (option is in Preferences), which should probably fix this. Feel free to re-open if that is not the case!

deanishe commented 7 years ago

That won't work with the system proxy settings. macOS doesn't export them to your shell environment and—as noted above—extracting them via the networksetup command is difficult.

It would "just work" if Übersicht retrieved the settings itself and set http_proxy and https_proxy. This is much easier for a native program than for scripts.

Also, it won't work for people who use zsh, fish etc.

felixhageloh commented 7 years ago

I see, sorry I was too quick closing this then!

zacklocx commented 7 years ago

the default shell which uebersicht use is bash, but i use zsh as my default shell, uebersicht can not use zsh's profile, that makes me inconvenience to write scripts, hope this can be improved soon

thanks so much

zacklocx commented 7 years ago

i try to modify command_server.coffee, the code is:

{spawn} = require('child_process')
module.exports = (workingDir, useLoginShell) ->
  args = if useLoginShell then ['-l'] else []
  # the Connect middleware
  (req, res, next) ->
    return next() unless req.method == 'POST' and req.url == '/run/'
    shell = spawn 'bash', args, cwd: workingDir

change "bash" to "zsh", but still i can NOT get a correct result

btw: there are some commands which are only available in my zsh shell

felixhageloh commented 7 years ago

@zacklocx you could try prefixing your commands with chsh -s /bin/zsh, i.e. switch to zsh. Not sure if there is a noticeable performance impact tho

leveneg commented 7 years ago
cors_host = '127.0.0.1' # bind to loopback only
  cors_port = port + 1
  cors_proxy.createServer(
    originWhitelist: ['http://127.0.0.1:' + port]
    requireHeader: ['origin']
    removeHeaders: ['cookie']
    httpProxyOptions:
        secure: false
  ).listen(cors_port, cors_host, ->
    console.log 'CORS Anywhere on port', cors_port
  )

Isn't cors-anywhere using proxy-from-env ? I've added httpProxyOptions: { secure: false } to my server config here for now. Hoping to get a chance to dig into this later.