SiteAdvanced.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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 <HelpWin.h>
  10. #include <VCLCommon.h>
  11. #include "WinInterface.h"
  12. #include "SiteAdvanced.h"
  13. #include "GUITools.h"
  14. #include "Tools.h"
  15. #include "WinConfiguration.h"
  16. #include "PuttyTools.h"
  17. //---------------------------------------------------------------------
  18. #pragma link "ComboEdit"
  19. #pragma link "PasswordEdit"
  20. #pragma link "UpDownEdit"
  21. #ifndef NO_RESOURCES
  22. #pragma resource "*.dfm"
  23. #endif
  24. //---------------------------------------------------------------------------
  25. // Sheet tag:
  26. // 01 top, 02 indented
  27. //---------------------------------------------------------------------------
  28. bool __fastcall DoSiteAdvancedDialog(TSessionData * SessionData, int Options)
  29. {
  30. TSiteAdvancedDialog * SiteAdvancedDialog = new TSiteAdvancedDialog(Application, Options);
  31. bool Result;
  32. try
  33. {
  34. Result = SiteAdvancedDialog->Execute(SessionData);
  35. }
  36. __finally
  37. {
  38. delete SiteAdvancedDialog;
  39. }
  40. return Result;
  41. }
  42. //---------------------------------------------------------------------
  43. static const UnicodeString DefaultRecycleBinPath = L"/tmp";
  44. //---------------------------------------------------------------------
  45. __fastcall TSiteAdvancedDialog::TSiteAdvancedDialog(
  46. TComponent * AOwner, int Options) :
  47. TForm(AOwner)
  48. {
  49. NoUpdate = 0;
  50. FOptions = Options;
  51. // we need to make sure that window procedure is set asap
  52. // (so that CM_SHOWINGCHANGED handling is applied)
  53. UseSystemSettings(this);
  54. InitControls();
  55. PageControl->ActivePage = EnvironmentSheet;
  56. }
  57. //---------------------------------------------------------------------
  58. void __fastcall TSiteAdvancedDialog::InitControls()
  59. {
  60. ComboAutoSwitchInitialize(UtfCombo);
  61. ComboAutoSwitchInitialize(BugIgnore1Combo);
  62. ComboAutoSwitchInitialize(BugPlainPW1Combo);
  63. ComboAutoSwitchInitialize(BugRSA1Combo);
  64. ComboAutoSwitchInitialize(BugHMAC2Combo);
  65. ComboAutoSwitchInitialize(BugDeriveKey2Combo);
  66. ComboAutoSwitchInitialize(BugRSAPad2Combo);
  67. ComboAutoSwitchInitialize(BugPKSessID2Combo);
  68. ComboAutoSwitchInitialize(BugRekey2Combo);
  69. ComboAutoSwitchInitialize(BugMaxPkt2Combo);
  70. ComboAutoSwitchInitialize(BugIgnore2Combo);
  71. ComboAutoSwitchInitialize(BugWinAdjCombo);
  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. if (FLAGCLEAR(FOptions, loLocalDirectory))
  98. {
  99. LocalDirectoryLabel->Visible = false;
  100. LocalDirectoryEdit->Visible = false;
  101. LocalDirectoryDescLabel->Visible = false;
  102. DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + ScaleByTextHeight(this, 12);
  103. DirectoryOptionsGroup->Top = DirectoriesGroup->Top + DirectoriesGroup->Height + ScaleByTextHeight(this, 8);
  104. }
  105. ColorButton->Visible = (FOptions & loColor);
  106. SetSessionColor((TColor)0);
  107. }
  108. //---------------------------------------------------------------------
  109. void __fastcall TSiteAdvancedDialog::LoadSession()
  110. {
  111. {
  112. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  113. // Directories page
  114. SynchronizeBrowsingCheck->Checked = FSessionData->SynchronizeBrowsing;
  115. LocalDirectoryEdit->Text = FSessionData->LocalDirectory;
  116. RemoteDirectoryEdit->Text = FSessionData->RemoteDirectory;
  117. UpdateDirectoriesCheck->Checked = FSessionData->UpdateDirectories;
  118. CacheDirectoriesCheck->Checked = FSessionData->CacheDirectories;
  119. CacheDirectoryChangesCheck->Checked = FSessionData->CacheDirectoryChanges;
  120. PreserveDirectoryChangesCheck->Checked = FSessionData->PreserveDirectoryChanges;
  121. ResolveSymlinksCheck->Checked = FSessionData->ResolveSymlinks;
  122. // Environment page
  123. switch (FSessionData->DSTMode)
  124. {
  125. case dstmWin:
  126. DSTModeWinCheck->Checked = true;
  127. break;
  128. case dstmKeep:
  129. DSTModeKeepCheck->Checked = true;
  130. break;
  131. default:
  132. case dstmUnix:
  133. DSTModeUnixCheck->Checked = true;
  134. break;
  135. }
  136. if (FSessionData->EOLType == eolLF)
  137. {
  138. EOLTypeCombo->ItemIndex = 0;
  139. }
  140. else
  141. {
  142. EOLTypeCombo->ItemIndex = 1;
  143. }
  144. switch (FSessionData->NotUtf)
  145. {
  146. case asOn:
  147. UtfCombo->ItemIndex = 1;
  148. break;
  149. case asOff:
  150. UtfCombo->ItemIndex = 2;
  151. break;
  152. default:
  153. UtfCombo->ItemIndex = 0;
  154. break;
  155. }
  156. int TimeDifferenceMin = TimeToMinutes(FSessionData->TimeDifference);
  157. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / MinsPerHour;
  158. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % MinsPerHour;
  159. TimeDifferenceAutoCheck->Checked = FSessionData->TimeDifferenceAuto;
  160. // Environment/Recycle bin page
  161. DeleteToRecycleBinCheck->Checked = FSessionData->DeleteToRecycleBin;
  162. OverwrittenToRecycleBinCheck->Checked = FSessionData->OverwrittenToRecycleBin;
  163. RecycleBinPathEdit->Text =
  164. !FSessionData->RecycleBinPath.IsEmpty() ?
  165. FSessionData->RecycleBinPath : DefaultRecycleBinPath;
  166. // SFTP page
  167. if (FSessionData->SftpServer.IsEmpty())
  168. {
  169. SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
  170. }
  171. else
  172. {
  173. SftpServerEdit->Text = FSessionData->SftpServer;
  174. }
  175. // hide selection, which is wrongly shown initially even when the box has not focus
  176. SftpServerEdit->SelLength = 0;
  177. AllowScpFallbackCheck->Checked = (FSessionData->FSProtocol == fsSFTP);
  178. SFTPMaxVersionCombo->ItemIndex = FSessionData->SFTPMaxVersion;
  179. #define LOAD_SFTP_BUG_COMBO(BUG) \
  180. ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, FSessionData->SFTPBug[sb ## BUG])
  181. LOAD_SFTP_BUG_COMBO(Symlink);
  182. LOAD_SFTP_BUG_COMBO(SignedTS);
  183. #undef LOAD_SFTP_BUG_COMBO
  184. // FTP page
  185. FtpAccountEdit->Text = FSessionData->FtpAccount;
  186. PostLoginCommandsMemo->Lines->Text = FSessionData->PostLoginCommands;
  187. ComboAutoSwitchLoad(FtpListAllCombo, FSessionData->FtpListAll);
  188. ComboAutoSwitchLoad(FtpUseMlsdCombo, FSessionData->FtpUseMlsd);
  189. ComboAutoSwitchLoad(FtpForcePasvIpCombo, FSessionData->FtpForcePasvIp);
  190. ComboAutoSwitchLoad(FtpHostCombo, FSessionData->FtpHost);
  191. // Authentication page
  192. SshNoUserAuthCheck->Checked = FSessionData->SshNoUserAuth;
  193. TryAgentCheck->Checked = FSessionData->TryAgent;
  194. AuthTISCheck->Checked = FSessionData->AuthTIS;
  195. AuthKICheck->Checked = FSessionData->AuthKI;
  196. AuthKIPasswordCheck->Checked = FSessionData->AuthKIPassword;
  197. AuthGSSAPICheck3->Checked = FSessionData->AuthGSSAPI;
  198. GSSAPIFwdTGTCheck->Checked = FSessionData->GSSAPIFwdTGT;
  199. AgentFwdCheck->Checked = FSessionData->AgentFwd;
  200. PrivateKeyEdit2->Text = FSessionData->PublicKeyFile;
  201. // SSH page
  202. Ssh2LegacyDESCheck->Checked = FSessionData->Ssh2DES;
  203. CompressionCheck->Checked = FSessionData->Compression;
  204. switch (FSessionData->SshProt)
  205. {
  206. case ssh1only: SshProt1onlyButton->Checked = true; break;
  207. case ssh1: SshProt1Button->Checked = true; break;
  208. case ssh2: SshProt2Button->Checked = true; break;
  209. case ssh2only: SshProt2onlyButton->Checked = true; break;
  210. }
  211. CipherListBox->Items->Clear();
  212. assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_ARCFOUR);
  213. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  214. {
  215. CipherListBox->Items->AddObject(
  216. LoadStr(CIPHER_NAME_WARN+FSessionData->Cipher[Index]),
  217. (TObject*)FSessionData->Cipher[Index]);
  218. }
  219. // KEX page
  220. KexListBox->Items->Clear();
  221. assert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_RSA);
  222. for (int Index = 0; Index < KEX_COUNT; Index++)
  223. {
  224. KexListBox->Items->AddObject(
  225. LoadStr(KEX_NAME_WARN+FSessionData->Kex[Index]),
  226. (TObject*)FSessionData->Kex[Index]);
  227. }
  228. RekeyTimeEdit->AsInteger = FSessionData->RekeyTime;
  229. RekeyDataEdit->Text = FSessionData->RekeyData;
  230. // Connection page
  231. FtpPasvModeCheck->Checked = FSessionData->FtpPasvMode;
  232. BufferSizeCheck->Checked = (FSessionData->SendBuf > 0) && FSessionData->SshSimple;
  233. switch (FSessionData->PingType)
  234. {
  235. case ptNullPacket:
  236. PingNullPacketButton->Checked = true;
  237. break;
  238. case ptDummyCommand:
  239. PingDummyCommandButton->Checked = true;
  240. break;
  241. default:
  242. PingOffButton->Checked = true;
  243. break;
  244. }
  245. PingIntervalSecEdit->AsInteger = FSessionData->PingInterval;
  246. switch (FSessionData->FtpPingType)
  247. {
  248. case ptDummyCommand:
  249. FtpPingDummyCommandButton->Checked = true;
  250. break;
  251. default:
  252. FtpPingOffButton->Checked = true;
  253. break;
  254. }
  255. FtpPingIntervalSecEdit->AsInteger = FSessionData->FtpPingInterval;
  256. TimeoutEdit->AsInteger = FSessionData->Timeout;
  257. switch (FSessionData->AddressFamily)
  258. {
  259. case afIPv4:
  260. IPv4Button->Checked = true;
  261. break;
  262. case afIPv6:
  263. IPv6Button->Checked = true;
  264. break;
  265. case afAuto:
  266. default:
  267. IPAutoButton->Checked = true;
  268. break;
  269. }
  270. // Shell page
  271. if (FSessionData->DefaultShell)
  272. {
  273. ShellEdit->Text = ShellEdit->Items->Strings[0];
  274. }
  275. else
  276. {
  277. ShellEdit->Text = FSessionData->Shell;
  278. }
  279. // hide selection, which is wrongly shown initially even when the box has not focus
  280. ShellEdit->SelLength = 0;
  281. if (FSessionData->DetectReturnVar)
  282. {
  283. ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
  284. }
  285. else
  286. {
  287. ReturnVarEdit->Text = FSessionData->ReturnVar;
  288. }
  289. ReturnVarEdit->SelLength = 0;
  290. ListingCommandEdit->Text = FSessionData->ListingCommand;
  291. ListingCommandEdit->SelLength = 0;
  292. CheckBoxAutoSwitchLoad(LookupUserGroupsCheck, FSessionData->LookupUserGroups);
  293. ClearAliasesCheck->Checked = FSessionData->ClearAliases;
  294. IgnoreLsWarningsCheck->Checked = FSessionData->IgnoreLsWarnings;
  295. Scp1CompatibilityCheck->Checked = FSessionData->Scp1Compatibility;
  296. UnsetNationalVarsCheck->Checked = FSessionData->UnsetNationalVars;
  297. SCPLsFullTimeAutoCheck->Checked = (FSessionData->SCPLsFullTime != asOff);
  298. // Proxy page
  299. SshProxyMethodCombo->ItemIndex = FSessionData->ProxyMethod;
  300. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(FSessionData->ProxyMethod);
  301. if (FSessionData->FtpProxyLogonType != 0)
  302. {
  303. FtpProxyMethodCombo->ItemIndex = LastSupportedFtpProxyMethod() + FSessionData->FtpProxyLogonType;
  304. }
  305. WebDavProxyMethodCombo->ItemIndex = GetSupportedWebDavProxyMethod(FSessionData->ProxyMethod);
  306. ProxyHostEdit->Text = FSessionData->ProxyHost;
  307. ProxyPortEdit->AsInteger = FSessionData->ProxyPort;
  308. ProxyUsernameEdit->Text = FSessionData->ProxyUsername;
  309. ProxyPasswordEdit->Text = FSessionData->ProxyPassword;
  310. ProxyTelnetCommandEdit->Text = FSessionData->ProxyTelnetCommand;
  311. ProxyLocalCommandEdit->Text = FSessionData->ProxyLocalCommand;
  312. ProxyLocalhostCheck->Checked = FSessionData->ProxyLocalhost;
  313. ProxyDNSCombo->ItemIndex = 2 - FSessionData->ProxyDNS;
  314. // Bugs page
  315. #define LOAD_BUG_COMBO(BUG) \
  316. ComboAutoSwitchLoad(Bug ## BUG ## Combo, FSessionData->Bug[sb ## BUG])
  317. LOAD_BUG_COMBO(Ignore1);
  318. LOAD_BUG_COMBO(PlainPW1);
  319. LOAD_BUG_COMBO(RSA1);
  320. LOAD_BUG_COMBO(HMAC2);
  321. LOAD_BUG_COMBO(DeriveKey2);
  322. LOAD_BUG_COMBO(RSAPad2);
  323. LOAD_BUG_COMBO(PKSessID2);
  324. LOAD_BUG_COMBO(Rekey2);
  325. LOAD_BUG_COMBO(MaxPkt2);
  326. LOAD_BUG_COMBO(Ignore2);
  327. LOAD_BUG_COMBO(WinAdj);
  328. #undef LOAD_BUG_COMBO
  329. // Tunnel page
  330. TunnelCheck->Checked = FSessionData->Tunnel;
  331. TunnelUserNameEdit->Text = FSessionData->TunnelUserName;
  332. TunnelPortNumberEdit->AsInteger = FSessionData->TunnelPortNumber;
  333. TunnelHostNameEdit->Text = FSessionData->TunnelHostName;
  334. TunnelPasswordEdit->Text = FSessionData->TunnelPassword;
  335. TunnelPrivateKeyEdit2->Text = FSessionData->TunnelPublicKeyFile;
  336. if (FSessionData->TunnelAutoassignLocalPortNumber)
  337. {
  338. TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
  339. }
  340. else
  341. {
  342. TunnelLocalPortNumberEdit->Text = IntToStr(FSessionData->TunnelLocalPortNumber);
  343. }
  344. // hide selection, which is wrongly shown initially even when the box has not focus
  345. TunnelLocalPortNumberEdit->SelLength = 0;
  346. // connection/tls/ssl page
  347. MinTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MinTlsVersion);
  348. MaxTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MaxTlsVersion);
  349. SslSessionReuseCheck->Checked = FSessionData->SslSessionReuse;
  350. // Note page
  351. NoteMemo->Lines->Text = FSessionData->Note;
  352. // color
  353. SetSessionColor((TColor)FSessionData->Color);
  354. }
  355. UpdateControls();
  356. }
  357. //---------------------------------------------------------------------
  358. TSshProt __fastcall TSiteAdvancedDialog::GetSshProt()
  359. {
  360. if (SshProt1onlyButton->Checked)
  361. {
  362. return ssh1only;
  363. }
  364. else if (SshProt1Button->Checked)
  365. {
  366. return ssh1;
  367. }
  368. else if (SshProt2Button->Checked)
  369. {
  370. return ssh2;
  371. }
  372. else
  373. {
  374. return ssh2only;
  375. }
  376. }
  377. //---------------------------------------------------------------------
  378. void __fastcall TSiteAdvancedDialog::SaveSession()
  379. {
  380. // SSH page
  381. FSessionData->Compression = CompressionCheck->Checked;
  382. FSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  383. FSessionData->SshProt = GetSshProt();
  384. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  385. {
  386. FSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  387. }
  388. // Kex page
  389. for (int Index = 0; Index < KEX_COUNT; Index++)
  390. {
  391. FSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  392. }
  393. FSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  394. FSessionData->RekeyData = RekeyDataEdit->Text;
  395. // Authentication page
  396. FSessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
  397. FSessionData->TryAgent = TryAgentCheck->Checked;
  398. FSessionData->AuthTIS = AuthTISCheck->Checked;
  399. FSessionData->AuthKI = AuthKICheck->Checked;
  400. FSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  401. FSessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
  402. FSessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  403. FSessionData->AgentFwd = AgentFwdCheck->Checked;
  404. FSessionData->PublicKeyFile = PrivateKeyEdit2->Text;
  405. // Connection page
  406. FSessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  407. FSessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
  408. FSessionData->SshSimple = BufferSizeCheck->Checked;
  409. if (PingNullPacketButton->Checked)
  410. {
  411. FSessionData->PingType = ptNullPacket;
  412. }
  413. else if (PingDummyCommandButton->Checked)
  414. {
  415. FSessionData->PingType = ptDummyCommand;
  416. }
  417. else
  418. {
  419. FSessionData->PingType = ptOff;
  420. }
  421. FSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  422. FSessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
  423. FSessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
  424. FSessionData->Timeout = TimeoutEdit->AsInteger;
  425. if (IPv4Button->Checked)
  426. {
  427. FSessionData->AddressFamily = afIPv4;
  428. }
  429. else if (IPv6Button->Checked)
  430. {
  431. FSessionData->AddressFamily = afIPv6;
  432. }
  433. else
  434. {
  435. FSessionData->AddressFamily = afAuto;
  436. }
  437. // Directories page
  438. FSessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
  439. FSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  440. FSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  441. FSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  442. FSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  443. FSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  444. FSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  445. FSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  446. // Environment page
  447. if (DSTModeUnixCheck->Checked)
  448. {
  449. FSessionData->DSTMode = dstmUnix;
  450. }
  451. else if (DSTModeKeepCheck->Checked)
  452. {
  453. FSessionData->DSTMode = dstmKeep;
  454. }
  455. else
  456. {
  457. FSessionData->DSTMode = dstmWin;
  458. }
  459. if (EOLTypeCombo->ItemIndex == 0)
  460. {
  461. FSessionData->EOLType = eolLF;
  462. }
  463. else
  464. {
  465. FSessionData->EOLType = eolCRLF;
  466. }
  467. switch (UtfCombo->ItemIndex)
  468. {
  469. case 1:
  470. FSessionData->NotUtf = asOn;
  471. break;
  472. case 2:
  473. FSessionData->NotUtf = asOff;
  474. break;
  475. default:
  476. FSessionData->NotUtf = asAuto;
  477. break;
  478. }
  479. FSessionData->TimeDifference =
  480. (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
  481. (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
  482. FSessionData->TimeDifferenceAuto = TimeDifferenceAutoCheck->Checked;
  483. // Environment/Recycle bin page
  484. FSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  485. FSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  486. FSessionData->RecycleBinPath =
  487. FSessionData->DeleteToRecycleBin || FSessionData->OverwrittenToRecycleBin ||
  488. (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
  489. RecycleBinPathEdit->Text : UnicodeString();
  490. // SCP page
  491. FSessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  492. FSessionData->Shell = (FSessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
  493. FSessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  494. FSessionData->ReturnVar = (FSessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
  495. FSessionData->ListingCommand = ListingCommandEdit->Text;
  496. FSessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
  497. FSessionData->ClearAliases = ClearAliasesCheck->Checked;
  498. FSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  499. FSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  500. FSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  501. FSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  502. // SFTP page
  503. FSessionData->SftpServer =
  504. ((SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]) ?
  505. UnicodeString() : SftpServerEdit->Text);
  506. FSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  507. if (AllowScpFallbackCheck->Checked != (FSessionData->FSProtocol == fsSFTP))
  508. {
  509. if (AllowScpFallbackCheck->Checked)
  510. {
  511. assert(FSessionData->FSProtocol == fsSFTPonly);
  512. FSessionData->FSProtocol = fsSFTP;
  513. }
  514. else
  515. {
  516. assert(FSessionData->FSProtocol == fsSFTP);
  517. FSessionData->FSProtocol = fsSFTPonly;
  518. }
  519. }
  520. #define SAVE_SFTP_BUG_COMBO(BUG) FSessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
  521. SAVE_SFTP_BUG_COMBO(Symlink);
  522. SAVE_SFTP_BUG_COMBO(SignedTS);
  523. #undef SAVE_SFTP_BUG_COMBO
  524. // FTP page
  525. FSessionData->FtpAccount = FtpAccountEdit->Text;
  526. FSessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
  527. FSessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
  528. FSessionData->FtpUseMlsd = ComboAutoSwitchSave(FtpUseMlsdCombo);
  529. FSessionData->FtpForcePasvIp = ComboAutoSwitchSave(FtpForcePasvIpCombo);
  530. FSessionData->FtpHost = ComboAutoSwitchSave(FtpHostCombo);
  531. // Proxy page
  532. FSessionData->ProxyMethod = GetProxyMethod();
  533. FSessionData->FtpProxyLogonType = GetFtpProxyLogonType();
  534. FSessionData->ProxyHost = ProxyHostEdit->Text;
  535. FSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  536. FSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  537. FSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  538. FSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  539. FSessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
  540. FSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  541. FSessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
  542. // Bugs page
  543. #define SAVE_BUG_COMBO(BUG) FSessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
  544. SAVE_BUG_COMBO(Ignore1);
  545. SAVE_BUG_COMBO(PlainPW1);
  546. SAVE_BUG_COMBO(RSA1);
  547. SAVE_BUG_COMBO(HMAC2);
  548. SAVE_BUG_COMBO(DeriveKey2);
  549. SAVE_BUG_COMBO(RSAPad2);
  550. SAVE_BUG_COMBO(PKSessID2);
  551. SAVE_BUG_COMBO(Rekey2);
  552. SAVE_BUG_COMBO(MaxPkt2);
  553. SAVE_BUG_COMBO(Ignore2);
  554. SAVE_BUG_COMBO(WinAdj);
  555. #undef SAVE_BUG_COMBO
  556. // Tunnel page
  557. FSessionData->Tunnel = TunnelCheck->Checked;
  558. FSessionData->TunnelUserName = TunnelUserNameEdit->Text;
  559. FSessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  560. FSessionData->TunnelHostName = TunnelHostNameEdit->Text;
  561. FSessionData->TunnelPassword = TunnelPasswordEdit->Text;
  562. FSessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit2->Text;
  563. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  564. {
  565. FSessionData->TunnelLocalPortNumber = 0;
  566. }
  567. else
  568. {
  569. FSessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  570. }
  571. // connection/tls/ssl page
  572. FSessionData->MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  573. FSessionData->MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  574. FSessionData->SslSessionReuse = SslSessionReuseCheck->Checked;
  575. // Note page
  576. FSessionData->Note = NoteMemo->Lines->Text;
  577. // color
  578. FSessionData->Color = FColor;
  579. }
  580. //---------------------------------------------------------------------
  581. void __fastcall TSiteAdvancedDialog::UpdateNavigationTree()
  582. {
  583. TTreeNode * ActiveNode = NULL;
  584. {
  585. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  586. int Index = 0;
  587. TTreeNode * PrevNode = NULL;
  588. while (Index < PageControl->PageCount)
  589. {
  590. TTabSheet * Tab = PageControl->Pages[Index];
  591. if (Tab->Enabled)
  592. {
  593. bool Indented = ((Tab->Tag % 100) == 2);
  594. UnicodeString Label = Tab->Caption;
  595. TTreeNode * Node;
  596. if (PrevNode == NULL)
  597. {
  598. assert(!Indented);
  599. Node = NavigationTree->Items->GetFirstNode();
  600. }
  601. else
  602. {
  603. if (Indented)
  604. {
  605. if (PrevNode->Level == 0)
  606. {
  607. Node = PrevNode->getFirstChild();
  608. if (Node == NULL)
  609. {
  610. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  611. }
  612. }
  613. else
  614. {
  615. Node = PrevNode->getNextSibling();
  616. if (Node == NULL)
  617. {
  618. Node = NavigationTree->Items->Add(PrevNode, Label);
  619. }
  620. }
  621. }
  622. else
  623. {
  624. if (PrevNode->Level == 0)
  625. {
  626. // delete all excess children of previous top level node
  627. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  628. {
  629. Node->Delete();
  630. }
  631. Node = PrevNode->getNextSibling();
  632. if (Node == NULL)
  633. {
  634. Node = NavigationTree->Items->Add(PrevNode, Label);
  635. }
  636. }
  637. else
  638. {
  639. // delete all excess children of previous top level node
  640. while ((Node = PrevNode->getNextSibling()) != NULL)
  641. {
  642. Node->Delete();
  643. }
  644. Node = PrevNode->GetNext();
  645. if (Node == NULL)
  646. {
  647. Node = NavigationTree->Items->Add(NULL, Label);
  648. }
  649. }
  650. }
  651. }
  652. Node->Text = Label;
  653. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  654. PrevNode = Node;
  655. if (PageControl->ActivePage == Tab)
  656. {
  657. Node->Selected = true;
  658. ActiveNode = Node;
  659. }
  660. }
  661. Index++;
  662. }
  663. TTreeNode * Node;
  664. while ((Node = PrevNode->GetNext()) != NULL)
  665. {
  666. Node->Delete();
  667. }
  668. NavigationTree->FullExpand();
  669. }
  670. // node of active page was hidden
  671. if (ActiveNode == NULL)
  672. {
  673. ChangePage(EnvironmentSheet);
  674. }
  675. }
  676. //---------------------------------------------------------------------
  677. void __fastcall TSiteAdvancedDialog::UpdateControls()
  678. {
  679. if (Visible)
  680. {
  681. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  682. bool SshProtocol = FSessionData->UsesSsh;
  683. bool SftpProtocol =
  684. (FSessionData->FSProtocol == fsSFTPonly) || (FSessionData->FSProtocol == fsSFTP);
  685. bool ScpProtocol = (FSessionData->FSProtocol == fsSCPonly);
  686. bool FtpProtocol = (FSessionData->FSProtocol == fsFTP);
  687. bool WebDavProtocol = (FSessionData->FSProtocol == fsWebDAV);
  688. bool Ssl = (FtpProtocol || WebDavProtocol) && (FSessionData->Ftps != ftpsNone);
  689. // connection sheet
  690. EnableControl(FtpPasvModeCheck, FtpProtocol);
  691. if (FtpProtocol &&
  692. (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
  693. SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
  694. !FtpPasvModeCheck->Checked)
  695. {
  696. FtpPasvModeCheck->Checked = true;
  697. MessageDialog(MainInstructions(LoadStr(FTP_PASV_MODE_REQUIRED)), qtInformation, qaOK);
  698. }
  699. EnableControl(BufferSizeCheck, SshProtocol);
  700. PingGroup->Visible = !FtpProtocol;
  701. EnableControl(PingGroup, SshProtocol);
  702. EnableControl(PingIntervalSecEdit, PingGroup->Enabled && !PingOffButton->Checked);
  703. EnableControl(PingIntervalLabel, PingGroup->Enabled && PingIntervalSecEdit->Enabled);
  704. FtpPingGroup->Visible = FtpProtocol;
  705. EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
  706. EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
  707. EnableControl(IPvGroup, SshProtocol || FtpProtocol);
  708. EnableControl(IPAutoButton, IPvGroup->Enabled && SshProtocol);
  709. // ssh/authentication sheet
  710. AuthSheet->Enabled = SshProtocol;
  711. EnableControl(SshNoUserAuthCheck, !SshProt1onlyButton->Checked);
  712. EnableControl(AuthenticationGroup,
  713. !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
  714. EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && !SshProt2onlyButton->Checked);
  715. EnableControl(AuthKICheck, AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
  716. EnableControl(AuthKIPasswordCheck,
  717. AuthenticationGroup->Enabled &&
  718. ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  719. (AuthKICheck->Enabled && AuthKICheck->Checked)));
  720. EnableControl(AuthGSSAPICheck3,
  721. AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
  722. EnableControl(GSSAPIFwdTGTCheck,
  723. AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
  724. // ssh sheet
  725. AdvancedSheet->Enabled = SshProtocol;
  726. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  727. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  728. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  729. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  730. // ssh/kex sheet
  731. KexSheet->Enabled = SshProtocol && !SshProt1onlyButton->Checked &&
  732. (BugRekey2Combo->ItemIndex != 2);
  733. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  734. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  735. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  736. // ssh/bugs sheet
  737. BugsSheet->Enabled = SshProtocol;
  738. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  739. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  740. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  741. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  742. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  743. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  744. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  745. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  746. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  747. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  748. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  749. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  750. EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
  751. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  752. EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
  753. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  754. EnableControl(BugMaxPkt2Combo, !SshProt1onlyButton->Checked);
  755. EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
  756. EnableControl(BugIgnore2Combo, !SshProt1onlyButton->Checked);
  757. EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
  758. EnableControl(BugWinAdjCombo, !SshProt1onlyButton->Checked);
  759. EnableControl(BugWinAdjLabel, BugWinAdjCombo->Enabled);
  760. // connection/proxy sheet
  761. // this is probaqbly overkill, now we do not allow changing protocol on
  762. // the same window as changing proxy
  763. TComboBox * ProxyMethodCombo =
  764. (SshProtocol ? SshProxyMethodCombo : (FtpProtocol ? FtpProxyMethodCombo : WebDavProxyMethodCombo));
  765. TProxyMethod ProxyMethod = GetProxyMethod();
  766. ProxyMethodCombo->Visible = true;
  767. ProxyMethodLabel->FocusControl = ProxyMethodCombo;
  768. if (!SshProtocol)
  769. {
  770. SshProxyMethodCombo->Visible = false;
  771. SshProxyMethodCombo->ItemIndex = ProxyMethod;
  772. }
  773. if (!FtpProtocol)
  774. {
  775. FtpProxyMethodCombo->Visible = false;
  776. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(ProxyMethod);
  777. }
  778. if (!WebDavProtocol)
  779. {
  780. WebDavProxyMethodCombo->Visible = false;
  781. WebDavProxyMethodCombo->ItemIndex = GetSupportedWebDavProxyMethod(ProxyMethod);
  782. }
  783. int FtpProxyLogonType = GetFtpProxyLogonType();
  784. UnicodeString ProxyCommand =
  785. ((ProxyMethod == pmCmd) ?
  786. ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
  787. EnableControl(ProxyHostEdit,
  788. (ProxyMethod == pmSocks4) ||
  789. (ProxyMethod == pmSocks5) ||
  790. (ProxyMethod == pmHTTP) ||
  791. (ProxyMethod == pmTelnet) ||
  792. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
  793. (FtpProxyLogonType > 0));
  794. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  795. EnableControl(ProxyPortEdit,
  796. (ProxyMethod == pmSocks4) ||
  797. (ProxyMethod == pmSocks5) ||
  798. (ProxyMethod == pmHTTP) ||
  799. (ProxyMethod == pmTelnet) ||
  800. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
  801. (FtpProxyLogonType > 0));
  802. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  803. EnableControl(ProxyUsernameEdit,
  804. // FZAPI does not support username for SOCKS4
  805. ((ProxyMethod == pmSocks4) && (SshProtocol || WebDavProtocol)) ||
  806. (ProxyMethod == pmSocks5) ||
  807. (ProxyMethod == pmHTTP) ||
  808. (((ProxyMethod == pmTelnet) ||
  809. (ProxyMethod == pmCmd)) &&
  810. AnsiContainsText(ProxyCommand, L"%user")) ||
  811. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  812. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  813. EnableControl(ProxyPasswordEdit,
  814. (ProxyMethod == pmSocks5) ||
  815. (ProxyMethod == pmHTTP) ||
  816. (((ProxyMethod == pmTelnet) ||
  817. (ProxyMethod == pmCmd)) &&
  818. AnsiContainsText(ProxyCommand, L"%pass")) ||
  819. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  820. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  821. bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
  822. ProxySettingsGroup->Visible = SshProtocol;
  823. EnableControl(ProxySettingsGroup, ProxySettings);
  824. EnableControl(ProxyTelnetCommandEdit,
  825. ProxySettings && (ProxyMethod == pmTelnet));
  826. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  827. EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
  828. ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
  829. ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
  830. ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
  831. ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
  832. ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
  833. ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
  834. ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
  835. // environment/directories sheet
  836. EnableControl(SynchronizeBrowsingCheck,
  837. (CustomWinConfiguration->Interface == ifCommander) &&
  838. WinConfiguration->PreservePanelState &&
  839. !WinConfiguration->ScpCommander.PreserveLocalDirectory);
  840. EnableControl(CacheDirectoryChangesCheck,
  841. (!ScpProtocol || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  842. EnableControl(PreserveDirectoryChangesCheck,
  843. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  844. DirectoriesSheet->Enabled);
  845. EnableControl(ResolveSymlinksCheck, (SftpProtocol || ScpProtocol) && DirectoriesSheet->Enabled);
  846. // environment sheet
  847. EnableControl(EOLTypeCombo, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  848. EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
  849. EnableControl(DSTModeGroup, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  850. EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
  851. EnableControl(UtfCombo, (SftpProtocol || FtpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  852. EnableControl(UtfLabel, UtfCombo->Enabled);
  853. // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
  854. bool FtpProtocolWithMlsdOff = FtpProtocol && (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff);
  855. EnableControl(TimeDifferenceAutoCheck, FtpProtocolWithMlsdOff);
  856. EnableControl(TimeDifferenceEdit,
  857. ((FtpProtocolWithMlsdOff && !TimeDifferenceAutoCheck->Checked) ||
  858. ScpProtocol) &&
  859. EnvironmentSheet->Enabled);
  860. EnableControl(TimeDifferenceLabel,
  861. TimeDifferenceEdit->Enabled || TimeDifferenceAutoCheck->Enabled);
  862. EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
  863. EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
  864. EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
  865. // environment/recycle bin sheet
  866. EnableControl(OverwrittenToRecycleBinCheck, SftpProtocol && RecycleBinSheet->Enabled);
  867. EnableControl(RecycleBinPathEdit,
  868. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  869. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  870. RecycleBinSheet->Enabled);
  871. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  872. RecycleBinSheet->Enabled);
  873. // environment/sftp sheet
  874. SftpSheet->Enabled = SftpProtocol;
  875. // environment/scp/shell
  876. ScpSheet->Enabled = SshProtocol;
  877. ScpSheet->Caption = LoadStr(ScpProtocol ? LOGIN_SCP_SHELL_PAGE : LOGIN_SHELL_PAGE);
  878. // hide also for SFTP with SCP fallback, as if someone wants to configure
  879. // these he/she probably intends to use SCP and should explicitly select it.
  880. // (note that these are not used for separate shell session)
  881. ScpLsOptionsGroup->Visible = ScpProtocol;
  882. OtherShellOptionsGroup->Visible = ScpProtocol;
  883. // environment/ftp
  884. FtpSheet->Enabled = FtpProtocol;
  885. EnableControl(FtpListAllCombo,
  886. (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff));
  887. EnableControl(FtpListAllLabel, FtpListAllCombo->Enabled);
  888. EnableControl(FtpForcePasvIpCombo,
  889. FtpPasvModeCheck->Checked &&
  890. (IPAutoButton->Checked || IPv4Button->Checked));
  891. EnableControl(FtpForcePasvIpLabel, FtpForcePasvIpCombo->Enabled);
  892. // tunnel sheet
  893. TunnelSheet->Enabled = SshProtocol;
  894. // probably needless
  895. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  896. EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
  897. EnableControl(TunnelAuthenticationParamsGroup, TunnelSessionGroup->Enabled);
  898. // connection/ssl/tls
  899. SslSheet->Enabled = Ssl;
  900. // TLS/SSL session reuse is not configurable for WebDAV yet
  901. SslSessionReuseCheck->Enabled = SslSheet->Enabled && FtpProtocol;
  902. UpdateNavigationTree();
  903. // color
  904. if (FColor == 0)
  905. {
  906. MenuButton(ColorButton);
  907. }
  908. else
  909. {
  910. ColorButton->Images = ColorImageList;
  911. ColorButton->ImageIndex = 1;
  912. ColorButton->ImageAlignment = iaRight;
  913. }
  914. }
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TSiteAdvancedDialog::DataChange(TObject * /*Sender*/)
  918. {
  919. if (NoUpdate == 0)
  920. {
  921. UpdateControls();
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TSiteAdvancedDialog::FormShow(TObject * /*Sender*/)
  926. {
  927. InstallPathWordBreakProc(PrivateKeyEdit2);
  928. InstallPathWordBreakProc(TunnelPrivateKeyEdit2);
  929. InstallPathWordBreakProc(RemoteDirectoryEdit);
  930. InstallPathWordBreakProc(LocalDirectoryEdit);
  931. InstallPathWordBreakProc(RecycleBinPathEdit);
  932. ChangePage(EnvironmentSheet);
  933. UpdateControls();
  934. }
  935. //---------------------------------------------------------------------------
  936. bool __fastcall TSiteAdvancedDialog::Execute(TSessionData * SessionData)
  937. {
  938. FSessionData = SessionData;
  939. LoadSession();
  940. bool Result = (ShowModal() == DefaultResult(this));
  941. if (Result)
  942. {
  943. SaveSession();
  944. }
  945. return Result;
  946. }
  947. //---------------------------------------------------------------------------
  948. void __fastcall TSiteAdvancedDialog::NavigationTreeChange(TObject * /*Sender*/,
  949. TTreeNode * Node)
  950. {
  951. if (NoUpdate == 0)
  952. {
  953. TAutoNestingCounter Guard(NoUpdate);
  954. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  955. // should happen only while loading language
  956. // (UpdateNavigationTree may not be called yet)
  957. if (Tab != NULL)
  958. {
  959. PageControl->ActivePage = Tab;
  960. // reshow the accelerators, etc
  961. ResetSystemSettings(this);
  962. }
  963. UpdateControls();
  964. }
  965. }
  966. //---------------------------------------------------------------------------
  967. void __fastcall TSiteAdvancedDialog::ChangePage(TTabSheet * Tab)
  968. {
  969. PageControl->ActivePage = Tab;
  970. PageControlChange(PageControl);
  971. }
  972. //---------------------------------------------------------------------------
  973. void __fastcall TSiteAdvancedDialog::PageControlChange(TObject *Sender)
  974. {
  975. bool Found = false;
  976. if (PageControl->ActivePage)
  977. {
  978. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  979. {
  980. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  981. reinterpret_cast<int>(PageControl->ActivePage))
  982. {
  983. NavigationTree->Items->Item[Index]->Selected = true;
  984. Found = true;
  985. }
  986. }
  987. }
  988. if (ALWAYS_TRUE(Found))
  989. {
  990. DataChange(Sender);
  991. }
  992. }
  993. //---------------------------------------------------------------------------
  994. void __fastcall TSiteAdvancedDialog::CMDialogKey(TWMKeyDown & Message)
  995. {
  996. if (Message.CharCode == VK_TAB)
  997. {
  998. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  999. if (Shift.Contains(ssCtrl))
  1000. {
  1001. TTreeNode * Node = NavigationTree->Selected;
  1002. if (!Shift.Contains(ssShift))
  1003. {
  1004. Node = Node->GetNext();
  1005. if (Node == NULL)
  1006. {
  1007. Node = NavigationTree->Items->GetFirstNode();
  1008. }
  1009. }
  1010. else
  1011. {
  1012. if (Node->GetPrev() != NULL)
  1013. {
  1014. Node = Node->GetPrev();
  1015. }
  1016. else
  1017. {
  1018. while (Node->GetNext() != NULL)
  1019. {
  1020. Node = Node->GetNext();
  1021. }
  1022. }
  1023. }
  1024. Node->Selected = True;
  1025. Message.Result = 1;
  1026. return;
  1027. }
  1028. }
  1029. TForm::Dispatch(&Message);
  1030. }
  1031. //---------------------------------------------------------------------------
  1032. void __fastcall TSiteAdvancedDialog::WMHelp(TWMHelp & Message)
  1033. {
  1034. assert(Message.HelpInfo != NULL);
  1035. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1036. {
  1037. // invoke help for active page (not for whole form), regardless of focus
  1038. // (e.g. even if focus is on control outside pagecontrol)
  1039. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1040. }
  1041. TForm::Dispatch(&Message);
  1042. }
  1043. //---------------------------------------------------------------------------
  1044. void __fastcall TSiteAdvancedDialog::Dispatch(void * Message)
  1045. {
  1046. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1047. assert(M);
  1048. if (M->Msg == CM_DIALOGKEY)
  1049. {
  1050. CMDialogKey(*((TWMKeyDown *)Message));
  1051. }
  1052. else if (M->Msg == WM_HELP)
  1053. {
  1054. WMHelp(*((TWMHelp *)Message));
  1055. }
  1056. else
  1057. {
  1058. TForm::Dispatch(Message);
  1059. }
  1060. }
  1061. //---------------------------------------------------------------------------
  1062. void __fastcall TSiteAdvancedDialog::AlgListBoxStartDrag(TObject * Sender,
  1063. TDragObject *& /*DragObject*/)
  1064. {
  1065. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1066. FAlgDragDest = -1;
  1067. }
  1068. //---------------------------------------------------------------------------
  1069. void __fastcall TSiteAdvancedDialog::AlgListBoxDragOver(TObject * Sender,
  1070. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  1071. {
  1072. if (Source == Sender)
  1073. {
  1074. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1075. }
  1076. else
  1077. {
  1078. Accept = false;
  1079. }
  1080. }
  1081. //---------------------------------------------------------------------------
  1082. void __fastcall TSiteAdvancedDialog::AlgListBoxDragDrop(TObject * Sender,
  1083. TObject * Source, int X, int Y)
  1084. {
  1085. if (Source == Sender)
  1086. {
  1087. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1088. if (AllowAlgDrag(AlgListBox, X, Y))
  1089. {
  1090. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1091. }
  1092. }
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. void __fastcall TSiteAdvancedDialog::CipherButtonClick(TObject *Sender)
  1096. {
  1097. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1098. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1099. }
  1100. //---------------------------------------------------------------------------
  1101. void __fastcall TSiteAdvancedDialog::KexButtonClick(TObject *Sender)
  1102. {
  1103. AlgMove(KexListBox, KexListBox->ItemIndex,
  1104. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1105. }
  1106. //---------------------------------------------------------------------------
  1107. bool __fastcall TSiteAdvancedDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1108. {
  1109. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1110. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. void __fastcall TSiteAdvancedDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1114. {
  1115. if ((Source >= 0) && (Source < AlgListBox->Items->Count) &&
  1116. (Dest >= 0) && (Dest < AlgListBox->Items->Count))
  1117. {
  1118. AlgListBox->Items->Move(Source, Dest);
  1119. AlgListBox->ItemIndex = Dest;
  1120. AlgListBox->SetFocus();
  1121. }
  1122. UpdateControls();
  1123. }
  1124. //---------------------------------------------------------------------------
  1125. void __fastcall TSiteAdvancedDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
  1126. {
  1127. if (NoUpdate == 0)
  1128. {
  1129. UpdateControls();
  1130. if (AuthGSSAPICheck3->Checked && !HasGSSAPI(L""))
  1131. {
  1132. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
  1133. }
  1134. }
  1135. }
  1136. //---------------------------------------------------------------------------
  1137. void __fastcall TSiteAdvancedDialog::HelpButtonClick(TObject * /*Sender*/)
  1138. {
  1139. FormHelp(this);
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. void __fastcall TSiteAdvancedDialog::PrivateKeyEdit2AfterDialog(TObject * Sender,
  1143. UnicodeString & Name, bool & /*Action*/)
  1144. {
  1145. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1146. {
  1147. Name = FBeforeDialogPath;
  1148. }
  1149. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1150. if (Name != Edit->Text)
  1151. {
  1152. VerifyKey(Name);
  1153. }
  1154. }
  1155. //---------------------------------------------------------------------------
  1156. void __fastcall TSiteAdvancedDialog::FormCloseQuery(TObject * /*Sender*/,
  1157. bool & /*CanClose*/)
  1158. {
  1159. if (ModalResult == DefaultResult(this))
  1160. {
  1161. VerifyKeyIncludingVersion(StripPathQuotes(PrivateKeyEdit2->Text), GetSshProt());
  1162. // for tunnel key do not check SSH version as it is not configurable
  1163. VerifyKey(StripPathQuotes(TunnelPrivateKeyEdit2->Text));
  1164. }
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TSiteAdvancedDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1168. UnicodeString & Name, bool & /*Action*/)
  1169. {
  1170. FBeforeDialogPath = Name;
  1171. Name = ExpandEnvironmentVariables(Name);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. int __fastcall TSiteAdvancedDialog::LastSupportedFtpProxyMethod()
  1175. {
  1176. return pmHTTP;
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. bool __fastcall TSiteAdvancedDialog::SupportedFtpProxyMethod(int Method)
  1180. {
  1181. return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. int __fastcall TSiteAdvancedDialog::GetSupportedFtpProxyMethod(int Method)
  1185. {
  1186. if (SupportedFtpProxyMethod(Method))
  1187. {
  1188. return Method;
  1189. }
  1190. else
  1191. {
  1192. return ::pmNone;
  1193. }
  1194. }
  1195. //---------------------------------------------------------------------------
  1196. int __fastcall TSiteAdvancedDialog::GetSupportedWebDavProxyMethod(int Method)
  1197. {
  1198. if ((Method >= 0) && (Method <= pmHTTP))
  1199. {
  1200. return Method;
  1201. }
  1202. else
  1203. {
  1204. return ::pmNone;
  1205. }
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. TProxyMethod __fastcall TSiteAdvancedDialog::GetProxyMethod()
  1209. {
  1210. TProxyMethod Result;
  1211. TFSProtocol FSProtocol = FSessionData->FSProtocol;
  1212. if (FSessionData->UsesSsh)
  1213. {
  1214. Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
  1215. }
  1216. else if (FSProtocol == fsFTP)
  1217. {
  1218. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1219. {
  1220. Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
  1221. }
  1222. else
  1223. {
  1224. Result = ::pmNone;
  1225. }
  1226. }
  1227. else if (FSProtocol == fsWebDAV)
  1228. {
  1229. Result = (TProxyMethod)WebDavProxyMethodCombo->ItemIndex;
  1230. }
  1231. else
  1232. {
  1233. FAIL;
  1234. Result = ::pmNone;
  1235. }
  1236. return Result;
  1237. }
  1238. //---------------------------------------------------------------------------
  1239. int __fastcall TSiteAdvancedDialog::GetFtpProxyLogonType()
  1240. {
  1241. int Result;
  1242. if (FSessionData->FSProtocol != fsFTP)
  1243. {
  1244. Result = 0;
  1245. }
  1246. else
  1247. {
  1248. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1249. {
  1250. Result = 0;
  1251. }
  1252. else
  1253. {
  1254. Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
  1255. }
  1256. }
  1257. return Result;
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TSiteAdvancedDialog::NavigationTreeCollapsing(
  1261. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1262. {
  1263. AllowCollapse = false;
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. void __fastcall TSiteAdvancedDialog::ProxyLocalCommandBrowseButtonClick(
  1267. TObject * /*Sender*/)
  1268. {
  1269. BrowseForExecutable(ProxyLocalCommandEdit,
  1270. LoadStr(LOGIN_SELECT_LOCAL_PROXY),
  1271. LoadStr(EXECUTABLE_FILTER), false, true);
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TSiteAdvancedDialog::ColorButtonClick(TObject * /*Sender*/)
  1275. {
  1276. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1277. FColorPopupMenu.reset(CreateSessionColorPopupMenu(FColor, SessionColorChange));
  1278. MenuPopup(FColorPopupMenu.get(), ColorButton);
  1279. }
  1280. //---------------------------------------------------------------------------
  1281. void __fastcall TSiteAdvancedDialog::SessionColorChange(TColor Color)
  1282. {
  1283. SetSessionColor(Color);
  1284. UpdateControls();
  1285. }
  1286. //---------------------------------------------------------------------------
  1287. void __fastcall TSiteAdvancedDialog::SetSessionColor(TColor Color)
  1288. {
  1289. FColor = Color;
  1290. while (ColorImageList->Count > 1)
  1291. {
  1292. ColorImageList->Delete(1);
  1293. }
  1294. if (Color != 0)
  1295. {
  1296. AddSessionColorImage(ColorImageList, Color, 0);
  1297. }
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. TTlsVersion __fastcall TSiteAdvancedDialog::IndexToTlsVersion(int Index)
  1301. {
  1302. switch (Index)
  1303. {
  1304. default:
  1305. FAIL;
  1306. case 0:
  1307. return ssl3;
  1308. case 1:
  1309. return tls10;
  1310. case 2:
  1311. return tls11;
  1312. case 3:
  1313. return tls12;
  1314. }
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. int __fastcall TSiteAdvancedDialog::TlsVersionToIndex(TTlsVersion TlsVersion)
  1318. {
  1319. switch (TlsVersion)
  1320. {
  1321. default:
  1322. FAIL;
  1323. case ssl2:
  1324. case ssl3:
  1325. return 0;
  1326. case tls10:
  1327. return 1;
  1328. case tls11:
  1329. return 2;
  1330. case tls12:
  1331. return 3;
  1332. }
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TSiteAdvancedDialog::MinTlsVersionComboChange(TObject */*Sender*/)
  1336. {
  1337. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1338. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1339. if (MaxTlsVersion < MinTlsVersion)
  1340. {
  1341. MaxTlsVersionCombo->ItemIndex = MinTlsVersionCombo->ItemIndex;
  1342. }
  1343. }
  1344. //---------------------------------------------------------------------------
  1345. void __fastcall TSiteAdvancedDialog::MaxTlsVersionComboChange(TObject * /*Sender*/)
  1346. {
  1347. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1348. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1349. if (MinTlsVersion > MaxTlsVersion)
  1350. {
  1351. MinTlsVersionCombo->ItemIndex = MaxTlsVersionCombo->ItemIndex;
  1352. }
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TSiteAdvancedDialog::ProxyAutodetectButtonClick(TObject * /*Sender*/)
  1356. {
  1357. TInstantOperationVisualizer Visualizer;
  1358. UnicodeString Proxy;
  1359. if (AutodetectProxyUrl(Proxy) && !Proxy.IsEmpty())
  1360. {
  1361. ProxyHostEdit->Text = ::CutToChar(Proxy, L':', true);
  1362. ProxyPortEdit->AsInteger = StrToIntDef(Proxy, ProxyPortNumber);
  1363. SshProxyMethodCombo->ItemIndex = pmHTTP;
  1364. FtpProxyMethodCombo->ItemIndex = pmHTTP;
  1365. WebDavProxyMethodCombo->ItemIndex = pmHTTP;
  1366. UpdateControls();
  1367. }
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TSiteAdvancedDialog::NoteMemoKeyDown(
  1371. TObject * Sender, WORD & Key, TShiftState Shift)
  1372. {
  1373. MemoKeyDown(Sender, Key, Shift);
  1374. }
  1375. //---------------------------------------------------------------------------