SiteAdvanced.cpp 65 KB

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