SiteAdvanced.cpp 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  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_ECDH);
  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. SslSessionReuseCheck->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 = SslSessionReuseCheck->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/SSL session reuse is not configurable for WebDAV/S3 yet
  949. SslSessionReuseCheck->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 ssl3;
  1403. case 1:
  1404. return tls10;
  1405. case 2:
  1406. return tls11;
  1407. case 3:
  1408. return tls12;
  1409. case 4:
  1410. return tls13;
  1411. }
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. int __fastcall TSiteAdvancedDialog::TlsVersionToIndex(TTlsVersion TlsVersion)
  1415. {
  1416. switch (TlsVersion)
  1417. {
  1418. default:
  1419. DebugFail();
  1420. case ssl2:
  1421. case ssl3:
  1422. return 0;
  1423. case tls10:
  1424. return 1;
  1425. case tls11:
  1426. return 2;
  1427. case tls12:
  1428. return 3;
  1429. case tls13:
  1430. return 4;
  1431. }
  1432. }
  1433. //---------------------------------------------------------------------------
  1434. void __fastcall TSiteAdvancedDialog::MinTlsVersionComboChange(TObject */*Sender*/)
  1435. {
  1436. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1437. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1438. if (MaxTlsVersion < MinTlsVersion)
  1439. {
  1440. MaxTlsVersionCombo->ItemIndex = MinTlsVersionCombo->ItemIndex;
  1441. }
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. void __fastcall TSiteAdvancedDialog::MaxTlsVersionComboChange(TObject * /*Sender*/)
  1445. {
  1446. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1447. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1448. if (MinTlsVersion > MaxTlsVersion)
  1449. {
  1450. MinTlsVersionCombo->ItemIndex = MaxTlsVersionCombo->ItemIndex;
  1451. }
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. void __fastcall TSiteAdvancedDialog::ProxyAutodetectButtonClick(TObject * /*Sender*/)
  1455. {
  1456. TInstantOperationVisualizer Visualizer;
  1457. UnicodeString ProxyHost;
  1458. int ProxyPort;
  1459. if (AutodetectProxy(ProxyHost, ProxyPort))
  1460. {
  1461. ProxyHostEdit->Text = ProxyHost;
  1462. ProxyPortEdit->AsInteger = ProxyPort;
  1463. SshProxyMethodCombo->ItemIndex = pmHTTP;
  1464. FtpProxyMethodCombo->ItemIndex = pmHTTP;
  1465. NeonProxyMethodCombo->ItemIndex = pmHTTP;
  1466. UpdateControls();
  1467. }
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. void __fastcall TSiteAdvancedDialog::NoteMemoKeyDown(
  1471. TObject * Sender, WORD & Key, TShiftState Shift)
  1472. {
  1473. MemoKeyDown(Sender, Key, Shift);
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. void __fastcall TSiteAdvancedDialog::TlsCertificateFileEditAfterDialog(TObject *Sender,
  1477. UnicodeString &Name, bool &Action)
  1478. {
  1479. PathEditAfterDialog(Sender, Name, Action);
  1480. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1481. if (Name != Edit->Text)
  1482. {
  1483. VerifyCertificate(Name);
  1484. }
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. void __fastcall TSiteAdvancedDialog::PrivateKeyCreatedOrModified(TObject * /*Sender*/, const UnicodeString FileName)
  1488. {
  1489. if (SameText(ExtractFileExt(FileName), FORMAT(L".%s", (PuttyKeyExt))))
  1490. {
  1491. PrivateKeyEdit3->Text = FileName;
  1492. }
  1493. }
  1494. //---------------------------------------------------------------------------
  1495. void __fastcall TSiteAdvancedDialog::PrivateKeyToolsButtonClick(TObject * /*Sender*/)
  1496. {
  1497. UnicodeString Dummy;
  1498. PrivateKeyGenerateItem->Enabled = FindTool(PuttygenTool, Dummy);
  1499. PrivateKeyUploadItem->Enabled = (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  1500. MenuPopup(PrivateKeyMenu, PrivateKeyToolsButton);
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TSiteAdvancedDialog::PrivateKeyGenerateItemClick(TObject * /*Sender*/)
  1504. {
  1505. unsigned int Filters = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE;
  1506. TObjectList * PrivateKeyMonitors =
  1507. StartCreationDirectoryMonitorsOnEachDrive(Filters, PrivateKeyCreatedOrModified);
  1508. FPrivateKeyMonitors.reset(PrivateKeyMonitors);
  1509. ExecuteTool(PuttygenTool);
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. void __fastcall TSiteAdvancedDialog::PrivateKeyUploadItemClick(TObject * /*Sender*/)
  1513. {
  1514. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1515. SessionData->FSProtocol = fsSFTPonly; // no SCP fallback, as SCP does not implement GetHomeDirectory
  1516. SessionData->RemoteDirectory = UnicodeString();
  1517. UnicodeString FileName = PrivateKeyEdit3->Text;
  1518. if (TTerminalManager::Instance()->UploadPublicKey(NULL, SessionData.get(), FileName))
  1519. {
  1520. PrivateKeyEdit3->Text = FileName;
  1521. PrivateKeyEdit3->SetFocus();
  1522. }
  1523. }
  1524. //---------------------------------------------------------------------------
  1525. void __fastcall TSiteAdvancedDialog::PrivateKeyViewButtonClick(TObject * /*Sender*/)
  1526. {
  1527. UnicodeString FileName = PrivateKeyEdit3->Text;
  1528. VerifyAndConvertKey(FileName, false);
  1529. PrivateKeyEdit3->Text = FileName;
  1530. UnicodeString CommentDummy;
  1531. bool HasCertificate;
  1532. UnicodeString Line = GetPublicKeyLine(FileName, CommentDummy, HasCertificate);
  1533. std::unique_ptr<TStrings> Messages(TextToStringList(Line));
  1534. TClipboardHandler ClipboardHandler;
  1535. ClipboardHandler.Text = Line;
  1536. TMessageParams Params;
  1537. TQueryButtonAlias Aliases[1];
  1538. Aliases[0].Button = qaRetry;
  1539. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1540. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1541. Params.Aliases = Aliases;
  1542. Params.AliasesCount = LENOF(Aliases);
  1543. UnicodeString Message = LoadStr(HasCertificate ? LOGIN_KEY_WITH_CERTIFICATE : LOGIN_AUTHORIZED_KEYS);
  1544. int Answers = qaOK | qaRetry;
  1545. MoreMessageDialog(Message, Messages.get(), qtInformation, Answers, HELP_LOGIN_AUTHORIZED_KEYS, &Params);
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. TCustomEdit * __fastcall TSiteAdvancedDialog::GetEncryptKeyEdit(bool AShow)
  1549. {
  1550. bool Show = (ShowEncryptionKeyCheck->Checked == AShow);
  1551. return (Show ? static_cast<TCustomEdit *>(EncryptKeyVisibleEdit) : static_cast<TCustomEdit *>(EncryptKeyPasswordEdit));
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TSiteAdvancedDialog::ShowEncryptionKeyCheckClick(TObject * /*Sender*/)
  1555. {
  1556. TCustomEdit * ShowEdit = GetEncryptKeyEdit();
  1557. TCustomEdit * HideEdit = GetEncryptKeyEdit(false);
  1558. if (DebugAlwaysTrue(ShowEdit->Visible != HideEdit->Visible) &&
  1559. DebugAlwaysTrue(!ShowEdit->Visible))
  1560. {
  1561. UnicodeString Key = HideEdit->Text;
  1562. ShowEdit->Visible = true;
  1563. ShowEdit->Text = Key;
  1564. HideEdit->Visible = false;
  1565. }
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. void __fastcall TSiteAdvancedDialog::GenerateKeyButtonClick(TObject * /*Sender*/)
  1569. {
  1570. UnicodeString Key = BytesToHex(GenerateEncryptKey());
  1571. GetEncryptKeyEdit()->Text = Key;
  1572. TClipboardHandler ClipboardHandler;
  1573. ClipboardHandler.Text = Key;
  1574. TMessageParams Params;
  1575. TQueryButtonAlias Aliases[1];
  1576. Aliases[0].Button = qaRetry;
  1577. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1578. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1579. Params.Aliases = Aliases;
  1580. Params.AliasesCount = LENOF(Aliases);
  1581. MessageDialog(LoadStr(ENCRYPT_KEY_GENERATED), qtInformation, qaOK | qaRetry, HELP_FILE_ENCRYPTION, &Params);
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. void __fastcall TSiteAdvancedDialog::EncryptKeyEditExit(TObject * /*Sender*/)
  1585. {
  1586. if (!IsCancelButtonBeingClicked(this))
  1587. {
  1588. UnicodeString HexKey = GetEncryptKeyEdit()->Text;
  1589. if (!HexKey.IsEmpty())
  1590. {
  1591. ValidateEncryptKey(HexToBytes(HexKey));
  1592. }
  1593. }
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. void TSiteAdvancedDialog::SerializePuttyRegistry(const UnicodeString & Key, TStrings * Values)
  1597. {
  1598. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1599. if (DebugAlwaysTrue(Registry->OpenKeyReadOnly(Key)))
  1600. {
  1601. std::unique_ptr<TStrings> Names(new TStringList());
  1602. Registry->GetValueNames(Names.get());
  1603. for (int Index = 0; Index < Names->Count; Index++)
  1604. {
  1605. UnicodeString Name = Names->Strings[Index];
  1606. TRegDataType Type = Registry->GetDataType(Name);
  1607. UnicodeString Value;
  1608. if (Type == rdString)
  1609. {
  1610. Value = UnicodeString(PuttyStr(Registry->ReadString(Name)));
  1611. }
  1612. else if (DebugAlwaysTrue(Type == rdInteger))
  1613. {
  1614. Value = StrToInt(Registry->ReadInteger(Name));
  1615. }
  1616. SetStringValueEvenIfEmpty(Values, Name, Value);
  1617. }
  1618. }
  1619. }
  1620. //---------------------------------------------------------------------------
  1621. void __fastcall TSiteAdvancedDialog::PuttySettingsTimer(TObject *)
  1622. {
  1623. if (PuttySettingsEdit->Modified)
  1624. {
  1625. FPuttySettingsTimer->Enabled = false;
  1626. }
  1627. else
  1628. {
  1629. std::unique_ptr<TStrings> NewPuttyRegSettings(new TStringList());
  1630. SerializePuttyRegistry(GetPuttySiteKey(), NewPuttyRegSettings.get());
  1631. std::unique_ptr<TStrings> PuttySettings(new TStringList());
  1632. for (int NewIndex = 0; NewIndex < NewPuttyRegSettings->Count; NewIndex++)
  1633. {
  1634. UnicodeString Name = NewPuttyRegSettings->Names[NewIndex];
  1635. UnicodeString NewValue = NewPuttyRegSettings->ValueFromIndex[NewIndex];
  1636. int Index = FPuttyRegSettings->IndexOfName(Name);
  1637. // Ignoring values we do not know (from future versions of PuTTY),
  1638. // as we cannot tell if they are modified or not.
  1639. // Ignoring also all values that we export ourselves from WinSCP settings
  1640. // (primarily to avoid collecting all those values, when the user forgets to load the temporary site in PuTTY,
  1641. // and only saves the changed terminal settings with the basic session settings set to empty values)
  1642. if ((Index >= 0) &&
  1643. (FPuttyRegSettings->ValueFromIndex[Index] != NewValue))
  1644. {
  1645. SetStringValueEvenIfEmpty(PuttySettings.get(), Name, NewValue);
  1646. }
  1647. }
  1648. PuttySettingsEdit->Text = StringsToParams(PuttySettings.get()).TrimLeft();
  1649. UpdateControls();
  1650. }
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteName()
  1654. {
  1655. return FORMAT(L"(%s)", (FMTLOAD(PUTTY_SETTINGS_SITE_NAME, (FSessionData->SessionName))));
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteKey()
  1659. {
  1660. return OriginalPuttyRegistryStorageKey + L"\\" + Configuration->PuttySessionsSubKey + L"\\" + PuttyMungeStr(GetPuttySiteName());
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TSiteAdvancedDialog::ClosePuttySettings()
  1664. {
  1665. if (FPuttySettingsTimer.get() != NULL)
  1666. {
  1667. FPuttySettingsTimer.reset(NULL);
  1668. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1669. Registry->DeleteKey(GetPuttySiteKey());
  1670. }
  1671. }
  1672. //---------------------------------------------------------------------------
  1673. void __fastcall TSiteAdvancedDialog::PuttySettingsButtonClick(TObject *)
  1674. {
  1675. ClosePuttySettings();
  1676. UnicodeString SiteName = GetPuttySiteName();
  1677. MessageDialog(FMTLOAD(PUTTY_SETTINGS_INSTRUCTIONS, (SiteName, SiteName)), qtInformation, qaOK, HELP_PUTTY_SETTINGS);
  1678. PuttySettingsEdit->Modified = false;
  1679. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1680. UnicodeString PuttySettings = SessionData->PuttySettings;
  1681. SessionData->PuttySettings = UnicodeString();
  1682. SavePuttyDefaults(SiteName);
  1683. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1684. UnicodeString PuttySiteKey = GetPuttySiteKey();
  1685. FPuttyRegSettings.reset(new TStringList());
  1686. SerializePuttyRegistry(PuttySiteKey, FPuttyRegSettings.get());
  1687. std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(true));
  1688. for (int Index = 0; Index < AllOptions->Count; Index++)
  1689. {
  1690. int I = FPuttyRegSettings->IndexOfName(AllOptions->Names[Index]);
  1691. if (I >= 0)
  1692. {
  1693. FPuttyRegSettings->Delete(I);
  1694. }
  1695. }
  1696. SessionData->PuttySettings = PuttySettings;
  1697. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1698. UnicodeString Program, Params, Dir;
  1699. SplitCommand(GUIConfiguration->PuttyPath, Program, Params, Dir);
  1700. Program = ExpandEnvironmentVariables(Program);
  1701. if (!FindFile(Program))
  1702. {
  1703. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1704. }
  1705. ExecuteShellChecked(Program, L"");
  1706. FPuttySettingsTimer.reset(new TTimer(this));
  1707. FPuttySettingsTimer->OnTimer = PuttySettingsTimer;
  1708. FPuttySettingsTimer->Interval = MSecsPerSec;
  1709. FPuttySettingsTimer->Enabled = true;
  1710. UpdateControls();
  1711. }
  1712. //---------------------------------------------------------------------------
  1713. void __fastcall TSiteAdvancedDialog::FormClose(TObject *, TCloseAction &)
  1714. {
  1715. ClosePuttySettings();
  1716. }
  1717. //---------------------------------------------------------------------------