SiteAdvanced.cpp 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <CoreMain.h>
  6. #include <Common.h>
  7. #include <TextsWin.h>
  8. #include <TextsCore.h>
  9. #include <HelpWin.h>
  10. #include <VCLCommon.h>
  11. #include "WinInterface.h"
  12. #include "SiteAdvanced.h"
  13. #include "GUITools.h"
  14. #include "Tools.h"
  15. #include "WinConfiguration.h"
  16. #include "PuttyTools.h"
  17. #include "TerminalManager.h"
  18. #include "Authenticate.h"
  19. //---------------------------------------------------------------------
  20. #pragma link "ComboEdit"
  21. #pragma link "PasswordEdit"
  22. #pragma link "UpDownEdit"
  23. #ifndef NO_RESOURCES
  24. #pragma resource "*.dfm"
  25. #endif
  26. //---------------------------------------------------------------------------
  27. // Sheet tag:
  28. // 01 top, 02 indented
  29. //---------------------------------------------------------------------------
  30. bool __fastcall DoSiteAdvancedDialog(TSessionData * SessionData)
  31. {
  32. TSiteAdvancedDialog * SiteAdvancedDialog = new TSiteAdvancedDialog(Application);
  33. bool Result;
  34. try
  35. {
  36. Result = SiteAdvancedDialog->Execute(SessionData);
  37. }
  38. __finally
  39. {
  40. delete SiteAdvancedDialog;
  41. }
  42. return Result;
  43. }
  44. //---------------------------------------------------------------------
  45. static const UnicodeString DefaultRecycleBinPath = L"/tmp";
  46. //---------------------------------------------------------------------
  47. __fastcall TSiteAdvancedDialog::TSiteAdvancedDialog(TComponent * AOwner) :
  48. TForm(AOwner)
  49. {
  50. NoUpdate = 0;
  51. // we need to make sure that window procedure is set asap
  52. // (so that CM_SHOWINGCHANGED handling is applied)
  53. UseSystemSettings(this);
  54. InitControls();
  55. PageControl->ActivePage = EnvironmentSheet;
  56. }
  57. //---------------------------------------------------------------------
  58. void __fastcall TSiteAdvancedDialog::InitControls()
  59. {
  60. ComboAutoSwitchInitialize(UtfCombo);
  61. ComboAutoSwitchInitialize(BugIgnore1Combo);
  62. ComboAutoSwitchInitialize(BugPlainPW1Combo);
  63. ComboAutoSwitchInitialize(BugRSA1Combo);
  64. ComboAutoSwitchInitialize(BugHMAC2Combo);
  65. ComboAutoSwitchInitialize(BugDeriveKey2Combo);
  66. ComboAutoSwitchInitialize(BugRSAPad2Combo);
  67. ComboAutoSwitchInitialize(BugPKSessID2Combo);
  68. ComboAutoSwitchInitialize(BugRekey2Combo);
  69. ComboAutoSwitchInitialize(BugMaxPkt2Combo);
  70. ComboAutoSwitchInitialize(BugIgnore2Combo);
  71. ComboAutoSwitchInitialize(BugWinAdjCombo);
  72. ComboAutoSwitchInitialize(SFTPBugSymlinkCombo);
  73. ComboAutoSwitchInitialize(SFTPBugSignedTSCombo);
  74. ComboAutoSwitchInitialize(FtpListAllCombo);
  75. ComboAutoSwitchInitialize(FtpUseMlsdCombo);
  76. ComboAutoSwitchInitialize(FtpForcePasvIpCombo);
  77. ComboAutoSwitchInitialize(FtpHostCombo);
  78. TunnelLocalPortNumberEdit->Items->BeginUpdate();
  79. try
  80. {
  81. UnicodeString TunnelLocalPortNumberAutoassign = TunnelLocalPortNumberEdit->Items->Strings[0];
  82. TunnelLocalPortNumberEdit->Items->Clear();
  83. TunnelLocalPortNumberEdit->Items->Add(TunnelLocalPortNumberAutoassign);
  84. for (int Index = Configuration->TunnelLocalPortNumberLow;
  85. Index <= Configuration->TunnelLocalPortNumberHigh; Index++)
  86. {
  87. TunnelLocalPortNumberEdit->Items->Add(IntToStr(Index));
  88. }
  89. }
  90. __finally
  91. {
  92. TunnelLocalPortNumberEdit->Items->EndUpdate();
  93. }
  94. HintLabel(ProxyTelnetCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  95. HintLabel(ProxyLocalCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  96. UpdateNavigationTree();
  97. SelectScaledImageList(ColorImageList);
  98. SetSessionColor((TColor)0);
  99. MenuButton(PrivateKeyToolsButton);
  100. }
  101. //---------------------------------------------------------------------
  102. void __fastcall TSiteAdvancedDialog::LoadSession()
  103. {
  104. {
  105. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  106. // Directories page
  107. SynchronizeBrowsingCheck->Checked = FSessionData->SynchronizeBrowsing;
  108. LocalDirectoryEdit->Text = FSessionData->LocalDirectory;
  109. RemoteDirectoryEdit->Text = FSessionData->RemoteDirectory;
  110. UpdateDirectoriesCheck->Checked = FSessionData->UpdateDirectories;
  111. CacheDirectoriesCheck->Checked = FSessionData->CacheDirectories;
  112. CacheDirectoryChangesCheck->Checked = FSessionData->CacheDirectoryChanges;
  113. PreserveDirectoryChangesCheck->Checked = FSessionData->PreserveDirectoryChanges;
  114. ResolveSymlinksCheck->Checked = FSessionData->ResolveSymlinks;
  115. FollowDirectorySymlinksCheck->Checked = FSessionData->FollowDirectorySymlinks;
  116. // Environment page
  117. switch (FSessionData->DSTMode)
  118. {
  119. case dstmWin:
  120. DSTModeWinCheck->Checked = true;
  121. break;
  122. case dstmKeep:
  123. DSTModeKeepCheck->Checked = true;
  124. break;
  125. default:
  126. case dstmUnix:
  127. DSTModeUnixCheck->Checked = true;
  128. break;
  129. }
  130. if (FSessionData->EOLType == eolLF)
  131. {
  132. EOLTypeCombo->ItemIndex = 0;
  133. }
  134. else
  135. {
  136. EOLTypeCombo->ItemIndex = 1;
  137. }
  138. switch (FSessionData->NotUtf)
  139. {
  140. case asOn:
  141. UtfCombo->ItemIndex = 1;
  142. break;
  143. case asOff:
  144. UtfCombo->ItemIndex = 2;
  145. break;
  146. default:
  147. UtfCombo->ItemIndex = 0;
  148. break;
  149. }
  150. int TimeDifferenceMin = TimeToMinutes(FSessionData->TimeDifference);
  151. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / MinsPerHour;
  152. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % MinsPerHour;
  153. TimeDifferenceAutoCheck->Checked = FSessionData->TimeDifferenceAuto;
  154. TrimVMSVersionsCheck->Checked = FSessionData->TrimVMSVersions;
  155. // Environment/Recycle bin page
  156. DeleteToRecycleBinCheck->Checked = FSessionData->DeleteToRecycleBin;
  157. OverwrittenToRecycleBinCheck->Checked = FSessionData->OverwrittenToRecycleBin;
  158. RecycleBinPathEdit->Text =
  159. !FSessionData->RecycleBinPath.IsEmpty() ?
  160. FSessionData->RecycleBinPath : DefaultRecycleBinPath;
  161. // SFTP page
  162. if (FSessionData->SftpServer.IsEmpty())
  163. {
  164. SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
  165. }
  166. else
  167. {
  168. SftpServerEdit->Text = FSessionData->SftpServer;
  169. }
  170. // hide selection, which is wrongly shown initially even when the box has not focus
  171. SftpServerEdit->SelLength = 0;
  172. AllowScpFallbackCheck->Checked = (FSessionData->FSProtocol == fsSFTP);
  173. SFTPMaxVersionCombo->ItemIndex = FSessionData->SFTPMaxVersion;
  174. #define LOAD_SFTP_BUG_COMBO(BUG) \
  175. ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, FSessionData->SFTPBug[sb ## BUG])
  176. LOAD_SFTP_BUG_COMBO(Symlink);
  177. LOAD_SFTP_BUG_COMBO(SignedTS);
  178. #undef LOAD_SFTP_BUG_COMBO
  179. // FTP page
  180. FtpAccountEdit->Text = FSessionData->FtpAccount;
  181. PostLoginCommandsMemo->Lines->Text = FSessionData->PostLoginCommands;
  182. ComboAutoSwitchLoad(FtpListAllCombo, FSessionData->FtpListAll);
  183. ComboAutoSwitchLoad(FtpUseMlsdCombo, FSessionData->FtpUseMlsd);
  184. ComboAutoSwitchLoad(FtpForcePasvIpCombo, FSessionData->FtpForcePasvIp);
  185. ComboAutoSwitchLoad(FtpHostCombo, FSessionData->FtpHost);
  186. // Authentication page
  187. SshNoUserAuthCheck->Checked = FSessionData->SshNoUserAuth;
  188. TryAgentCheck->Checked = FSessionData->TryAgent;
  189. AuthTISCheck->Checked = FSessionData->AuthTIS;
  190. AuthKICheck->Checked = FSessionData->AuthKI;
  191. AuthKIPasswordCheck->Checked = FSessionData->AuthKIPassword;
  192. AuthGSSAPICheck3->Checked = FSessionData->AuthGSSAPI;
  193. GSSAPIFwdTGTCheck->Checked = FSessionData->GSSAPIFwdTGT;
  194. AgentFwdCheck->Checked = FSessionData->AgentFwd;
  195. PrivateKeyEdit3->Text = FSessionData->PublicKeyFile;
  196. // SSH page
  197. Ssh2LegacyDESCheck->Checked = FSessionData->Ssh2DES;
  198. CompressionCheck->Checked = FSessionData->Compression;
  199. if (FSessionData->SshProt == ssh1only)
  200. {
  201. SshProtCombo2->ItemIndex = 0;
  202. }
  203. else
  204. {
  205. SshProtCombo2->ItemIndex = 1;
  206. }
  207. CipherListBox->Items->Clear();
  208. DebugAssert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_CHACHA20);
  209. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  210. {
  211. CipherListBox->Items->AddObject(
  212. LoadStr(CIPHER_NAME_WARN+FSessionData->Cipher[Index]),
  213. (TObject*)FSessionData->Cipher[Index]);
  214. }
  215. // KEX page
  216. KexListBox->Items->Clear();
  217. DebugAssert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_ECDH);
  218. for (int Index = 0; Index < KEX_COUNT; Index++)
  219. {
  220. KexListBox->Items->AddObject(
  221. LoadStr(KEX_NAME_WARN+FSessionData->Kex[Index]),
  222. (TObject*)FSessionData->Kex[Index]);
  223. }
  224. RekeyTimeEdit->AsInteger = FSessionData->RekeyTime;
  225. RekeyDataEdit->Text = FSessionData->RekeyData;
  226. // Connection page
  227. FtpPasvModeCheck->Checked = FSessionData->FtpPasvMode;
  228. BufferSizeCheck->Checked = (FSessionData->SendBuf > 0) && FSessionData->SshSimple;
  229. switch (FSessionData->PingType)
  230. {
  231. case ptNullPacket:
  232. PingNullPacketButton->Checked = true;
  233. break;
  234. case ptDummyCommand:
  235. PingDummyCommandButton->Checked = true;
  236. break;
  237. default:
  238. PingOffButton->Checked = true;
  239. break;
  240. }
  241. PingIntervalSecEdit->AsInteger = FSessionData->PingInterval;
  242. switch (FSessionData->FtpPingType)
  243. {
  244. case ptDummyCommand:
  245. FtpPingDummyCommandButton->Checked = true;
  246. break;
  247. default:
  248. FtpPingOffButton->Checked = true;
  249. break;
  250. }
  251. FtpPingIntervalSecEdit->AsInteger = FSessionData->FtpPingInterval;
  252. TimeoutEdit->AsInteger = FSessionData->Timeout;
  253. switch (FSessionData->AddressFamily)
  254. {
  255. case afIPv4:
  256. IPv4Button->Checked = true;
  257. break;
  258. case afIPv6:
  259. IPv6Button->Checked = true;
  260. break;
  261. case afAuto:
  262. default:
  263. IPAutoButton->Checked = true;
  264. break;
  265. }
  266. // Shell page
  267. if (FSessionData->DefaultShell)
  268. {
  269. ShellEdit->Text = ShellEdit->Items->Strings[0];
  270. }
  271. else
  272. {
  273. ShellEdit->Text = FSessionData->Shell;
  274. }
  275. // hide selection, which is wrongly shown initially even when the box has not focus
  276. ShellEdit->SelLength = 0;
  277. if (FSessionData->DetectReturnVar)
  278. {
  279. ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
  280. }
  281. else
  282. {
  283. ReturnVarEdit->Text = FSessionData->ReturnVar;
  284. }
  285. ReturnVarEdit->SelLength = 0;
  286. ListingCommandEdit->Text = FSessionData->ListingCommand;
  287. ListingCommandEdit->SelLength = 0;
  288. CheckBoxAutoSwitchLoad(LookupUserGroupsCheck, FSessionData->LookupUserGroups);
  289. ClearAliasesCheck->Checked = FSessionData->ClearAliases;
  290. IgnoreLsWarningsCheck->Checked = FSessionData->IgnoreLsWarnings;
  291. Scp1CompatibilityCheck->Checked = FSessionData->Scp1Compatibility;
  292. UnsetNationalVarsCheck->Checked = FSessionData->UnsetNationalVars;
  293. SCPLsFullTimeAutoCheck->Checked = (FSessionData->SCPLsFullTime != asOff);
  294. // Proxy page
  295. SshProxyMethodCombo->ItemIndex = FSessionData->ProxyMethod;
  296. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(FSessionData->ProxyMethod);
  297. if (FSessionData->FtpProxyLogonType != 0)
  298. {
  299. FtpProxyMethodCombo->ItemIndex = LastSupportedFtpProxyMethod() + FSessionData->FtpProxyLogonType;
  300. }
  301. NeonProxyMethodCombo->ItemIndex = GetSupportedNeonProxyMethod(FSessionData->ProxyMethod);
  302. ProxyHostEdit->Text = FSessionData->ProxyHost;
  303. ProxyPortEdit->AsInteger = FSessionData->ProxyPort;
  304. ProxyUsernameEdit->Text = FSessionData->ProxyUsername;
  305. ProxyPasswordEdit->Text = FSessionData->ProxyPassword;
  306. ProxyTelnetCommandEdit->Text = FSessionData->ProxyTelnetCommand;
  307. ProxyLocalCommandEdit->Text = FSessionData->ProxyLocalCommand;
  308. ProxyLocalhostCheck->Checked = FSessionData->ProxyLocalhost;
  309. ProxyDNSCombo->ItemIndex = 2 - FSessionData->ProxyDNS;
  310. // Bugs page
  311. #define LOAD_BUG_COMBO(BUG) \
  312. ComboAutoSwitchLoad(Bug ## BUG ## Combo, FSessionData->Bug[sb ## BUG])
  313. LOAD_BUG_COMBO(Ignore1);
  314. LOAD_BUG_COMBO(PlainPW1);
  315. LOAD_BUG_COMBO(RSA1);
  316. LOAD_BUG_COMBO(HMAC2);
  317. LOAD_BUG_COMBO(DeriveKey2);
  318. LOAD_BUG_COMBO(RSAPad2);
  319. LOAD_BUG_COMBO(PKSessID2);
  320. LOAD_BUG_COMBO(Rekey2);
  321. LOAD_BUG_COMBO(MaxPkt2);
  322. LOAD_BUG_COMBO(Ignore2);
  323. LOAD_BUG_COMBO(WinAdj);
  324. #undef LOAD_BUG_COMBO
  325. // Tunnel page
  326. TunnelCheck->Checked = FSessionData->Tunnel;
  327. TunnelUserNameEdit->Text = FSessionData->TunnelUserName;
  328. TunnelPortNumberEdit->AsInteger = FSessionData->TunnelPortNumber;
  329. TunnelHostNameEdit->Text = FSessionData->TunnelHostName;
  330. TunnelPasswordEdit->Text = FSessionData->TunnelPassword;
  331. TunnelPrivateKeyEdit3->Text = FSessionData->TunnelPublicKeyFile;
  332. if (FSessionData->TunnelAutoassignLocalPortNumber)
  333. {
  334. TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
  335. }
  336. else
  337. {
  338. TunnelLocalPortNumberEdit->Text = IntToStr(FSessionData->TunnelLocalPortNumber);
  339. }
  340. // hide selection, which is wrongly shown initially even when the box has not focus
  341. TunnelLocalPortNumberEdit->SelLength = 0;
  342. // connection/tls/ssl page
  343. MinTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MinTlsVersion);
  344. MaxTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MaxTlsVersion);
  345. SslSessionReuseCheck->Checked = FSessionData->SslSessionReuse;
  346. TlsCertificateFileEdit->Text = FSessionData->TlsCertificateFile;
  347. // Note page
  348. NoteMemo->Lines->Text = FSessionData->Note;
  349. // color
  350. SetSessionColor((TColor)FSessionData->Color);
  351. }
  352. UpdateControls();
  353. }
  354. //---------------------------------------------------------------------
  355. TSshProt __fastcall TSiteAdvancedDialog::GetSshProt()
  356. {
  357. return (SshProtCombo2->ItemIndex == 0) ? ssh1only : ssh2only;
  358. }
  359. //---------------------------------------------------------------------
  360. void __fastcall TSiteAdvancedDialog::SaveSession()
  361. {
  362. // SSH page
  363. FSessionData->Compression = CompressionCheck->Checked;
  364. FSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  365. FSessionData->SshProt = GetSshProt();
  366. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  367. {
  368. FSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  369. }
  370. // Kex page
  371. for (int Index = 0; Index < KEX_COUNT; Index++)
  372. {
  373. FSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  374. }
  375. FSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  376. FSessionData->RekeyData = RekeyDataEdit->Text;
  377. // Authentication page
  378. FSessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
  379. FSessionData->TryAgent = TryAgentCheck->Checked;
  380. FSessionData->AuthTIS = AuthTISCheck->Checked;
  381. FSessionData->AuthKI = AuthKICheck->Checked;
  382. FSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  383. FSessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
  384. FSessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  385. FSessionData->AgentFwd = AgentFwdCheck->Checked;
  386. FSessionData->PublicKeyFile = PrivateKeyEdit3->Text;
  387. // Connection page
  388. FSessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  389. FSessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
  390. FSessionData->SshSimple = BufferSizeCheck->Checked;
  391. if (PingNullPacketButton->Checked)
  392. {
  393. FSessionData->PingType = ptNullPacket;
  394. }
  395. else if (PingDummyCommandButton->Checked)
  396. {
  397. FSessionData->PingType = ptDummyCommand;
  398. }
  399. else
  400. {
  401. FSessionData->PingType = ptOff;
  402. }
  403. FSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  404. FSessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
  405. FSessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
  406. FSessionData->Timeout = TimeoutEdit->AsInteger;
  407. if (IPv4Button->Checked)
  408. {
  409. FSessionData->AddressFamily = afIPv4;
  410. }
  411. else if (IPv6Button->Checked)
  412. {
  413. FSessionData->AddressFamily = afIPv6;
  414. }
  415. else
  416. {
  417. FSessionData->AddressFamily = afAuto;
  418. }
  419. // Directories page
  420. FSessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
  421. FSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  422. FSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  423. FSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  424. FSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  425. FSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  426. FSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  427. FSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  428. FSessionData->FollowDirectorySymlinks = FollowDirectorySymlinksCheck->Checked;
  429. // Environment page
  430. if (DSTModeUnixCheck->Checked)
  431. {
  432. FSessionData->DSTMode = dstmUnix;
  433. }
  434. else if (DSTModeKeepCheck->Checked)
  435. {
  436. FSessionData->DSTMode = dstmKeep;
  437. }
  438. else
  439. {
  440. FSessionData->DSTMode = dstmWin;
  441. }
  442. if (EOLTypeCombo->ItemIndex == 0)
  443. {
  444. FSessionData->EOLType = eolLF;
  445. }
  446. else
  447. {
  448. FSessionData->EOLType = eolCRLF;
  449. }
  450. switch (UtfCombo->ItemIndex)
  451. {
  452. case 1:
  453. FSessionData->NotUtf = asOn;
  454. break;
  455. case 2:
  456. FSessionData->NotUtf = asOff;
  457. break;
  458. default:
  459. FSessionData->NotUtf = asAuto;
  460. break;
  461. }
  462. FSessionData->TimeDifference =
  463. (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
  464. (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
  465. FSessionData->TimeDifferenceAuto = TimeDifferenceAutoCheck->Checked;
  466. FSessionData->TrimVMSVersions = TrimVMSVersionsCheck->Checked;
  467. // Environment/Recycle bin page
  468. FSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  469. FSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  470. FSessionData->RecycleBinPath =
  471. FSessionData->DeleteToRecycleBin || FSessionData->OverwrittenToRecycleBin ||
  472. (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
  473. RecycleBinPathEdit->Text : UnicodeString();
  474. // SCP page
  475. FSessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  476. FSessionData->Shell = (FSessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
  477. FSessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  478. FSessionData->ReturnVar = (FSessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
  479. FSessionData->ListingCommand = ListingCommandEdit->Text;
  480. FSessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
  481. FSessionData->ClearAliases = ClearAliasesCheck->Checked;
  482. FSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  483. FSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  484. FSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  485. FSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  486. // SFTP page
  487. FSessionData->SftpServer =
  488. ((SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]) ?
  489. UnicodeString() : SftpServerEdit->Text);
  490. FSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  491. if (AllowScpFallbackCheck->Checked != (FSessionData->FSProtocol == fsSFTP))
  492. {
  493. if (AllowScpFallbackCheck->Checked)
  494. {
  495. DebugAssert(FSessionData->FSProtocol == fsSFTPonly);
  496. FSessionData->FSProtocol = fsSFTP;
  497. }
  498. else
  499. {
  500. DebugAssert(FSessionData->FSProtocol == fsSFTP);
  501. FSessionData->FSProtocol = fsSFTPonly;
  502. }
  503. }
  504. #define SAVE_SFTP_BUG_COMBO(BUG) FSessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
  505. SAVE_SFTP_BUG_COMBO(Symlink);
  506. SAVE_SFTP_BUG_COMBO(SignedTS);
  507. #undef SAVE_SFTP_BUG_COMBO
  508. // FTP page
  509. FSessionData->FtpAccount = FtpAccountEdit->Text;
  510. FSessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
  511. FSessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
  512. FSessionData->FtpUseMlsd = ComboAutoSwitchSave(FtpUseMlsdCombo);
  513. FSessionData->FtpForcePasvIp = ComboAutoSwitchSave(FtpForcePasvIpCombo);
  514. FSessionData->FtpHost = ComboAutoSwitchSave(FtpHostCombo);
  515. // Proxy page
  516. FSessionData->ProxyMethod = GetProxyMethod();
  517. FSessionData->FtpProxyLogonType = GetFtpProxyLogonType();
  518. FSessionData->ProxyHost = ProxyHostEdit->Text;
  519. FSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  520. FSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  521. FSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  522. FSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  523. FSessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
  524. FSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  525. FSessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
  526. // Bugs page
  527. #define SAVE_BUG_COMBO(BUG) FSessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
  528. SAVE_BUG_COMBO(Ignore1);
  529. SAVE_BUG_COMBO(PlainPW1);
  530. SAVE_BUG_COMBO(RSA1);
  531. SAVE_BUG_COMBO(HMAC2);
  532. SAVE_BUG_COMBO(DeriveKey2);
  533. SAVE_BUG_COMBO(RSAPad2);
  534. SAVE_BUG_COMBO(PKSessID2);
  535. SAVE_BUG_COMBO(Rekey2);
  536. SAVE_BUG_COMBO(MaxPkt2);
  537. SAVE_BUG_COMBO(Ignore2);
  538. SAVE_BUG_COMBO(WinAdj);
  539. #undef SAVE_BUG_COMBO
  540. // Tunnel page
  541. FSessionData->Tunnel = TunnelCheck->Checked;
  542. FSessionData->TunnelUserName = TunnelUserNameEdit->Text;
  543. FSessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  544. FSessionData->TunnelHostName = TunnelHostNameEdit->Text;
  545. FSessionData->TunnelPassword = TunnelPasswordEdit->Text;
  546. FSessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit3->Text;
  547. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  548. {
  549. FSessionData->TunnelLocalPortNumber = 0;
  550. }
  551. else
  552. {
  553. FSessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  554. }
  555. // connection/tls/ssl page
  556. FSessionData->MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  557. FSessionData->MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  558. FSessionData->SslSessionReuse = SslSessionReuseCheck->Checked;
  559. FSessionData->TlsCertificateFile = TlsCertificateFileEdit->Text;
  560. // Note page
  561. FSessionData->Note = NoteMemo->Lines->Text;
  562. // color
  563. FSessionData->Color = FColor;
  564. }
  565. //---------------------------------------------------------------------
  566. void __fastcall TSiteAdvancedDialog::UpdateNavigationTree()
  567. {
  568. TTreeNode * ActiveNode = NULL;
  569. {
  570. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  571. int Index = 0;
  572. TTreeNode * PrevNode = NULL;
  573. while (Index < PageControl->PageCount)
  574. {
  575. TTabSheet * Tab = PageControl->Pages[Index];
  576. if (Tab->Enabled)
  577. {
  578. bool Indented = ((Tab->Tag % 100) == 2);
  579. UnicodeString Label = Tab->Caption;
  580. TTreeNode * Node;
  581. if (PrevNode == NULL)
  582. {
  583. DebugAssert(!Indented);
  584. Node = NavigationTree->Items->GetFirstNode();
  585. }
  586. else
  587. {
  588. if (Indented)
  589. {
  590. if (PrevNode->Level == 0)
  591. {
  592. Node = PrevNode->getFirstChild();
  593. if (Node == NULL)
  594. {
  595. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  596. }
  597. }
  598. else
  599. {
  600. Node = PrevNode->getNextSibling();
  601. if (Node == NULL)
  602. {
  603. Node = NavigationTree->Items->Add(PrevNode, Label);
  604. }
  605. }
  606. }
  607. else
  608. {
  609. if (PrevNode->Level == 0)
  610. {
  611. // delete all excess children of previous top level node
  612. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  613. {
  614. Node->Delete();
  615. }
  616. Node = PrevNode->getNextSibling();
  617. if (Node == NULL)
  618. {
  619. Node = NavigationTree->Items->Add(PrevNode, Label);
  620. }
  621. }
  622. else
  623. {
  624. // delete all excess children of previous top level node
  625. while ((Node = PrevNode->getNextSibling()) != NULL)
  626. {
  627. Node->Delete();
  628. }
  629. Node = PrevNode->GetNext();
  630. if (Node == NULL)
  631. {
  632. Node = NavigationTree->Items->Add(NULL, Label);
  633. }
  634. }
  635. }
  636. }
  637. Node->Text = Label;
  638. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  639. PrevNode = Node;
  640. if (PageControl->ActivePage == Tab)
  641. {
  642. Node->Selected = true;
  643. ActiveNode = Node;
  644. }
  645. }
  646. Index++;
  647. }
  648. TTreeNode * Node;
  649. while ((Node = PrevNode->GetNext()) != NULL)
  650. {
  651. Node->Delete();
  652. }
  653. NavigationTree->FullExpand();
  654. }
  655. // node of active page was hidden
  656. if (ActiveNode == NULL)
  657. {
  658. ChangePage(EnvironmentSheet);
  659. }
  660. }
  661. //---------------------------------------------------------------------
  662. void __fastcall TSiteAdvancedDialog::UpdateControls()
  663. {
  664. if (Visible)
  665. {
  666. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  667. bool SshProtocol = FSessionData->UsesSsh;
  668. bool SftpProtocol = (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  669. bool ScpProtocol = (FSessionData->FSProtocol == fsSCPonly);
  670. bool FtpProtocol = (FSessionData->FSProtocol == fsFTP);
  671. bool WebDavProtocol = (FSessionData->FSProtocol == fsWebDAV);
  672. bool S3Protocol = (FSessionData->FSProtocol == fsS3);
  673. bool Neon = IsNeon(FSessionData->FSProtocol);
  674. bool Ssl = (FtpProtocol || WebDavProtocol || S3Protocol) && (FSessionData->Ftps != ftpsNone);
  675. // connection sheet
  676. EnableControl(FtpPasvModeCheck, FtpProtocol);
  677. if (FtpProtocol &&
  678. (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
  679. SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
  680. !FtpPasvModeCheck->Checked)
  681. {
  682. FtpPasvModeCheck->Checked = true;
  683. MessageDialog(MainInstructions(LoadStr(FTP_PASV_MODE_REQUIRED)), qtInformation, qaOK);
  684. }
  685. EnableControl(BufferSizeCheck, SshProtocol);
  686. PingGroup->Visible = !FtpProtocol;
  687. EnableControl(PingGroup, SshProtocol);
  688. EnableControl(PingIntervalSecEdit, PingGroup->Enabled && !PingOffButton->Checked);
  689. EnableControl(PingIntervalLabel, PingGroup->Enabled && PingIntervalSecEdit->Enabled);
  690. FtpPingGroup->Visible = FtpProtocol;
  691. EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
  692. EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
  693. EnableControl(IPvGroup, SshProtocol || FtpProtocol);
  694. EnableControl(IPAutoButton, IPvGroup->Enabled && SshProtocol);
  695. // ssh/authentication sheet
  696. AuthSheet->Enabled = SshProtocol;
  697. EnableControl(SshNoUserAuthCheck, (GetSshProt() == ssh2only));
  698. EnableControl(AuthenticationGroup,
  699. !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
  700. EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh1only));
  701. EnableControl(AuthKICheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  702. EnableControl(AuthKIPasswordCheck,
  703. AuthenticationGroup->Enabled &&
  704. ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  705. (AuthKICheck->Enabled && AuthKICheck->Checked)));
  706. EnableControl(AuthenticationParamsGroup, AuthenticationGroup->Enabled);
  707. EnableControl(PrivateKeyViewButton, PrivateKeyEdit3->Enabled && !PrivateKeyEdit3->Text.IsEmpty());
  708. EnableControl(AuthGSSAPICheck3,
  709. AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  710. EnableControl(GSSAPIFwdTGTCheck,
  711. AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
  712. // ssh sheet
  713. AdvancedSheet->Enabled = SshProtocol;
  714. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  715. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  716. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  717. EnableControl(Ssh2LegacyDESCheck, (GetSshProt() == ssh2only));
  718. // ssh/kex sheet
  719. KexSheet->Enabled = SshProtocol && (GetSshProt() == ssh2only) &&
  720. (BugRekey2Combo->ItemIndex != 2);
  721. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  722. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  723. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  724. // ssh/bugs sheet
  725. BugsSheet->Enabled = SshProtocol;
  726. EnableControl(BugIgnore1Combo, (GetSshProt() == ssh1only));
  727. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  728. EnableControl(BugPlainPW1Combo, (GetSshProt() == ssh1only));
  729. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  730. EnableControl(BugRSA1Combo, (GetSshProt() == ssh1only));
  731. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  732. EnableControl(BugHMAC2Combo, (GetSshProt() == ssh2only));
  733. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  734. EnableControl(BugDeriveKey2Combo, (GetSshProt() == ssh2only));
  735. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  736. EnableControl(BugRSAPad2Combo, (GetSshProt() == ssh2only));
  737. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  738. EnableControl(BugPKSessID2Combo, (GetSshProt() == ssh2only));
  739. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  740. EnableControl(BugRekey2Combo, (GetSshProt() == ssh2only));
  741. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  742. EnableControl(BugMaxPkt2Combo, (GetSshProt() == ssh2only));
  743. EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
  744. EnableControl(BugIgnore2Combo, (GetSshProt() == ssh2only));
  745. EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
  746. EnableControl(BugWinAdjCombo, (GetSshProt() == ssh2only));
  747. EnableControl(BugWinAdjLabel, BugWinAdjCombo->Enabled);
  748. // connection/proxy sheet
  749. // this is probaqbly overkill, now we do not allow changing protocol on
  750. // the same window as changing proxy
  751. TComboBox * ProxyMethodCombo =
  752. (SshProtocol ? SshProxyMethodCombo : (FtpProtocol ? FtpProxyMethodCombo : NeonProxyMethodCombo));
  753. TProxyMethod ProxyMethod = GetProxyMethod();
  754. ProxyMethodCombo->Visible = true;
  755. ProxyMethodLabel->FocusControl = ProxyMethodCombo;
  756. if (!SshProtocol)
  757. {
  758. SshProxyMethodCombo->Visible = false;
  759. SshProxyMethodCombo->ItemIndex = ProxyMethod;
  760. }
  761. if (!FtpProtocol)
  762. {
  763. FtpProxyMethodCombo->Visible = false;
  764. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(ProxyMethod);
  765. }
  766. if (!Neon)
  767. {
  768. NeonProxyMethodCombo->Visible = false;
  769. NeonProxyMethodCombo->ItemIndex = GetSupportedNeonProxyMethod(ProxyMethod);
  770. }
  771. int FtpProxyLogonType = GetFtpProxyLogonType();
  772. UnicodeString ProxyCommand =
  773. ((ProxyMethod == pmCmd) ?
  774. ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
  775. EnableControl(ProxyHostEdit,
  776. (ProxyMethod == pmSocks4) ||
  777. (ProxyMethod == pmSocks5) ||
  778. (ProxyMethod == pmHTTP) ||
  779. (ProxyMethod == pmTelnet) ||
  780. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
  781. (FtpProxyLogonType > 0));
  782. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  783. EnableControl(ProxyPortEdit,
  784. (ProxyMethod == pmSocks4) ||
  785. (ProxyMethod == pmSocks5) ||
  786. (ProxyMethod == pmHTTP) ||
  787. (ProxyMethod == pmTelnet) ||
  788. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
  789. (FtpProxyLogonType > 0));
  790. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  791. EnableControl(ProxyUsernameEdit,
  792. // FZAPI does not support username for SOCKS4
  793. ((ProxyMethod == pmSocks4) && (SshProtocol || Neon)) ||
  794. (ProxyMethod == pmSocks5) ||
  795. (ProxyMethod == pmHTTP) ||
  796. (((ProxyMethod == pmTelnet) ||
  797. (ProxyMethod == pmCmd)) &&
  798. AnsiContainsText(ProxyCommand, L"%user")) ||
  799. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  800. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  801. EnableControl(ProxyPasswordEdit,
  802. (ProxyMethod == pmSocks5) ||
  803. (ProxyMethod == pmHTTP) ||
  804. (((ProxyMethod == pmTelnet) ||
  805. (ProxyMethod == pmCmd)) &&
  806. AnsiContainsText(ProxyCommand, L"%pass")) ||
  807. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  808. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  809. bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
  810. ProxySettingsGroup->Visible = SshProtocol;
  811. EnableControl(ProxySettingsGroup, ProxySettings);
  812. EnableControl(ProxyTelnetCommandEdit,
  813. ProxySettings && (ProxyMethod == pmTelnet));
  814. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  815. EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
  816. ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
  817. ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
  818. ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
  819. ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
  820. ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
  821. ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
  822. ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
  823. // environment/directories sheet
  824. EnableControl(SynchronizeBrowsingCheck,
  825. (CustomWinConfiguration->Interface == ifCommander) &&
  826. WinConfiguration->PreservePanelState &&
  827. !WinConfiguration->ScpCommander.PreserveLocalDirectory);
  828. EnableControl(CacheDirectoryChangesCheck,
  829. (!ScpProtocol || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  830. EnableControl(PreserveDirectoryChangesCheck,
  831. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  832. DirectoriesSheet->Enabled);
  833. EnableControl(ResolveSymlinksCheck, (SftpProtocol || ScpProtocol) && DirectoriesSheet->Enabled);
  834. EnableControl(FollowDirectorySymlinksCheck, (SftpProtocol || ScpProtocol || FtpProtocol));
  835. // environment sheet
  836. EnableControl(EOLTypeCombo, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  837. EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
  838. EnableControl(DSTModeGroup, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  839. EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
  840. EnableControl(UtfCombo, (SftpProtocol || FtpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  841. EnableControl(UtfLabel, UtfCombo->Enabled);
  842. // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
  843. bool FtpProtocolWithMlsdOff = FtpProtocol && (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff);
  844. EnableControl(TimeDifferenceAutoCheck, FtpProtocolWithMlsdOff);
  845. EnableControl(TimeDifferenceEdit,
  846. ((FtpProtocolWithMlsdOff && !TimeDifferenceAutoCheck->Checked) ||
  847. ScpProtocol) &&
  848. EnvironmentSheet->Enabled);
  849. EnableControl(TimeDifferenceLabel,
  850. TimeDifferenceEdit->Enabled || TimeDifferenceAutoCheck->Enabled);
  851. EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
  852. EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
  853. EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
  854. EnableControl(TrimVMSVersionsCheck, !S3Protocol);
  855. // environment/recycle bin sheet
  856. EnableControl(OverwrittenToRecycleBinCheck, SftpProtocol && RecycleBinSheet->Enabled);
  857. EnableControl(RecycleBinPathEdit,
  858. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  859. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  860. RecycleBinSheet->Enabled);
  861. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  862. RecycleBinSheet->Enabled);
  863. // environment/sftp sheet
  864. SftpSheet->Enabled = SftpProtocol;
  865. // environment/scp/shell
  866. ScpSheet->Enabled = SshProtocol;
  867. ScpSheet->Caption = LoadStr(ScpProtocol ? LOGIN_SCP_SHELL_PAGE : LOGIN_SHELL_PAGE);
  868. // hide also for SFTP with SCP fallback, as if someone wants to configure
  869. // these he/she probably intends to use SCP and should explicitly select it.
  870. // (note that these are not used for separate shell session)
  871. ScpLsOptionsGroup->Visible = ScpProtocol;
  872. OtherShellOptionsGroup->Visible = ScpProtocol;
  873. // environment/ftp
  874. FtpSheet->Enabled = FtpProtocol;
  875. EnableControl(FtpListAllCombo,
  876. (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff));
  877. EnableControl(FtpListAllLabel, FtpListAllCombo->Enabled);
  878. EnableControl(FtpForcePasvIpCombo,
  879. FtpPasvModeCheck->Checked &&
  880. (IPAutoButton->Checked || IPv4Button->Checked));
  881. EnableControl(FtpForcePasvIpLabel, FtpForcePasvIpCombo->Enabled);
  882. // tunnel sheet
  883. TunnelSheet->Enabled = SshProtocol;
  884. // probably needless
  885. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  886. EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
  887. EnableControl(TunnelAuthenticationParamsGroup, TunnelSessionGroup->Enabled);
  888. // connection/ssl/tls
  889. SslSheet->Enabled = Ssl;
  890. // TLS/SSL session reuse is not configurable for WebDAV/S3 yet
  891. SslSessionReuseCheck->Enabled = SslSheet->Enabled && FtpProtocol;
  892. UpdateNavigationTree();
  893. // color
  894. if (FColor == 0)
  895. {
  896. MenuButton(ColorButton);
  897. }
  898. else
  899. {
  900. ColorButton->Images = ColorImageList;
  901. ColorButton->ImageIndex = 1;
  902. ColorButton->ImageAlignment = iaRight;
  903. }
  904. }
  905. }
  906. //---------------------------------------------------------------------------
  907. void __fastcall TSiteAdvancedDialog::DataChange(TObject * /*Sender*/)
  908. {
  909. if (NoUpdate == 0)
  910. {
  911. UpdateControls();
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall TSiteAdvancedDialog::FormShow(TObject * /*Sender*/)
  916. {
  917. InstallPathWordBreakProc(PrivateKeyEdit3);
  918. InstallPathWordBreakProc(TunnelPrivateKeyEdit3);
  919. InstallPathWordBreakProc(RemoteDirectoryEdit);
  920. InstallPathWordBreakProc(LocalDirectoryEdit);
  921. InstallPathWordBreakProc(RecycleBinPathEdit);
  922. InstallPathWordBreakProc(TlsCertificateFileEdit);
  923. InstallPathWordBreakProc(SftpServerEdit);
  924. InstallPathWordBreakProc(ShellEdit);
  925. ChangePage(EnvironmentSheet);
  926. UpdateControls();
  927. }
  928. //---------------------------------------------------------------------------
  929. bool __fastcall TSiteAdvancedDialog::Execute(TSessionData * SessionData)
  930. {
  931. FSessionData = SessionData;
  932. LoadSession();
  933. bool Result = (ShowModal() == DefaultResult(this));
  934. if (Result)
  935. {
  936. SaveSession();
  937. }
  938. return Result;
  939. }
  940. //---------------------------------------------------------------------------
  941. void __fastcall TSiteAdvancedDialog::NavigationTreeChange(TObject * /*Sender*/,
  942. TTreeNode * Node)
  943. {
  944. if (NoUpdate == 0)
  945. {
  946. TAutoNestingCounter Guard(NoUpdate);
  947. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  948. // should happen only while loading language
  949. // (UpdateNavigationTree may not be called yet)
  950. if (Tab != NULL)
  951. {
  952. PageControl->ActivePage = Tab;
  953. // reshow the accelerators, etc
  954. ResetSystemSettings(this);
  955. }
  956. UpdateControls();
  957. }
  958. }
  959. //---------------------------------------------------------------------------
  960. void __fastcall TSiteAdvancedDialog::ChangePage(TTabSheet * Tab)
  961. {
  962. PageControl->ActivePage = Tab;
  963. PageControlChange(PageControl);
  964. FPrivateKeyMonitors.reset(NULL);
  965. }
  966. //---------------------------------------------------------------------------
  967. void __fastcall TSiteAdvancedDialog::PageControlChange(TObject *Sender)
  968. {
  969. bool Found = false;
  970. if (PageControl->ActivePage)
  971. {
  972. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  973. {
  974. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  975. reinterpret_cast<int>(PageControl->ActivePage))
  976. {
  977. NavigationTree->Items->Item[Index]->Selected = true;
  978. Found = true;
  979. }
  980. }
  981. }
  982. if (DebugAlwaysTrue(Found))
  983. {
  984. DataChange(Sender);
  985. }
  986. }
  987. //---------------------------------------------------------------------------
  988. void __fastcall TSiteAdvancedDialog::CMDialogKey(TWMKeyDown & Message)
  989. {
  990. if (Message.CharCode == VK_TAB)
  991. {
  992. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  993. if (Shift.Contains(ssCtrl))
  994. {
  995. TTreeNode * Node = NavigationTree->Selected;
  996. if (!Shift.Contains(ssShift))
  997. {
  998. Node = Node->GetNext();
  999. if (Node == NULL)
  1000. {
  1001. Node = NavigationTree->Items->GetFirstNode();
  1002. }
  1003. }
  1004. else
  1005. {
  1006. if (Node->GetPrev() != NULL)
  1007. {
  1008. Node = Node->GetPrev();
  1009. }
  1010. else
  1011. {
  1012. while (Node->GetNext() != NULL)
  1013. {
  1014. Node = Node->GetNext();
  1015. }
  1016. }
  1017. }
  1018. Node->Selected = True;
  1019. Message.Result = 1;
  1020. return;
  1021. }
  1022. }
  1023. TForm::Dispatch(&Message);
  1024. }
  1025. //---------------------------------------------------------------------------
  1026. void __fastcall TSiteAdvancedDialog::WMHelp(TWMHelp & Message)
  1027. {
  1028. DebugAssert(Message.HelpInfo != NULL);
  1029. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1030. {
  1031. // invoke help for active page (not for whole form), regardless of focus
  1032. // (e.g. even if focus is on control outside pagecontrol)
  1033. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1034. }
  1035. TForm::Dispatch(&Message);
  1036. }
  1037. //---------------------------------------------------------------------------
  1038. void __fastcall TSiteAdvancedDialog::Dispatch(void * Message)
  1039. {
  1040. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1041. DebugAssert(M);
  1042. if (M->Msg == CM_DIALOGKEY)
  1043. {
  1044. CMDialogKey(*((TWMKeyDown *)Message));
  1045. }
  1046. else if (M->Msg == WM_HELP)
  1047. {
  1048. WMHelp(*((TWMHelp *)Message));
  1049. }
  1050. else
  1051. {
  1052. TForm::Dispatch(Message);
  1053. }
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. void __fastcall TSiteAdvancedDialog::AlgListBoxStartDrag(TObject * Sender,
  1057. TDragObject *& /*DragObject*/)
  1058. {
  1059. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1060. FAlgDragDest = -1;
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. void __fastcall TSiteAdvancedDialog::AlgListBoxDragOver(TObject * Sender,
  1064. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  1065. {
  1066. if (Source == Sender)
  1067. {
  1068. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1069. }
  1070. else
  1071. {
  1072. Accept = false;
  1073. }
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall TSiteAdvancedDialog::AlgListBoxDragDrop(TObject * Sender,
  1077. TObject * Source, int X, int Y)
  1078. {
  1079. if (Source == Sender)
  1080. {
  1081. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1082. if (AllowAlgDrag(AlgListBox, X, Y))
  1083. {
  1084. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1085. }
  1086. }
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. void __fastcall TSiteAdvancedDialog::CipherButtonClick(TObject *Sender)
  1090. {
  1091. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1092. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. void __fastcall TSiteAdvancedDialog::KexButtonClick(TObject *Sender)
  1096. {
  1097. AlgMove(KexListBox, KexListBox->ItemIndex,
  1098. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1099. }
  1100. //---------------------------------------------------------------------------
  1101. bool __fastcall TSiteAdvancedDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1102. {
  1103. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1104. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1105. }
  1106. //---------------------------------------------------------------------------
  1107. void __fastcall TSiteAdvancedDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1108. {
  1109. if ((Source >= 0) && (Source < AlgListBox->Items->Count) &&
  1110. (Dest >= 0) && (Dest < AlgListBox->Items->Count))
  1111. {
  1112. AlgListBox->Items->Move(Source, Dest);
  1113. AlgListBox->ItemIndex = Dest;
  1114. AlgListBox->SetFocus();
  1115. }
  1116. UpdateControls();
  1117. }
  1118. //---------------------------------------------------------------------------
  1119. void __fastcall TSiteAdvancedDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
  1120. {
  1121. if (NoUpdate == 0)
  1122. {
  1123. UpdateControls();
  1124. if (AuthGSSAPICheck3->Checked && !HasGSSAPI(L""))
  1125. {
  1126. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
  1127. }
  1128. }
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. void __fastcall TSiteAdvancedDialog::HelpButtonClick(TObject * /*Sender*/)
  1132. {
  1133. FormHelp(this);
  1134. }
  1135. //---------------------------------------------------------------------------
  1136. void __fastcall TSiteAdvancedDialog::PrivateKeyEdit3AfterDialog(TObject * Sender,
  1137. UnicodeString & Name, bool & Action)
  1138. {
  1139. PathEditAfterDialog(Sender, Name, Action);
  1140. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1141. if (Name != Edit->Text)
  1142. {
  1143. VerifyAndConvertKey(Name, GetSshProt(), true);
  1144. }
  1145. }
  1146. //---------------------------------------------------------------------------
  1147. void __fastcall TSiteAdvancedDialog::FormCloseQuery(TObject * /*Sender*/,
  1148. bool & /*CanClose*/)
  1149. {
  1150. if (ModalResult == DefaultResult(this))
  1151. {
  1152. // StripPathQuotes should not be needed as we do not feed quotes anymore
  1153. VerifyKey(StripPathQuotes(PrivateKeyEdit3->Text), GetSshProt());
  1154. // for tunnel SSH version is not configurable
  1155. VerifyKey(StripPathQuotes(TunnelPrivateKeyEdit3->Text), ssh2only);
  1156. VerifyCertificate(StripPathQuotes(TlsCertificateFileEdit->Text));
  1157. }
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TSiteAdvancedDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1161. UnicodeString & Name, bool & /*Action*/)
  1162. {
  1163. FBeforeDialogPath = Name;
  1164. Name = ExpandEnvironmentVariables(Name);
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TSiteAdvancedDialog::PathEditAfterDialog(TObject * /*Sender*/,
  1168. UnicodeString & Name, bool & /*Action*/)
  1169. {
  1170. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1171. {
  1172. Name = FBeforeDialogPath;
  1173. }
  1174. }
  1175. //---------------------------------------------------------------------------
  1176. int __fastcall TSiteAdvancedDialog::LastSupportedFtpProxyMethod()
  1177. {
  1178. return pmHTTP;
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. bool __fastcall TSiteAdvancedDialog::SupportedFtpProxyMethod(int Method)
  1182. {
  1183. return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. int __fastcall TSiteAdvancedDialog::GetSupportedFtpProxyMethod(int Method)
  1187. {
  1188. if (SupportedFtpProxyMethod(Method))
  1189. {
  1190. return Method;
  1191. }
  1192. else
  1193. {
  1194. return ::pmNone;
  1195. }
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. int __fastcall TSiteAdvancedDialog::GetSupportedNeonProxyMethod(int Method)
  1199. {
  1200. if ((Method >= 0) && (Method <= pmHTTP))
  1201. {
  1202. return Method;
  1203. }
  1204. else
  1205. {
  1206. return ::pmNone;
  1207. }
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. bool __fastcall TSiteAdvancedDialog::IsNeon(TFSProtocol FSProtocol)
  1211. {
  1212. return (FSProtocol == fsWebDAV) || (FSProtocol == fsS3);
  1213. }
  1214. //---------------------------------------------------------------------------
  1215. TProxyMethod __fastcall TSiteAdvancedDialog::GetProxyMethod()
  1216. {
  1217. TProxyMethod Result;
  1218. TFSProtocol FSProtocol = FSessionData->FSProtocol;
  1219. if (FSessionData->UsesSsh)
  1220. {
  1221. Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
  1222. }
  1223. else if (FSProtocol == fsFTP)
  1224. {
  1225. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1226. {
  1227. Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
  1228. }
  1229. else
  1230. {
  1231. Result = ::pmNone;
  1232. }
  1233. }
  1234. else if (IsNeon(FSProtocol))
  1235. {
  1236. Result = (TProxyMethod)NeonProxyMethodCombo->ItemIndex;
  1237. }
  1238. else
  1239. {
  1240. DebugFail();
  1241. Result = ::pmNone;
  1242. }
  1243. return Result;
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. int __fastcall TSiteAdvancedDialog::GetFtpProxyLogonType()
  1247. {
  1248. int Result;
  1249. if (FSessionData->FSProtocol != fsFTP)
  1250. {
  1251. Result = 0;
  1252. }
  1253. else
  1254. {
  1255. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1256. {
  1257. Result = 0;
  1258. }
  1259. else
  1260. {
  1261. Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
  1262. }
  1263. }
  1264. return Result;
  1265. }
  1266. //---------------------------------------------------------------------------
  1267. void __fastcall TSiteAdvancedDialog::NavigationTreeCollapsing(
  1268. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1269. {
  1270. AllowCollapse = false;
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. void __fastcall TSiteAdvancedDialog::ProxyLocalCommandBrowseButtonClick(
  1274. TObject * /*Sender*/)
  1275. {
  1276. BrowseForExecutable(ProxyLocalCommandEdit,
  1277. LoadStr(LOGIN_SELECT_LOCAL_PROXY),
  1278. LoadStr(EXECUTABLE_FILTER), false, true);
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. void __fastcall TSiteAdvancedDialog::ColorButtonClick(TObject * /*Sender*/)
  1282. {
  1283. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1284. // "internal error" when passing menu directly to unique_ptr.
  1285. // Splitting it to two statements seems to help.
  1286. // The same hack exists in TPreferencesDialog::EditorFontColorButtonClick
  1287. TPopupMenu * Menu = CreateSessionColorPopupMenu(FColor, SessionColorChange);
  1288. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1289. FColorPopupMenu.reset(Menu);
  1290. MenuPopup(Menu, ColorButton);
  1291. }
  1292. //---------------------------------------------------------------------------
  1293. void __fastcall TSiteAdvancedDialog::SessionColorChange(TColor Color)
  1294. {
  1295. SetSessionColor(Color);
  1296. UpdateControls();
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. void __fastcall TSiteAdvancedDialog::SetSessionColor(TColor Color)
  1300. {
  1301. FColor = Color;
  1302. while (ColorImageList->Count > 1)
  1303. {
  1304. ColorImageList->Delete(1);
  1305. }
  1306. if (Color != 0)
  1307. {
  1308. AddSessionColorImage(ColorImageList, Color, 0);
  1309. }
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. TTlsVersion __fastcall TSiteAdvancedDialog::IndexToTlsVersion(int Index)
  1313. {
  1314. switch (Index)
  1315. {
  1316. default:
  1317. DebugFail();
  1318. case 0:
  1319. return ssl3;
  1320. case 1:
  1321. return tls10;
  1322. case 2:
  1323. return tls11;
  1324. case 3:
  1325. return tls12;
  1326. }
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. int __fastcall TSiteAdvancedDialog::TlsVersionToIndex(TTlsVersion TlsVersion)
  1330. {
  1331. switch (TlsVersion)
  1332. {
  1333. default:
  1334. DebugFail();
  1335. case ssl2:
  1336. case ssl3:
  1337. return 0;
  1338. case tls10:
  1339. return 1;
  1340. case tls11:
  1341. return 2;
  1342. case tls12:
  1343. return 3;
  1344. }
  1345. }
  1346. //---------------------------------------------------------------------------
  1347. void __fastcall TSiteAdvancedDialog::MinTlsVersionComboChange(TObject */*Sender*/)
  1348. {
  1349. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1350. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1351. if (MaxTlsVersion < MinTlsVersion)
  1352. {
  1353. MaxTlsVersionCombo->ItemIndex = MinTlsVersionCombo->ItemIndex;
  1354. }
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. void __fastcall TSiteAdvancedDialog::MaxTlsVersionComboChange(TObject * /*Sender*/)
  1358. {
  1359. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1360. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1361. if (MinTlsVersion > MaxTlsVersion)
  1362. {
  1363. MinTlsVersionCombo->ItemIndex = MaxTlsVersionCombo->ItemIndex;
  1364. }
  1365. }
  1366. //---------------------------------------------------------------------------
  1367. void __fastcall TSiteAdvancedDialog::ProxyAutodetectButtonClick(TObject * /*Sender*/)
  1368. {
  1369. TInstantOperationVisualizer Visualizer;
  1370. UnicodeString ProxyHost;
  1371. int ProxyPort;
  1372. if (AutodetectProxy(ProxyHost, ProxyPort))
  1373. {
  1374. ProxyHostEdit->Text = ProxyHost;
  1375. ProxyPortEdit->AsInteger = ProxyPort;
  1376. SshProxyMethodCombo->ItemIndex = pmHTTP;
  1377. FtpProxyMethodCombo->ItemIndex = pmHTTP;
  1378. NeonProxyMethodCombo->ItemIndex = pmHTTP;
  1379. UpdateControls();
  1380. }
  1381. }
  1382. //---------------------------------------------------------------------------
  1383. void __fastcall TSiteAdvancedDialog::NoteMemoKeyDown(
  1384. TObject * Sender, WORD & Key, TShiftState Shift)
  1385. {
  1386. MemoKeyDown(Sender, Key, Shift);
  1387. }
  1388. //---------------------------------------------------------------------------
  1389. void __fastcall TSiteAdvancedDialog::TlsCertificateFileEditAfterDialog(TObject *Sender,
  1390. UnicodeString &Name, bool &Action)
  1391. {
  1392. PathEditAfterDialog(Sender, Name, Action);
  1393. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1394. if (Name != Edit->Text)
  1395. {
  1396. VerifyCertificate(Name);
  1397. }
  1398. }
  1399. //---------------------------------------------------------------------------
  1400. void __fastcall TSiteAdvancedDialog::PrivateKeyCreatedOrModified(TObject * /*Sender*/, const UnicodeString FileName)
  1401. {
  1402. if (SameText(ExtractFileExt(FileName), FORMAT(L".%s", (PuttyKeyExt))))
  1403. {
  1404. PrivateKeyEdit3->Text = FileName;
  1405. }
  1406. }
  1407. //---------------------------------------------------------------------------
  1408. void __fastcall TSiteAdvancedDialog::PrivateKeyToolsButtonClick(TObject * /*Sender*/)
  1409. {
  1410. UnicodeString Dummy;
  1411. PrivateKeyGenerateItem->Enabled = FindTool(PuttygenTool, Dummy);
  1412. PrivateKeyUploadItem->Enabled = (GetSshProt() == ssh2only) && (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  1413. MenuPopup(PrivateKeyMenu, PrivateKeyToolsButton);
  1414. }
  1415. //---------------------------------------------------------------------------
  1416. void __fastcall TSiteAdvancedDialog::PrivateKeyGenerateItemClick(TObject * /*Sender*/)
  1417. {
  1418. unsigned int Filters = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE;
  1419. FPrivateKeyMonitors.reset(StartCreationDirectoryMonitorsOnEachDrive(Filters, PrivateKeyCreatedOrModified));
  1420. ExecuteTool(PuttygenTool);
  1421. }
  1422. //---------------------------------------------------------------------------
  1423. void __fastcall TSiteAdvancedDialog::PrivateKeyUploadItemClick(TObject * /*Sender*/)
  1424. {
  1425. SaveSession();
  1426. FSessionData->FSProtocol = fsSFTPonly; // no SCP fallback, as SCP does not implement GetHomeDirectory
  1427. FSessionData->RemoteDirectory = UnicodeString();
  1428. UnicodeString FileName = PrivateKeyEdit3->Text;
  1429. if (TTerminalManager::Instance()->UploadPublicKey(NULL, FSessionData, FileName))
  1430. {
  1431. PrivateKeyEdit3->Text = FileName;
  1432. PrivateKeyEdit3->SetFocus();
  1433. }
  1434. }
  1435. //---------------------------------------------------------------------------
  1436. void __fastcall TSiteAdvancedDialog::PrivateKeyViewButtonClick(TObject * /*Sender*/)
  1437. {
  1438. UnicodeString FileName = PrivateKeyEdit3->Text;
  1439. VerifyAndConvertKey(FileName, GetSshProt(), false);
  1440. PrivateKeyEdit3->Text = FileName;
  1441. UnicodeString CommentDummy;
  1442. UnicodeString Line = GetPublicKeyLine(FileName, CommentDummy);
  1443. std::unique_ptr<TStrings> Messages(TextToStringList(Line));
  1444. TClipboardHandler ClipboardHandler;
  1445. ClipboardHandler.Text = Line;
  1446. TMessageParams Params;
  1447. TQueryButtonAlias Aliases[1];
  1448. Aliases[0].Button = qaRetry;
  1449. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1450. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1451. Params.Aliases = Aliases;
  1452. Params.AliasesCount = LENOF(Aliases);
  1453. UnicodeString Message = LoadStr(LOGIN_AUTHORIZED_KEYS);
  1454. int Answers = qaOK | qaRetry;
  1455. MoreMessageDialog(Message, Messages.get(), qtInformation, Answers, HELP_LOGIN_AUTHORIZED_KEYS, &Params);
  1456. }
  1457. //---------------------------------------------------------------------------