giuspen / cherrytree

cherrytree
https://www.giuspen.net/cherrytree/
Other
3.29k stars 457 forks source link

[FR] Internet proxy configuration in menu Preferences missing #2522

Open jljuan opened 3 weeks ago

jljuan commented 3 weeks ago

Is your feature request related to a problem? Please describe. In some cases, my host is placed behind a proxy in order to access Internet. It seems that cherrytree lacks any UI/Configuration/Command line parameters in order to configure (and use) proxies connexions.

Describe the solution you'd like

gitvectors commented 3 weeks ago

Workaround

Often CodeBoxes are overlooked. Cannot you leverage CodeBox (Python) embedded in node to emulate proxy connection?

https://www.scrapingbee.com/blog/python-requests-proxy/#:~:text=To%20use%20a%20proxy%20in,webpage%20you're%20scraping%20from[.](https://www.scrapingbee.com/blog/python-requests-proxy/#:~:text=To%20use%20a%20proxy%20in,webpage%20you're%20scraping%20from.)

Create a node named Proxy Connection then execute the Python script embedded in Proxy Connection node.

jljuan commented 3 weeks ago

Thank you @gitvectors for your workaround but the purpose of my request is for cherrytree tool itself : controling availables updates for exemple, allowing to access an url directly from a node, etc. Every resources behind a proxy should be reachable directly from CT (well its my wish). I suppose that codeboxes will inherit CT environment, then, if a proxy is taken into account, its code will directly use the proxy in case of Internet access.

By the way, you are right, I don't know how to use codeboxes, I am just aware of them. I will look forward to enhance my cherrytree skills ;)

gitvectors commented 3 weeks ago

I'm not sure of your intended application but my own experiments allow CherryTree to "pair" with other apps to fill in any gaps. For example a CT session can drive a paired app such as Actiona which runs proxy operatons. I know that you prefer to see this as another feature but CherryTree creator giuspen is a one person team who has created a very versatile tool. Hence I first look for workarounds. Another workaround is using Heroku. What would be a good "issue" is creating a more formal discussion forum like ubuntuforums.org.

jljuan commented 3 weeks ago

Hi @gitvectors,

I do understand that Giuseppe is very busy and your effort to filter requests is very welcome. I appreciate the tool, Giuseppe investment into producing such a wonderful tool and your way to help.

My request is just about allowing a CT instance to access data over an internet proxy that needs (or not) credentials to go outside the premises.

What I think, perhaps I am wrong, is for exemple into the member function:

void CtActions::check_for_newer_version()
{
...
    std::string latest_debian_changelog_from_server = fs::download_file("https://raw.githubusercontent.com/giuspen/cherrytree/master/debian/changelog");
    std::size_t openp = latest_debian_changelog_from_server.find("(");
    std::size_t closep = latest_debian_changelog_from_server.find(")");
    if (std::string::npos == openp or std::string::npos == closep or closep < openp) {
        statusbar.update_status(_("Failed to Retrieve Latest Version Information - Try Again Later."));
        return;
    }
...

to updatefs::download_file to use the proxy settings with option CURLOPT_PROXY of curl_easy_setopt, if any, to actually reach the web resource.

In this case, without proxy settings, CT cannot see a newer version and doesn't really warn about it:

 if (res != CURLE_OK) {
        spdlog::error("fs::download_file: curl_easy_perform() failed, {}", curl_easy_strerror(res));
        return "";
    }

Which log as :

[2024-06-07 18:30:04.665] [   ] [debug] fs::download_file: start downloading https://raw.githubusercontent.com/giuspen/cherrytree/master/debian/changelog
[2024-06-07 18:30:07.670] [   ] [error] fs::download_file: curl_easy_perform() failed, Timeout was reached

Despite the message in the status bar, it is not possible to try again later and the log lead us to a bad fault interpretation in this case.

My naive analysis should be completed by a deeper one with the full knowledge of CT inner design. Code is very pleasant to be read, but I am not a seasoned coder enough to see all the impacts such evolution can involve.

It's just a feature request that can help to maintain an installed version up to date !

Best regards, JL

giuspen commented 2 weeks ago

Hello @jljuan I'm honestly not familiar with the proxy setup but it seems pretty easy as just a couple of options to add via curl_easy_setopt as you pointed out and I see an example in https://stackoverflow.com/questions/65237676/using-proxy-auth-with-libcurl-in-c which also includes the authentication. I can add this in the config.cfg for now as very quick and I'm planning to release this weekend. What is your operative system so that I can give you a version to try?

jljuan commented 2 weeks ago

Hi @giuspen, it's an honor to talk with you directly ! Thank you again for your very useful product!

A win64.portable will be enough to do the tests (win11 enterprise to be more precise). I'm excited to help with this feature :)

giuspen commented 2 weeks ago

Hello @jljuan, you are very kind thank you! ;) Please try https://www.giuspen.net/software/cherrytree_1.1.2.0+40_win64_portable.7z you should find a new group in the config.cfg file:

[proxy]
proxy_urlcolonport=
proxy_username=
proxy_password=

Let me know if that works, if not please copy/paste here the output log.

jljuan commented 2 weeks ago

Hurrah ! It works !! :fireworks: 🥇

Here are the logs with no traces of failure (except the [warning] with missing parameters information):

[2024-06-14 16:21:39.293] [che] [debug] C:\Users\lambda\AppData\Local\cherrytree\config.cfg parsed
[2024-06-14 16:21:40.263] [che] [debug] autosave on 1 min
[2024-06-14 16:21:40.542] [che] [debug] fs::download_file: start downloading https://raw.githubusercontent.com/giuspen/cherrytree/master/debian/changelog
>>> above is the autocheck at startup

[2024-06-14 16:21:50.552] [che] [warning] %s Couldn't open file: %s
>>> missing %s values

[2024-06-14 16:21:52.629] [che] [debug] shift images in MenuBar/context menu
[2024-06-14 16:21:53.855] [che] [debug] fs::download_file: start downloading https://raw.githubusercontent.com/giuspen/cherrytree/master/debian/changelog
>>> on request through Help menu

[2024-06-14 16:22:40.645] [che] [debug] autoSaveCounter->0
[2024-06-14 16:22:40.645] [che] [debug] autosave no need

The status bar is updated according to reality: statusbar-good-msg

For this test case, only the configuration item proxy_urlcolonport was updated with the url and port of the server proxy. As I don't need login/passwd, I can't confirm that these options works correctly, but I will suppose they will do, by the way, they seems to be skipped as expected.

Waiting for the official release now! Thanks again for implementing solution B. Any roadmap for solution A now :stuck_out_tongue_winking_eye: !

giuspen commented 2 weeks ago

Ok great, thanks for testing. The configurability in the GUI, even though a simple job, requires all languages updates, so cannot do it for now, I will try to put it in the next major release (v1.2.0)