SiteAdvanced.cpp 67 KB

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