1
0

SiteAdvanced.cpp 64 KB

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