SiteAdvanced.cpp 49 KB

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