SiteAdvanced.cpp 66 KB

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