SiteAdvanced.cpp 63 KB

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