SiteAdvanced.cpp 66 KB

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