Skip to content

Commit

Permalink
NetRocks: add proxychains proxifier support, also now proxifier setti…
Browse files Browse the repository at this point in the history
…ngs are configured on per-site basis but not one-for-all (touch #2200)
  • Loading branch information
elfmz committed May 6, 2024
1 parent 079172e commit fa01a50
Show file tree
Hide file tree
Showing 24 changed files with 321 additions and 66 deletions.
1 change: 1 addition & 0 deletions NetRocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ src/UI/DialogUtils.cpp
src/UI/Settings/ConfigurePlugin.cpp
src/UI/Settings/SiteConnectionEditor.cpp
src/UI/Settings/ExtraSiteSettings.cpp
src/UI/Settings/ProxySettings.cpp
src/UI/Settings/ConfigureProtocolSFTPSCP.cpp
src/UI/Settings/ConfigureProtocolFTP.cpp
src/UI/Settings/ConfigureProtocolSMB.cpp
Expand Down
11 changes: 8 additions & 3 deletions NetRocks/configs/plug/bel.lng
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"Капіяваць атрыбуты, якія супярэчаць &umask"
"Запамінаць працоўны каталог у наладах сайта"
"Таймаўт неўжываемых злучэнняў (сек.):"
"Падключацца праз проксі (патрабуе tsocks)"
"Мяняць файл наладак &tsocks"

"Запомніць мой выбар для гэтай аперацыі"
"Адбылася памылка"
Expand Down Expand Up @@ -46,7 +44,8 @@
"Папраўка &часу, сек. :"
"&Імя падлучэння :"
"&Дад. налады"
"Налады пратаколу"
"Нал. пратаколу"
"Нал. проксi"
"&Захаваць"
"Падклю&чыць"
"Захаваць/падклю&чыць"
Expand Down Expand Up @@ -303,3 +302,9 @@
"Налады пратаколу SHELL"
"Спосаб &доступу"
"Налады спосабу доступу"


"Налады проксі"
"Не выкарыстоўваць праксіфікатар"
"Выкарыстоўваны &праксіфікатар:"
"&Рэдагаваць канфігурацыю праксіфікатара"
8 changes: 6 additions & 2 deletions NetRocks/configs/plug/eng.lng
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"Copy attributes that override &umask"
"Remember working &directory in site settings"
"Connections pool e&xpiration (seconds):"
"Connect using &proxy (requires tsocks library)"
"Edit &tsocks configuration file"

"Re&member my choice for current operation"
"Operation failed"
Expand Down Expand Up @@ -47,6 +45,7 @@
"&Display name :"
"E&xtra options"
"Pro&tocol options"
"Prox&y options"
"&Save"
"C&onnect"
"Save/C&onnect"
Expand Down Expand Up @@ -303,3 +302,8 @@
"SHELL Protocol Options"
"&Way to access shell"
"Shell access way settings"

"Proxy settings"
"Not using proxifier"
"&Proxifier kind to use:"
"&Edit proxifier configuration"
16 changes: 15 additions & 1 deletion NetRocks/configs/plug/helpe.hlf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ $^#Configuration menu#
#Smart symlinks copying# if (by default) enabled then NetRocks will translate symlinks paths to refer file that copied in same copy operation, or, if symlinks refer file that is not being copied - then such symlink will be converted to plain file. If disabled then NetRocks will just copy symlinks as is, without any efforts to ensure their validity in the new location.
#Copy attributes that override umask# enable this options if want to have copied files modes to be exactly same as on source files, even in target system umask prevents some mode bits from being set.
#Connections pool expiration# when exiting from some remote FS navigation NetRocks will keep actual connection active for specified amount of time and if same server connection will be established before expiration - it will use preserved connection instead of establishing new.
#Connect using proxy# enable this option to enable protocol-invariant proxy server tunneling. This options uses tsocks library and thus can be enabled only if it installed. Also you will need to edit its configuration file to adjust it to your needs.

~Contents~@Contents@

Expand All @@ -83,6 +82,7 @@ $^#Site connection editor#
This dialog allows you to create new connection site or modify existing connection site settings. You should select protocol you want use and the define connection settings, like #hostname and port# to connect to, #login mode# and #username and password# if needed.
Also by clicking on #Extra options# button you can modify some ~extra site settings~@ExtraSiteSettings@.
Also by clicking on #Protocol options# button you can modify some protocol-specific settings.
Also by clicking on #Proxy options# button you can modify generic ~proxy settings~@ProxySettings@.
~SFTP:// and SCP:// protocols specific options~@ProtocolOptionsSFTPSCP@
~SHELL:// protocols specific options~@ProtocolOptionsSHELL@
~FTP:// and FTPS:// protocols specific options~@ProtocolOptionsFTP@
Expand Down Expand Up @@ -229,6 +229,20 @@ $^#DAV:// and DAVS:// protocol specific options#

~Contents~@Contents@

@ProxySettings
$^#NetRocks plugin#
$^#Version 1.0#
$^#Copyright (C) 2019 elfmz#
$^#Contents
$^#Proxy settings dialog#

This dialog allows you to specify generic proxy settings for connection. Currently such generic support is implemented by using of external 'proxifier' tool. Two such tools are supported: #proxychains# and #tsocks#. So in order to use this option
you have to install any of them (however proxychains is recommended) and edit its configuration in this dialog. This configuration will be used only with chosen connection and stored in site connection settings.

~Contents~@Contents@



@Contact
$^#NetRocks plugin#
$^#Version 1.0#
Expand Down
10 changes: 7 additions & 3 deletions NetRocks/configs/plug/rus.lng
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"Копировать атрибуты противоречащие &umask"
"Запоминать рабочий каталог в настройках сайта"
"Таймаут неиспользуемых соединений (сек.):"
"Подключаться через прокси (требует tsocks)"
"Редактировать файл конфигурации &tsocks"

"Запомнить мой выбор для этой операции"
"Произошла ошибка"
Expand Down Expand Up @@ -46,7 +44,8 @@
"Поправка &времени, сек:"
"&Имя подключения :"
"&Доп. настройки"
"Настройки протокола"
"Настр. протокола"
"Настр. прокси"
"&Сохранить"
"Под&ключить"
"Сохр./под&ключить"
Expand Down Expand Up @@ -303,3 +302,8 @@
"Настройки протокола SHELL"
"Способ &доступа:"
"Настройки способа доступа"

"Настройки прокси"
"Не использовать проксификатор"
"Используемый &проксификатор:"
"&Редактировать конфигурацию проксификатора"
25 changes: 20 additions & 5 deletions NetRocks/src/Host/HostRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ void HostRemote::ReInitialize()

fprintf(stderr, "NetRocks: starting broker '%s' '%s' '%s' in '%s'\n",
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, work_path.c_str());
const bool use_tsocks = G.GetGlobalConfigBool("UseProxy", false);

UnlinkScope prxf_cfg;
std::string prxf = sc_options.GetString("Proxifier");
if (!prxf.empty()) {
prxf_cfg = InMyTemp(StrPrintf("NetRocks/proxy/run_%u.cfg", getpid()).c_str());
const std::string &cfg_content = sc_options.GetString(std::string("Proxifier_").append(prxf).c_str());
if (!WriteWholeFile(prxf_cfg.c_str(), cfg_content)) {
fprintf(stderr, "NetRocks: error %d creating proxifier config '%s'\n", errno, prxf_cfg.c_str());
prxf.clear();
}
}

pid_t pid = fork();
if (pid == 0) {
Expand All @@ -271,13 +281,18 @@ void HostRemote::ReInitialize()
}
}
}
if (use_tsocks) {
if (prxf == "tsocks") {
setenv("LD_PRELOAD", "libtsocks.so", 1);
setenv("TSOCKS_CONFFILE", G.tsocks_config.c_str(), 1);
setenv("TSOCKS_CONFFILE", prxf_cfg.c_str(), 1);
}
if (fork() == 0) {
execl(broker_pathname.c_str(),
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, keep_alive_arg, NULL);
if (prxf == "proxychains") {
execlp("proxychains", "proxychains", "-f", prxf_cfg.c_str(),
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, keep_alive_arg, NULL);
} else {
execl(broker_pathname.c_str(),
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, keep_alive_arg, NULL);
}
_exit(-1);
exit(-2);
}
Expand Down
38 changes: 0 additions & 38 deletions NetRocks/src/UI/Settings/ConfigurePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
| [ ] Copy attributes that overrides umask |
| [ ] Remember working directory in site settings |
| Connections pool expiration (seconds): [ ] |
| [ ] Connect using proxy (requires tsocks library) |
| [ Edit tsocks configuration file ] |
|------------------------------------------------------------|
| [ OK ] [ Cancel ] |
============================================================
Expand Down Expand Up @@ -62,38 +60,9 @@ class ConfigurePlugin : protected BaseDialog
int _i_umask_override = -1;
int _i_remember_directory = -1;
int _i_conn_pool_expiration = -1;
int _i_use_proxy = -1, _i_edit_tsocks_config = -1;

int _i_ok = -1, _i_cancel = -1;

virtual LONG_PTR DlgProc(int msg, int param1, LONG_PTR param2)
{
if (msg == DN_INITDIALOG) {
struct stat s{};
if (stat(DEFAULT_TSOCKS_CONFIG, &s) == -1) {
SetEnabledDialogControl(_i_use_proxy, false);
SetEnabledDialogControl(_i_edit_tsocks_config, false);
} else {
SetEnabledDialogControl(_i_edit_tsocks_config, IsCheckedDialogControl(_i_use_proxy));
}

} else if (msg == DN_BTNCLICK && param1 == _i_use_proxy) {
bool checked = IsCheckedDialogControl(_i_use_proxy);
SetEnabledDialogControl(_i_edit_tsocks_config, checked);
if (checked) {
EnsureTSocksConfigExists();
}
return TRUE;

} else if (msg == DN_BTNCLICK && param1 == _i_edit_tsocks_config) {
G.info.Editor(StrMB2Wide(G.tsocks_config).c_str(),
NULL, -1, -1, -1, -1, EF_DISABLEHISTORY, 1, 1, CP_UTF8);
return TRUE;
}

return BaseDialog::DlgProc(msg, param1, param2);
}

public:
ConfigurePlugin()
{
Expand All @@ -118,11 +87,6 @@ class ConfigurePlugin : protected BaseDialog
_di.AddAtLine(DI_TEXT, 5,58, 0, MConnPoolExpiration);
_i_conn_pool_expiration = _di.AddAtLine(DI_FIXEDIT, 59,62, DIF_MASKEDIT, "30", "9999");

_di.NextLine();
_i_use_proxy = _di.AddAtLine(DI_CHECKBOX, 5,62, 0, MConnectUsingProxy);
_di.NextLine();
_i_edit_tsocks_config = _di.AddAtLine(DI_BUTTON, 9,60, 0, MEditTSocksConfig);

_di.NextLine();
_di.AddAtLine(DI_TEXT, 4,61, DIF_BOXCOLOR | DIF_SEPARATOR);

Expand All @@ -144,7 +108,6 @@ class ConfigurePlugin : protected BaseDialog
SetCheckedDialogControl( _i_umask_override, G.GetGlobalConfigBool("UMaskOverride", false) );
SetCheckedDialogControl( _i_remember_directory, G.GetGlobalConfigBool("RememberDirectory", false) );
LongLongToDialogControl( _i_conn_pool_expiration, G.GetGlobalConfigInt("ConnectionsPoolExpiration", 30) );
SetCheckedDialogControl( _i_use_proxy, G.GetGlobalConfigBool("UseProxy", false) );

if (Show(L"PluginOptions", 6, 2) == _i_ok) {
auto gcw = G.GetGlobalConfigWriter();
Expand All @@ -154,7 +117,6 @@ class ConfigurePlugin : protected BaseDialog
gcw.SetBool("UMaskOverride", IsCheckedDialogControl(_i_umask_override) );
gcw.SetBool("RememberDirectory", IsCheckedDialogControl(_i_remember_directory) );
gcw.SetInt("ConnectionsPoolExpiration", LongLongFromDialogControl( _i_conn_pool_expiration) );
gcw.SetBool("UseProxy", IsCheckedDialogControl(_i_use_proxy) );
}
}
};
Expand Down
Loading

0 comments on commit fa01a50

Please sign in to comment.