1
0

SiteAdvanced.cpp 65 KB

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