SiteAdvanced.cpp 52 KB

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