SiteAdvanced.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840
  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. #pragma resource "*.dfm"
  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. FColor = TColor();
  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. PuttySettingsEdit->Text = FSessionData->PuttySettings;
  156. // Environment/Recycle bin page
  157. DeleteToRecycleBinCheck->Checked = FSessionData->DeleteToRecycleBin;
  158. OverwrittenToRecycleBinCheck->Checked = FSessionData->OverwrittenToRecycleBin;
  159. RecycleBinPathEdit->Text =
  160. !FSessionData->RecycleBinPath.IsEmpty() ?
  161. FSessionData->RecycleBinPath : DefaultRecycleBinPath;
  162. // SFTP page
  163. if (FSessionData->SftpServer.IsEmpty())
  164. {
  165. SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
  166. }
  167. else
  168. {
  169. SftpServerEdit->Text = FSessionData->SftpServer;
  170. }
  171. // hide selection, which is wrongly shown initially even when the box has not focus
  172. SftpServerEdit->SelLength = 0;
  173. AllowScpFallbackCheck->Checked = (FSessionData->FSProtocol == fsSFTP);
  174. SFTPMaxVersionCombo->ItemIndex = FSessionData->SFTPMaxVersion;
  175. #define LOAD_SFTP_BUG_COMBO(BUG) \
  176. ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, FSessionData->SFTPBug[sb ## BUG])
  177. LOAD_SFTP_BUG_COMBO(Symlink);
  178. LOAD_SFTP_BUG_COMBO(SignedTS);
  179. #undef LOAD_SFTP_BUG_COMBO
  180. // FTP page
  181. FtpAccountEdit->Text = FSessionData->FtpAccount;
  182. PostLoginCommandsMemo->Lines->Text = FSessionData->PostLoginCommands;
  183. ComboAutoSwitchLoad(FtpListAllCombo, FSessionData->FtpListAll);
  184. ComboAutoSwitchLoad(FtpUseMlsdCombo, FSessionData->FtpUseMlsd);
  185. ComboAutoSwitchLoad(FtpForcePasvIpCombo, FSessionData->FtpForcePasvIp);
  186. ComboAutoSwitchLoad(FtpHostCombo, FSessionData->FtpHost);
  187. // S3 page
  188. S3DefaultReqionCombo->Text = FSessionData->S3DefaultRegion;
  189. if (FSessionData->S3UrlStyle == s3usPath)
  190. {
  191. S3UrlStyleCombo->ItemIndex = 1;
  192. }
  193. else
  194. {
  195. S3UrlStyleCombo->ItemIndex = 0;
  196. }
  197. // Authentication page
  198. SshNoUserAuthCheck->Checked = FSessionData->SshNoUserAuth;
  199. TryAgentCheck->Checked = FSessionData->TryAgent;
  200. AuthTISCheck->Checked = FSessionData->AuthTIS;
  201. AuthKICheck->Checked = FSessionData->AuthKI;
  202. AuthKIPasswordCheck->Checked = FSessionData->AuthKIPassword;
  203. AuthGSSAPICheck3->Checked = FSessionData->AuthGSSAPI;
  204. GSSAPIFwdTGTCheck->Checked = FSessionData->GSSAPIFwdTGT;
  205. AgentFwdCheck->Checked = FSessionData->AgentFwd;
  206. PrivateKeyEdit3->Text = FSessionData->PublicKeyFile;
  207. // SSH page
  208. Ssh2LegacyDESCheck->Checked = FSessionData->Ssh2DES;
  209. CompressionCheck->Checked = FSessionData->Compression;
  210. if (FSessionData->SshProt == ssh1only)
  211. {
  212. SshProtCombo2->ItemIndex = 0;
  213. }
  214. else
  215. {
  216. SshProtCombo2->ItemIndex = 1;
  217. }
  218. CipherListBox->Items->Clear();
  219. DebugAssert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_CHACHA20);
  220. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  221. {
  222. CipherListBox->Items->AddObject(
  223. LoadStr(CIPHER_NAME_WARN+FSessionData->Cipher[Index]),
  224. (TObject*)FSessionData->Cipher[Index]);
  225. }
  226. // KEX page
  227. KexListBox->Items->Clear();
  228. DebugAssert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_ECDH);
  229. for (int Index = 0; Index < KEX_COUNT; Index++)
  230. {
  231. KexListBox->Items->AddObject(
  232. LoadStr(KEX_NAME_WARN+FSessionData->Kex[Index]),
  233. (TObject*)FSessionData->Kex[Index]);
  234. }
  235. AuthGSSAPIKEXCheck->Checked = FSessionData->AuthGSSAPIKEX;
  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. // webdav page
  365. WebDavLiberalEscapingCheck->Checked = FSessionData->WebDavLiberalEscaping;
  366. // color
  367. FColor = (TColor)FSessionData->Color;
  368. }
  369. EnableControl(PuttyGroup, !DoesSessionExistInPutty(FSessionData));
  370. UpdateControls();
  371. }
  372. //---------------------------------------------------------------------
  373. TSshProt __fastcall TSiteAdvancedDialog::GetSshProt()
  374. {
  375. return (SshProtCombo2->ItemIndex == 0) ? ssh1only : ssh2only;
  376. }
  377. //---------------------------------------------------------------------
  378. bool TSiteAdvancedDialog::IsDefaultSftpServer()
  379. {
  380. return
  381. SftpServerEdit->Text.IsEmpty() ||
  382. (SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]);
  383. }
  384. //---------------------------------------------------------------------
  385. void __fastcall TSiteAdvancedDialog::SaveSession(TSessionData * SessionData)
  386. {
  387. // Last resort validation,
  388. // in case the test in EncryptKeyEditExit was previously bypassed due to IsCancelButtonBeingClicked
  389. EncryptKeyEditExit(GetEncryptKeyEdit());
  390. // SSH page
  391. SessionData->Compression = CompressionCheck->Checked;
  392. SessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  393. SessionData->SshProt = GetSshProt();
  394. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  395. {
  396. SessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  397. }
  398. // Kex page
  399. for (int Index = 0; Index < KEX_COUNT; Index++)
  400. {
  401. SessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  402. }
  403. FSessionData->AuthGSSAPIKEX = AuthGSSAPIKEXCheck->Checked;
  404. SessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  405. SessionData->RekeyData = RekeyDataEdit->Text;
  406. // Authentication page
  407. SessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
  408. SessionData->TryAgent = TryAgentCheck->Checked;
  409. SessionData->AuthTIS = AuthTISCheck->Checked;
  410. SessionData->AuthKI = AuthKICheck->Checked;
  411. SessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  412. SessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
  413. SessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  414. SessionData->AgentFwd = AgentFwdCheck->Checked;
  415. SessionData->PublicKeyFile = PrivateKeyEdit3->Text;
  416. // Connection page
  417. SessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  418. SessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
  419. SessionData->SshSimple = BufferSizeCheck->Checked;
  420. if (PingNullPacketButton->Checked)
  421. {
  422. SessionData->PingType = ptNullPacket;
  423. }
  424. else if (PingDummyCommandButton->Checked)
  425. {
  426. SessionData->PingType = ptDummyCommand;
  427. }
  428. else
  429. {
  430. SessionData->PingType = ptOff;
  431. }
  432. SessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  433. SessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
  434. SessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
  435. SessionData->Timeout = TimeoutEdit->AsInteger;
  436. if (IPv4Button->Checked)
  437. {
  438. SessionData->AddressFamily = afIPv4;
  439. }
  440. else if (IPv6Button->Checked)
  441. {
  442. SessionData->AddressFamily = afIPv6;
  443. }
  444. else
  445. {
  446. SessionData->AddressFamily = afAuto;
  447. }
  448. // Directories page
  449. SessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
  450. SessionData->LocalDirectory = LocalDirectoryEdit->Text;
  451. SessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  452. SessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  453. SessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  454. SessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  455. SessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  456. SessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  457. SessionData->FollowDirectorySymlinks = FollowDirectorySymlinksCheck->Checked;
  458. // Environment page
  459. if (DSTModeUnixCheck->Checked)
  460. {
  461. SessionData->DSTMode = dstmUnix;
  462. }
  463. else if (DSTModeKeepCheck->Checked)
  464. {
  465. SessionData->DSTMode = dstmKeep;
  466. }
  467. else
  468. {
  469. SessionData->DSTMode = dstmWin;
  470. }
  471. if (EOLTypeCombo->ItemIndex == 0)
  472. {
  473. SessionData->EOLType = eolLF;
  474. }
  475. else
  476. {
  477. SessionData->EOLType = eolCRLF;
  478. }
  479. switch (UtfCombo->ItemIndex)
  480. {
  481. case 1:
  482. SessionData->NotUtf = asOn;
  483. break;
  484. case 2:
  485. SessionData->NotUtf = asOff;
  486. break;
  487. default:
  488. SessionData->NotUtf = asAuto;
  489. break;
  490. }
  491. SessionData->TimeDifference =
  492. (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
  493. (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
  494. SessionData->TimeDifferenceAuto = TimeDifferenceAutoCheck->Checked;
  495. SessionData->TrimVMSVersions = TrimVMSVersionsCheck->Checked;
  496. SessionData->PuttySettings = PuttySettingsEdit->Text;
  497. // Environment/Recycle bin page
  498. SessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  499. SessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  500. SessionData->RecycleBinPath =
  501. SessionData->DeleteToRecycleBin || SessionData->OverwrittenToRecycleBin ||
  502. (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
  503. RecycleBinPathEdit->Text : UnicodeString();
  504. // SCP page
  505. SessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  506. SessionData->Shell = (SessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
  507. SessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  508. SessionData->ReturnVar = (SessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
  509. SessionData->ListingCommand = ListingCommandEdit->Text;
  510. SessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
  511. SessionData->ClearAliases = ClearAliasesCheck->Checked;
  512. SessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  513. SessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  514. SessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  515. SessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  516. // SFTP page
  517. SessionData->SftpServer = (IsDefaultSftpServer() ? UnicodeString() : SftpServerEdit->Text);
  518. SessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  519. if (AllowScpFallbackCheck->Checked != (SessionData->FSProtocol == fsSFTP))
  520. {
  521. if (AllowScpFallbackCheck->Checked)
  522. {
  523. DebugAssert(SessionData->FSProtocol == fsSFTPonly);
  524. SessionData->FSProtocol = fsSFTP;
  525. }
  526. else
  527. {
  528. DebugAssert(SessionData->FSProtocol == fsSFTP);
  529. SessionData->FSProtocol = fsSFTPonly;
  530. }
  531. }
  532. #define SAVE_SFTP_BUG_COMBO(BUG) SessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
  533. SAVE_SFTP_BUG_COMBO(Symlink);
  534. SAVE_SFTP_BUG_COMBO(SignedTS);
  535. #undef SAVE_SFTP_BUG_COMBO
  536. // FTP page
  537. SessionData->FtpAccount = FtpAccountEdit->Text;
  538. SessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
  539. SessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
  540. SessionData->FtpUseMlsd = ComboAutoSwitchSave(FtpUseMlsdCombo);
  541. SessionData->FtpForcePasvIp = ComboAutoSwitchSave(FtpForcePasvIpCombo);
  542. SessionData->FtpHost = ComboAutoSwitchSave(FtpHostCombo);
  543. // S3 page
  544. SessionData->S3DefaultRegion = S3DefaultReqionCombo->Text;
  545. if (S3UrlStyleCombo->ItemIndex == 1)
  546. {
  547. SessionData->S3UrlStyle = s3usPath;
  548. }
  549. else
  550. {
  551. SessionData->S3UrlStyle = s3usVirtualHost;
  552. }
  553. // Proxy page
  554. SessionData->ProxyMethod = GetProxyMethod();
  555. SessionData->FtpProxyLogonType = GetFtpProxyLogonType();
  556. SessionData->ProxyHost = ProxyHostEdit->Text;
  557. SessionData->ProxyPort = ProxyPortEdit->AsInteger;
  558. SessionData->ProxyUsername = ProxyUsernameEdit->Text;
  559. SessionData->ProxyPassword = ProxyPasswordEdit->Text;
  560. SessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  561. SessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
  562. SessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  563. SessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
  564. // Bugs page
  565. #define SAVE_BUG_COMBO(BUG) SessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
  566. SAVE_BUG_COMBO(Ignore1);
  567. SAVE_BUG_COMBO(PlainPW1);
  568. SAVE_BUG_COMBO(RSA1);
  569. SAVE_BUG_COMBO(HMAC2);
  570. SAVE_BUG_COMBO(DeriveKey2);
  571. SAVE_BUG_COMBO(RSAPad2);
  572. SAVE_BUG_COMBO(PKSessID2);
  573. SAVE_BUG_COMBO(Rekey2);
  574. SAVE_BUG_COMBO(MaxPkt2);
  575. SAVE_BUG_COMBO(Ignore2);
  576. SAVE_BUG_COMBO(WinAdj);
  577. #undef SAVE_BUG_COMBO
  578. // Tunnel page
  579. SessionData->Tunnel = TunnelCheck->Checked;
  580. SessionData->TunnelUserName = TunnelUserNameEdit->Text;
  581. SessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  582. SessionData->TunnelHostName = TunnelHostNameEdit->Text;
  583. SessionData->TunnelPassword = TunnelPasswordEdit->Text;
  584. SessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit3->Text;
  585. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  586. {
  587. SessionData->TunnelLocalPortNumber = 0;
  588. }
  589. else
  590. {
  591. SessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  592. }
  593. // connection/tls/ssl page
  594. SessionData->MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  595. SessionData->MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  596. SessionData->SslSessionReuse = SslSessionReuseCheck->Checked;
  597. SessionData->TlsCertificateFile = TlsCertificateFileEdit->Text;
  598. // Note page
  599. SessionData->Note = NoteMemo->Lines->Text;
  600. // Encryption page
  601. SessionData->EncryptKey = EncryptFilesCheck->Checked ? GetEncryptKeyEdit()->Text : UnicodeString();
  602. // webdav page
  603. SessionData->WebDavLiberalEscaping = WebDavLiberalEscapingCheck->Checked;
  604. // color
  605. SessionData->Color = FColor;
  606. }
  607. //---------------------------------------------------------------------
  608. TSessionData * __fastcall TSiteAdvancedDialog::GetSessionData()
  609. {
  610. std::unique_ptr<TSessionData> SessionData(new TSessionData(UnicodeString()));
  611. SessionData->Assign(FSessionData);
  612. SaveSession(SessionData.get());
  613. return SessionData.release();
  614. }
  615. //---------------------------------------------------------------------
  616. void __fastcall TSiteAdvancedDialog::UpdateNavigationTree()
  617. {
  618. TTreeNode * ActiveNode = NULL;
  619. {
  620. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  621. int Index = 0;
  622. TTreeNode * PrevNode = NULL;
  623. while (Index < PageControl->PageCount)
  624. {
  625. TTabSheet * Tab = PageControl->Pages[Index];
  626. if (Tab->Enabled)
  627. {
  628. bool Indented = ((Tab->Tag % 100) == 2);
  629. UnicodeString Label = Tab->Caption;
  630. TTreeNode * Node;
  631. if (PrevNode == NULL)
  632. {
  633. DebugAssert(!Indented);
  634. Node = NavigationTree->Items->GetFirstNode();
  635. }
  636. else
  637. {
  638. if (Indented)
  639. {
  640. if (PrevNode->Level == 0)
  641. {
  642. Node = PrevNode->getFirstChild();
  643. if (Node == NULL)
  644. {
  645. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  646. }
  647. }
  648. else
  649. {
  650. Node = PrevNode->getNextSibling();
  651. if (Node == NULL)
  652. {
  653. Node = NavigationTree->Items->Add(PrevNode, Label);
  654. }
  655. }
  656. }
  657. else
  658. {
  659. if (PrevNode->Level == 0)
  660. {
  661. // delete all excess children of previous top level node
  662. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  663. {
  664. Node->Delete();
  665. }
  666. Node = PrevNode->getNextSibling();
  667. if (Node == NULL)
  668. {
  669. Node = NavigationTree->Items->Add(PrevNode, Label);
  670. }
  671. }
  672. else
  673. {
  674. // delete all excess children of previous top level node
  675. while ((Node = PrevNode->getNextSibling()) != NULL)
  676. {
  677. Node->Delete();
  678. }
  679. Node = PrevNode->GetNext();
  680. if (Node == NULL)
  681. {
  682. Node = NavigationTree->Items->Add(NULL, Label);
  683. }
  684. }
  685. }
  686. }
  687. Node->Text = Label;
  688. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  689. PrevNode = Node;
  690. if (PageControl->ActivePage == Tab)
  691. {
  692. Node->Selected = true;
  693. ActiveNode = Node;
  694. }
  695. }
  696. Index++;
  697. }
  698. TTreeNode * Node;
  699. while ((Node = PrevNode->GetNext()) != NULL)
  700. {
  701. Node->Delete();
  702. }
  703. NavigationTree->FullExpand();
  704. }
  705. // node of active page was hidden
  706. if (ActiveNode == NULL)
  707. {
  708. ChangePage(EnvironmentSheet);
  709. }
  710. }
  711. //---------------------------------------------------------------------
  712. void __fastcall TSiteAdvancedDialog::UpdateControls()
  713. {
  714. if (Visible)
  715. {
  716. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  717. bool SshProtocol = FSessionData->UsesSsh;
  718. bool SftpProtocol = (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  719. bool ScpProtocol = (FSessionData->FSProtocol == fsSCPonly);
  720. bool FtpProtocol = (FSessionData->FSProtocol == fsFTP);
  721. bool WebDavProtocol = (FSessionData->FSProtocol == fsWebDAV);
  722. bool S3Protocol = (FSessionData->FSProtocol == fsS3);
  723. bool Neon = IsNeon(FSessionData->FSProtocol);
  724. bool Ssl = (FtpProtocol || WebDavProtocol || S3Protocol) && (FSessionData->Ftps != ftpsNone);
  725. // connection sheet
  726. EnableControl(FtpPasvModeCheck, FtpProtocol);
  727. if (FtpProtocol &&
  728. (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
  729. SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
  730. !FtpPasvModeCheck->Checked)
  731. {
  732. FtpPasvModeCheck->Checked = true;
  733. MessageDialog(MainInstructions(LoadStr(FTP_PASV_MODE_REQUIRED)), qtInformation, qaOK);
  734. }
  735. EnableControl(BufferSizeCheck, SshProtocol || FtpProtocol);
  736. PingGroup->Visible = !FtpProtocol;
  737. EnableControl(PingGroup, SshProtocol);
  738. EnableControl(PingIntervalSecEdit, PingGroup->Enabled && !PingOffButton->Checked);
  739. EnableControl(PingIntervalLabel, PingGroup->Enabled && PingIntervalSecEdit->Enabled);
  740. FtpPingGroup->Visible = FtpProtocol;
  741. EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
  742. EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
  743. EnableControl(IPvGroup, SshProtocol || FtpProtocol);
  744. EnableControl(IPAutoButton, IPvGroup->Enabled && SshProtocol);
  745. // ssh/authentication sheet
  746. AuthSheet->Enabled = SshProtocol;
  747. EnableControl(SshNoUserAuthCheck, (GetSshProt() == ssh2only));
  748. EnableControl(AuthenticationGroup,
  749. !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
  750. EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh1only));
  751. EnableControl(AuthKICheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  752. EnableControl(AuthKIPasswordCheck,
  753. AuthenticationGroup->Enabled &&
  754. ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  755. (AuthKICheck->Enabled && AuthKICheck->Checked)));
  756. EnableControl(AuthenticationParamsGroup, AuthenticationGroup->Enabled);
  757. EnableControl(AgentFwdCheck, AuthenticationParamsGroup->Enabled && TryAgentCheck->Checked);
  758. EnableControl(PrivateKeyViewButton, PrivateKeyEdit3->Enabled && !PrivateKeyEdit3->Text.IsEmpty());
  759. EnableControl(AuthGSSAPICheck3,
  760. AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  761. EnableControl(GSSAPIFwdTGTCheck,
  762. AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
  763. // ssh sheet
  764. AdvancedSheet->Enabled = SshProtocol;
  765. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  766. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  767. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  768. EnableControl(Ssh2LegacyDESCheck, (GetSshProt() == ssh2only));
  769. // ssh/kex sheet
  770. KexSheet->Enabled = SshProtocol && (GetSshProt() == ssh2only) &&
  771. (BugRekey2Combo->ItemIndex != 2);
  772. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  773. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  774. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  775. // ssh/bugs sheet
  776. BugsSheet->Enabled = SshProtocol;
  777. EnableControl(BugIgnore1Combo, (GetSshProt() == ssh1only));
  778. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  779. EnableControl(BugPlainPW1Combo, (GetSshProt() == ssh1only));
  780. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  781. EnableControl(BugRSA1Combo, (GetSshProt() == ssh1only));
  782. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  783. EnableControl(BugHMAC2Combo, (GetSshProt() == ssh2only));
  784. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  785. EnableControl(BugDeriveKey2Combo, (GetSshProt() == ssh2only));
  786. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  787. EnableControl(BugRSAPad2Combo, (GetSshProt() == ssh2only));
  788. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  789. EnableControl(BugPKSessID2Combo, (GetSshProt() == ssh2only));
  790. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  791. EnableControl(BugRekey2Combo, (GetSshProt() == ssh2only));
  792. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  793. EnableControl(BugMaxPkt2Combo, (GetSshProt() == ssh2only));
  794. EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
  795. EnableControl(BugIgnore2Combo, (GetSshProt() == ssh2only));
  796. EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
  797. EnableControl(BugWinAdjCombo, (GetSshProt() == ssh2only));
  798. EnableControl(BugWinAdjLabel, BugWinAdjCombo->Enabled);
  799. // connection/proxy sheet
  800. // this is probaqbly overkill, now we do not allow changing protocol on
  801. // the same window as changing proxy
  802. TComboBox * ProxyMethodCombo =
  803. (SshProtocol ? SshProxyMethodCombo : (FtpProtocol ? FtpProxyMethodCombo : NeonProxyMethodCombo));
  804. TProxyMethod ProxyMethod = GetProxyMethod();
  805. ProxyMethodCombo->Visible = true;
  806. ProxyMethodLabel->FocusControl = ProxyMethodCombo;
  807. if (!SshProtocol)
  808. {
  809. SshProxyMethodCombo->Visible = false;
  810. SshProxyMethodCombo->ItemIndex = ProxyMethod;
  811. }
  812. if (!FtpProtocol)
  813. {
  814. FtpProxyMethodCombo->Visible = false;
  815. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(ProxyMethod);
  816. }
  817. if (!Neon)
  818. {
  819. NeonProxyMethodCombo->Visible = false;
  820. NeonProxyMethodCombo->ItemIndex = GetSupportedNeonProxyMethod(ProxyMethod);
  821. }
  822. int FtpProxyLogonType = GetFtpProxyLogonType();
  823. UnicodeString ProxyCommand =
  824. ((ProxyMethod == pmCmd) ?
  825. ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
  826. EnableControl(ProxyHostEdit,
  827. (ProxyMethod == pmSocks4) ||
  828. (ProxyMethod == pmSocks5) ||
  829. (ProxyMethod == pmHTTP) ||
  830. (ProxyMethod == pmTelnet) ||
  831. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
  832. (FtpProxyLogonType > 0));
  833. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  834. EnableControl(ProxyPortEdit,
  835. (ProxyMethod == pmSocks4) ||
  836. (ProxyMethod == pmSocks5) ||
  837. (ProxyMethod == pmHTTP) ||
  838. (ProxyMethod == pmTelnet) ||
  839. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
  840. (FtpProxyLogonType > 0));
  841. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  842. EnableControl(ProxyUsernameEdit,
  843. // FZAPI does not support username for SOCKS4
  844. ((ProxyMethod == pmSocks4) && (SshProtocol || Neon)) ||
  845. (ProxyMethod == pmSocks5) ||
  846. (ProxyMethod == pmHTTP) ||
  847. (((ProxyMethod == pmTelnet) ||
  848. (ProxyMethod == pmCmd)) &&
  849. AnsiContainsText(ProxyCommand, L"%user")) ||
  850. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  851. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  852. EnableControl(ProxyPasswordEdit,
  853. (ProxyMethod == pmSocks5) ||
  854. (ProxyMethod == pmHTTP) ||
  855. (((ProxyMethod == pmTelnet) ||
  856. (ProxyMethod == pmCmd)) &&
  857. AnsiContainsText(ProxyCommand, L"%pass")) ||
  858. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  859. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  860. bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
  861. ProxySettingsGroup->Visible = SshProtocol;
  862. EnableControl(ProxySettingsGroup, ProxySettings);
  863. EnableControl(ProxyTelnetCommandEdit,
  864. ProxySettings && (ProxyMethod == pmTelnet));
  865. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  866. EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
  867. ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
  868. ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
  869. ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
  870. ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
  871. ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
  872. ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
  873. ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
  874. // environment/directories sheet
  875. EnableControl(SynchronizeBrowsingCheck,
  876. (CustomWinConfiguration->Interface == ifCommander) &&
  877. WinConfiguration->PreservePanelState &&
  878. !WinConfiguration->ScpCommander.PreserveLocalDirectory);
  879. EnableControl(CacheDirectoryChangesCheck,
  880. (!ScpProtocol || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  881. EnableControl(PreserveDirectoryChangesCheck,
  882. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  883. DirectoriesSheet->Enabled);
  884. EnableControl(ResolveSymlinksCheck, (SftpProtocol || ScpProtocol) && DirectoriesSheet->Enabled);
  885. EnableControl(FollowDirectorySymlinksCheck, (SftpProtocol || ScpProtocol || FtpProtocol));
  886. // environment sheet
  887. EnableControl(EOLTypeCombo, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  888. EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
  889. EnableControl(DSTModeGroup, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  890. EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
  891. EnableControl(UtfCombo, (SftpProtocol || FtpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  892. EnableControl(UtfLabel, UtfCombo->Enabled);
  893. // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
  894. bool FtpProtocolWithMlsdOff = FtpProtocol && (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff);
  895. EnableControl(TimeDifferenceAutoCheck, FtpProtocolWithMlsdOff);
  896. EnableControl(TimeDifferenceEdit,
  897. ((FtpProtocolWithMlsdOff && !TimeDifferenceAutoCheck->Checked) ||
  898. ScpProtocol) &&
  899. EnvironmentSheet->Enabled);
  900. EnableControl(TimeDifferenceLabel,
  901. TimeDifferenceEdit->Enabled || TimeDifferenceAutoCheck->Enabled);
  902. EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
  903. EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
  904. EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
  905. EnableControl(TrimVMSVersionsCheck, !S3Protocol);
  906. // environment/recycle bin sheet
  907. EnableControl(OverwrittenToRecycleBinCheck, SftpProtocol && RecycleBinSheet->Enabled);
  908. EnableControl(RecycleBinPathEdit,
  909. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  910. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  911. RecycleBinSheet->Enabled);
  912. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  913. RecycleBinSheet->Enabled);
  914. // environment/sftp sheet
  915. SftpSheet->Enabled = SftpProtocol;
  916. EnableControl(AllowScpFallbackCheck, IsDefaultSftpServer());
  917. // environment/scp/shell
  918. ScpSheet->Enabled = SshProtocol;
  919. ScpSheet->Caption = LoadStr(ScpProtocol ? LOGIN_SCP_SHELL_PAGE : LOGIN_SHELL_PAGE);
  920. // hide also for SFTP with SCP fallback, as if someone wants to configure
  921. // these he/she probably intends to use SCP and should explicitly select it.
  922. // (note that these are not used for separate shell session)
  923. ScpLsOptionsGroup->Visible = ScpProtocol;
  924. OtherShellOptionsGroup->Visible = ScpProtocol;
  925. // environment/ftp
  926. FtpSheet->Enabled = FtpProtocol;
  927. EnableControl(FtpListAllCombo,
  928. (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff));
  929. EnableControl(FtpListAllLabel, FtpListAllCombo->Enabled);
  930. EnableControl(FtpForcePasvIpCombo,
  931. FtpPasvModeCheck->Checked &&
  932. (IPAutoButton->Checked || IPv4Button->Checked));
  933. EnableControl(FtpForcePasvIpLabel, FtpForcePasvIpCombo->Enabled);
  934. // environment/s3
  935. S3Sheet->Enabled = S3Protocol;
  936. // tunnel sheet
  937. TunnelSheet->Enabled = SshProtocol;
  938. // probably needless
  939. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  940. EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
  941. EnableControl(TunnelAuthenticationParamsGroup, TunnelSessionGroup->Enabled);
  942. // connection/ssl/tls
  943. SslSheet->Enabled = Ssl;
  944. // TLS/SSL session reuse is not configurable for WebDAV/S3 yet
  945. SslSessionReuseCheck->Enabled = SslSheet->Enabled && FtpProtocol;
  946. TlsAuthenticationGroup->Visible = Ssl && (FtpProtocol || WebDavProtocol);
  947. // encryption sheet
  948. EncryptionSheet->Enabled = SftpProtocol;
  949. EnableControl(EncryptFilesGroup, EncryptFilesCheck->Checked);
  950. // environment/webdav
  951. WebDavSheet->Enabled = WebDavProtocol;
  952. UpdateNavigationTree();
  953. // color
  954. if (FColor == 0)
  955. {
  956. MenuButton(ColorButton);
  957. }
  958. else
  959. {
  960. ColorButton->Images = ColorImageList;
  961. ColorButton->ImageIndex = GetSessionColorImage(ColorImageList, FColor, 0);
  962. ColorButton->ImageAlignment = iaRight;
  963. }
  964. }
  965. }
  966. //---------------------------------------------------------------------------
  967. void __fastcall TSiteAdvancedDialog::DataChange(TObject * /*Sender*/)
  968. {
  969. if (NoUpdate == 0)
  970. {
  971. UpdateControls();
  972. }
  973. }
  974. //---------------------------------------------------------------------------
  975. void __fastcall TSiteAdvancedDialog::FormShow(TObject * /*Sender*/)
  976. {
  977. InstallPathWordBreakProc(PrivateKeyEdit3);
  978. InstallPathWordBreakProc(TunnelPrivateKeyEdit3);
  979. InstallPathWordBreakProc(RemoteDirectoryEdit);
  980. InstallPathWordBreakProc(LocalDirectoryEdit);
  981. InstallPathWordBreakProc(RecycleBinPathEdit);
  982. InstallPathWordBreakProc(TlsCertificateFileEdit);
  983. InstallPathWordBreakProc(SftpServerEdit);
  984. InstallPathWordBreakProc(ShellEdit);
  985. ChangePage(EnvironmentSheet);
  986. UpdateControls();
  987. }
  988. //---------------------------------------------------------------------------
  989. bool __fastcall TSiteAdvancedDialog::Execute(TSessionData * SessionData)
  990. {
  991. FSessionData = SessionData;
  992. LoadSession();
  993. bool Result = (ShowModal() == DefaultResult(this));
  994. if (Result)
  995. {
  996. SaveSession(SessionData);
  997. }
  998. return Result;
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TSiteAdvancedDialog::NavigationTreeChange(TObject * /*Sender*/,
  1002. TTreeNode * Node)
  1003. {
  1004. if (NoUpdate == 0)
  1005. {
  1006. TAutoNestingCounter Guard(NoUpdate);
  1007. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  1008. // should happen only while loading language
  1009. // (UpdateNavigationTree may not be called yet)
  1010. if (Tab != NULL)
  1011. {
  1012. PageControl->ActivePage = Tab;
  1013. // reshow the accelerators, etc
  1014. ResetSystemSettings(this);
  1015. }
  1016. PageChanged();
  1017. UpdateControls();
  1018. }
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void __fastcall TSiteAdvancedDialog::ChangePage(TTabSheet * Tab)
  1022. {
  1023. PageControl->ActivePage = Tab;
  1024. PageChanged();
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. void __fastcall TSiteAdvancedDialog::PageChanged()
  1028. {
  1029. FPrivateKeyMonitors.reset(NULL);
  1030. ClosePuttySettings();
  1031. bool Found = false;
  1032. if (PageControl->ActivePage)
  1033. {
  1034. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1035. {
  1036. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1037. reinterpret_cast<int>(PageControl->ActivePage))
  1038. {
  1039. NavigationTree->Items->Item[Index]->Selected = true;
  1040. Found = true;
  1041. }
  1042. }
  1043. }
  1044. if (DebugAlwaysTrue(Found))
  1045. {
  1046. DataChange(NULL);
  1047. }
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. void __fastcall TSiteAdvancedDialog::PageControlChange(TObject *)
  1051. {
  1052. DebugFail(); // should never happen as user cannot change the page
  1053. PageChanged();
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. void __fastcall TSiteAdvancedDialog::CMDialogKey(TWMKeyDown & Message)
  1057. {
  1058. if (Message.CharCode == VK_TAB)
  1059. {
  1060. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1061. if (Shift.Contains(ssCtrl))
  1062. {
  1063. TTreeNode * Node = NavigationTree->Selected;
  1064. if (!Shift.Contains(ssShift))
  1065. {
  1066. Node = Node->GetNext();
  1067. if (Node == NULL)
  1068. {
  1069. Node = NavigationTree->Items->GetFirstNode();
  1070. }
  1071. }
  1072. else
  1073. {
  1074. if (Node->GetPrev() != NULL)
  1075. {
  1076. Node = Node->GetPrev();
  1077. }
  1078. else
  1079. {
  1080. while (Node->GetNext() != NULL)
  1081. {
  1082. Node = Node->GetNext();
  1083. }
  1084. }
  1085. }
  1086. Node->Selected = True;
  1087. Message.Result = 1;
  1088. return;
  1089. }
  1090. }
  1091. TForm::Dispatch(&Message);
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TSiteAdvancedDialog::WMHelp(TWMHelp & Message)
  1095. {
  1096. DebugAssert(Message.HelpInfo != NULL);
  1097. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1098. {
  1099. // invoke help for active page (not for whole form), regardless of focus
  1100. // (e.g. even if focus is on control outside pagecontrol)
  1101. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1102. }
  1103. TForm::Dispatch(&Message);
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TSiteAdvancedDialog::Dispatch(void * Message)
  1107. {
  1108. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1109. DebugAssert(M);
  1110. if (M->Msg == CM_DIALOGKEY)
  1111. {
  1112. CMDialogKey(*((TWMKeyDown *)Message));
  1113. }
  1114. else if (M->Msg == WM_HELP)
  1115. {
  1116. WMHelp(*((TWMHelp *)Message));
  1117. }
  1118. else
  1119. {
  1120. TForm::Dispatch(Message);
  1121. }
  1122. }
  1123. //---------------------------------------------------------------------------
  1124. void __fastcall TSiteAdvancedDialog::AlgListBoxStartDrag(TObject * Sender,
  1125. TDragObject *& /*DragObject*/)
  1126. {
  1127. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1128. FAlgDragDest = -1;
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. void __fastcall TSiteAdvancedDialog::AlgListBoxDragOver(TObject * Sender,
  1132. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  1133. {
  1134. if (Source == Sender)
  1135. {
  1136. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1137. }
  1138. else
  1139. {
  1140. Accept = false;
  1141. }
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TSiteAdvancedDialog::AlgListBoxDragDrop(TObject * Sender,
  1145. TObject * Source, int X, int Y)
  1146. {
  1147. if (Source == Sender)
  1148. {
  1149. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1150. if (AllowAlgDrag(AlgListBox, X, Y))
  1151. {
  1152. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1153. }
  1154. }
  1155. }
  1156. //---------------------------------------------------------------------------
  1157. void __fastcall TSiteAdvancedDialog::CipherButtonClick(TObject *Sender)
  1158. {
  1159. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1160. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TSiteAdvancedDialog::KexButtonClick(TObject *Sender)
  1164. {
  1165. AlgMove(KexListBox, KexListBox->ItemIndex,
  1166. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1167. }
  1168. //---------------------------------------------------------------------------
  1169. bool __fastcall TSiteAdvancedDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1170. {
  1171. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1172. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TSiteAdvancedDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1176. {
  1177. if ((Source >= 0) && (Source < AlgListBox->Items->Count) &&
  1178. (Dest >= 0) && (Dest < AlgListBox->Items->Count))
  1179. {
  1180. AlgListBox->Items->Move(Source, Dest);
  1181. AlgListBox->ItemIndex = Dest;
  1182. AlgListBox->SetFocus();
  1183. }
  1184. UpdateControls();
  1185. }
  1186. //---------------------------------------------------------------------------
  1187. void __fastcall TSiteAdvancedDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
  1188. {
  1189. if (NoUpdate == 0)
  1190. {
  1191. UpdateControls();
  1192. if (AuthGSSAPICheck3->Checked && !HasGSSAPI(L""))
  1193. {
  1194. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
  1195. }
  1196. }
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TSiteAdvancedDialog::HelpButtonClick(TObject * /*Sender*/)
  1200. {
  1201. FormHelp(this);
  1202. }
  1203. //---------------------------------------------------------------------------
  1204. void __fastcall TSiteAdvancedDialog::PrivateKeyEdit3AfterDialog(TObject * Sender,
  1205. UnicodeString & Name, bool & Action)
  1206. {
  1207. PathEditAfterDialog(Sender, Name, Action);
  1208. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1209. if (Name != Edit->Text)
  1210. {
  1211. VerifyAndConvertKey(Name, GetSshProt(), true);
  1212. }
  1213. }
  1214. //---------------------------------------------------------------------------
  1215. void __fastcall TSiteAdvancedDialog::FormCloseQuery(TObject * /*Sender*/,
  1216. bool & /*CanClose*/)
  1217. {
  1218. if (ModalResult == DefaultResult(this))
  1219. {
  1220. // StripPathQuotes should not be needed as we do not feed quotes anymore
  1221. VerifyKey(StripPathQuotes(PrivateKeyEdit3->Text), GetSshProt());
  1222. // for tunnel SSH version is not configurable
  1223. VerifyKey(StripPathQuotes(TunnelPrivateKeyEdit3->Text), ssh2only);
  1224. VerifyCertificate(StripPathQuotes(TlsCertificateFileEdit->Text));
  1225. // Particularly for EncryptKey*Edit's
  1226. ExitActiveControl(this);
  1227. }
  1228. }
  1229. //---------------------------------------------------------------------------
  1230. void __fastcall TSiteAdvancedDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1231. UnicodeString & Name, bool & /*Action*/)
  1232. {
  1233. FBeforeDialogPath = Name;
  1234. Name = ExpandEnvironmentVariables(Name);
  1235. }
  1236. //---------------------------------------------------------------------------
  1237. void __fastcall TSiteAdvancedDialog::PathEditAfterDialog(TObject * /*Sender*/,
  1238. UnicodeString & Name, bool & /*Action*/)
  1239. {
  1240. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1241. {
  1242. Name = FBeforeDialogPath;
  1243. }
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. int __fastcall TSiteAdvancedDialog::LastSupportedFtpProxyMethod()
  1247. {
  1248. return pmHTTP;
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. bool __fastcall TSiteAdvancedDialog::SupportedFtpProxyMethod(int Method)
  1252. {
  1253. return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. int __fastcall TSiteAdvancedDialog::GetSupportedFtpProxyMethod(int Method)
  1257. {
  1258. if (SupportedFtpProxyMethod(Method))
  1259. {
  1260. return Method;
  1261. }
  1262. else
  1263. {
  1264. return ::pmNone;
  1265. }
  1266. }
  1267. //---------------------------------------------------------------------------
  1268. int __fastcall TSiteAdvancedDialog::GetSupportedNeonProxyMethod(int Method)
  1269. {
  1270. if ((Method >= 0) && (Method <= pmHTTP))
  1271. {
  1272. return Method;
  1273. }
  1274. else
  1275. {
  1276. return ::pmNone;
  1277. }
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. bool __fastcall TSiteAdvancedDialog::IsNeon(TFSProtocol FSProtocol)
  1281. {
  1282. return (FSProtocol == fsWebDAV) || (FSProtocol == fsS3);
  1283. }
  1284. //---------------------------------------------------------------------------
  1285. TProxyMethod __fastcall TSiteAdvancedDialog::GetProxyMethod()
  1286. {
  1287. TProxyMethod Result;
  1288. TFSProtocol FSProtocol = FSessionData->FSProtocol;
  1289. if (FSessionData->UsesSsh)
  1290. {
  1291. Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
  1292. }
  1293. else if (FSProtocol == fsFTP)
  1294. {
  1295. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1296. {
  1297. Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
  1298. }
  1299. else
  1300. {
  1301. Result = ::pmNone;
  1302. }
  1303. }
  1304. else if (IsNeon(FSProtocol))
  1305. {
  1306. Result = (TProxyMethod)NeonProxyMethodCombo->ItemIndex;
  1307. }
  1308. else
  1309. {
  1310. DebugFail();
  1311. Result = ::pmNone;
  1312. }
  1313. return Result;
  1314. }
  1315. //---------------------------------------------------------------------------
  1316. int __fastcall TSiteAdvancedDialog::GetFtpProxyLogonType()
  1317. {
  1318. int Result;
  1319. if (FSessionData->FSProtocol != fsFTP)
  1320. {
  1321. Result = 0;
  1322. }
  1323. else
  1324. {
  1325. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1326. {
  1327. Result = 0;
  1328. }
  1329. else
  1330. {
  1331. Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
  1332. }
  1333. }
  1334. return Result;
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TSiteAdvancedDialog::NavigationTreeCollapsing(
  1338. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1339. {
  1340. AllowCollapse = false;
  1341. }
  1342. //---------------------------------------------------------------------------
  1343. void __fastcall TSiteAdvancedDialog::ProxyLocalCommandBrowseButtonClick(
  1344. TObject * /*Sender*/)
  1345. {
  1346. BrowseForExecutable(ProxyLocalCommandEdit,
  1347. LoadStr(LOGIN_SELECT_LOCAL_PROXY),
  1348. LoadStr(EXECUTABLE_FILTER), false, true);
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TSiteAdvancedDialog::ColorButtonClick(TObject * /*Sender*/)
  1352. {
  1353. // Reason for separate Menu variable is given in TPreferencesDialog::EditorFontColorButtonClick
  1354. TPopupMenu * Menu = CreateSessionColorPopupMenu(FColor, SessionColorChange);
  1355. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1356. FColorPopupMenu.reset(Menu);
  1357. MenuPopup(Menu, ColorButton);
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. void __fastcall TSiteAdvancedDialog::SessionColorChange(TColor Color)
  1361. {
  1362. FColor = Color;
  1363. UpdateControls();
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. TTlsVersion __fastcall TSiteAdvancedDialog::IndexToTlsVersion(int Index)
  1367. {
  1368. switch (Index)
  1369. {
  1370. default:
  1371. DebugFail();
  1372. case 0:
  1373. return ssl3;
  1374. case 1:
  1375. return tls10;
  1376. case 2:
  1377. return tls11;
  1378. case 3:
  1379. return tls12;
  1380. case 4:
  1381. return tls13;
  1382. }
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. int __fastcall TSiteAdvancedDialog::TlsVersionToIndex(TTlsVersion TlsVersion)
  1386. {
  1387. switch (TlsVersion)
  1388. {
  1389. default:
  1390. DebugFail();
  1391. case ssl2:
  1392. case ssl3:
  1393. return 0;
  1394. case tls10:
  1395. return 1;
  1396. case tls11:
  1397. return 2;
  1398. case tls12:
  1399. return 3;
  1400. case tls13:
  1401. return 4;
  1402. }
  1403. }
  1404. //---------------------------------------------------------------------------
  1405. void __fastcall TSiteAdvancedDialog::MinTlsVersionComboChange(TObject */*Sender*/)
  1406. {
  1407. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1408. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1409. if (MaxTlsVersion < MinTlsVersion)
  1410. {
  1411. MaxTlsVersionCombo->ItemIndex = MinTlsVersionCombo->ItemIndex;
  1412. }
  1413. }
  1414. //---------------------------------------------------------------------------
  1415. void __fastcall TSiteAdvancedDialog::MaxTlsVersionComboChange(TObject * /*Sender*/)
  1416. {
  1417. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1418. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1419. if (MinTlsVersion > MaxTlsVersion)
  1420. {
  1421. MinTlsVersionCombo->ItemIndex = MaxTlsVersionCombo->ItemIndex;
  1422. }
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TSiteAdvancedDialog::ProxyAutodetectButtonClick(TObject * /*Sender*/)
  1426. {
  1427. TInstantOperationVisualizer Visualizer;
  1428. UnicodeString ProxyHost;
  1429. int ProxyPort;
  1430. if (AutodetectProxy(ProxyHost, ProxyPort))
  1431. {
  1432. ProxyHostEdit->Text = ProxyHost;
  1433. ProxyPortEdit->AsInteger = ProxyPort;
  1434. SshProxyMethodCombo->ItemIndex = pmHTTP;
  1435. FtpProxyMethodCombo->ItemIndex = pmHTTP;
  1436. NeonProxyMethodCombo->ItemIndex = pmHTTP;
  1437. UpdateControls();
  1438. }
  1439. }
  1440. //---------------------------------------------------------------------------
  1441. void __fastcall TSiteAdvancedDialog::NoteMemoKeyDown(
  1442. TObject * Sender, WORD & Key, TShiftState Shift)
  1443. {
  1444. MemoKeyDown(Sender, Key, Shift);
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TSiteAdvancedDialog::TlsCertificateFileEditAfterDialog(TObject *Sender,
  1448. UnicodeString &Name, bool &Action)
  1449. {
  1450. PathEditAfterDialog(Sender, Name, Action);
  1451. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1452. if (Name != Edit->Text)
  1453. {
  1454. VerifyCertificate(Name);
  1455. }
  1456. }
  1457. //---------------------------------------------------------------------------
  1458. void __fastcall TSiteAdvancedDialog::PrivateKeyCreatedOrModified(TObject * /*Sender*/, const UnicodeString FileName)
  1459. {
  1460. if (SameText(ExtractFileExt(FileName), FORMAT(L".%s", (PuttyKeyExt))))
  1461. {
  1462. PrivateKeyEdit3->Text = FileName;
  1463. }
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TSiteAdvancedDialog::PrivateKeyToolsButtonClick(TObject * /*Sender*/)
  1467. {
  1468. UnicodeString Dummy;
  1469. PrivateKeyGenerateItem->Enabled = FindTool(PuttygenTool, Dummy);
  1470. PrivateKeyUploadItem->Enabled = (GetSshProt() == ssh2only) && (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  1471. MenuPopup(PrivateKeyMenu, PrivateKeyToolsButton);
  1472. }
  1473. //---------------------------------------------------------------------------
  1474. void __fastcall TSiteAdvancedDialog::PrivateKeyGenerateItemClick(TObject * /*Sender*/)
  1475. {
  1476. unsigned int Filters = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE;
  1477. TObjectList * PrivateKeyMonitors =
  1478. StartCreationDirectoryMonitorsOnEachDrive(Filters, PrivateKeyCreatedOrModified);
  1479. FPrivateKeyMonitors.reset(PrivateKeyMonitors);
  1480. ExecuteTool(PuttygenTool);
  1481. }
  1482. //---------------------------------------------------------------------------
  1483. void __fastcall TSiteAdvancedDialog::PrivateKeyUploadItemClick(TObject * /*Sender*/)
  1484. {
  1485. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1486. SessionData->FSProtocol = fsSFTPonly; // no SCP fallback, as SCP does not implement GetHomeDirectory
  1487. SessionData->RemoteDirectory = UnicodeString();
  1488. UnicodeString FileName = PrivateKeyEdit3->Text;
  1489. if (TTerminalManager::Instance()->UploadPublicKey(NULL, SessionData.get(), FileName))
  1490. {
  1491. PrivateKeyEdit3->Text = FileName;
  1492. PrivateKeyEdit3->SetFocus();
  1493. }
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TSiteAdvancedDialog::PrivateKeyViewButtonClick(TObject * /*Sender*/)
  1497. {
  1498. UnicodeString FileName = PrivateKeyEdit3->Text;
  1499. VerifyAndConvertKey(FileName, GetSshProt(), false);
  1500. PrivateKeyEdit3->Text = FileName;
  1501. UnicodeString CommentDummy;
  1502. UnicodeString Line = GetPublicKeyLine(FileName, CommentDummy);
  1503. std::unique_ptr<TStrings> Messages(TextToStringList(Line));
  1504. TClipboardHandler ClipboardHandler;
  1505. ClipboardHandler.Text = Line;
  1506. TMessageParams Params;
  1507. TQueryButtonAlias Aliases[1];
  1508. Aliases[0].Button = qaRetry;
  1509. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1510. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1511. Params.Aliases = Aliases;
  1512. Params.AliasesCount = LENOF(Aliases);
  1513. UnicodeString Message = LoadStr(LOGIN_AUTHORIZED_KEYS);
  1514. int Answers = qaOK | qaRetry;
  1515. MoreMessageDialog(Message, Messages.get(), qtInformation, Answers, HELP_LOGIN_AUTHORIZED_KEYS, &Params);
  1516. }
  1517. //---------------------------------------------------------------------------
  1518. TCustomEdit * __fastcall TSiteAdvancedDialog::GetEncryptKeyEdit(bool AShow)
  1519. {
  1520. bool Show = (ShowEncryptionKeyCheck->Checked == AShow);
  1521. return (Show ? static_cast<TCustomEdit *>(EncryptKeyVisibleEdit) : static_cast<TCustomEdit *>(EncryptKeyPasswordEdit));
  1522. }
  1523. //---------------------------------------------------------------------------
  1524. void __fastcall TSiteAdvancedDialog::ShowEncryptionKeyCheckClick(TObject * /*Sender*/)
  1525. {
  1526. TCustomEdit * ShowEdit = GetEncryptKeyEdit();
  1527. TCustomEdit * HideEdit = GetEncryptKeyEdit(false);
  1528. if (DebugAlwaysTrue(ShowEdit->Visible != HideEdit->Visible) &&
  1529. DebugAlwaysTrue(!ShowEdit->Visible))
  1530. {
  1531. UnicodeString Key = HideEdit->Text;
  1532. ShowEdit->Visible = true;
  1533. ShowEdit->Text = Key;
  1534. HideEdit->Visible = false;
  1535. }
  1536. }
  1537. //---------------------------------------------------------------------------
  1538. void __fastcall TSiteAdvancedDialog::GenerateKeyButtonClick(TObject * /*Sender*/)
  1539. {
  1540. UnicodeString Key = BytesToHex(GenerateEncryptKey());
  1541. GetEncryptKeyEdit()->Text = Key;
  1542. TClipboardHandler ClipboardHandler;
  1543. ClipboardHandler.Text = Key;
  1544. TMessageParams Params;
  1545. TQueryButtonAlias Aliases[1];
  1546. Aliases[0].Button = qaRetry;
  1547. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1548. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1549. Params.Aliases = Aliases;
  1550. Params.AliasesCount = LENOF(Aliases);
  1551. MessageDialog(LoadStr(ENCRYPT_KEY_GENERATED), qtInformation, qaOK | qaRetry, HELP_FILE_ENCRYPTION, &Params);
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TSiteAdvancedDialog::EncryptKeyEditExit(TObject * /*Sender*/)
  1555. {
  1556. if (!IsCancelButtonBeingClicked(this))
  1557. {
  1558. UnicodeString HexKey = GetEncryptKeyEdit()->Text;
  1559. if (!HexKey.IsEmpty())
  1560. {
  1561. ValidateEncryptKey(HexToBytes(HexKey));
  1562. }
  1563. }
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void TSiteAdvancedDialog::SerializePuttyRegistry(const UnicodeString & Key, TStrings * Values)
  1567. {
  1568. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1569. if (DebugAlwaysTrue(Registry->OpenKeyReadOnly(Key)))
  1570. {
  1571. std::unique_ptr<TStrings> Names(new TStringList());
  1572. Registry->GetValueNames(Names.get());
  1573. for (int Index = 0; Index < Names->Count; Index++)
  1574. {
  1575. UnicodeString Name = Names->Strings[Index];
  1576. TRegDataType Type = Registry->GetDataType(Name);
  1577. UnicodeString Value;
  1578. if (Type == rdString)
  1579. {
  1580. Value = UnicodeString(PuttyStr(Registry->ReadString(Name)));
  1581. }
  1582. else if (DebugAlwaysTrue(Type == rdInteger))
  1583. {
  1584. Value = StrToInt(Registry->ReadInteger(Name));
  1585. }
  1586. SetStringValueEvenIfEmpty(Values, Name, Value);
  1587. }
  1588. }
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. void __fastcall TSiteAdvancedDialog::PuttySettingsTimer(TObject *)
  1592. {
  1593. if (PuttySettingsEdit->Modified)
  1594. {
  1595. FPuttySettingsTimer->Enabled = false;
  1596. }
  1597. else
  1598. {
  1599. std::unique_ptr<TStrings> NewPuttyRegSettings(new TStringList());
  1600. SerializePuttyRegistry(GetPuttySiteKey(), NewPuttyRegSettings.get());
  1601. std::unique_ptr<TStrings> PuttySettings(new TStringList());
  1602. for (int NewIndex = 0; NewIndex < NewPuttyRegSettings->Count; NewIndex++)
  1603. {
  1604. UnicodeString Name = NewPuttyRegSettings->Names[NewIndex];
  1605. UnicodeString NewValue = NewPuttyRegSettings->ValueFromIndex[NewIndex];
  1606. int Index = FPuttyRegSettings->IndexOfName(Name);
  1607. // Ignoring values we do not know (from future versions of PuTTY),
  1608. // as we cannot tell if they are modified or not.
  1609. // Ignoring also all value that we export outselves from WinSCP settings
  1610. // (primarily to avoid collecting all those values, when the user forgets to load the temporary site in PuTTY,
  1611. // and only saves the changed terminal settings with the basic session settings set to empty values)
  1612. if ((Index >= 0) &&
  1613. (FPuttyRegSettings->ValueFromIndex[Index] != NewValue))
  1614. {
  1615. SetStringValueEvenIfEmpty(PuttySettings.get(), Name, NewValue);
  1616. }
  1617. }
  1618. PuttySettingsEdit->Text = StringsToParams(PuttySettings.get()).TrimLeft();
  1619. UpdateControls();
  1620. }
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteName()
  1624. {
  1625. return FORMAT(L"(%s)", (FMTLOAD(PUTTY_SETTINGS_SITE_NAME, (FSessionData->SessionName))));
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteKey()
  1629. {
  1630. return OriginalPuttyRegistryStorageKey + L"\\" + Configuration->PuttySessionsSubKey + L"\\" + PuttyMungeStr(GetPuttySiteName());
  1631. }
  1632. //---------------------------------------------------------------------------
  1633. void __fastcall TSiteAdvancedDialog::ClosePuttySettings()
  1634. {
  1635. if (FPuttySettingsTimer.get() != NULL)
  1636. {
  1637. FPuttySettingsTimer.reset(NULL);
  1638. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1639. Registry->DeleteKey(GetPuttySiteKey());
  1640. }
  1641. }
  1642. //---------------------------------------------------------------------------
  1643. void __fastcall TSiteAdvancedDialog::PuttySettingsButtonClick(TObject *)
  1644. {
  1645. ClosePuttySettings();
  1646. UnicodeString SiteName = GetPuttySiteName();
  1647. MessageDialog(FMTLOAD(PUTTY_SETTINGS_INSTRUCTIONS, (SiteName, SiteName)), qtInformation, qaOK, HELP_PUTTY_SETTINGS);
  1648. PuttySettingsEdit->Modified = false;
  1649. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1650. UnicodeString PuttySettings = SessionData->PuttySettings;
  1651. SessionData->PuttySettings = UnicodeString();
  1652. SavePuttyDefaults(SiteName);
  1653. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1654. UnicodeString PuttySiteKey = GetPuttySiteKey();
  1655. FPuttyRegSettings.reset(new TStringList());
  1656. SerializePuttyRegistry(PuttySiteKey, FPuttyRegSettings.get());
  1657. std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(true));
  1658. for (int Index = 0; Index < AllOptions->Count; Index++)
  1659. {
  1660. int I = FPuttyRegSettings->IndexOfName(AllOptions->Names[Index]);
  1661. if (I >= 0)
  1662. {
  1663. FPuttyRegSettings->Delete(I);
  1664. }
  1665. }
  1666. SessionData->PuttySettings = PuttySettings;
  1667. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1668. UnicodeString Program, Params, Dir;
  1669. SplitCommand(GUIConfiguration->PuttyPath, Program, Params, Dir);
  1670. Program = ExpandEnvironmentVariables(Program);
  1671. if (!FindFile(Program))
  1672. {
  1673. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1674. }
  1675. ExecuteShellChecked(Program, L"");
  1676. FPuttySettingsTimer.reset(new TTimer(this));
  1677. FPuttySettingsTimer->OnTimer = PuttySettingsTimer;
  1678. FPuttySettingsTimer->Interval = MSecsPerSec;
  1679. FPuttySettingsTimer->Enabled = true;
  1680. UpdateControls();
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TSiteAdvancedDialog::FormClose(TObject *, TCloseAction &)
  1684. {
  1685. ClosePuttySettings();
  1686. }
  1687. //---------------------------------------------------------------------------