SiteAdvanced.cpp 49 KB

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