SiteAdvanced.cpp 66 KB

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