SiteAdvanced.cpp 63 KB

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