Login.cpp 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <CoreMain.h>
  6. #include <Common.h>
  7. #include <PuttyTools.h>
  8. #include <TextsWin.h>
  9. #include <TextsCore.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include "Login.h"
  13. #include "WinInterface.h"
  14. #include "GUITools.h"
  15. #include "Tools.h"
  16. #include "Setup.h"
  17. #include "CustomWinConfiguration.h"
  18. //---------------------------------------------------------------------
  19. #pragma link "ComboEdit"
  20. #pragma link "LogSettings"
  21. #pragma link "GeneralSettings"
  22. #pragma link "UpDownEdit"
  23. #pragma link "PasswordEdit"
  24. #pragma resource "*.dfm"
  25. //---------------------------------------------------------------------------
  26. // Sheet tag:
  27. // 01 top, 02 indented
  28. //---------------------------------------------------------------------------
  29. bool __fastcall DoLoginDialog(TStoredSessionList *SessionList,
  30. TSessionData * Data, int Options)
  31. {
  32. assert(Data);
  33. TLoginDialog *LoginDialog = new TLoginDialog(Application);
  34. bool Result;
  35. try
  36. {
  37. LoginDialog->StoredSessions = SessionList;
  38. LoginDialog->SessionData = Data;
  39. LoginDialog->Options = Options;
  40. Result = LoginDialog->Execute();
  41. if (Result)
  42. {
  43. Data->Assign(LoginDialog->SessionData);
  44. };
  45. }
  46. __finally
  47. {
  48. delete LoginDialog;
  49. }
  50. return Result;
  51. }
  52. //---------------------------------------------------------------------
  53. static const TFSProtocol FSOrder[] = { fsSFTPonly, fsSCPonly, fsFTP, fsExternalSSH, fsExternalSFTP };
  54. //---------------------------------------------------------------------
  55. __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
  56. : TForm(AOwner)
  57. {
  58. FSessionData = new TSessionData("");
  59. NoUpdate = 0;
  60. FLanguagesPopupMenu = NULL;
  61. FInitialized = false;
  62. FSavedTab = NULL;
  63. FSavedSession = -1;
  64. FOptions = loStartup;
  65. FLocaleChanging = false;
  66. FColor = (TColor)0;
  67. FEditingSessionData = NULL;
  68. FTreeLabels = new TStringList();
  69. InitControls();
  70. }
  71. //---------------------------------------------------------------------
  72. __fastcall TLoginDialog::~TLoginDialog()
  73. {
  74. // SelectItem event is called after destructor! Why?
  75. SessionListView->Selected = NULL;
  76. assert(FSystemSettings);
  77. DeleteSystemSettings(this, FSystemSettings);
  78. FSystemSettings = NULL;
  79. delete FTreeLabels;
  80. delete FSessionData;
  81. delete FLanguagesPopupMenu;
  82. }
  83. //---------------------------------------------------------------------
  84. void __fastcall TLoginDialog::ShowTabs(bool Show)
  85. {
  86. for (int Index = 0; Index < PageControl->PageCount; Index++)
  87. {
  88. PageControl->Pages[Index]->TabVisible = Show;
  89. }
  90. // change form height by height of hidden tabs
  91. ClientHeight += (Show ? 1 : -1) * 45;
  92. }
  93. //---------------------------------------------------------------------
  94. void __fastcall TLoginDialog::InitControls()
  95. {
  96. InitializeBugsCombo(BugIgnore1Combo);
  97. InitializeBugsCombo(BugPlainPW1Combo);
  98. InitializeBugsCombo(BugRSA1Combo);
  99. InitializeBugsCombo(BugHMAC2Combo);
  100. InitializeBugsCombo(BugDeriveKey2Combo);
  101. InitializeBugsCombo(BugRSAPad2Combo);
  102. InitializeBugsCombo(BugRekey2Combo);
  103. InitializeBugsCombo(BugPKSessID2Combo);
  104. InitializeBugsCombo(SFTPBugSymlinkCombo);
  105. InitializeBugsCombo(SFTPBugUtfCombo);
  106. InitializeBugsCombo(SFTPBugSignedTSCombo);
  107. InstallPathWordBreakProc(RemoteDirectoryEdit);
  108. InstallPathWordBreakProc(LocalDirectoryEdit);
  109. InstallPathWordBreakProc(PrivateKeyEdit);
  110. InstallPathWordBreakProc(RecycleBinPathEdit);
  111. TunnelLocalPortNumberEdit->Items->BeginUpdate();
  112. try
  113. {
  114. AnsiString TunnelLocalPortNumberAutoassign = TunnelLocalPortNumberEdit->Items->Strings[0];
  115. TunnelLocalPortNumberEdit->Items->Clear();
  116. TunnelLocalPortNumberEdit->Items->Add(TunnelLocalPortNumberAutoassign);
  117. for (int Index = Configuration->TunnelLocalPortNumberLow;
  118. Index <= Configuration->TunnelLocalPortNumberHigh; Index++)
  119. {
  120. TunnelLocalPortNumberEdit->Items->Add(IntToStr(Index));
  121. }
  122. }
  123. __finally
  124. {
  125. TunnelLocalPortNumberEdit->Items->EndUpdate();
  126. }
  127. }
  128. //---------------------------------------------------------------------
  129. void __fastcall TLoginDialog::Init()
  130. {
  131. UseSystemSettings(this, &FSystemSettings);
  132. Caption = FORMAT("%s %s", (AppName, Caption));
  133. InitControls();
  134. FTreeLabels->Clear();
  135. int Index = 0;
  136. while (Index < PageControl->PageCount)
  137. {
  138. FTreeLabels->Add(PageControl->Pages[Index]->Hint);
  139. PageControl->Pages[Index]->Hint = "";
  140. Index++;
  141. }
  142. UpdateNavigationTree();
  143. if ((Options & loLocalDirectory) == 0)
  144. {
  145. LocalDirectoryLabel->Visible = false;
  146. LocalDirectoryEdit->Visible = false;
  147. LocalDirectoryDescLabel->Visible = false;
  148. DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + 12;
  149. DirectoryOptionsGroup->Top = DirectoriesGroup->Top + DirectoriesGroup->Height + 8;
  150. }
  151. if (FLAGCLEAR(Options, loExternalProtocols))
  152. {
  153. assert(TransferProtocolCombo->Items->Count == FSPROTOCOL_COUNT - 1);
  154. TransferProtocolCombo->Items->Delete(TransferProtocolCombo->Items->Count - 2);
  155. TransferProtocolCombo->Items->Delete(TransferProtocolCombo->Items->Count - 1);
  156. }
  157. #ifdef NO_FILEZILLA
  158. assert(FLAGCLEAR(Options, loExternalProtocols));
  159. assert(TransferProtocolCombo->Items->Count == FSPROTOCOL_COUNT - 2 - 1);
  160. TransferProtocolCombo->Items->Delete(TransferProtocolCombo->Items->Count - 1);
  161. #endif
  162. ShowTabs(false);
  163. if (StoredSessions && StoredSessions->Count &&
  164. (FSessionData->Name == StoredSessions->DefaultSettings->Name))
  165. {
  166. ChangePage(SessionListSheet);
  167. SessionListView->SetFocus();
  168. assert(SessionListView->Items->Count > 0);
  169. if (SessionListView->Items->Count > 0)
  170. {
  171. SessionListView->ItemIndex = 0;
  172. SessionListView->ItemFocused = SessionListView->Selected;
  173. }
  174. }
  175. else
  176. {
  177. EditSession();
  178. }
  179. UpdateControls();
  180. }
  181. //---------------------------------------------------------------------
  182. void __fastcall TLoginDialog::InitializeBugsCombo(TComboBox * BugsCombo)
  183. {
  184. int PrevIndex = BugsCombo->ItemIndex;
  185. BugsCombo->Items->BeginUpdate();
  186. try
  187. {
  188. BugsCombo->Clear();
  189. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_AUTO));
  190. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_OFF));
  191. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_ON));
  192. }
  193. __finally
  194. {
  195. BugsCombo->Items->EndUpdate();
  196. }
  197. assert(PrevIndex < BugsCombo->Items->Count);
  198. BugsCombo->ItemIndex = PrevIndex;
  199. }
  200. //---------------------------------------------------------------------
  201. void __fastcall TLoginDialog::LoadSessions()
  202. {
  203. SessionListView->Items->BeginUpdate();
  204. try
  205. {
  206. SessionListView->Items->Clear();
  207. if (StoredSessions)
  208. {
  209. for (int Index = 0; Index < StoredSessions->Count; Index++)
  210. {
  211. TListItem *Item;
  212. Item = SessionListView->Items->Add();
  213. LoadSessionItem(Item);
  214. }
  215. }
  216. }
  217. __finally
  218. {
  219. SessionListView->Items->EndUpdate();
  220. }
  221. SelectedSession = StoredSessions->Count > 0 ?
  222. dynamic_cast<TSessionData*>(StoredSessions->AtObject(0)) : NULL;
  223. UpdateControls();
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TLoginDialog::Default()
  227. {
  228. if (StoredSessions)
  229. {
  230. FSessionData->Assign(StoredSessions->DefaultSettings);
  231. }
  232. else
  233. {
  234. FSessionData->Default();
  235. }
  236. FEditingSessionData = NULL;
  237. LoadSession(FSessionData);
  238. FCurrentSessionName = "";
  239. }
  240. //---------------------------------------------------------------------
  241. void __fastcall TLoginDialog::LoadSession(TSessionData * aSessionData)
  242. {
  243. // it was always true, and now must be true because of ping/keepalive settings
  244. assert(aSessionData == FSessionData);
  245. NoUpdate++;
  246. try
  247. {
  248. FFSProtocol = aSessionData->FSProtocol;
  249. // Basic tab
  250. UserNameEdit->Text = aSessionData->UserName;
  251. PortNumberEdit->AsInteger = aSessionData->PortNumber;
  252. HostNameEdit->Text = aSessionData->HostName;
  253. PasswordEdit->Text = aSessionData->Password;
  254. PrivateKeyEdit->Text = aSessionData->PublicKeyFile;
  255. FColor = (TColor)aSessionData->Color;
  256. bool AllowScpFallback;
  257. TransferProtocolCombo->ItemIndex =
  258. FSProtocolToIndex(aSessionData->FSProtocol, AllowScpFallback);
  259. AllowScpFallbackCheck->Checked = AllowScpFallback;
  260. // Directories tab
  261. LocalDirectoryEdit->Text = aSessionData->LocalDirectory;
  262. RemoteDirectoryEdit->Text = aSessionData->RemoteDirectory;
  263. UpdateDirectoriesCheck->Checked = aSessionData->UpdateDirectories;
  264. CacheDirectoriesCheck->Checked = aSessionData->CacheDirectories;
  265. CacheDirectoryChangesCheck->Checked = aSessionData->CacheDirectoryChanges;
  266. PreserveDirectoryChangesCheck->Checked = aSessionData->PreserveDirectoryChanges;
  267. ResolveSymlinksCheck->Checked = aSessionData->ResolveSymlinks;
  268. // Environment tab
  269. switch (aSessionData->DSTMode)
  270. {
  271. case dstmWin:
  272. DSTModeWinCheck->Checked = true;
  273. break;
  274. case dstmKeep:
  275. DSTModeKeepCheck->Checked = true;
  276. break;
  277. default:
  278. case dstmUnix:
  279. DSTModeUnixCheck->Checked = true;
  280. break;
  281. }
  282. if (aSessionData->EOLType == eolLF)
  283. {
  284. EOLTypeLFButton->Checked = true;
  285. }
  286. else
  287. {
  288. EOLTypeCRLFButton->Checked = true;
  289. }
  290. DeleteToRecycleBinCheck->Checked = aSessionData->DeleteToRecycleBin;
  291. OverwrittenToRecycleBinCheck->Checked = aSessionData->OverwrittenToRecycleBin;
  292. RecycleBinPathEdit->Text = aSessionData->RecycleBinPath;
  293. // SFTP tab
  294. #define LOAD_SFTP_BUG_COMBO(BUG) \
  295. SFTPBug ## BUG ## Combo->ItemIndex = 2 - aSessionData->SFTPBug[sb ## BUG]; \
  296. if (SFTPBug ## BUG ## Combo->ItemIndex < 0) SFTPBug ## BUG ## Combo->ItemIndex = 0
  297. LOAD_SFTP_BUG_COMBO(Symlink);
  298. LOAD_SFTP_BUG_COMBO(Utf);
  299. LOAD_SFTP_BUG_COMBO(SignedTS);
  300. #undef LOAD_SFTP_BUG_COMBO
  301. SFTPMaxVersionCombo->ItemIndex = aSessionData->SFTPMaxVersion;
  302. // Authentication tab
  303. AuthTISCheck->Checked = aSessionData->AuthTIS;
  304. AuthKICheck->Checked = aSessionData->AuthKI;
  305. AuthKIPasswordCheck->Checked = aSessionData->AuthKIPassword;
  306. AuthGSSAPICheck->Checked = aSessionData->AuthGSSAPI;
  307. AgentFwdCheck->Checked = aSessionData->AgentFwd;
  308. GSSAPIFwdTGTCheck->Checked = aSessionData->GSSAPIFwdTGT;
  309. GSSAPIServerRealmEdit->Text = aSessionData->GSSAPIServerRealm;
  310. // SSH tab
  311. Ssh2LegacyDESCheck->Checked = aSessionData->Ssh2DES;
  312. CompressionCheck->Checked = aSessionData->Compression;
  313. switch (aSessionData->SshProt) {
  314. case ssh1only: SshProt1onlyButton->Checked = true; break;
  315. case ssh1: SshProt1Button->Checked = true; break;
  316. case ssh2: SshProt2Button->Checked = true; break;
  317. case ssh2only: SshProt2onlyButton->Checked = true; break;
  318. }
  319. CipherListBox->Items->Clear();
  320. assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_DES);
  321. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  322. {
  323. CipherListBox->Items->AddObject(
  324. LoadStr(CIPHER_NAME_WARN+aSessionData->Cipher[Index]),
  325. (TObject*)aSessionData->Cipher[Index]);
  326. }
  327. // KEX tab
  328. KexListBox->Items->Clear();
  329. assert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_DHGEX);
  330. for (int Index = 0; Index < KEX_COUNT; Index++)
  331. {
  332. KexListBox->Items->AddObject(
  333. LoadStr(KEX_NAME_WARN+aSessionData->Kex[Index]),
  334. (TObject*)aSessionData->Kex[Index]);
  335. }
  336. RekeyTimeEdit->AsInteger = aSessionData->RekeyTime;
  337. RekeyDataEdit->Text = aSessionData->RekeyData;
  338. // Connection tab
  339. FtpPasvModeCheck->Checked = aSessionData->FtpPasvMode;
  340. LoadPing(aSessionData);
  341. TimeoutEdit->AsInteger = aSessionData->Timeout;
  342. switch (aSessionData->AddressFamily)
  343. {
  344. case afIPv4:
  345. IPv4Button->Checked = true;
  346. break;
  347. case afIPv6:
  348. IPv6Button->Checked = true;
  349. break;
  350. case afAuto:
  351. default:
  352. IPAutoButton->Checked = true;
  353. break;
  354. }
  355. // Shell tab
  356. if (aSessionData->DefaultShell)
  357. {
  358. ShellEdit->Text = ShellEdit->Items->Strings[0];
  359. }
  360. else
  361. {
  362. ShellEdit->Text = aSessionData->Shell;
  363. }
  364. // hide selection, which is wrongly shown initially even when the box has not focus
  365. ShellEdit->SelLength = 0;
  366. if (aSessionData->DetectReturnVar)
  367. {
  368. ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
  369. }
  370. else
  371. {
  372. ReturnVarEdit->Text = aSessionData->ReturnVar;
  373. }
  374. ReturnVarEdit->SelLength = 0;
  375. LookupUserGroupsCheck->Checked = aSessionData->LookupUserGroups;
  376. ClearAliasesCheck->Checked = aSessionData->ClearAliases;
  377. IgnoreLsWarningsCheck->Checked = aSessionData->IgnoreLsWarnings;
  378. Scp1CompatibilityCheck->Checked = aSessionData->Scp1Compatibility;
  379. UnsetNationalVarsCheck->Checked = aSessionData->UnsetNationalVars;
  380. AliasGroupListCheck->Checked = aSessionData->AliasGroupList;
  381. SCPLsFullTimeAutoCheck->Checked = (aSessionData->SCPLsFullTime != asOff);
  382. int TimeDifferenceMin = DateTimeToTimeStamp(aSessionData->TimeDifference).Time / 60000;
  383. if (double(aSessionData->TimeDifference) < 0)
  384. {
  385. TimeDifferenceMin = -TimeDifferenceMin;
  386. }
  387. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / 60;
  388. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % 60;
  389. // Proxy tab
  390. switch (aSessionData->ProxyMethod) {
  391. case pmHTTP: ProxyHTTPButton->Checked = true; break;
  392. case pmSocks4: ProxySocks4Button->Checked = true; break;
  393. case pmSocks5: ProxySocks5Button->Checked = true; break;
  394. case pmTelnet: ProxyTelnetButton->Checked = true; break;
  395. default: ProxyNoneButton->Checked = true; break;
  396. }
  397. ProxyHostEdit->Text = aSessionData->ProxyHost;
  398. ProxyPortEdit->AsInteger = aSessionData->ProxyPort;
  399. ProxyUsernameEdit->Text = aSessionData->ProxyUsername;
  400. ProxyPasswordEdit->Text = aSessionData->ProxyPassword;
  401. ProxyTelnetCommandEdit->Text = aSessionData->ProxyTelnetCommand;
  402. ProxyLocalhostCheck->Checked = aSessionData->ProxyLocalhost;
  403. switch (aSessionData->ProxyDNS) {
  404. case asOn: ProxyDNSOnButton->Checked = true; break;
  405. case asOff: ProxyDNSOffButton->Checked = true; break;
  406. default: ProxyDNSAutoButton->Checked = true; break;
  407. }
  408. // Bugs tab
  409. #define LOAD_BUG_COMBO(BUG) \
  410. Bug ## BUG ## Combo->ItemIndex = 2 - aSessionData->Bug[sb ## BUG]; \
  411. if (Bug ## BUG ## Combo->ItemIndex < 0) Bug ## BUG ## Combo->ItemIndex = 0
  412. LOAD_BUG_COMBO(Ignore1);
  413. LOAD_BUG_COMBO(PlainPW1);
  414. LOAD_BUG_COMBO(RSA1);
  415. LOAD_BUG_COMBO(HMAC2);
  416. LOAD_BUG_COMBO(DeriveKey2);
  417. LOAD_BUG_COMBO(RSAPad2);
  418. LOAD_BUG_COMBO(Rekey2);
  419. LOAD_BUG_COMBO(PKSessID2);
  420. #undef LOAD_BUG_COMBO
  421. // Tunnel tab
  422. TunnelCheck->Checked = aSessionData->Tunnel;
  423. TunnelUserNameEdit->Text = aSessionData->TunnelUserName;
  424. TunnelPortNumberEdit->AsInteger = aSessionData->TunnelPortNumber;
  425. TunnelHostNameEdit->Text = aSessionData->TunnelHostName;
  426. TunnelPasswordEdit->Text = aSessionData->TunnelPassword;
  427. TunnelPrivateKeyEdit->Text = aSessionData->TunnelPublicKeyFile;
  428. if (aSessionData->TunnelAutoassignLocalPortNumber)
  429. {
  430. TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
  431. }
  432. else
  433. {
  434. TunnelLocalPortNumberEdit->Text = IntToStr(aSessionData->TunnelLocalPortNumber);
  435. }
  436. // hide selection, which is wrongly shown initially even when the box has not focus
  437. TunnelLocalPortNumberEdit->SelLength = 0;
  438. }
  439. __finally
  440. {
  441. NoUpdate--;
  442. UpdateControls();
  443. }
  444. FCurrentSessionName = aSessionData->Name;
  445. }
  446. //---------------------------------------------------------------------
  447. void __fastcall TLoginDialog::LoadPing(TSessionData * aSessionData)
  448. {
  449. switch (FFSProtocol == fsFTP ? aSessionData->FtpPingType : aSessionData->PingType)
  450. {
  451. case ptNullPacket:
  452. PingNullPacketButton->Checked = true;
  453. break;
  454. case ptDummyCommand:
  455. PingDummyCommandButton->Checked = true;
  456. break;
  457. default:
  458. PingOffButton->Checked = true;
  459. break;
  460. }
  461. PingIntervalSecEdit->AsInteger =
  462. (FFSProtocol == fsFTP ? aSessionData->FtpPingInterval : aSessionData->PingInterval);
  463. }
  464. //---------------------------------------------------------------------
  465. void __fastcall TLoginDialog::SaveSession(TSessionData * aSessionData)
  466. {
  467. // it was always true, and now must be true because of ping/keepalive settings
  468. assert(aSessionData == FSessionData);
  469. aSessionData->Name = FCurrentSessionName;
  470. // Basic tab
  471. aSessionData->UserName = UserNameEdit->Text.Trim();
  472. aSessionData->PortNumber = PortNumberEdit->AsInteger;
  473. // must be loaded after UserName, because HostName may be in format user@host
  474. aSessionData->HostName = HostNameEdit->Text.Trim();
  475. aSessionData->Password = PasswordEdit->Text;
  476. aSessionData->PublicKeyFile = PrivateKeyEdit->Text;
  477. aSessionData->Color = FColor;
  478. aSessionData->FSProtocol = IndexToFSProtocol(
  479. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  480. // SSH tab
  481. aSessionData->Compression = CompressionCheck->Checked;
  482. aSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  483. if (SshProt1onlyButton->Checked) aSessionData->SshProt = ssh1only;
  484. else
  485. if (SshProt1Button->Checked) aSessionData->SshProt = ssh1;
  486. else
  487. if (SshProt2Button->Checked) aSessionData->SshProt = ssh2;
  488. else aSessionData->SshProt = ssh2only;
  489. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  490. {
  491. aSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  492. }
  493. // Kex tab
  494. for (int Index = 0; Index < KEX_COUNT; Index++)
  495. {
  496. aSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  497. }
  498. aSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  499. aSessionData->RekeyData = RekeyDataEdit->Text;
  500. // Authentication tab
  501. aSessionData->AuthTIS = AuthTISCheck->Checked;
  502. aSessionData->AuthKI = AuthKICheck->Checked;
  503. aSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  504. aSessionData->AuthGSSAPI = AuthGSSAPICheck->Checked;
  505. aSessionData->AgentFwd = AgentFwdCheck->Checked;
  506. aSessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
  507. aSessionData->GSSAPIServerRealm = GSSAPIServerRealmEdit->Text;
  508. // Connection tab
  509. aSessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
  510. SavePing(aSessionData);
  511. aSessionData->Timeout = TimeoutEdit->AsInteger;
  512. if (IPv4Button->Checked)
  513. {
  514. aSessionData->AddressFamily = afIPv4;
  515. }
  516. else if (IPv6Button->Checked)
  517. {
  518. aSessionData->AddressFamily = afIPv6;
  519. }
  520. else
  521. {
  522. aSessionData->AddressFamily = afAuto;
  523. }
  524. // Directories tab
  525. aSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  526. aSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  527. aSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  528. aSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  529. aSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  530. aSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  531. aSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  532. // Environment tab
  533. if (DSTModeUnixCheck->Checked) aSessionData->DSTMode = dstmUnix;
  534. else
  535. if (DSTModeKeepCheck->Checked) aSessionData->DSTMode = dstmKeep;
  536. else aSessionData->DSTMode = dstmWin;
  537. if (EOLTypeLFButton->Checked) aSessionData->EOLType = eolLF;
  538. else aSessionData->EOLType = eolCRLF;
  539. aSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  540. aSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  541. aSessionData->RecycleBinPath = RecycleBinPathEdit->Text;
  542. // SCP tab
  543. aSessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
  544. aSessionData->Shell = (aSessionData->DefaultShell ? AnsiString() : ShellEdit->Text);
  545. aSessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
  546. aSessionData->ReturnVar = (aSessionData->DetectReturnVar ? AnsiString() : ReturnVarEdit->Text);
  547. aSessionData->LookupUserGroups = LookupUserGroupsCheck->Checked;
  548. aSessionData->ClearAliases = ClearAliasesCheck->Checked;
  549. aSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  550. aSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  551. aSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  552. aSessionData->AliasGroupList = AliasGroupListCheck->Checked;
  553. aSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  554. aSessionData->TimeDifference =
  555. (double(TimeDifferenceEdit->AsInteger) / 24) +
  556. (double(TimeDifferenceMinutesEdit->AsInteger) / 24 / 60);
  557. // SFTP tab
  558. #define SAVE_SFTP_BUG_COMBO(BUG) aSessionData->SFTPBug[sb ## BUG] = (TAutoSwitch)(2 - SFTPBug ## BUG ## Combo->ItemIndex);
  559. SAVE_SFTP_BUG_COMBO(Symlink);
  560. SAVE_SFTP_BUG_COMBO(Utf);
  561. SAVE_SFTP_BUG_COMBO(SignedTS);
  562. #undef SAVE_SFTP_BUG_COMBO
  563. aSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  564. // Proxy tab
  565. if (ProxyHTTPButton->Checked) aSessionData->ProxyMethod = pmHTTP;
  566. else
  567. if (ProxySocks4Button->Checked) aSessionData->ProxyMethod = pmSocks4;
  568. else
  569. if (ProxySocks5Button->Checked) aSessionData->ProxyMethod = pmSocks5;
  570. else
  571. if (ProxyTelnetButton->Checked) aSessionData->ProxyMethod = pmTelnet;
  572. else aSessionData->ProxyMethod = pmNone;
  573. aSessionData->ProxyHost = ProxyHostEdit->Text;
  574. aSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  575. aSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  576. aSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  577. aSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  578. aSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  579. if (ProxyDNSOnButton->Checked) aSessionData->ProxyDNS = asOn;
  580. else
  581. if (ProxyDNSOffButton->Checked) aSessionData->ProxyDNS = asOff;
  582. else aSessionData->ProxyDNS = asAuto;
  583. // Bugs tab
  584. #define SAVE_BUG_COMBO(BUG) aSessionData->Bug[sb ## BUG] = (TAutoSwitch)(2 - Bug ## BUG ## Combo->ItemIndex);
  585. SAVE_BUG_COMBO(Ignore1);
  586. SAVE_BUG_COMBO(PlainPW1);
  587. SAVE_BUG_COMBO(RSA1);
  588. SAVE_BUG_COMBO(HMAC2);
  589. SAVE_BUG_COMBO(DeriveKey2);
  590. SAVE_BUG_COMBO(RSAPad2);
  591. SAVE_BUG_COMBO(Rekey2);
  592. SAVE_BUG_COMBO(PKSessID2);
  593. #undef SAVE_BUG_COMBO
  594. // Tunnel tab
  595. aSessionData->Tunnel = TunnelCheck->Checked;
  596. aSessionData->TunnelUserName = TunnelUserNameEdit->Text;
  597. aSessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
  598. aSessionData->TunnelHostName = TunnelHostNameEdit->Text;
  599. aSessionData->TunnelPassword = TunnelPasswordEdit->Text;
  600. aSessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit->Text;
  601. if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
  602. {
  603. aSessionData->TunnelLocalPortNumber = 0;
  604. }
  605. else
  606. {
  607. aSessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
  608. }
  609. }
  610. //---------------------------------------------------------------------
  611. void __fastcall TLoginDialog::SavePing(TSessionData * aSessionData)
  612. {
  613. TPingType PingType;
  614. if (PingNullPacketButton->Checked)
  615. {
  616. PingType = ptNullPacket;
  617. }
  618. else if (PingDummyCommandButton->Checked)
  619. {
  620. PingType = ptDummyCommand;
  621. }
  622. else
  623. {
  624. PingType = ptOff;
  625. }
  626. (FFSProtocol == fsFTP ? aSessionData->FtpPingType : aSessionData->PingType) =
  627. PingType;
  628. (FFSProtocol == fsFTP ? aSessionData->FtpPingInterval : aSessionData->PingInterval) =
  629. PingIntervalSecEdit->AsInteger;
  630. }
  631. //---------------------------------------------------------------------
  632. void __fastcall TLoginDialog::UpdateNavigationTree()
  633. {
  634. TTreeNode * ActiveNode = NULL;
  635. NoUpdate++;
  636. try
  637. {
  638. int Index = 0;
  639. TTreeNode * PrevNode = NULL;
  640. while (Index < PageControl->PageCount)
  641. {
  642. TTabSheet * Tab = PageControl->Pages[Index];
  643. if (Tab->Enabled)
  644. {
  645. bool Indented = ((Tab->Tag % 100) == 2);
  646. AnsiString Label = FTreeLabels->Strings[Index];
  647. TTreeNode * Node;
  648. if (PrevNode == NULL)
  649. {
  650. assert(!Indented);
  651. Node = NavigationTree->Items->GetFirstNode();
  652. }
  653. else
  654. {
  655. if (Indented)
  656. {
  657. if (PrevNode->Level == 0)
  658. {
  659. Node = PrevNode->getFirstChild();
  660. if (Node == NULL)
  661. {
  662. Node = NavigationTree->Items->AddChild(PrevNode, Label);
  663. }
  664. }
  665. else
  666. {
  667. Node = PrevNode->getNextSibling();
  668. if (Node == NULL)
  669. {
  670. Node = NavigationTree->Items->Add(PrevNode, Label);
  671. }
  672. }
  673. }
  674. else
  675. {
  676. if (PrevNode->Level == 0)
  677. {
  678. // delete all excess children of previous top level node
  679. while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
  680. {
  681. Node->Delete();
  682. }
  683. Node = PrevNode->getNextSibling();
  684. if (Node == NULL)
  685. {
  686. Node = NavigationTree->Items->Add(PrevNode, Label);
  687. }
  688. }
  689. else
  690. {
  691. // delete all excess children of previous top level node
  692. while ((Node = PrevNode->getNextSibling()) != NULL)
  693. {
  694. Node->Delete();
  695. }
  696. Node = PrevNode->GetNext();
  697. if (Node == NULL)
  698. {
  699. Node = NavigationTree->Items->Add(NULL, Label);
  700. }
  701. }
  702. }
  703. }
  704. Node->Text = Label;
  705. Node->SelectedIndex = reinterpret_cast<int>(Tab);
  706. PrevNode = Node;
  707. if (PageControl->ActivePage == Tab)
  708. {
  709. Node->Selected = true;
  710. ActiveNode = Node;
  711. }
  712. }
  713. Index++;
  714. }
  715. TTreeNode * Node;
  716. while ((Node = PrevNode->GetNext()) != NULL)
  717. {
  718. Node->Delete();
  719. }
  720. NavigationTree->FullExpand();
  721. }
  722. __finally
  723. {
  724. NoUpdate--;
  725. }
  726. // node of active page was hidden
  727. if (ActiveNode == NULL)
  728. {
  729. ChangePage(BasicSheet);
  730. }
  731. }
  732. //---------------------------------------------------------------------
  733. void __fastcall TLoginDialog::UpdateControls()
  734. {
  735. if (Visible)
  736. {
  737. NoUpdate++;
  738. try
  739. {
  740. TFSProtocol FSProtocol = IndexToFSProtocol(
  741. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  742. bool ExternalProtocol = (FSProtocol == fsExternalSSH) || (FSProtocol == fsExternalSFTP);
  743. bool InternalSshProtocol =
  744. (FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP) || (FSProtocol == fsSCPonly);
  745. bool SshProtocol = ExternalProtocol || InternalSshProtocol;
  746. bool FtpProtocol = (FSProtocol == fsFTP);
  747. bool Advanced = ShowAdvancedLoginOptionsCheck->Checked;
  748. // basic/session sheet
  749. AllowScpFallbackCheck->Visible =
  750. (IndexToFSProtocol(TransferProtocolCombo->ItemIndex, false) == fsSFTPonly);
  751. InsecureLabel->Visible = !SshProtocol;
  752. EnableControl(PrivateKeyEdit, SshProtocol);
  753. EnableControl(PrivateKeyLabel, PrivateKeyEdit->Enabled);
  754. // log sheet
  755. LogSheet->Enabled = Advanced;
  756. // connection sheet
  757. ConnSheet->Enabled = Advanced;
  758. EnableControl(FtpPasvModeCheck, FtpProtocol);
  759. if (FtpProtocol && !ProxyNoneButton->Checked && !FtpPasvModeCheck->Checked)
  760. {
  761. FtpPasvModeCheck->Checked = true;
  762. MessageDialog(LoadStr(FTP_PASV_MODE_REQUIRED), qtInformation, qaOK);
  763. }
  764. EnableControl(PingIntervalSecEdit, !PingOffButton->Checked);
  765. EnableControl(PingIntervalLabel, PingIntervalSecEdit->Enabled);
  766. EnableControl(PingNullPacketButton, SshProtocol);
  767. EnableControl(IPAutoButton, SshProtocol);
  768. // stored sessions sheet
  769. EnableControl(SessionListView, SessionListView->Items->Count);
  770. // keep 2 pixels on right free
  771. AdjustListColumnsWidth(SessionListView, -1, 2);
  772. // ssh/authentication sheet
  773. AuthSheet->Enabled = SshProtocol && Advanced;
  774. EnableControl(AuthTISCheck, !SshProt2onlyButton->Checked);
  775. EnableControl(AuthKICheck, !SshProt1onlyButton->Checked);
  776. EnableControl(AuthKIPasswordCheck,
  777. (AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  778. (AuthKICheck->Enabled && AuthKICheck->Checked));
  779. EnableControl(AuthGSSAPICheck, !SshProt1onlyButton->Checked);
  780. EnableControl(GSSAPIFwdTGTCheck,
  781. AuthGSSAPICheck->Enabled && AuthGSSAPICheck->Checked);
  782. EnableControl(GSSAPIServerRealmEdit,
  783. AuthGSSAPICheck->Enabled && AuthGSSAPICheck->Checked);
  784. EnableControl(GSSAPIServerRealmLabel, GSSAPIServerRealmEdit->Enabled);
  785. // ssh sheet
  786. AdvancedSheet->Enabled = SshProtocol;
  787. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  788. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  789. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  790. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  791. // ssh/kex sheet
  792. KexSheet->Enabled = SshProtocol && Advanced && !SshProt1onlyButton->Checked &&
  793. (BugRekey2Combo->ItemIndex != 2);
  794. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  795. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  796. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  797. // ssh/bugs sheet
  798. BugsSheet->Enabled = SshProtocol && Advanced;
  799. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  800. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  801. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  802. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  803. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  804. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  805. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  806. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  807. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  808. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  809. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  810. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  811. EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
  812. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  813. EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
  814. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  815. // environment/scp/shell sheet
  816. ScpSheet->Enabled = Advanced && InternalSshProtocol;
  817. // connection/proxy sheet
  818. ProxySheet->Enabled = Advanced;
  819. EnableControl(ProxyTelnetButton, SshProtocol);
  820. bool Proxy = !ProxyNoneButton->Checked &&
  821. (!ProxyTelnetButton->Checked || ProxyTelnetButton->Enabled);
  822. EnableControl(ProxyHostEdit, Proxy);
  823. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  824. EnableControl(ProxyPortEdit, Proxy);
  825. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  826. EnableControl(ProxyUsernameEdit, Proxy &&
  827. // FZAPI does not support username for SOCKS4
  828. ((ProxySocks4Button->Checked && SshProtocol) ||
  829. (ProxySocks5Button->Checked) ||
  830. (ProxyHTTPButton->Checked) ||
  831. (ProxyTelnetButton->Checked &&
  832. AnsiContainsText(ProxyTelnetCommandEdit->Text, "%user"))));
  833. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  834. EnableControl(ProxyPasswordEdit, Proxy &&
  835. (!ProxySocks4Button->Checked &&
  836. (!ProxyTelnetButton->Checked ||
  837. AnsiContainsText(ProxyTelnetCommandEdit->Text, "%pass"))));
  838. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  839. EnableControl(ProxySettingsGroup, Proxy && SshProtocol);
  840. EnableControl(ProxyTelnetCommandEdit, Proxy && ProxyTelnetButton->Checked);
  841. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  842. // environment/directories sheet
  843. DirectoriesSheet->Enabled = !ExternalProtocol;
  844. DirectoryOptionsGroup->Visible = Advanced;
  845. EnableControl(CacheDirectoryChangesCheck,
  846. ((FSProtocol != fsSCPonly) || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  847. EnableControl(PreserveDirectoryChangesCheck,
  848. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  849. DirectoriesSheet->Enabled);
  850. EnableControl(ResolveSymlinksCheck, (FSProtocol != fsFTP) && DirectoriesSheet->Enabled);
  851. // environment sheet
  852. EnvironmentSheet->Enabled = !ExternalProtocol;
  853. EnableControl(DSTModeGroup, (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  854. UnixEnvironmentButton->Visible = !ShowAdvancedLoginOptionsCheck->Checked;
  855. WindowsEnvironmentButton->Visible = !ShowAdvancedLoginOptionsCheck->Checked;
  856. RecycleBinGroup->Visible = ShowAdvancedLoginOptionsCheck->Checked;
  857. EnableControl(OverwrittenToRecycleBinCheck, (FSProtocol != fsSCPonly) &&
  858. (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  859. EnableControl(RecycleBinPathEdit,
  860. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  861. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  862. EnvironmentSheet->Enabled);
  863. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  864. EnvironmentSheet->Enabled);
  865. // environment/sftp sheet
  866. SftpSheet->Enabled = Advanced && ((FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP));
  867. // tunnel sheet
  868. TunnelSheet->Enabled = Advanced && InternalSshProtocol;
  869. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  870. EnableControl(TunnelOptionsGroup, TunnelCheck->Enabled && TunnelSessionGroup->Enabled);
  871. // preferences sheet
  872. GeneralSheet->Enabled = FLAGSET(Options, loPreferences);
  873. AboutButton->Visible = (Options & loAbout);
  874. LanguagesButton->Visible = (Options & loLanguage);
  875. ShellIconsButton->Visible = (Options & loTools);
  876. ToolsMenuButton->Visible = (Options & loTools);
  877. LoggingFrame->EnableLogWindow = (Options & loLogWindow);
  878. UpdateNavigationTree();
  879. }
  880. __finally
  881. {
  882. NoUpdate--;
  883. }
  884. }
  885. }
  886. //---------------------------------------------------------------------------
  887. void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
  888. {
  889. if (!NoUpdate) UpdateControls();
  890. }
  891. //---------------------------------------------------------------------------
  892. void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
  893. {
  894. if (!FInitialized)
  895. {
  896. FInitialized = true;
  897. Init();
  898. TSessionData * Data = GetSessionData();
  899. if (Data == FSessionData)
  900. {
  901. LoadSession(Data);
  902. }
  903. else
  904. {
  905. Default();
  906. }
  907. }
  908. if (FLocaleChanging)
  909. {
  910. Init();
  911. LoadSession(FSessionData);
  912. ChangePage(FSavedTab);
  913. SessionListView->ItemIndex = FSavedSession;
  914. LoadConfiguration();
  915. }
  916. }
  917. //---------------------------------------------------------------------------
  918. void __fastcall TLoginDialog::SessionListViewSelectItem(TObject * /*Sender*/,
  919. TListItem * /*Item*/, bool /*Selected*/)
  920. {
  921. UpdateControls();
  922. }
  923. //---------------------------------------------------------------------------
  924. void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
  925. {
  926. FSessionData->Assign(value);
  927. FSessionData->Special = false;
  928. FEditingSessionData = value;
  929. LoadSession(FSessionData);
  930. }
  931. //---------------------------------------------------------------------------
  932. TSessionData * __fastcall TLoginDialog::GetSessionData()
  933. {
  934. if (PageControl->ActivePage == SessionListSheet)
  935. {
  936. return SelectedSession;
  937. }
  938. else
  939. {
  940. SaveSession(FSessionData);
  941. return FSessionData;
  942. }
  943. }
  944. //---------------------------------------------------------------------------
  945. void __fastcall TLoginDialog::SetStoredSessions(TStoredSessionList * value)
  946. {
  947. if (FStoredSessions != value)
  948. {
  949. FStoredSessions = value;
  950. LoadSessions();
  951. }
  952. }
  953. //---------------------------------------------------------------------------
  954. void __fastcall TLoginDialog::LoadSessionItem(TListItem * Item)
  955. {
  956. Item->Data = StoredSessions->AtObject(Item->Index);
  957. Item->Caption = ((TSessionData*)Item->Data)->Name;
  958. }
  959. //---------------------------------------------------------------------------
  960. void __fastcall TLoginDialog::SessionListViewDblClick(TObject * /*Sender*/)
  961. {
  962. if (SelectedSession)
  963. {
  964. if (SelectedSession->CanLogin) ModalResult = mrOk;
  965. else
  966. {
  967. SessionData = SelectedSession;
  968. EditSession();
  969. }
  970. }
  971. }
  972. //---------------------------------------------------------------------------
  973. void __fastcall TLoginDialog::SetSelectedSession(TSessionData * value)
  974. {
  975. if (value)
  976. {
  977. int Index = StoredSessions->IndexOf(value);
  978. if (Index >= 0)
  979. {
  980. TListItem *Item = SessionListView->Items->Item[Index];
  981. Item->Focused = true;
  982. Item->Selected = true;
  983. Item->MakeVisible(false);
  984. }
  985. }
  986. else
  987. {
  988. SessionListView->Selected = NULL;
  989. }
  990. }
  991. //---------------------------------------------------------------------------
  992. TSessionData * __fastcall TLoginDialog::GetSelectedSession()
  993. {
  994. if (SessionListView->Selected)
  995. return (TSessionData *)SessionListView->Selected->Data;
  996. else
  997. return NULL;
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TLoginDialog::SessionListViewInfoTip(TObject * /*Sender*/,
  1001. TListItem * Item, AnsiString & InfoTip)
  1002. {
  1003. InfoTip = ((TSessionData*)Item->Data)->InfoTip;
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. void __fastcall TLoginDialog::SessionListViewKeyDown(TObject * /*Sender*/,
  1007. WORD & Key, TShiftState /*Shift*/)
  1008. {
  1009. if (!SessionListView->IsEditing())
  1010. {
  1011. if (Key == VK_DELETE)
  1012. {
  1013. DeleteSessionAction->Execute();
  1014. Key = 0;
  1015. }
  1016. else if (Key == VK_F2)
  1017. {
  1018. RenameSessionAction->Execute();
  1019. Key = 0;
  1020. }
  1021. }
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TLoginDialog::EditSession()
  1025. {
  1026. ChangePage(BasicSheet);
  1027. HostNameEdit->SetFocus();
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall TLoginDialog::EditSessionActionExecute(TObject * /*Sender*/)
  1031. {
  1032. if (SelectedSession)
  1033. {
  1034. SessionData = SelectedSession;
  1035. EditSession();
  1036. }
  1037. }
  1038. //---------------------------------------------------------------------------
  1039. void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
  1040. {
  1041. AnsiString SessionName;
  1042. SaveSession(FSessionData);
  1043. if (FSessionData->Password.IsEmpty() ||
  1044. Configuration->DisablePasswordStoring ||
  1045. (MessageDialog(LoadStr(SAVE_PASSWORD), qtWarning, qaOK | qaCancel,
  1046. HELP_SESSION_SAVE_PASSWORD) == qaOK))
  1047. {
  1048. SessionName = DoSaveSessionDialog(FSessionData->SessionName, FEditingSessionData);
  1049. if (!SessionName.IsEmpty())
  1050. {
  1051. TListItem * Item;
  1052. TSessionData *NewSession =
  1053. StoredSessions->NewSession(SessionName, FSessionData);
  1054. StoredSessions->Save();
  1055. SaveConfiguration();
  1056. // by now list must contais same number of items or one less
  1057. assert(StoredSessions->Count == SessionListView->Items->Count ||
  1058. StoredSessions->Count == SessionListView->Items->Count+1);
  1059. if (StoredSessions->Count > SessionListView->Items->Count)
  1060. Item = SessionListView->Items->Insert(StoredSessions->IndexOf(NewSession));
  1061. else
  1062. Item = SessionListView->Items->Item[StoredSessions->IndexOf(NewSession)];
  1063. LoadSessionItem(Item);
  1064. SelectedSession = NewSession;
  1065. SessionData = NewSession;
  1066. ChangePage(SessionListSheet);
  1067. SessionListView->SetFocus();
  1068. }
  1069. }
  1070. }
  1071. //---------------------------------------------------------------------------
  1072. void __fastcall TLoginDialog::DeleteSessionActionExecute(TObject * /*Sender*/)
  1073. {
  1074. if (SelectedSession &&
  1075. (MessageDialog(FMTLOAD(CONFIRM_DELETE_SESSION, (SelectedSession->SessionName)),
  1076. qtConfirmation, qaOK | qaCancel, HELP_DELETE_SESSION) == qaOK))
  1077. {
  1078. int PrevSelectedIndex = SessionListView->Selected->Index;
  1079. if (FEditingSessionData == SelectedSession)
  1080. {
  1081. FEditingSessionData = NULL;
  1082. }
  1083. SelectedSession->Remove();
  1084. StoredSessions->Remove(SelectedSession);
  1085. SessionListView->Selected->Delete();
  1086. if (SessionListView->Items->Count)
  1087. {
  1088. if (PrevSelectedIndex >= SessionListView->Items->Count)
  1089. PrevSelectedIndex = SessionListView->Items->Count - 1;
  1090. SelectedSession =
  1091. (TSessionData *)StoredSessions->AtObject(PrevSelectedIndex);
  1092. }
  1093. }
  1094. }
  1095. //---------------------------------------------------------------------------
  1096. void __fastcall TLoginDialog::ImportSessionsActionExecute(TObject * /*Sender*/)
  1097. {
  1098. if (DoImportSessionsDialog(StoredSessions))
  1099. {
  1100. LoadSessions();
  1101. if (SessionListView->Items->Count)
  1102. SessionListView->Items->Item[0]->MakeVisible(False);
  1103. }
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TLoginDialog::CleanUpActionExecute(TObject * /*Sender*/)
  1107. {
  1108. if (DoCleanupDialog(StoredSessions, Configuration))
  1109. LoadSessions();
  1110. }
  1111. //---------------------------------------------------------------------------
  1112. void __fastcall TLoginDialog::AboutActionExecute(TObject * /*Sender*/)
  1113. {
  1114. DoAboutDialog(Configuration);
  1115. }
  1116. //---------------------------------------------------------------------------
  1117. void __fastcall TLoginDialog::ActionListUpdate(TBasicAction *Action,
  1118. bool &Handled)
  1119. {
  1120. if (Action == EditSessionAction)
  1121. {
  1122. EditSessionAction->Enabled = SessionListView->Selected;
  1123. }
  1124. else if (Action == DeleteSessionAction)
  1125. {
  1126. TSessionData * Data = SessionData;
  1127. DeleteSessionAction->Enabled =
  1128. SessionListView->Selected && Data && !Data->Special;
  1129. }
  1130. else if (Action == RenameSessionAction)
  1131. {
  1132. TSessionData * Data = SessionData;
  1133. RenameSessionAction->Enabled =
  1134. SessionListView->Selected && Data && !Data->Special;
  1135. }
  1136. else if (Action == DesktopIconAction)
  1137. {
  1138. DesktopIconAction->Enabled = SessionListView->Selected;
  1139. }
  1140. else if (Action == SendToHookAction)
  1141. {
  1142. SendToHookAction->Enabled = SessionListView->Selected;
  1143. }
  1144. else if (Action == LoginAction)
  1145. {
  1146. TSessionData * Data = SessionData;
  1147. LoginAction->Enabled = Data && Data->CanLogin;
  1148. }
  1149. else if (Action == SaveSessionAction)
  1150. {
  1151. SaveSessionAction->Enabled = (PageControl->ActivePage != SessionListSheet);
  1152. }
  1153. else if (Action == ShellIconSessionAction)
  1154. {
  1155. ShellIconSessionAction->Enabled = SessionListView->Selected;
  1156. }
  1157. Handled = true;
  1158. if (!LoginButton->Default && !SessionListView->IsEditing())
  1159. {
  1160. LoginButton->Default = true;
  1161. }
  1162. }
  1163. //---------------------------------------------------------------------------
  1164. bool __fastcall TLoginDialog::Execute()
  1165. {
  1166. LoadConfiguration();
  1167. bool Result = (ShowModal() == mrOk);
  1168. if (Result)
  1169. {
  1170. SaveConfiguration();
  1171. }
  1172. return Result;
  1173. }
  1174. //---------------------------------------------------------------------------
  1175. void __fastcall TLoginDialog::SaveConfiguration()
  1176. {
  1177. assert(CustomWinConfiguration);
  1178. CustomWinConfiguration->BeginUpdate();
  1179. try
  1180. {
  1181. LoggingFrame->SaveConfiguration();
  1182. GeneralSettingsFrame->SaveConfiguration();
  1183. CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
  1184. }
  1185. __finally
  1186. {
  1187. CustomWinConfiguration->EndUpdate();
  1188. }
  1189. }
  1190. //---------------------------------------------------------------------------
  1191. void __fastcall TLoginDialog::LoadConfiguration()
  1192. {
  1193. assert(CustomWinConfiguration);
  1194. LoggingFrame->LoadConfiguration();
  1195. GeneralSettingsFrame->LoadConfiguration();
  1196. ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
  1197. UpdateControls();
  1198. }
  1199. //---------------------------------------------------------------------------
  1200. void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
  1201. {
  1202. ShowPreferencesDialog();
  1203. UpdateControls();
  1204. }
  1205. //---------------------------------------------------------------------------
  1206. void __fastcall TLoginDialog::ShowPreferencesDialog()
  1207. {
  1208. DoPreferencesDialog(pmLogin);
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
  1212. {
  1213. Default();
  1214. EditSession();
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
  1218. TTreeNode *Node)
  1219. {
  1220. if (NoUpdate == 0)
  1221. {
  1222. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  1223. // should happen only while loading language
  1224. // (UpdateNavigationTree may not be called yet)
  1225. if (Tab != NULL)
  1226. {
  1227. PageControl->ActivePage = Tab;
  1228. // reshow the accelerators, etc
  1229. ResetSystemSettings(this);
  1230. }
  1231. }
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
  1235. {
  1236. PageControl->ActivePage = Tab;
  1237. PageControlChange(PageControl);
  1238. }
  1239. //---------------------------------------------------------------------------
  1240. void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
  1241. {
  1242. bool Found = false;
  1243. if (PageControl->ActivePage)
  1244. {
  1245. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1246. {
  1247. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1248. reinterpret_cast<int>(PageControl->ActivePage))
  1249. {
  1250. NavigationTree->Items->Item[Index]->Selected = true;
  1251. Found = true;
  1252. }
  1253. }
  1254. }
  1255. if (!Found)
  1256. {
  1257. assert(false);
  1258. ChangePage(BasicSheet);
  1259. }
  1260. else
  1261. {
  1262. DataChange(Sender);
  1263. }
  1264. }
  1265. //---------------------------------------------------------------------------
  1266. void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
  1267. {
  1268. if (Message.CharCode == VK_TAB)
  1269. {
  1270. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1271. if (Shift.Contains(ssCtrl))
  1272. {
  1273. TTreeNode * Node = NavigationTree->Selected;
  1274. if (!Shift.Contains(ssShift))
  1275. {
  1276. Node = Node->GetNext();
  1277. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1278. }
  1279. else
  1280. {
  1281. if (Node->GetPrev()) Node = Node->GetPrev();
  1282. else
  1283. while (Node->GetNext()) Node = Node->GetNext();
  1284. }
  1285. Node->Selected = True;
  1286. Message.Result = 1;
  1287. return;
  1288. }
  1289. }
  1290. TForm::Dispatch(&Message);
  1291. }
  1292. //---------------------------------------------------------------------------
  1293. void __fastcall TLoginDialog::WMHelp(TWMHelp & Message)
  1294. {
  1295. assert(Message.HelpInfo != NULL);
  1296. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1297. {
  1298. // invoke help for active page (not for whole form), regardless of focus
  1299. // (e.g. even if focus is on control outside pagecontrol)
  1300. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1301. }
  1302. TForm::Dispatch(&Message);
  1303. }
  1304. //---------------------------------------------------------------------------
  1305. void __fastcall TLoginDialog::Dispatch(void *Message)
  1306. {
  1307. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1308. assert(M);
  1309. if (M->Msg == CM_DIALOGKEY)
  1310. {
  1311. CMDialogKey(*((TWMKeyDown *)Message));
  1312. }
  1313. else if (M->Msg == WM_LOCALE_CHANGE)
  1314. {
  1315. if (M->WParam == 0)
  1316. {
  1317. SaveConfiguration();
  1318. SaveSession(FSessionData);
  1319. FSavedTab = PageControl->ActivePage;
  1320. FSavedSession = SessionListView->ItemIndex;
  1321. assert(FSystemSettings);
  1322. RevokeSystemSettings(this, FSystemSettings);
  1323. FSystemSettings = NULL;
  1324. ShowTabs(true);
  1325. Hide();
  1326. }
  1327. else
  1328. {
  1329. FLocaleChanging = true;
  1330. try
  1331. {
  1332. Show();
  1333. }
  1334. __finally
  1335. {
  1336. FLocaleChanging = false;
  1337. }
  1338. }
  1339. }
  1340. else if (M->Msg == WM_HELP)
  1341. {
  1342. WMHelp(*((TWMHelp *)Message));
  1343. }
  1344. else
  1345. {
  1346. TForm::Dispatch(Message);
  1347. }
  1348. }
  1349. //---------------------------------------------------------------------------
  1350. void __fastcall TLoginDialog::AlgListBoxStartDrag(TObject * Sender,
  1351. TDragObject *& /*DragObject*/)
  1352. {
  1353. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1354. FAlgDragDest = -1;
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. void __fastcall TLoginDialog::AlgListBoxDragOver(TObject * Sender,
  1358. TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
  1359. {
  1360. if (Source == Sender)
  1361. {
  1362. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1363. }
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TLoginDialog::AlgListBoxDragDrop(TObject * Sender,
  1367. TObject *Source, int X, int Y)
  1368. {
  1369. if (Source == Sender)
  1370. {
  1371. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1372. if (AllowAlgDrag(AlgListBox, X, Y))
  1373. {
  1374. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1375. }
  1376. }
  1377. }
  1378. //---------------------------------------------------------------------------
  1379. void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
  1380. {
  1381. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1382. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1383. }
  1384. //---------------------------------------------------------------------------
  1385. void __fastcall TLoginDialog::KexButtonClick(TObject *Sender)
  1386. {
  1387. AlgMove(KexListBox, KexListBox->ItemIndex,
  1388. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. bool __fastcall TLoginDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1392. {
  1393. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1394. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1395. }
  1396. //---------------------------------------------------------------------------
  1397. void __fastcall TLoginDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1398. {
  1399. if (Source >= 0 && Source < AlgListBox->Items->Count &&
  1400. Dest >= 0 && Dest < AlgListBox->Items->Count)
  1401. {
  1402. AlgListBox->Items->Move(Source, Dest);
  1403. AlgListBox->ItemIndex = Dest;
  1404. AlgListBox->SetFocus();
  1405. }
  1406. UpdateControls();
  1407. }
  1408. //---------------------------------------------------------------------------
  1409. void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
  1410. TObject * /*Sender*/)
  1411. {
  1412. if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
  1413. qaOK | qaCancel, HELP_SESSION_SAVE_DEFAULT) == qaOK)
  1414. {
  1415. SaveSession(FSessionData);
  1416. StoredSessions->DefaultSettings = FSessionData;
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
  1421. {
  1422. MenuPopup(ToolsPopupMenu, ToolsMenuButton);
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TLoginDialog::ShellIconSessionActionExecute(
  1426. TObject * /*Sender*/)
  1427. {
  1428. MenuPopup(IconsPopupMenu, ShellIconsButton);
  1429. }
  1430. //---------------------------------------------------------------------------
  1431. void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
  1432. {
  1433. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SHORTCUT, (SelectedSession->Name)),
  1434. qtConfirmation, qaYes | qaNo, HELP_CREATE_SHORTCUT) == qaYes)
  1435. {
  1436. assert(SelectedSession);
  1437. CreateDesktopShortCut(SelectedSession->Name, Application->ExeName,
  1438. FORMAT("\"%s\" /UploadIfAny", (SelectedSession->Name)),
  1439. FMTLOAD(SHORTCUT_INFO_TIP, (SelectedSession->Name, SelectedSession->InfoTip)));
  1440. }
  1441. }
  1442. //---------------------------------------------------------------------------
  1443. void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
  1444. {
  1445. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
  1446. qtConfirmation, qaYes | qaNo, HELP_CREATE_SENDTO) == qaYes)
  1447. {
  1448. assert(SelectedSession);
  1449. CreateDesktopShortCut(FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->Name)),
  1450. Application->ExeName,
  1451. FORMAT("\"%s\" /Upload", (SelectedSession->Name)), "",
  1452. CSIDL_SENDTO);
  1453. }
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. void __fastcall TLoginDialog::SessionListViewCustomDrawItem(
  1457. TCustomListView *Sender, TListItem *Item, TCustomDrawState /*State*/,
  1458. bool &DefaultDraw)
  1459. {
  1460. TSessionData * Data = (TSessionData *)Item->Data;
  1461. TFontStyles Styles = Sender->Canvas->Font->Style;
  1462. if (Data->Special) Styles = Styles /*< fsItalic*/ << fsBold << fsUnderline;
  1463. else Styles = Styles /*>> fsItalic*/ >> fsBold >> fsUnderline;
  1464. Sender->Canvas->Font->Style = Styles;
  1465. DefaultDraw = true;
  1466. }
  1467. //---------------------------------------------------------------------------
  1468. void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
  1469. {
  1470. CheckForUpdates(false);
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TLoginDialog::SetOptions(int value)
  1474. {
  1475. if (Options != value)
  1476. {
  1477. FOptions = value;
  1478. UpdateControls();
  1479. }
  1480. }
  1481. //---------------------------------------------------------------------------
  1482. void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
  1483. {
  1484. delete FLanguagesPopupMenu;
  1485. FLanguagesPopupMenu = new TPopupMenu(this);
  1486. TMenuItem * Item;
  1487. TStrings * Locales = GUIConfiguration->Locales;
  1488. for (int Index = 0; Index < Locales->Count; Index++)
  1489. {
  1490. Item = new TMenuItem(FLanguagesPopupMenu);
  1491. FLanguagesPopupMenu->Items->Add(Item);
  1492. Item->Caption = Locales->Strings[Index];
  1493. Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
  1494. Item->OnClick = LocaleClick;
  1495. Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
  1496. GUIConfiguration->Locale);
  1497. }
  1498. Item = new TMenuItem(FLanguagesPopupMenu);
  1499. FLanguagesPopupMenu->Items->Add(Item);
  1500. Item->Caption = "-";
  1501. Item = new TMenuItem(FLanguagesPopupMenu);
  1502. FLanguagesPopupMenu->Items->Add(Item);
  1503. Item->Caption = LoadStr(LOGIN_GET_LOCALES);
  1504. Item->OnClick = LocaleGetClick;
  1505. MenuPopup(FLanguagesPopupMenu, LanguagesButton);
  1506. }
  1507. //---------------------------------------------------------------------------
  1508. void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
  1509. {
  1510. assert(Sender);
  1511. GUIConfiguration->Locale =
  1512. static_cast<LCID>(dynamic_cast<TComponent*>(Sender)->Tag);
  1513. LanguagesButton->SetFocus();
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. void __fastcall TLoginDialog::LocaleGetClick(TObject * /*Sender*/)
  1517. {
  1518. OpenBrowser(LoadStr(LOCALES_URL));
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. void __fastcall TLoginDialog::AuthGSSAPICheckClick(TObject * /*Sender*/)
  1522. {
  1523. if (!NoUpdate)
  1524. {
  1525. UpdateControls();
  1526. if (AuthGSSAPICheck->Checked && !Configuration->GSSAPIInstalled)
  1527. {
  1528. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED));
  1529. }
  1530. }
  1531. }
  1532. //---------------------------------------------------------------------------
  1533. void __fastcall TLoginDialog::HelpButtonClick(TObject * /*Sender*/)
  1534. {
  1535. FormHelp(this);
  1536. }
  1537. //---------------------------------------------------------------------------
  1538. void __fastcall TLoginDialog::FormKeyDown(TObject * /*Sender*/, WORD &Key,
  1539. TShiftState /*Shift*/)
  1540. {
  1541. // we don't have "cancel" button, so we must handle "esc" ourselves
  1542. if (Key == VK_ESCAPE)
  1543. {
  1544. ModalResult = mrCancel;
  1545. }
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. void __fastcall TLoginDialog::VerifyKey(AnsiString FileName, bool TypeOnly)
  1549. {
  1550. if (!FileName.Trim().IsEmpty())
  1551. {
  1552. FileName = ExpandEnvironmentVariables(FileName);
  1553. TKeyType Type = KeyType(FileName);
  1554. AnsiString Message;
  1555. switch (Type)
  1556. {
  1557. case ktOpenSSH:
  1558. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "OpenSSH SSH-2"));
  1559. break;
  1560. case ktSSHCom:
  1561. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "ssh.com SSH-2"));
  1562. break;
  1563. case ktSSH1:
  1564. case ktSSH2:
  1565. // on file select do not check for SSH version as user may
  1566. // intend to change it only after he/she selects key file
  1567. if (!TypeOnly)
  1568. {
  1569. TSessionData * Data = SessionData;
  1570. if ((Type == ktSSH1) !=
  1571. ((Data->SshProt == ssh1only) || (Data->SshProt == ssh1)))
  1572. {
  1573. Message = FMTLOAD(KEY_TYPE_DIFFERENT_SSH,
  1574. (FileName, (Type == ktSSH1 ? "SSH-1" : "PuTTY SSH-2")));
  1575. }
  1576. }
  1577. break;
  1578. default:
  1579. assert(false);
  1580. // fallthru
  1581. case ktUnopenable:
  1582. case ktUnknown:
  1583. Message = FMTLOAD(KEY_TYPE_UNKNOWN, (FileName));
  1584. break;
  1585. }
  1586. if (!Message.IsEmpty())
  1587. {
  1588. if (MessageDialog(Message, qtWarning, qaIgnore | qaAbort,
  1589. HELP_LOGIN_KEY_TYPE) == qaAbort)
  1590. {
  1591. Abort();
  1592. }
  1593. }
  1594. }
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TLoginDialog::PrivateKeyEditAfterDialog(TObject * Sender,
  1598. AnsiString & Name, bool & /*Action*/)
  1599. {
  1600. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1601. {
  1602. Name = FBeforeDialogPath;
  1603. }
  1604. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1605. if (Name != Edit->Text)
  1606. {
  1607. VerifyKey(Name, true);
  1608. }
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TLoginDialog::FormCloseQuery(TObject * /*Sender*/,
  1612. bool & /*CanClose*/)
  1613. {
  1614. if (ModalResult != mrCancel)
  1615. {
  1616. VerifyKey(SessionData->PublicKeyFile, false);
  1617. // for tunnel key do not check SSH version as it is not configurable
  1618. VerifyKey(SessionData->TunnelPublicKeyFile, true);
  1619. }
  1620. }
  1621. //---------------------------------------------------------------------------
  1622. void __fastcall TLoginDialog::ColorButtonClick(TObject * /*Sender*/)
  1623. {
  1624. ColorDefaultItem->Checked = (FColor == 0);
  1625. PickColorItem->Checked = (FColor != 0);
  1626. PickColorItem->ImageIndex = (FColor != 0 ? 0 : -1);
  1627. ColorImageList->BkColor = FColor;
  1628. MenuPopup(ColorPopupMenu, ColorButton);
  1629. }
  1630. //---------------------------------------------------------------------------
  1631. void __fastcall TLoginDialog::ColorDefaultItemClick(TObject * /*Sender*/)
  1632. {
  1633. FColor = (TColor)0;
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. void __fastcall TLoginDialog::PickColorItemClick(TObject * /*Sender*/)
  1637. {
  1638. TColorDialog * Dialog = new TColorDialog(this);
  1639. try
  1640. {
  1641. Dialog->Options = Dialog->Options << cdFullOpen;
  1642. Dialog->Color = (FColor != 0 ? FColor : clSkyBlue);
  1643. if (Dialog->Execute())
  1644. {
  1645. FColor = Dialog->Color;
  1646. }
  1647. }
  1648. __finally
  1649. {
  1650. delete Dialog;
  1651. }
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TLoginDialog::SessionListViewEditing(TObject * /*Sender*/,
  1655. TListItem * Item, bool & AllowEdit)
  1656. {
  1657. TSessionData * Data = static_cast<TSessionData *>(Item->Data);
  1658. AllowEdit = !Data->Special;
  1659. if (AllowEdit)
  1660. {
  1661. LoginButton->Default = false;
  1662. }
  1663. }
  1664. //---------------------------------------------------------------------------
  1665. void __fastcall TLoginDialog::RenameSessionActionExecute(TObject * /*Sender*/)
  1666. {
  1667. if (SessionListView->Selected != NULL)
  1668. {
  1669. SessionListView->Selected->EditCaption();
  1670. }
  1671. }
  1672. //---------------------------------------------------------------------------
  1673. void __fastcall TLoginDialog::SessionListViewEdited(TObject * /*Sender*/,
  1674. TListItem * Item, AnsiString & S)
  1675. {
  1676. if (Item->Caption != S)
  1677. {
  1678. TSessionData * Session = SelectedSession;
  1679. SessionNameValidate(S, Session);
  1680. // remove from storage
  1681. Session->Remove();
  1682. int PrevCount = StoredSessions->Count;
  1683. TSessionData * NewSession = StoredSessions->NewSession(S, Session);
  1684. StoredSessions->Save();
  1685. // the session may be the same, if only letter case has changed
  1686. if (Session != NewSession)
  1687. {
  1688. SessionListView->Selected->Data = NewSession;
  1689. // if we overwrite editing session, remove the original item
  1690. // (we must preserve the one we are editing)
  1691. if (PrevCount == StoredSessions->Count)
  1692. {
  1693. int Index = StoredSessions->IndexOf(NewSession);
  1694. TListItem * OldItem = SessionListView->Items->Item[Index];
  1695. assert(OldItem->Data == NewSession);
  1696. OldItem->Delete();
  1697. }
  1698. StoredSessions->Remove(Session);
  1699. }
  1700. // sort items to the same order as in the container
  1701. SessionListView->AlphaSort();
  1702. SessionData = NewSession;
  1703. }
  1704. }
  1705. //---------------------------------------------------------------------------
  1706. void __fastcall TLoginDialog::SessionListViewCompare(TObject * /*Sender*/,
  1707. TListItem * Item1, TListItem * Item2, int /*Data*/, int & Compare)
  1708. {
  1709. int Index1 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item1->Data));
  1710. int Index2 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item2->Data));
  1711. if (Index1 < Index2)
  1712. {
  1713. Compare = -1;
  1714. }
  1715. else if (Index1 > Index2)
  1716. {
  1717. Compare = 1;
  1718. }
  1719. else
  1720. {
  1721. Compare = 0;
  1722. }
  1723. }
  1724. //---------------------------------------------------------------------------
  1725. void __fastcall TLoginDialog::UnixEnvironmentButtonClick(TObject * /*Sender*/)
  1726. {
  1727. EOLTypeLFButton->Checked = true;
  1728. DSTModeUnixCheck->Checked = true;
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. void __fastcall TLoginDialog::WindowsEnvironmentButtonClick(
  1732. TObject * /*Sender*/)
  1733. {
  1734. EOLTypeCRLFButton->Checked = true;
  1735. DSTModeWinCheck->Checked = true;
  1736. }
  1737. //---------------------------------------------------------------------------
  1738. void __fastcall TLoginDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1739. AnsiString & Name, bool & /*Action*/)
  1740. {
  1741. FBeforeDialogPath = Name;
  1742. Name = ExpandEnvironmentVariables(Name);
  1743. }
  1744. //---------------------------------------------------------------------------
  1745. int __fastcall TLoginDialog::FSProtocolToIndex(TFSProtocol FSProtocol,
  1746. bool & AllowScpFallback)
  1747. {
  1748. if (FSProtocol == fsSFTP)
  1749. {
  1750. AllowScpFallback = true;
  1751. bool Dummy;
  1752. return FSProtocolToIndex(fsSFTPonly, Dummy);
  1753. }
  1754. else
  1755. {
  1756. AllowScpFallback = false;
  1757. for (int Index = 0; Index < LENOF(FSOrder); Index++)
  1758. {
  1759. if ((FSOrder[Index] == FSProtocol) &&
  1760. (Index < TransferProtocolCombo->Items->Count))
  1761. {
  1762. return Index;
  1763. }
  1764. }
  1765. // SFTP is always present
  1766. return FSProtocolToIndex(fsSFTP, AllowScpFallback);
  1767. }
  1768. }
  1769. //---------------------------------------------------------------------------
  1770. TFSProtocol __fastcall TLoginDialog::IndexToFSProtocol(int Index, bool AllowScpFallback)
  1771. {
  1772. bool InBounds = (Index >= 0) && (Index < LENOF(FSOrder));
  1773. // can be temporary "unselected" while new language is being loaded
  1774. assert(InBounds || (Index == -1));
  1775. TFSProtocol Result = fsSFTP;
  1776. if (InBounds)
  1777. {
  1778. Result = FSOrder[Index];
  1779. if ((Result == fsSFTPonly) && AllowScpFallback)
  1780. {
  1781. Result = fsSFTP;
  1782. }
  1783. }
  1784. return Result;
  1785. }
  1786. //---------------------------------------------------------------------------
  1787. void __fastcall TLoginDialog::TransferProtocolComboChange(TObject * Sender)
  1788. {
  1789. if (!NoUpdate)
  1790. {
  1791. SavePing(FSessionData);
  1792. FFSProtocol = IndexToFSProtocol(
  1793. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  1794. LoadPing(FSessionData);
  1795. if (FFSProtocol == fsFTP)
  1796. {
  1797. if (PortNumberEdit->AsInteger == 22)
  1798. {
  1799. PortNumberEdit->AsInteger = 21;
  1800. }
  1801. }
  1802. else
  1803. {
  1804. if (PortNumberEdit->AsInteger == 21)
  1805. {
  1806. PortNumberEdit->AsInteger = 22;
  1807. }
  1808. }
  1809. }
  1810. DataChange(Sender);
  1811. }
  1812. //---------------------------------------------------------------------------
  1813. void __fastcall TLoginDialog::NavigationTreeCollapsing(
  1814. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1815. {
  1816. AllowCollapse = false;
  1817. }
  1818. //---------------------------------------------------------------------------