SiteAdvanced.cpp 66 KB

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