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