SiteAdvanced.cpp 67 KB

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