SiteAdvanced.cpp 59 KB

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