SiteAdvanced.cpp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  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 <HelpCore.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include <Cryptography.h>
  13. #include <S3FileSystem.h>
  14. #include "WinInterface.h"
  15. #include "SiteAdvanced.h"
  16. #include "GUITools.h"
  17. #include "Tools.h"
  18. #include "WinConfiguration.h"
  19. #include "PuttyTools.h"
  20. #include "TerminalManager.h"
  21. #include "Authenticate.h"
  22. //---------------------------------------------------------------------
  23. #pragma link "ComboEdit"
  24. #pragma link "PasswordEdit"
  25. #pragma link "UpDownEdit"
  26. #pragma resource "*.dfm"
  27. //---------------------------------------------------------------------------
  28. // Sheet tag:
  29. // 01 top, 02 indented
  30. //---------------------------------------------------------------------------
  31. bool __fastcall DoSiteAdvancedDialog(TSessionData * SessionData)
  32. {
  33. TSiteAdvancedDialog * SiteAdvancedDialog = new TSiteAdvancedDialog(Application);
  34. bool Result;
  35. try
  36. {
  37. Result = SiteAdvancedDialog->Execute(SessionData);
  38. }
  39. __finally
  40. {
  41. delete SiteAdvancedDialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. static const UnicodeString DefaultRecycleBinPath = L"/tmp";
  47. //---------------------------------------------------------------------
  48. __fastcall TSiteAdvancedDialog::TSiteAdvancedDialog(TComponent * AOwner) :
  49. TForm(AOwner)
  50. {
  51. NoUpdate = 0;
  52. // we need to make sure that window procedure is set asap
  53. // (so that CM_SHOWINGCHANGED handling is applied)
  54. UseSystemSettings(this);
  55. InitControls();
  56. PageControl->ActivePage = EnvironmentSheet;
  57. }
  58. //---------------------------------------------------------------------
  59. void __fastcall TSiteAdvancedDialog::InitControls()
  60. {
  61. ComboAutoSwitchInitialize(UtfCombo);
  62. ComboAutoSwitchInitialize(BugIgnore1Combo);
  63. ComboAutoSwitchInitialize(BugPlainPW1Combo);
  64. ComboAutoSwitchInitialize(BugRSA1Combo);
  65. ComboAutoSwitchInitialize(BugHMAC2Combo);
  66. ComboAutoSwitchInitialize(BugDeriveKey2Combo);
  67. ComboAutoSwitchInitialize(BugRSAPad2Combo);
  68. ComboAutoSwitchInitialize(BugPKSessID2Combo);
  69. ComboAutoSwitchInitialize(BugRekey2Combo);
  70. ComboAutoSwitchInitialize(BugMaxPkt2Combo);
  71. ComboAutoSwitchInitialize(BugIgnore2Combo);
  72. ComboAutoSwitchInitialize(BugWinAdjCombo);
  73. ComboAutoSwitchInitialize(SFTPBugSymlinkCombo);
  74. ComboAutoSwitchInitialize(SFTPBugSignedTSCombo);
  75. ComboAutoSwitchInitialize(FtpListAllCombo);
  76. ComboAutoSwitchInitialize(FtpUseMlsdCombo);
  77. ComboAutoSwitchInitialize(FtpForcePasvIpCombo);
  78. ComboAutoSwitchInitialize(FtpHostCombo);
  79. TunnelLocalPortNumberEdit->Items->BeginUpdate();
  80. try
  81. {
  82. UnicodeString TunnelLocalPortNumberAutoassign = TunnelLocalPortNumberEdit->Items->Strings[0];
  83. TunnelLocalPortNumberEdit->Items->Clear();
  84. TunnelLocalPortNumberEdit->Items->Add(TunnelLocalPortNumberAutoassign);
  85. for (int Index = Configuration->TunnelLocalPortNumberLow;
  86. Index <= Configuration->TunnelLocalPortNumberHigh; Index++)
  87. {
  88. TunnelLocalPortNumberEdit->Items->Add(IntToStr(Index));
  89. }
  90. }
  91. __finally
  92. {
  93. TunnelLocalPortNumberEdit->Items->EndUpdate();
  94. }
  95. HintLabel(ProxyTelnetCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  96. HintLabel(ProxyLocalCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
  97. UpdateNavigationTree();
  98. SelectScaledImageList(ColorImageList);
  99. FColor = TColor();
  100. MenuButton(PrivateKeyToolsButton);
  101. }
  102. //---------------------------------------------------------------------
  103. void __fastcall TSiteAdvancedDialog::LoadSession()
  104. {
  105. {
  106. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  107. // Directories page
  108. SynchronizeBrowsingCheck->Checked = FSessionData->SynchronizeBrowsing;
  109. LocalDirectoryEdit->Text = FSessionData->LocalDirectory;
  110. RemoteDirectoryEdit->Text = FSessionData->RemoteDirectory;
  111. UpdateDirectoriesCheck->Checked = FSessionData->UpdateDirectories;
  112. CacheDirectoriesCheck->Checked = FSessionData->CacheDirectories;
  113. CacheDirectoryChangesCheck->Checked = FSessionData->CacheDirectoryChanges;
  114. PreserveDirectoryChangesCheck->Checked = FSessionData->PreserveDirectoryChanges;
  115. ResolveSymlinksCheck->Checked = FSessionData->ResolveSymlinks;
  116. FollowDirectorySymlinksCheck->Checked = FSessionData->FollowDirectorySymlinks;
  117. // Environment page
  118. switch (FSessionData->DSTMode)
  119. {
  120. case dstmWin:
  121. DSTModeWinCheck->Checked = true;
  122. break;
  123. case dstmKeep:
  124. DSTModeKeepCheck->Checked = true;
  125. break;
  126. default:
  127. case dstmUnix:
  128. DSTModeUnixCheck->Checked = true;
  129. break;
  130. }
  131. if (FSessionData->EOLType == eolLF)
  132. {
  133. EOLTypeCombo->ItemIndex = 0;
  134. }
  135. else
  136. {
  137. EOLTypeCombo->ItemIndex = 1;
  138. }
  139. switch (FSessionData->NotUtf)
  140. {
  141. case asOn:
  142. UtfCombo->ItemIndex = 1;
  143. break;
  144. case asOff:
  145. UtfCombo->ItemIndex = 2;
  146. break;
  147. default:
  148. UtfCombo->ItemIndex = 0;
  149. break;
  150. }
  151. int TimeDifferenceMin = TimeToMinutes(FSessionData->TimeDifference);
  152. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / MinsPerHour;
  153. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % MinsPerHour;
  154. TimeDifferenceAutoCheck->Checked = FSessionData->TimeDifferenceAuto;
  155. TrimVMSVersionsCheck->Checked = FSessionData->TrimVMSVersions;
  156. VMSAllRevisionsCheck->Checked = FSessionData->VMSAllRevisions;
  157. PuttySettingsEdit->Text = FSessionData->PuttySettings;
  158. // Environment/Recycle bin page
  159. DeleteToRecycleBinCheck->Checked = FSessionData->DeleteToRecycleBin;
  160. OverwrittenToRecycleBinCheck->Checked = FSessionData->OverwrittenToRecycleBin;
  161. RecycleBinPathEdit->Text =
  162. !FSessionData->RecycleBinPath.IsEmpty() ?
  163. FSessionData->RecycleBinPath : DefaultRecycleBinPath;
  164. // SFTP page
  165. if (FSessionData->SftpServer.IsEmpty())
  166. {
  167. SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
  168. }
  169. else
  170. {
  171. SftpServerEdit->Text = FSessionData->SftpServer;
  172. }
  173. // hide selection, which is wrongly shown initially even when the box has not focus
  174. SftpServerEdit->SelLength = 0;
  175. AllowScpFallbackCheck->Checked = (FSessionData->FSProtocol == fsSFTP);
  176. SFTPMaxVersionCombo->ItemIndex = FSessionData->SFTPMaxVersion;
  177. #define LOAD_SFTP_BUG_COMBO(BUG) \
  178. ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, FSessionData->SFTPBug[sb ## BUG])
  179. LOAD_SFTP_BUG_COMBO(Symlink);
  180. LOAD_SFTP_BUG_COMBO(SignedTS);
  181. #undef LOAD_SFTP_BUG_COMBO
  182. // FTP page
  183. FtpAccountEdit->Text = FSessionData->FtpAccount;
  184. PostLoginCommandsMemo->Lines->Text = FSessionData->PostLoginCommands;
  185. ComboAutoSwitchLoad(FtpListAllCombo, FSessionData->FtpListAll);
  186. ComboAutoSwitchLoad(FtpUseMlsdCombo, FSessionData->FtpUseMlsd);
  187. ComboAutoSwitchLoad(FtpForcePasvIpCombo, FSessionData->FtpForcePasvIp);
  188. ComboAutoSwitchLoad(FtpHostCombo, FSessionData->FtpHost);
  189. // S3 page
  190. S3DefaultReqionCombo->Text = FSessionData->S3DefaultRegion;
  191. if (FSessionData->S3UrlStyle == s3usPath)
  192. {
  193. S3UrlStyleCombo->ItemIndex = 1;
  194. }
  195. else
  196. {
  197. S3UrlStyleCombo->ItemIndex = 0;
  198. }
  199. UnicodeString S3SessionToken = FSessionData->S3SessionToken;
  200. if (FSessionData->HasAutoCredentials())
  201. {
  202. try
  203. {
  204. S3SessionToken = S3EnvSessionToken();
  205. }
  206. catch (...)
  207. {
  208. // noop
  209. }
  210. }
  211. S3SessionTokenMemo->Lines->Text = S3SessionToken;
  212. // Authentication page
  213. SshNoUserAuthCheck->Checked = FSessionData->SshNoUserAuth;
  214. TryAgentCheck->Checked = FSessionData->TryAgent;
  215. AuthTISCheck->Checked = FSessionData->AuthTIS;
  216. AuthKICheck->Checked = FSessionData->AuthKI;
  217. AuthKIPasswordCheck->Checked = FSessionData->AuthKIPassword;
  218. AuthGSSAPICheck3->Checked = FSessionData->AuthGSSAPI;
  219. GSSAPIFwdTGTCheck->Checked = FSessionData->GSSAPIFwdTGT;
  220. AgentFwdCheck->Checked = FSessionData->AgentFwd;
  221. PrivateKeyEdit3->Text = FSessionData->PublicKeyFile;
  222. // SSH page
  223. Ssh2LegacyDESCheck->Checked = FSessionData->Ssh2DES;
  224. CompressionCheck->Checked = FSessionData->Compression;
  225. if (FSessionData->SshProt == ssh1only)
  226. {
  227. SshProtCombo2->ItemIndex = 0;
  228. }
  229. else
  230. {
  231. SshProtCombo2->ItemIndex = 1;
  232. }
  233. CipherListBox->Items->Clear();
  234. DebugAssert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_CHACHA20);
  235. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  236. {
  237. CipherListBox->Items->AddObject(
  238. LoadStr(CIPHER_NAME_WARN+FSessionData->Cipher[Index]),
  239. (TObject*)FSessionData->Cipher[Index]);
  240. }
  241. // KEX page
  242. KexListBox->Items->Clear();
  243. DebugAssert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_ECDH);
  244. for (int Index = 0; Index < KEX_COUNT; Index++)
  245. {
  246. KexListBox->Items->AddObject(
  247. LoadStr(KEX_NAME_WARN+FSessionData->Kex[Index]),
  248. (TObject*)FSessionData->Kex[Index]);
  249. }
  250. AuthGSSAPIKEXCheck->Checked = FSessionData->AuthGSSAPIKEX;
  251. RekeyTimeEdit->AsInteger = FSessionData->RekeyTime;
  252. RekeyDataEdit->Text = FSessionData->RekeyData;
  253. // Connection page
  254. FtpPasvModeCheck->Checked = FSessionData->FtpPasvMode;
  255. BufferSizeCheck->Checked = (FSessionData->SendBuf > 0) && FSessionData->SshSimple;
  256. switch (FSessionData->PingType)
  257. {
  258. case ptNullPacket:
  259. PingNullPacketButton->Checked = true;
  260. break;
  261. case ptDummyCommand:
  262. PingDummyCommandButton->Checked = true;
  263. break;
  264. default:
  265. PingOffButton->Checked = true;
  266. break;
  267. }
  268. PingIntervalSecEdit->AsInteger = FSessionData->PingInterval;
  269. switch (FSessionData->FtpPingType)
  270. {
  271. case ptDummyCommand:
  272. FtpPingDummyCommandButton->Checked = true;
  273. break;
  274. default:
  275. FtpPingOffButton->Checked = true;
  276. break;
  277. }
  278. FtpPingIntervalSecEdit->AsInteger = FSessionData->FtpPingInterval;
  279. TimeoutEdit->AsInteger = FSessionData->Timeout;
  280. switch (FSessionData->AddressFamily)
  281. {
  282. case afIPv4:
  283. IPv4Button->Checked = true;
  284. break;
  285. case afIPv6:
  286. IPv6Button->Checked = true;
  287. break;
  288. case afAuto:
  289. default:
  290. IPAutoButton->Checked = true;
  291. break;
  292. }
  293. // Shell page
  294. if (FSessionData->DefaultShell)
  295. {
  296. ShellEdit->Text = ShellEdit->Items->Strings[0];
  297. }
  298. else
  299. {
  300. ShellEdit->Text = FSessionData->Shell;
  301. }
  302. // hide selection, which is wrongly shown initially even when the box has not focus
  303. ShellEdit->SelLength = 0;
  304. if (FSessionData->DetectReturnVar)
  305. {
  306. ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
  307. }
  308. else
  309. {
  310. ReturnVarEdit->Text = FSessionData->ReturnVar;
  311. }
  312. ReturnVarEdit->SelLength = 0;
  313. ListingCommandEdit->Text = FSessionData->ListingCommand;
  314. ListingCommandEdit->SelLength = 0;
  315. CheckBoxAutoSwitchLoad(LookupUserGroupsCheck, FSessionData->LookupUserGroups);
  316. ClearAliasesCheck->Checked = FSessionData->ClearAliases;
  317. IgnoreLsWarningsCheck->Checked = FSessionData->IgnoreLsWarnings;
  318. Scp1CompatibilityCheck->Checked = FSessionData->Scp1Compatibility;
  319. UnsetNationalVarsCheck->Checked = FSessionData->UnsetNationalVars;
  320. SCPLsFullTimeAutoCheck->Checked = (FSessionData->SCPLsFullTime != asOff);
  321. // Proxy page
  322. SshProxyMethodCombo->ItemIndex = FSessionData->ProxyMethod;
  323. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(FSessionData->ProxyMethod);
  324. if (FSessionData->FtpProxyLogonType != 0)
  325. {
  326. FtpProxyMethodCombo->ItemIndex = LastSupportedFtpProxyMethod() + FSessionData->FtpProxyLogonType;
  327. }
  328. NeonProxyMethodCombo->ItemIndex = GetSupportedNeonProxyMethod(FSessionData->ProxyMethod);
  329. ProxyHostEdit->Text = FSessionData->ProxyHost;
  330. ProxyPortEdit->AsInteger = FSessionData->ProxyPort;
  331. ProxyUsernameEdit->Text = FSessionData->ProxyUsername;
  332. ProxyPasswordEdit->Text = FSessionData->ProxyPassword;
  333. ProxyTelnetCommandEdit->Text = FSessionData->ProxyTelnetCommand;
  334. ProxyLocalCommandEdit->Text = FSessionData->ProxyLocalCommand;
  335. ProxyLocalhostCheck->Checked = FSessionData->ProxyLocalhost;
  336. ProxyDNSCombo->ItemIndex = 2 - FSessionData->ProxyDNS;
  337. // Bugs page
  338. #define LOAD_BUG_COMBO(BUG) \
  339. ComboAutoSwitchLoad(Bug ## BUG ## Combo, FSessionData->Bug[sb ## BUG])
  340. LOAD_BUG_COMBO(Ignore1);
  341. LOAD_BUG_COMBO(PlainPW1);
  342. LOAD_BUG_COMBO(RSA1);
  343. LOAD_BUG_COMBO(HMAC2);
  344. LOAD_BUG_COMBO(DeriveKey2);
  345. LOAD_BUG_COMBO(RSAPad2);
  346. LOAD_BUG_COMBO(PKSessID2);
  347. LOAD_BUG_COMBO(Rekey2);
  348. LOAD_BUG_COMBO(MaxPkt2);
  349. LOAD_BUG_COMBO(Ignore2);
  350. LOAD_BUG_COMBO(WinAdj);
  351. #undef LOAD_BUG_COMBO
  352. // Tunnel page
  353. TunnelCheck->Checked = FSessionData->Tunnel;
  354. TunnelUserNameEdit->Text = FSessionData->TunnelUserName;
  355. TunnelPortNumberEdit->AsInteger = FSessionData->TunnelPortNumber;
  356. TunnelHostNameEdit->Text = FSessionData->TunnelHostName;
  357. TunnelPasswordEdit->Text = FSessionData->TunnelPassword;
  358. TunnelPrivateKeyEdit3->Text = FSessionData->TunnelPublicKeyFile;
  359. if (FSessionData->TunnelAutoassignLocalPortNumber)
  360. {
  361. TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
  362. }
  363. else
  364. {
  365. TunnelLocalPortNumberEdit->Text = IntToStr(FSessionData->TunnelLocalPortNumber);
  366. }
  367. // hide selection, which is wrongly shown initially even when the box has not focus
  368. TunnelLocalPortNumberEdit->SelLength = 0;
  369. // connection/tls/ssl page
  370. MinTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MinTlsVersion);
  371. MaxTlsVersionCombo->ItemIndex = TlsVersionToIndex(FSessionData->MaxTlsVersion);
  372. SslSessionReuseCheck->Checked = FSessionData->SslSessionReuse;
  373. TlsCertificateFileEdit->Text = FSessionData->TlsCertificateFile;
  374. // Note page
  375. NoteMemo->Lines->Text = FSessionData->Note;
  376. // Encryption page
  377. EncryptFilesCheck->Checked = !FSessionData->EncryptKey.IsEmpty();
  378. GetEncryptKeyEdit()->Text = FSessionData->EncryptKey;
  379. // webdav page
  380. WebDavLiberalEscapingCheck->Checked = FSessionData->WebDavLiberalEscaping;
  381. // color
  382. FColor = (TColor)FSessionData->Color;
  383. }
  384. EnableControl(PuttyGroup, !DoesSessionExistInPutty(FSessionData));
  385. UpdateControls();
  386. }
  387. //---------------------------------------------------------------------
  388. TSshProt __fastcall TSiteAdvancedDialog::GetSshProt()
  389. {
  390. return (SshProtCombo2->ItemIndex == 0) ? ssh1only : ssh2only;
  391. }
  392. //---------------------------------------------------------------------
  393. bool TSiteAdvancedDialog::IsDefaultSftpServer()
  394. {
  395. return
  396. SftpServerEdit->Text.IsEmpty() ||
  397. (SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]);
  398. }
  399. //---------------------------------------------------------------------
  400. void __fastcall TSiteAdvancedDialog::SaveSession(TSessionData * SessionData)
  401. {
  402. // Last resort validation,
  403. // in case the test in EncryptKeyEditExit was previously bypassed due to IsCancelButtonBeingClicked
  404. EncryptKeyEditExit(GetEncryptKeyEdit());
  405. // SSH page
  406. SessionData->Compression = CompressionCheck->Checked;
  407. SessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  408. SessionData->SshProt = GetSshProt();
  409. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  410. {
  411. SessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  412. }
  413. // Kex page
  414. for (int Index = 0; Index < KEX_COUNT; Index++)
  415. {
  416. SessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  417. }
  418. FSessionData->AuthGSSAPIKEX = AuthGSSAPIKEXCheck->Checked;
  419. SessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  420. SessionData->RekeyData = RekeyDataEdit->Text;
  421. // Authentication page
  422. SessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
  423. SessionData->TryAgent = TryAgentCheck->Checked;
  424. SessionData->AuthTIS = AuthTISCheck->Checked;
  425. SessionData->AuthKI = AuthKICheck->Checked;
  426. SessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  427. SessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
  428. SessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  429. SessionData->AgentFwd = AgentFwdCheck->Checked;
  430. SessionData->PublicKeyFile = PrivateKeyEdit3->Text;
  431. // Connection page
  432. SessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  433. SessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
  434. SessionData->SshSimple = BufferSizeCheck->Checked;
  435. if (PingNullPacketButton->Checked)
  436. {
  437. SessionData->PingType = ptNullPacket;
  438. }
  439. else if (PingDummyCommandButton->Checked)
  440. {
  441. SessionData->PingType = ptDummyCommand;
  442. }
  443. else
  444. {
  445. SessionData->PingType = ptOff;
  446. }
  447. SessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  448. SessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
  449. SessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
  450. SessionData->Timeout = TimeoutEdit->AsInteger;
  451. if (IPv4Button->Checked)
  452. {
  453. SessionData->AddressFamily = afIPv4;
  454. }
  455. else if (IPv6Button->Checked)
  456. {
  457. SessionData->AddressFamily = afIPv6;
  458. }
  459. else
  460. {
  461. SessionData->AddressFamily = afAuto;
  462. }
  463. // Directories page
  464. SessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
  465. SessionData->LocalDirectory = LocalDirectoryEdit->Text;
  466. SessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  467. SessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  468. SessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  469. SessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  470. SessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  471. SessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  472. SessionData->FollowDirectorySymlinks = FollowDirectorySymlinksCheck->Checked;
  473. // Environment page
  474. if (DSTModeUnixCheck->Checked)
  475. {
  476. SessionData->DSTMode = dstmUnix;
  477. }
  478. else if (DSTModeKeepCheck->Checked)
  479. {
  480. SessionData->DSTMode = dstmKeep;
  481. }
  482. else
  483. {
  484. SessionData->DSTMode = dstmWin;
  485. }
  486. if (EOLTypeCombo->ItemIndex == 0)
  487. {
  488. SessionData->EOLType = eolLF;
  489. }
  490. else
  491. {
  492. SessionData->EOLType = eolCRLF;
  493. }
  494. switch (UtfCombo->ItemIndex)
  495. {
  496. case 1:
  497. SessionData->NotUtf = asOn;
  498. break;
  499. case 2:
  500. SessionData->NotUtf = asOff;
  501. break;
  502. default:
  503. SessionData->NotUtf = asAuto;
  504. break;
  505. }
  506. SessionData->TimeDifference =
  507. (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
  508. (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
  509. SessionData->TimeDifferenceAuto = TimeDifferenceAutoCheck->Checked;
  510. SessionData->TrimVMSVersions = TrimVMSVersionsCheck->Checked;
  511. SessionData->VMSAllRevisions = VMSAllRevisionsCheck->Checked;
  512. SessionData->PuttySettings = PuttySettingsEdit->Text;
  513. // Environment/Recycle bin page
  514. SessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  515. SessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  516. SessionData->RecycleBinPath =
  517. SessionData->DeleteToRecycleBin || SessionData->OverwrittenToRecycleBin ||
  518. (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
  519. RecycleBinPathEdit->Text : UnicodeString();
  520. // SCP page
  521. SessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  522. SessionData->Shell = (SessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
  523. SessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  524. SessionData->ReturnVar = (SessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
  525. SessionData->ListingCommand = ListingCommandEdit->Text;
  526. SessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
  527. SessionData->ClearAliases = ClearAliasesCheck->Checked;
  528. SessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  529. SessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  530. SessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  531. SessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  532. // SFTP page
  533. SessionData->SftpServer = (IsDefaultSftpServer() ? UnicodeString() : SftpServerEdit->Text);
  534. SessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  535. if (AllowScpFallbackCheck->Checked != (SessionData->FSProtocol == fsSFTP))
  536. {
  537. if (AllowScpFallbackCheck->Checked)
  538. {
  539. DebugAssert(SessionData->FSProtocol == fsSFTPonly);
  540. SessionData->FSProtocol = fsSFTP;
  541. }
  542. else
  543. {
  544. DebugAssert(SessionData->FSProtocol == fsSFTP);
  545. SessionData->FSProtocol = fsSFTPonly;
  546. }
  547. }
  548. #define SAVE_SFTP_BUG_COMBO(BUG) SessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
  549. SAVE_SFTP_BUG_COMBO(Symlink);
  550. SAVE_SFTP_BUG_COMBO(SignedTS);
  551. #undef SAVE_SFTP_BUG_COMBO
  552. // FTP page
  553. SessionData->FtpAccount = FtpAccountEdit->Text;
  554. SessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
  555. SessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
  556. SessionData->FtpUseMlsd = ComboAutoSwitchSave(FtpUseMlsdCombo);
  557. SessionData->FtpForcePasvIp = ComboAutoSwitchSave(FtpForcePasvIpCombo);
  558. SessionData->FtpHost = ComboAutoSwitchSave(FtpHostCombo);
  559. // S3 page
  560. SessionData->S3DefaultRegion = S3DefaultReqionCombo->Text;
  561. if (S3UrlStyleCombo->ItemIndex == 1)
  562. {
  563. SessionData->S3UrlStyle = s3usPath;
  564. }
  565. else
  566. {
  567. SessionData->S3UrlStyle = s3usVirtualHost;
  568. }
  569. if (SessionData->HasAutoCredentials())
  570. {
  571. SessionData->S3SessionToken = EmptyStr;
  572. }
  573. else
  574. {
  575. // Trim not to try to authenticate with a stray new-line
  576. SessionData->S3SessionToken = S3SessionTokenMemo->Lines->Text.Trim();
  577. }
  578. // Proxy page
  579. SessionData->ProxyMethod = GetProxyMethod();
  580. SessionData->FtpProxyLogonType = GetFtpProxyLogonType();
  581. SessionData->ProxyHost = ProxyHostEdit->Text;
  582. SessionData->ProxyPort = ProxyPortEdit->AsInteger;
  583. SessionData->ProxyUsername = ProxyUsernameEdit->Text;
  584. SessionData->ProxyPassword = ProxyPasswordEdit->Text;
  585. SessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  586. SessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
  587. SessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  588. SessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
  589. // Bugs page
  590. #define SAVE_BUG_COMBO(BUG) SessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
  591. SAVE_BUG_COMBO(Ignore1);
  592. SAVE_BUG_COMBO(PlainPW1);
  593. SAVE_BUG_COMBO(RSA1);
  594. SAVE_BUG_COMBO(HMAC2);
  595. SAVE_BUG_COMBO(DeriveKey2);
  596. SAVE_BUG_COMBO(RSAPad2);
  597. SAVE_BUG_COMBO(PKSessID2);
  598. SAVE_BUG_COMBO(Rekey2);
  599. SAVE_BUG_COMBO(MaxPkt2);
  600. SAVE_BUG_COMBO(Ignore2);
  601. SAVE_BUG_COMBO(WinAdj);
  602. #undef SAVE_BUG_COMBO
  603. // Tunnel page
  604. SessionData->Tunnel = TunnelCheck->Checked;
  605. SessionData->TunnelUserName = TunnelUserNameEdit->Text;
  606. SessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  607. SessionData->TunnelHostName = TunnelHostNameEdit->Text;
  608. SessionData->TunnelPassword = TunnelPasswordEdit->Text;
  609. SessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit3->Text;
  610. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  611. {
  612. SessionData->TunnelLocalPortNumber = 0;
  613. }
  614. else
  615. {
  616. SessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  617. }
  618. // connection/tls/ssl page
  619. SessionData->MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  620. SessionData->MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  621. SessionData->SslSessionReuse = SslSessionReuseCheck->Checked;
  622. SessionData->TlsCertificateFile = TlsCertificateFileEdit->Text;
  623. // Note page
  624. SessionData->Note = NoteMemo->Lines->Text;
  625. // Encryption page
  626. SessionData->EncryptKey = EncryptFilesCheck->Checked ? GetEncryptKeyEdit()->Text : UnicodeString();
  627. // webdav page
  628. SessionData->WebDavLiberalEscaping = WebDavLiberalEscapingCheck->Checked;
  629. // color
  630. SessionData->Color = FColor;
  631. }
  632. //---------------------------------------------------------------------
  633. TSessionData * __fastcall TSiteAdvancedDialog::GetSessionData()
  634. {
  635. std::unique_ptr<TSessionData> SessionData(new TSessionData(UnicodeString()));
  636. SessionData->Assign(FSessionData);
  637. SaveSession(SessionData.get());
  638. return SessionData.release();
  639. }
  640. //---------------------------------------------------------------------
  641. void __fastcall TSiteAdvancedDialog::UpdateNavigationTree()
  642. {
  643. TTreeNode * ActiveNode = NULL;
  644. {
  645. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  646. int Index = 0;
  647. TTreeNode * PrevNode = NULL;
  648. while (Index < PageControl->PageCount)
  649. {
  650. TTabSheet * Tab = PageControl->Pages[Index];
  651. if (Tab->Enabled)
  652. {
  653. bool Indented = ((Tab->Tag % 100) == 2);
  654. UnicodeString Label = Tab->Caption;
  655. TTreeNode * Node;
  656. if (PrevNode == NULL)
  657. {
  658. DebugAssert(!Indented);
  659. Node = NavigationTree->Items->GetFirstNode();
  660. }
  661. else
  662. {
  663. if (Indented)
  664. {
  665. if (PrevNode->Level == 0)
  666. {
  667. Node = PrevNode->getFirstChild();
  668. if (Node == NULL)
  669. {
  670. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  671. }
  672. }
  673. else
  674. {
  675. Node = PrevNode->getNextSibling();
  676. if (Node == NULL)
  677. {
  678. Node = NavigationTree->Items->Add(PrevNode, Label);
  679. }
  680. }
  681. }
  682. else
  683. {
  684. if (PrevNode->Level == 0)
  685. {
  686. // delete all excess children of previous top level node
  687. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  688. {
  689. Node->Delete();
  690. }
  691. Node = PrevNode->getNextSibling();
  692. if (Node == NULL)
  693. {
  694. Node = NavigationTree->Items->Add(PrevNode, Label);
  695. }
  696. }
  697. else
  698. {
  699. // delete all excess children of previous top level node
  700. while ((Node = PrevNode->getNextSibling()) != NULL)
  701. {
  702. Node->Delete();
  703. }
  704. Node = PrevNode->GetNext();
  705. if (Node == NULL)
  706. {
  707. Node = NavigationTree->Items->Add(NULL, Label);
  708. }
  709. }
  710. }
  711. }
  712. Node->Text = Label;
  713. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  714. PrevNode = Node;
  715. if (PageControl->ActivePage == Tab)
  716. {
  717. Node->Selected = true;
  718. ActiveNode = Node;
  719. }
  720. }
  721. Index++;
  722. }
  723. TTreeNode * Node;
  724. while ((Node = PrevNode->GetNext()) != NULL)
  725. {
  726. Node->Delete();
  727. }
  728. NavigationTree->FullExpand();
  729. }
  730. // node of active page was hidden
  731. if (ActiveNode == NULL)
  732. {
  733. ChangePage(EnvironmentSheet);
  734. }
  735. }
  736. //---------------------------------------------------------------------
  737. void __fastcall TSiteAdvancedDialog::UpdateControls()
  738. {
  739. if (Visible)
  740. {
  741. TAutoNestingCounter NoUpdateCounter(NoUpdate);
  742. bool SshProtocol = FSessionData->UsesSsh;
  743. bool SftpProtocol = (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  744. bool ScpProtocol = (FSessionData->FSProtocol == fsSCPonly);
  745. bool FtpProtocol = (FSessionData->FSProtocol == fsFTP);
  746. bool WebDavProtocol = (FSessionData->FSProtocol == fsWebDAV);
  747. bool S3Protocol = (FSessionData->FSProtocol == fsS3);
  748. bool Neon = IsNeon(FSessionData->FSProtocol);
  749. bool Ssl = (FtpProtocol || WebDavProtocol || S3Protocol) && (FSessionData->Ftps != ftpsNone);
  750. // connection sheet
  751. EnableControl(FtpPasvModeCheck, FtpProtocol);
  752. if (FtpProtocol &&
  753. (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
  754. SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
  755. !FtpPasvModeCheck->Checked)
  756. {
  757. FtpPasvModeCheck->Checked = true;
  758. MessageDialog(MainInstructions(LoadStr(FTP_PASV_MODE_REQUIRED)), qtInformation, qaOK);
  759. }
  760. EnableControl(BufferSizeCheck, SshProtocol || FtpProtocol);
  761. PingGroup->Visible = !FtpProtocol;
  762. EnableControl(PingGroup, SshProtocol);
  763. EnableControl(PingIntervalSecEdit, PingGroup->Enabled && !PingOffButton->Checked);
  764. EnableControl(PingIntervalLabel, PingGroup->Enabled && PingIntervalSecEdit->Enabled);
  765. FtpPingGroup->Visible = FtpProtocol;
  766. EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
  767. EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
  768. EnableControl(IPvGroup, SshProtocol || FtpProtocol);
  769. EnableControl(IPAutoButton, IPvGroup->Enabled && SshProtocol);
  770. // ssh/authentication sheet
  771. AuthSheet->Enabled = SshProtocol;
  772. EnableControl(SshNoUserAuthCheck, (GetSshProt() == ssh2only));
  773. EnableControl(AuthenticationGroup,
  774. !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
  775. EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh1only));
  776. EnableControl(AuthKICheck, AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  777. EnableControl(AuthKIPasswordCheck,
  778. AuthenticationGroup->Enabled &&
  779. ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  780. (AuthKICheck->Enabled && AuthKICheck->Checked)));
  781. EnableControl(AuthenticationParamsGroup, AuthenticationGroup->Enabled);
  782. EnableControl(AgentFwdCheck, AuthenticationParamsGroup->Enabled && TryAgentCheck->Checked);
  783. EnableControl(PrivateKeyViewButton, PrivateKeyEdit3->Enabled && !PrivateKeyEdit3->Text.IsEmpty());
  784. EnableControl(AuthGSSAPICheck3,
  785. AuthenticationGroup->Enabled && (GetSshProt() == ssh2only));
  786. EnableControl(GSSAPIFwdTGTCheck,
  787. AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
  788. // ssh sheet
  789. AdvancedSheet->Enabled = SshProtocol;
  790. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  791. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  792. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  793. EnableControl(Ssh2LegacyDESCheck, (GetSshProt() == ssh2only));
  794. // ssh/kex sheet
  795. KexSheet->Enabled = SshProtocol && (GetSshProt() == ssh2only) &&
  796. (BugRekey2Combo->ItemIndex != 2);
  797. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  798. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  799. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  800. // ssh/bugs sheet
  801. BugsSheet->Enabled = SshProtocol;
  802. EnableControl(BugIgnore1Combo, (GetSshProt() == ssh1only));
  803. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  804. EnableControl(BugPlainPW1Combo, (GetSshProt() == ssh1only));
  805. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  806. EnableControl(BugRSA1Combo, (GetSshProt() == ssh1only));
  807. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  808. EnableControl(BugHMAC2Combo, (GetSshProt() == ssh2only));
  809. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  810. EnableControl(BugDeriveKey2Combo, (GetSshProt() == ssh2only));
  811. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  812. EnableControl(BugRSAPad2Combo, (GetSshProt() == ssh2only));
  813. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  814. EnableControl(BugPKSessID2Combo, (GetSshProt() == ssh2only));
  815. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  816. EnableControl(BugRekey2Combo, (GetSshProt() == ssh2only));
  817. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  818. EnableControl(BugMaxPkt2Combo, (GetSshProt() == ssh2only));
  819. EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
  820. EnableControl(BugIgnore2Combo, (GetSshProt() == ssh2only));
  821. EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
  822. EnableControl(BugWinAdjCombo, (GetSshProt() == ssh2only));
  823. EnableControl(BugWinAdjLabel, BugWinAdjCombo->Enabled);
  824. // connection/proxy sheet
  825. // this is probaqbly overkill, now we do not allow changing protocol on
  826. // the same window as changing proxy
  827. TComboBox * ProxyMethodCombo =
  828. (SshProtocol ? SshProxyMethodCombo : (FtpProtocol ? FtpProxyMethodCombo : NeonProxyMethodCombo));
  829. TProxyMethod ProxyMethod = GetProxyMethod();
  830. ProxyMethodCombo->Visible = true;
  831. ProxyMethodLabel->FocusControl = ProxyMethodCombo;
  832. if (!SshProtocol)
  833. {
  834. SshProxyMethodCombo->Visible = false;
  835. SshProxyMethodCombo->ItemIndex = ProxyMethod;
  836. }
  837. if (!FtpProtocol)
  838. {
  839. FtpProxyMethodCombo->Visible = false;
  840. FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(ProxyMethod);
  841. }
  842. if (!Neon)
  843. {
  844. NeonProxyMethodCombo->Visible = false;
  845. NeonProxyMethodCombo->ItemIndex = GetSupportedNeonProxyMethod(ProxyMethod);
  846. }
  847. int FtpProxyLogonType = GetFtpProxyLogonType();
  848. UnicodeString ProxyCommand =
  849. ((ProxyMethod == pmCmd) ?
  850. ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
  851. EnableControl(ProxyHostEdit,
  852. (ProxyMethod == pmSocks4) ||
  853. (ProxyMethod == pmSocks5) ||
  854. (ProxyMethod == pmHTTP) ||
  855. (ProxyMethod == pmTelnet) ||
  856. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
  857. (FtpProxyLogonType > 0));
  858. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  859. EnableControl(ProxyPortEdit,
  860. (ProxyMethod == pmSocks4) ||
  861. (ProxyMethod == pmSocks5) ||
  862. (ProxyMethod == pmHTTP) ||
  863. (ProxyMethod == pmTelnet) ||
  864. ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
  865. (FtpProxyLogonType > 0));
  866. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  867. EnableControl(ProxyUsernameEdit,
  868. // FZAPI does not support username for SOCKS4
  869. ((ProxyMethod == pmSocks4) && (SshProtocol || Neon)) ||
  870. (ProxyMethod == pmSocks5) ||
  871. (ProxyMethod == pmHTTP) ||
  872. (((ProxyMethod == pmTelnet) ||
  873. (ProxyMethod == pmCmd)) &&
  874. AnsiContainsText(ProxyCommand, L"%user")) ||
  875. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  876. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  877. EnableControl(ProxyPasswordEdit,
  878. (ProxyMethod == pmSocks5) ||
  879. (ProxyMethod == pmHTTP) ||
  880. (((ProxyMethod == pmTelnet) ||
  881. (ProxyMethod == pmCmd)) &&
  882. AnsiContainsText(ProxyCommand, L"%pass")) ||
  883. ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
  884. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  885. bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
  886. ProxySettingsGroup->Visible = SshProtocol;
  887. EnableControl(ProxySettingsGroup, ProxySettings);
  888. EnableControl(ProxyTelnetCommandEdit,
  889. ProxySettings && (ProxyMethod == pmTelnet));
  890. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  891. EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
  892. ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
  893. ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
  894. ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
  895. ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
  896. ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
  897. ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
  898. ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
  899. // environment/directories sheet
  900. EnableControl(SynchronizeBrowsingCheck,
  901. (CustomWinConfiguration->Interface == ifCommander) &&
  902. WinConfiguration->PreservePanelState &&
  903. !WinConfiguration->ScpCommander.PreserveLocalDirectory);
  904. EnableControl(CacheDirectoryChangesCheck,
  905. (!ScpProtocol || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  906. EnableControl(PreserveDirectoryChangesCheck,
  907. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  908. DirectoriesSheet->Enabled);
  909. EnableControl(ResolveSymlinksCheck, (SftpProtocol || ScpProtocol) && DirectoriesSheet->Enabled);
  910. EnableControl(FollowDirectorySymlinksCheck, (SftpProtocol || ScpProtocol || FtpProtocol));
  911. // environment sheet
  912. EnableControl(EOLTypeCombo, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  913. EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
  914. EnableControl(DSTModeGroup, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  915. EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
  916. EnableControl(UtfCombo, (SftpProtocol || FtpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
  917. EnableControl(UtfLabel, UtfCombo->Enabled);
  918. // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
  919. bool FtpProtocolWithMlsdOff = FtpProtocol && (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff);
  920. EnableControl(TimeDifferenceAutoCheck, FtpProtocolWithMlsdOff);
  921. EnableControl(TimeDifferenceEdit,
  922. ((FtpProtocolWithMlsdOff && !TimeDifferenceAutoCheck->Checked) ||
  923. ScpProtocol) &&
  924. EnvironmentSheet->Enabled);
  925. EnableControl(TimeDifferenceLabel,
  926. TimeDifferenceEdit->Enabled || TimeDifferenceAutoCheck->Enabled);
  927. EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
  928. EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
  929. EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
  930. EnableControl(TrimVMSVersionsCheck, !S3Protocol);
  931. // environment/recycle bin sheet
  932. EnableControl(OverwrittenToRecycleBinCheck, SftpProtocol && RecycleBinSheet->Enabled);
  933. EnableControl(RecycleBinPathEdit,
  934. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  935. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  936. RecycleBinSheet->Enabled);
  937. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  938. RecycleBinSheet->Enabled);
  939. // environment/sftp sheet
  940. SftpSheet->Enabled = SftpProtocol;
  941. EnableControl(AllowScpFallbackCheck, IsDefaultSftpServer());
  942. // environment/scp/shell
  943. ScpSheet->Enabled = SshProtocol;
  944. ScpSheet->Caption = LoadStr(ScpProtocol ? LOGIN_SCP_SHELL_PAGE : LOGIN_SHELL_PAGE);
  945. // hide also for SFTP with SCP fallback, as if someone wants to configure
  946. // these he/she probably intends to use SCP and should explicitly select it.
  947. // (note that these are not used for separate shell session)
  948. ScpLsOptionsGroup->Visible = ScpProtocol;
  949. OtherShellOptionsGroup->Visible = ScpProtocol;
  950. // environment/ftp
  951. FtpSheet->Enabled = FtpProtocol;
  952. EnableControl(FtpListAllCombo,
  953. (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff));
  954. EnableControl(FtpListAllLabel, FtpListAllCombo->Enabled);
  955. EnableControl(FtpForcePasvIpCombo,
  956. FtpPasvModeCheck->Checked &&
  957. (IPAutoButton->Checked || IPv4Button->Checked));
  958. EnableControl(FtpForcePasvIpLabel, FtpForcePasvIpCombo->Enabled);
  959. // environment/s3
  960. S3Sheet->Enabled = S3Protocol;
  961. EnableControl(S3SessionTokenMemo, S3Sheet->Enabled && !FSessionData->HasAutoCredentials());
  962. EnableControl(S3SessionTokenLabel, S3SessionTokenMemo->Enabled);
  963. // tunnel sheet
  964. TunnelSheet->Enabled = SshProtocol;
  965. // probably needless
  966. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  967. EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
  968. EnableControl(TunnelAuthenticationParamsGroup, TunnelSessionGroup->Enabled);
  969. // connection/ssl/tls
  970. SslSheet->Enabled = Ssl;
  971. // TLS/SSL session reuse is not configurable for WebDAV/S3 yet
  972. SslSessionReuseCheck->Enabled = SslSheet->Enabled && FtpProtocol;
  973. TlsAuthenticationGroup->Visible = Ssl && (FtpProtocol || WebDavProtocol);
  974. // encryption sheet
  975. EncryptionSheet->Enabled = SftpProtocol;
  976. EnableControl(EncryptFilesGroup, EncryptFilesCheck->Checked);
  977. // environment/webdav
  978. WebDavSheet->Enabled = WebDavProtocol;
  979. UpdateNavigationTree();
  980. // color
  981. if (FColor == 0)
  982. {
  983. MenuButton(ColorButton);
  984. }
  985. else
  986. {
  987. ColorButton->Images = ColorImageList;
  988. ColorButton->ImageIndex = GetSessionColorImage(ColorImageList, FColor, 0);
  989. ColorButton->ImageAlignment = iaRight;
  990. }
  991. }
  992. }
  993. //---------------------------------------------------------------------------
  994. void __fastcall TSiteAdvancedDialog::DataChange(TObject * /*Sender*/)
  995. {
  996. if (NoUpdate == 0)
  997. {
  998. UpdateControls();
  999. }
  1000. }
  1001. //---------------------------------------------------------------------------
  1002. void __fastcall TSiteAdvancedDialog::FormShow(TObject * /*Sender*/)
  1003. {
  1004. InstallPathWordBreakProc(PrivateKeyEdit3);
  1005. InstallPathWordBreakProc(TunnelPrivateKeyEdit3);
  1006. InstallPathWordBreakProc(RemoteDirectoryEdit);
  1007. InstallPathWordBreakProc(LocalDirectoryEdit);
  1008. InstallPathWordBreakProc(RecycleBinPathEdit);
  1009. InstallPathWordBreakProc(TlsCertificateFileEdit);
  1010. InstallPathWordBreakProc(SftpServerEdit);
  1011. InstallPathWordBreakProc(ShellEdit);
  1012. ChangePage(EnvironmentSheet);
  1013. UpdateControls();
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. bool __fastcall TSiteAdvancedDialog::Execute(TSessionData * SessionData)
  1017. {
  1018. FSessionData = SessionData;
  1019. LoadSession();
  1020. bool Result = (ShowModal() == DefaultResult(this));
  1021. if (Result)
  1022. {
  1023. SaveSession(SessionData);
  1024. }
  1025. return Result;
  1026. }
  1027. //---------------------------------------------------------------------------
  1028. void __fastcall TSiteAdvancedDialog::NavigationTreeChange(TObject * /*Sender*/,
  1029. TTreeNode * Node)
  1030. {
  1031. if (NoUpdate == 0)
  1032. {
  1033. TAutoNestingCounter Guard(NoUpdate);
  1034. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  1035. // should happen only while loading language
  1036. // (UpdateNavigationTree may not be called yet)
  1037. if (Tab != NULL)
  1038. {
  1039. PageControl->ActivePage = Tab;
  1040. // reshow the accelerators, etc
  1041. ResetSystemSettings(this);
  1042. }
  1043. PageChanged();
  1044. UpdateControls();
  1045. }
  1046. }
  1047. //---------------------------------------------------------------------------
  1048. void __fastcall TSiteAdvancedDialog::ChangePage(TTabSheet * Tab)
  1049. {
  1050. PageControl->ActivePage = Tab;
  1051. PageChanged();
  1052. }
  1053. //---------------------------------------------------------------------------
  1054. void __fastcall TSiteAdvancedDialog::PageChanged()
  1055. {
  1056. FPrivateKeyMonitors.reset(NULL);
  1057. ClosePuttySettings();
  1058. bool Found = false;
  1059. if (PageControl->ActivePage)
  1060. {
  1061. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1062. {
  1063. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1064. reinterpret_cast<int>(PageControl->ActivePage))
  1065. {
  1066. NavigationTree->Items->Item[Index]->Selected = true;
  1067. Found = true;
  1068. }
  1069. }
  1070. }
  1071. if (DebugAlwaysTrue(Found))
  1072. {
  1073. DataChange(NULL);
  1074. }
  1075. }
  1076. //---------------------------------------------------------------------------
  1077. void __fastcall TSiteAdvancedDialog::PageControlChange(TObject *)
  1078. {
  1079. DebugFail(); // should never happen as user cannot change the page
  1080. PageChanged();
  1081. }
  1082. //---------------------------------------------------------------------------
  1083. void __fastcall TSiteAdvancedDialog::CMDialogKey(TWMKeyDown & Message)
  1084. {
  1085. if (Message.CharCode == VK_TAB)
  1086. {
  1087. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1088. if (Shift.Contains(ssCtrl))
  1089. {
  1090. TTreeNode * Node = NavigationTree->Selected;
  1091. if (!Shift.Contains(ssShift))
  1092. {
  1093. Node = Node->GetNext();
  1094. if (Node == NULL)
  1095. {
  1096. Node = NavigationTree->Items->GetFirstNode();
  1097. }
  1098. }
  1099. else
  1100. {
  1101. if (Node->GetPrev() != NULL)
  1102. {
  1103. Node = Node->GetPrev();
  1104. }
  1105. else
  1106. {
  1107. while (Node->GetNext() != NULL)
  1108. {
  1109. Node = Node->GetNext();
  1110. }
  1111. }
  1112. }
  1113. Node->Selected = True;
  1114. Message.Result = 1;
  1115. return;
  1116. }
  1117. }
  1118. TForm::Dispatch(&Message);
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. void __fastcall TSiteAdvancedDialog::WMHelp(TWMHelp & Message)
  1122. {
  1123. DebugAssert(Message.HelpInfo != NULL);
  1124. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1125. {
  1126. // invoke help for active page (not for whole form), regardless of focus
  1127. // (e.g. even if focus is on control outside pagecontrol)
  1128. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1129. }
  1130. TForm::Dispatch(&Message);
  1131. }
  1132. //---------------------------------------------------------------------------
  1133. void __fastcall TSiteAdvancedDialog::Dispatch(void * Message)
  1134. {
  1135. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1136. DebugAssert(M);
  1137. if (M->Msg == CM_DIALOGKEY)
  1138. {
  1139. CMDialogKey(*((TWMKeyDown *)Message));
  1140. }
  1141. else if (M->Msg == WM_HELP)
  1142. {
  1143. WMHelp(*((TWMHelp *)Message));
  1144. }
  1145. else
  1146. {
  1147. TForm::Dispatch(Message);
  1148. }
  1149. }
  1150. //---------------------------------------------------------------------------
  1151. void __fastcall TSiteAdvancedDialog::AlgListBoxStartDrag(TObject * Sender,
  1152. TDragObject *& /*DragObject*/)
  1153. {
  1154. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1155. FAlgDragDest = -1;
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TSiteAdvancedDialog::AlgListBoxDragOver(TObject * Sender,
  1159. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  1160. {
  1161. if (Source == Sender)
  1162. {
  1163. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1164. }
  1165. else
  1166. {
  1167. Accept = false;
  1168. }
  1169. }
  1170. //---------------------------------------------------------------------------
  1171. void __fastcall TSiteAdvancedDialog::AlgListBoxDragDrop(TObject * Sender,
  1172. TObject * Source, int X, int Y)
  1173. {
  1174. if (Source == Sender)
  1175. {
  1176. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1177. if (AllowAlgDrag(AlgListBox, X, Y))
  1178. {
  1179. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1180. }
  1181. }
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. void __fastcall TSiteAdvancedDialog::CipherButtonClick(TObject *Sender)
  1185. {
  1186. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1187. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1188. }
  1189. //---------------------------------------------------------------------------
  1190. void __fastcall TSiteAdvancedDialog::KexButtonClick(TObject *Sender)
  1191. {
  1192. AlgMove(KexListBox, KexListBox->ItemIndex,
  1193. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1194. }
  1195. //---------------------------------------------------------------------------
  1196. bool __fastcall TSiteAdvancedDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1197. {
  1198. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1199. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TSiteAdvancedDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1203. {
  1204. if ((Source >= 0) && (Source < AlgListBox->Items->Count) &&
  1205. (Dest >= 0) && (Dest < AlgListBox->Items->Count))
  1206. {
  1207. AlgListBox->Items->Move(Source, Dest);
  1208. AlgListBox->ItemIndex = Dest;
  1209. AlgListBox->SetFocus();
  1210. }
  1211. UpdateControls();
  1212. }
  1213. //---------------------------------------------------------------------------
  1214. void __fastcall TSiteAdvancedDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
  1215. {
  1216. if (NoUpdate == 0)
  1217. {
  1218. UpdateControls();
  1219. if (AuthGSSAPICheck3->Checked && !HasGSSAPI(L""))
  1220. {
  1221. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
  1222. }
  1223. }
  1224. }
  1225. //---------------------------------------------------------------------------
  1226. void __fastcall TSiteAdvancedDialog::HelpButtonClick(TObject * /*Sender*/)
  1227. {
  1228. FormHelp(this);
  1229. }
  1230. //---------------------------------------------------------------------------
  1231. void __fastcall TSiteAdvancedDialog::PrivateKeyEdit3AfterDialog(TObject * Sender,
  1232. UnicodeString & Name, bool & Action)
  1233. {
  1234. PathEditAfterDialog(Sender, Name, Action);
  1235. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1236. if (Name != Edit->Text)
  1237. {
  1238. VerifyAndConvertKey(Name, GetSshProt(), true);
  1239. }
  1240. }
  1241. //---------------------------------------------------------------------------
  1242. void __fastcall TSiteAdvancedDialog::FormCloseQuery(TObject * /*Sender*/,
  1243. bool & /*CanClose*/)
  1244. {
  1245. if (ModalResult == DefaultResult(this))
  1246. {
  1247. // StripPathQuotes should not be needed as we do not feed quotes anymore
  1248. VerifyKey(StripPathQuotes(PrivateKeyEdit3->Text), GetSshProt());
  1249. // for tunnel SSH version is not configurable
  1250. VerifyKey(StripPathQuotes(TunnelPrivateKeyEdit3->Text), ssh2only);
  1251. VerifyCertificate(StripPathQuotes(TlsCertificateFileEdit->Text));
  1252. // Particularly for EncryptKey*Edit's
  1253. ExitActiveControl(this);
  1254. }
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. void __fastcall TSiteAdvancedDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1258. UnicodeString & Name, bool & /*Action*/)
  1259. {
  1260. FBeforeDialogPath = Name;
  1261. Name = ExpandEnvironmentVariables(Name);
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TSiteAdvancedDialog::PathEditAfterDialog(TObject * /*Sender*/,
  1265. UnicodeString & Name, bool & /*Action*/)
  1266. {
  1267. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1268. {
  1269. Name = FBeforeDialogPath;
  1270. }
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. int __fastcall TSiteAdvancedDialog::LastSupportedFtpProxyMethod()
  1274. {
  1275. return pmHTTP;
  1276. }
  1277. //---------------------------------------------------------------------------
  1278. bool __fastcall TSiteAdvancedDialog::SupportedFtpProxyMethod(int Method)
  1279. {
  1280. return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
  1281. }
  1282. //---------------------------------------------------------------------------
  1283. int __fastcall TSiteAdvancedDialog::GetSupportedFtpProxyMethod(int Method)
  1284. {
  1285. if (SupportedFtpProxyMethod(Method))
  1286. {
  1287. return Method;
  1288. }
  1289. else
  1290. {
  1291. return ::pmNone;
  1292. }
  1293. }
  1294. //---------------------------------------------------------------------------
  1295. int __fastcall TSiteAdvancedDialog::GetSupportedNeonProxyMethod(int Method)
  1296. {
  1297. if ((Method >= 0) && (Method <= pmHTTP))
  1298. {
  1299. return Method;
  1300. }
  1301. else
  1302. {
  1303. return ::pmNone;
  1304. }
  1305. }
  1306. //---------------------------------------------------------------------------
  1307. bool __fastcall TSiteAdvancedDialog::IsNeon(TFSProtocol FSProtocol)
  1308. {
  1309. return (FSProtocol == fsWebDAV) || (FSProtocol == fsS3);
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. TProxyMethod __fastcall TSiteAdvancedDialog::GetProxyMethod()
  1313. {
  1314. TProxyMethod Result;
  1315. TFSProtocol FSProtocol = FSessionData->FSProtocol;
  1316. if (FSessionData->UsesSsh)
  1317. {
  1318. Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
  1319. }
  1320. else if (FSProtocol == fsFTP)
  1321. {
  1322. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1323. {
  1324. Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
  1325. }
  1326. else
  1327. {
  1328. Result = ::pmNone;
  1329. }
  1330. }
  1331. else if (IsNeon(FSProtocol))
  1332. {
  1333. Result = (TProxyMethod)NeonProxyMethodCombo->ItemIndex;
  1334. }
  1335. else
  1336. {
  1337. DebugFail();
  1338. Result = ::pmNone;
  1339. }
  1340. return Result;
  1341. }
  1342. //---------------------------------------------------------------------------
  1343. int __fastcall TSiteAdvancedDialog::GetFtpProxyLogonType()
  1344. {
  1345. int Result;
  1346. if (FSessionData->FSProtocol != fsFTP)
  1347. {
  1348. Result = 0;
  1349. }
  1350. else
  1351. {
  1352. if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
  1353. {
  1354. Result = 0;
  1355. }
  1356. else
  1357. {
  1358. Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
  1359. }
  1360. }
  1361. return Result;
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TSiteAdvancedDialog::NavigationTreeCollapsing(
  1365. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1366. {
  1367. AllowCollapse = false;
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TSiteAdvancedDialog::ProxyLocalCommandBrowseButtonClick(
  1371. TObject * /*Sender*/)
  1372. {
  1373. BrowseForExecutable(ProxyLocalCommandEdit,
  1374. LoadStr(LOGIN_SELECT_LOCAL_PROXY),
  1375. LoadStr(EXECUTABLE_FILTER), false, true);
  1376. }
  1377. //---------------------------------------------------------------------------
  1378. void __fastcall TSiteAdvancedDialog::ColorButtonClick(TObject * /*Sender*/)
  1379. {
  1380. // Reason for separate Menu variable is given in TPreferencesDialog::EditorFontColorButtonClick
  1381. TPopupMenu * Menu = CreateSessionColorPopupMenu(FColor, SessionColorChange);
  1382. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1383. FColorPopupMenu.reset(Menu);
  1384. MenuPopup(Menu, ColorButton);
  1385. }
  1386. //---------------------------------------------------------------------------
  1387. void __fastcall TSiteAdvancedDialog::SessionColorChange(TColor Color)
  1388. {
  1389. FColor = Color;
  1390. UpdateControls();
  1391. }
  1392. //---------------------------------------------------------------------------
  1393. TTlsVersion __fastcall TSiteAdvancedDialog::IndexToTlsVersion(int Index)
  1394. {
  1395. switch (Index)
  1396. {
  1397. default:
  1398. DebugFail();
  1399. case 0:
  1400. return ssl3;
  1401. case 1:
  1402. return tls10;
  1403. case 2:
  1404. return tls11;
  1405. case 3:
  1406. return tls12;
  1407. case 4:
  1408. return tls13;
  1409. }
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. int __fastcall TSiteAdvancedDialog::TlsVersionToIndex(TTlsVersion TlsVersion)
  1413. {
  1414. switch (TlsVersion)
  1415. {
  1416. default:
  1417. DebugFail();
  1418. case ssl2:
  1419. case ssl3:
  1420. return 0;
  1421. case tls10:
  1422. return 1;
  1423. case tls11:
  1424. return 2;
  1425. case tls12:
  1426. return 3;
  1427. case tls13:
  1428. return 4;
  1429. }
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TSiteAdvancedDialog::MinTlsVersionComboChange(TObject */*Sender*/)
  1433. {
  1434. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1435. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1436. if (MaxTlsVersion < MinTlsVersion)
  1437. {
  1438. MaxTlsVersionCombo->ItemIndex = MinTlsVersionCombo->ItemIndex;
  1439. }
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TSiteAdvancedDialog::MaxTlsVersionComboChange(TObject * /*Sender*/)
  1443. {
  1444. TTlsVersion MinTlsVersion = IndexToTlsVersion(MinTlsVersionCombo->ItemIndex);
  1445. TTlsVersion MaxTlsVersion = IndexToTlsVersion(MaxTlsVersionCombo->ItemIndex);
  1446. if (MinTlsVersion > MaxTlsVersion)
  1447. {
  1448. MinTlsVersionCombo->ItemIndex = MaxTlsVersionCombo->ItemIndex;
  1449. }
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TSiteAdvancedDialog::ProxyAutodetectButtonClick(TObject * /*Sender*/)
  1453. {
  1454. TInstantOperationVisualizer Visualizer;
  1455. UnicodeString ProxyHost;
  1456. int ProxyPort;
  1457. if (AutodetectProxy(ProxyHost, ProxyPort))
  1458. {
  1459. ProxyHostEdit->Text = ProxyHost;
  1460. ProxyPortEdit->AsInteger = ProxyPort;
  1461. SshProxyMethodCombo->ItemIndex = pmHTTP;
  1462. FtpProxyMethodCombo->ItemIndex = pmHTTP;
  1463. NeonProxyMethodCombo->ItemIndex = pmHTTP;
  1464. UpdateControls();
  1465. }
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TSiteAdvancedDialog::NoteMemoKeyDown(
  1469. TObject * Sender, WORD & Key, TShiftState Shift)
  1470. {
  1471. MemoKeyDown(Sender, Key, Shift);
  1472. }
  1473. //---------------------------------------------------------------------------
  1474. void __fastcall TSiteAdvancedDialog::TlsCertificateFileEditAfterDialog(TObject *Sender,
  1475. UnicodeString &Name, bool &Action)
  1476. {
  1477. PathEditAfterDialog(Sender, Name, Action);
  1478. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1479. if (Name != Edit->Text)
  1480. {
  1481. VerifyCertificate(Name);
  1482. }
  1483. }
  1484. //---------------------------------------------------------------------------
  1485. void __fastcall TSiteAdvancedDialog::PrivateKeyCreatedOrModified(TObject * /*Sender*/, const UnicodeString FileName)
  1486. {
  1487. if (SameText(ExtractFileExt(FileName), FORMAT(L".%s", (PuttyKeyExt))))
  1488. {
  1489. PrivateKeyEdit3->Text = FileName;
  1490. }
  1491. }
  1492. //---------------------------------------------------------------------------
  1493. void __fastcall TSiteAdvancedDialog::PrivateKeyToolsButtonClick(TObject * /*Sender*/)
  1494. {
  1495. UnicodeString Dummy;
  1496. PrivateKeyGenerateItem->Enabled = FindTool(PuttygenTool, Dummy);
  1497. PrivateKeyUploadItem->Enabled = (GetSshProt() == ssh2only) && (NormalizeFSProtocol(FSessionData->FSProtocol) == fsSFTP);
  1498. MenuPopup(PrivateKeyMenu, PrivateKeyToolsButton);
  1499. }
  1500. //---------------------------------------------------------------------------
  1501. void __fastcall TSiteAdvancedDialog::PrivateKeyGenerateItemClick(TObject * /*Sender*/)
  1502. {
  1503. unsigned int Filters = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE;
  1504. TObjectList * PrivateKeyMonitors =
  1505. StartCreationDirectoryMonitorsOnEachDrive(Filters, PrivateKeyCreatedOrModified);
  1506. FPrivateKeyMonitors.reset(PrivateKeyMonitors);
  1507. ExecuteTool(PuttygenTool);
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. void __fastcall TSiteAdvancedDialog::PrivateKeyUploadItemClick(TObject * /*Sender*/)
  1511. {
  1512. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1513. SessionData->FSProtocol = fsSFTPonly; // no SCP fallback, as SCP does not implement GetHomeDirectory
  1514. SessionData->RemoteDirectory = UnicodeString();
  1515. UnicodeString FileName = PrivateKeyEdit3->Text;
  1516. if (TTerminalManager::Instance()->UploadPublicKey(NULL, SessionData.get(), FileName))
  1517. {
  1518. PrivateKeyEdit3->Text = FileName;
  1519. PrivateKeyEdit3->SetFocus();
  1520. }
  1521. }
  1522. //---------------------------------------------------------------------------
  1523. void __fastcall TSiteAdvancedDialog::PrivateKeyViewButtonClick(TObject * /*Sender*/)
  1524. {
  1525. UnicodeString FileName = PrivateKeyEdit3->Text;
  1526. VerifyAndConvertKey(FileName, GetSshProt(), false);
  1527. PrivateKeyEdit3->Text = FileName;
  1528. UnicodeString CommentDummy;
  1529. UnicodeString Line = GetPublicKeyLine(FileName, CommentDummy);
  1530. std::unique_ptr<TStrings> Messages(TextToStringList(Line));
  1531. TClipboardHandler ClipboardHandler;
  1532. ClipboardHandler.Text = Line;
  1533. TMessageParams Params;
  1534. TQueryButtonAlias Aliases[1];
  1535. Aliases[0].Button = qaRetry;
  1536. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1537. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1538. Params.Aliases = Aliases;
  1539. Params.AliasesCount = LENOF(Aliases);
  1540. UnicodeString Message = LoadStr(LOGIN_AUTHORIZED_KEYS);
  1541. int Answers = qaOK | qaRetry;
  1542. MoreMessageDialog(Message, Messages.get(), qtInformation, Answers, HELP_LOGIN_AUTHORIZED_KEYS, &Params);
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. TCustomEdit * __fastcall TSiteAdvancedDialog::GetEncryptKeyEdit(bool AShow)
  1546. {
  1547. bool Show = (ShowEncryptionKeyCheck->Checked == AShow);
  1548. return (Show ? static_cast<TCustomEdit *>(EncryptKeyVisibleEdit) : static_cast<TCustomEdit *>(EncryptKeyPasswordEdit));
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. void __fastcall TSiteAdvancedDialog::ShowEncryptionKeyCheckClick(TObject * /*Sender*/)
  1552. {
  1553. TCustomEdit * ShowEdit = GetEncryptKeyEdit();
  1554. TCustomEdit * HideEdit = GetEncryptKeyEdit(false);
  1555. if (DebugAlwaysTrue(ShowEdit->Visible != HideEdit->Visible) &&
  1556. DebugAlwaysTrue(!ShowEdit->Visible))
  1557. {
  1558. UnicodeString Key = HideEdit->Text;
  1559. ShowEdit->Visible = true;
  1560. ShowEdit->Text = Key;
  1561. HideEdit->Visible = false;
  1562. }
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. void __fastcall TSiteAdvancedDialog::GenerateKeyButtonClick(TObject * /*Sender*/)
  1566. {
  1567. UnicodeString Key = BytesToHex(GenerateEncryptKey());
  1568. GetEncryptKeyEdit()->Text = Key;
  1569. TClipboardHandler ClipboardHandler;
  1570. ClipboardHandler.Text = Key;
  1571. TMessageParams Params;
  1572. TQueryButtonAlias Aliases[1];
  1573. Aliases[0].Button = qaRetry;
  1574. Aliases[0].Alias = LoadStr(COPY_KEY_BUTTON);
  1575. Aliases[0].OnSubmit = &ClipboardHandler.Copy;
  1576. Params.Aliases = Aliases;
  1577. Params.AliasesCount = LENOF(Aliases);
  1578. MessageDialog(LoadStr(ENCRYPT_KEY_GENERATED), qtInformation, qaOK | qaRetry, HELP_FILE_ENCRYPTION, &Params);
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. void __fastcall TSiteAdvancedDialog::EncryptKeyEditExit(TObject * /*Sender*/)
  1582. {
  1583. if (!IsCancelButtonBeingClicked(this))
  1584. {
  1585. UnicodeString HexKey = GetEncryptKeyEdit()->Text;
  1586. if (!HexKey.IsEmpty())
  1587. {
  1588. ValidateEncryptKey(HexToBytes(HexKey));
  1589. }
  1590. }
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. void TSiteAdvancedDialog::SerializePuttyRegistry(const UnicodeString & Key, TStrings * Values)
  1594. {
  1595. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1596. if (DebugAlwaysTrue(Registry->OpenKeyReadOnly(Key)))
  1597. {
  1598. std::unique_ptr<TStrings> Names(new TStringList());
  1599. Registry->GetValueNames(Names.get());
  1600. for (int Index = 0; Index < Names->Count; Index++)
  1601. {
  1602. UnicodeString Name = Names->Strings[Index];
  1603. TRegDataType Type = Registry->GetDataType(Name);
  1604. UnicodeString Value;
  1605. if (Type == rdString)
  1606. {
  1607. Value = UnicodeString(PuttyStr(Registry->ReadString(Name)));
  1608. }
  1609. else if (DebugAlwaysTrue(Type == rdInteger))
  1610. {
  1611. Value = StrToInt(Registry->ReadInteger(Name));
  1612. }
  1613. SetStringValueEvenIfEmpty(Values, Name, Value);
  1614. }
  1615. }
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TSiteAdvancedDialog::PuttySettingsTimer(TObject *)
  1619. {
  1620. if (PuttySettingsEdit->Modified)
  1621. {
  1622. FPuttySettingsTimer->Enabled = false;
  1623. }
  1624. else
  1625. {
  1626. std::unique_ptr<TStrings> NewPuttyRegSettings(new TStringList());
  1627. SerializePuttyRegistry(GetPuttySiteKey(), NewPuttyRegSettings.get());
  1628. std::unique_ptr<TStrings> PuttySettings(new TStringList());
  1629. for (int NewIndex = 0; NewIndex < NewPuttyRegSettings->Count; NewIndex++)
  1630. {
  1631. UnicodeString Name = NewPuttyRegSettings->Names[NewIndex];
  1632. UnicodeString NewValue = NewPuttyRegSettings->ValueFromIndex[NewIndex];
  1633. int Index = FPuttyRegSettings->IndexOfName(Name);
  1634. // Ignoring values we do not know (from future versions of PuTTY),
  1635. // as we cannot tell if they are modified or not.
  1636. // Ignoring also all value that we export outselves from WinSCP settings
  1637. // (primarily to avoid collecting all those values, when the user forgets to load the temporary site in PuTTY,
  1638. // and only saves the changed terminal settings with the basic session settings set to empty values)
  1639. if ((Index >= 0) &&
  1640. (FPuttyRegSettings->ValueFromIndex[Index] != NewValue))
  1641. {
  1642. SetStringValueEvenIfEmpty(PuttySettings.get(), Name, NewValue);
  1643. }
  1644. }
  1645. PuttySettingsEdit->Text = StringsToParams(PuttySettings.get()).TrimLeft();
  1646. UpdateControls();
  1647. }
  1648. }
  1649. //---------------------------------------------------------------------------
  1650. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteName()
  1651. {
  1652. return FORMAT(L"(%s)", (FMTLOAD(PUTTY_SETTINGS_SITE_NAME, (FSessionData->SessionName))));
  1653. }
  1654. //---------------------------------------------------------------------------
  1655. UnicodeString __fastcall TSiteAdvancedDialog::GetPuttySiteKey()
  1656. {
  1657. return OriginalPuttyRegistryStorageKey + L"\\" + Configuration->PuttySessionsSubKey + L"\\" + PuttyMungeStr(GetPuttySiteName());
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. void __fastcall TSiteAdvancedDialog::ClosePuttySettings()
  1661. {
  1662. if (FPuttySettingsTimer.get() != NULL)
  1663. {
  1664. FPuttySettingsTimer.reset(NULL);
  1665. std::unique_ptr<TRegistry> Registry(new TRegistry());
  1666. Registry->DeleteKey(GetPuttySiteKey());
  1667. }
  1668. }
  1669. //---------------------------------------------------------------------------
  1670. void __fastcall TSiteAdvancedDialog::PuttySettingsButtonClick(TObject *)
  1671. {
  1672. ClosePuttySettings();
  1673. UnicodeString SiteName = GetPuttySiteName();
  1674. MessageDialog(FMTLOAD(PUTTY_SETTINGS_INSTRUCTIONS, (SiteName, SiteName)), qtInformation, qaOK, HELP_PUTTY_SETTINGS);
  1675. PuttySettingsEdit->Modified = false;
  1676. std::unique_ptr<TSessionData> SessionData(GetSessionData());
  1677. UnicodeString PuttySettings = SessionData->PuttySettings;
  1678. SessionData->PuttySettings = UnicodeString();
  1679. SavePuttyDefaults(SiteName);
  1680. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1681. UnicodeString PuttySiteKey = GetPuttySiteKey();
  1682. FPuttyRegSettings.reset(new TStringList());
  1683. SerializePuttyRegistry(PuttySiteKey, FPuttyRegSettings.get());
  1684. std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(true));
  1685. for (int Index = 0; Index < AllOptions->Count; Index++)
  1686. {
  1687. int I = FPuttyRegSettings->IndexOfName(AllOptions->Names[Index]);
  1688. if (I >= 0)
  1689. {
  1690. FPuttyRegSettings->Delete(I);
  1691. }
  1692. }
  1693. SessionData->PuttySettings = PuttySettings;
  1694. ExportSessionToPutty(SessionData.get(), false, SiteName);
  1695. UnicodeString Program, Params, Dir;
  1696. SplitCommand(GUIConfiguration->PuttyPath, Program, Params, Dir);
  1697. Program = ExpandEnvironmentVariables(Program);
  1698. if (!FindFile(Program))
  1699. {
  1700. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1701. }
  1702. ExecuteShellChecked(Program, L"");
  1703. FPuttySettingsTimer.reset(new TTimer(this));
  1704. FPuttySettingsTimer->OnTimer = PuttySettingsTimer;
  1705. FPuttySettingsTimer->Interval = MSecsPerSec;
  1706. FPuttySettingsTimer->Enabled = true;
  1707. UpdateControls();
  1708. }
  1709. //---------------------------------------------------------------------------
  1710. void __fastcall TSiteAdvancedDialog::FormClose(TObject *, TCloseAction &)
  1711. {
  1712. ClosePuttySettings();
  1713. }
  1714. //---------------------------------------------------------------------------