SiteAdvanced.cpp 65 KB

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