Login.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <ScpMain.h>
  5. #include <Common.h>
  6. #include <TextsWin.h>
  7. #include <TextsCore.h>
  8. #include <HelpWin.h>
  9. #include <VCLCommon.h>
  10. #include "Login.h"
  11. #include "WinInterface.h"
  12. #include "GUITools.h"
  13. #include "Tools.h"
  14. #include "Setup.h"
  15. #include "CustomWinConfiguration.h"
  16. //---------------------------------------------------------------------
  17. #pragma link "ComboEdit"
  18. #pragma link "LogSettings"
  19. #pragma link "GeneralSettings"
  20. #pragma link "UpDownEdit"
  21. #pragma link "XPThemes"
  22. #pragma link "PasswordEdit"
  23. #pragma resource "*.dfm"
  24. //---------------------------------------------------------------------------
  25. bool __fastcall DoLoginDialog(TStoredSessionList *SessionList,
  26. TSessionData * Data, int Options)
  27. {
  28. assert(Data);
  29. TLoginDialog *LoginDialog = new TLoginDialog(Application);
  30. bool Result;
  31. try
  32. {
  33. LoginDialog->StoredSessions = SessionList;
  34. LoginDialog->SessionData = Data;
  35. LoginDialog->Options = Options;
  36. Result = LoginDialog->Execute();
  37. if (Result)
  38. {
  39. Data->Assign(LoginDialog->SessionData);
  40. };
  41. }
  42. __finally
  43. {
  44. delete LoginDialog;
  45. }
  46. return Result;
  47. }
  48. //---------------------------------------------------------------------
  49. __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
  50. : TForm(AOwner)
  51. {
  52. FSessionData = new TSessionData("");
  53. NoUpdate = 0;
  54. FLanguagesPopupMenu = NULL;
  55. FInitialized = false;
  56. FSavedTab = NULL;
  57. FSavedSession = -1;
  58. FOptions = loStartup;
  59. FLocaleChanging = false;
  60. FColor = (TColor)0;
  61. InitControls();
  62. }
  63. //---------------------------------------------------------------------
  64. __fastcall TLoginDialog::~TLoginDialog()
  65. {
  66. // SelectItem event is called after destructor! Why?
  67. SessionListView->Selected = NULL;
  68. delete FSystemSettings;
  69. FSystemSettings = NULL;
  70. delete FSessionData;
  71. delete FLanguagesPopupMenu;
  72. }
  73. //---------------------------------------------------------------------
  74. void __fastcall TLoginDialog::ShowTabs(bool Show)
  75. {
  76. for (int Index = 0; Index < PageControl->PageCount; Index++)
  77. {
  78. PageControl->Pages[Index]->TabVisible = Show;
  79. }
  80. // change form height by height of hidden tabs
  81. ClientHeight += (Show ? 1 : -1) * 50;
  82. }
  83. //---------------------------------------------------------------------
  84. void __fastcall TLoginDialog::InitControls()
  85. {
  86. InitializeBugsCombo(BugIgnore1Combo);
  87. InitializeBugsCombo(BugPlainPW1Combo);
  88. InitializeBugsCombo(BugRSA1Combo);
  89. InitializeBugsCombo(BugHMAC2Combo);
  90. InitializeBugsCombo(BugDeriveKey2Combo);
  91. InitializeBugsCombo(BugRSAPad2Combo);
  92. InitializeBugsCombo(BugRekey2Combo);
  93. InitializeBugsCombo(BugPKSessID2Combo);
  94. InitializeBugsCombo(SFTPBugSymlinkCombo);
  95. InitializeBugsCombo(SFTPBugUtfCombo);
  96. InitializeBugsCombo(SFTPBugSignedTSCombo);
  97. InstallPathWordBreakProc(RemoteDirectoryEdit);
  98. InstallPathWordBreakProc(LocalDirectoryEdit);
  99. InstallPathWordBreakProc(PrivateKeyEdit);
  100. InstallPathWordBreakProc(RecycleBinPathEdit);
  101. }
  102. //---------------------------------------------------------------------
  103. void __fastcall TLoginDialog::Init()
  104. {
  105. UseSystemSettings(this, &FSystemSettings);
  106. Caption = FORMAT("%s %s", (AppName, Caption));
  107. InitControls();
  108. PrepareNavigationTree(SimpleNavigationTree, false);
  109. PrepareNavigationTree(AdvancedNavigationTree, true);
  110. if ((Options & loLocalDirectory) == 0)
  111. {
  112. LocalDirectoryLabel->Visible = false;
  113. LocalDirectoryEdit->Visible = false;
  114. LocalDirectoryDescLabel->Visible = false;
  115. DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + 12;
  116. DirectoryOptionsGroup->Top = DirectoriesGroup->Top + DirectoriesGroup->Height + 8;
  117. }
  118. if (FLAGCLEAR(Options, loExternalProtocols))
  119. {
  120. ExternalSSHButton->Visible = false;
  121. ExternalSFTPButton->Visible = false;
  122. TransferProtocolGroup->Height = TransferProtocolGroup->Height -
  123. (ExternalSSHButton->Top - SFTPonlyButton->Top);
  124. }
  125. ShowTabs(false);
  126. if (StoredSessions && StoredSessions->Count &&
  127. (FSessionData->Name == StoredSessions->DefaultSettings->Name))
  128. {
  129. ChangePage(SessionListSheet);
  130. SessionListView->SetFocus();
  131. assert(SessionListView->Items->Count > 0);
  132. if (SessionListView->Items->Count > 0)
  133. {
  134. SessionListView->ItemIndex = 0;
  135. SessionListView->ItemFocused = SessionListView->Selected;
  136. }
  137. }
  138. else
  139. {
  140. ChangePage(BasicSheet);
  141. HostNameEdit->SetFocus();
  142. }
  143. UpdateControls();
  144. }
  145. //---------------------------------------------------------------------
  146. void __fastcall TLoginDialog::InitializeBugsCombo(TComboBox * BugsCombo)
  147. {
  148. int PrevIndex = BugsCombo->ItemIndex;
  149. BugsCombo->Clear();
  150. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_AUTO));
  151. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_OFF));
  152. BugsCombo->Items->Add(LoadStr(LOGIN_BUG_ON));
  153. assert(PrevIndex < BugsCombo->Items->Count);
  154. BugsCombo->ItemIndex = PrevIndex;
  155. }
  156. //---------------------------------------------------------------------
  157. void __fastcall TLoginDialog::LoadSessions()
  158. {
  159. SessionListView->Items->BeginUpdate();
  160. try
  161. {
  162. SessionListView->Items->Clear();
  163. if (StoredSessions)
  164. {
  165. for (int Index = 0; Index < StoredSessions->Count; Index++)
  166. {
  167. TListItem *Item;
  168. Item = SessionListView->Items->Add();
  169. LoadSessionItem(Item);
  170. }
  171. }
  172. }
  173. __finally
  174. {
  175. SessionListView->Items->EndUpdate();
  176. }
  177. SelectedSession = StoredSessions->Count > 0 ?
  178. dynamic_cast<TSessionData*>(StoredSessions->AtObject(0)) : NULL;
  179. UpdateControls();
  180. }
  181. //---------------------------------------------------------------------------
  182. void __fastcall TLoginDialog::Default()
  183. {
  184. if (StoredSessions)
  185. {
  186. FSessionData->Assign(StoredSessions->DefaultSettings);
  187. }
  188. else
  189. {
  190. FSessionData->Default();
  191. }
  192. LoadSession(FSessionData);
  193. FCurrentSessionName = "";
  194. }
  195. //---------------------------------------------------------------------
  196. void __fastcall TLoginDialog::LoadSession(TSessionData * aSessionData)
  197. {
  198. NoUpdate++;
  199. try
  200. {
  201. // Basic tab
  202. UserNameEdit->Text = aSessionData->UserName;
  203. PortNumberEdit->AsInteger = aSessionData->PortNumber;
  204. HostNameEdit->Text = aSessionData->HostName;
  205. PasswordEdit->Text = aSessionData->Password;
  206. PrivateKeyEdit->Text = aSessionData->PublicKeyFile;
  207. FColor = (TColor)aSessionData->Color;
  208. switch (aSessionData->FSProtocol) {
  209. case fsSCPonly: SCPonlyButton->Checked = true; break;
  210. case fsSFTP: SFTPButton->Checked = true; break;
  211. case fsExternalSFTP: ExternalSFTPButton->Checked = true; break;
  212. case fsExternalSSH: ExternalSSHButton->Checked = true; break;
  213. case fsSFTPonly:
  214. default: SFTPonlyButton->Checked = true; break;
  215. }
  216. // Directories tab
  217. LocalDirectoryEdit->Text = aSessionData->LocalDirectory;
  218. RemoteDirectoryEdit->Text = aSessionData->RemoteDirectory;
  219. UpdateDirectoriesCheck->Checked = aSessionData->UpdateDirectories;
  220. CacheDirectoriesCheck->Checked = aSessionData->CacheDirectories;
  221. CacheDirectoryChangesCheck->Checked = aSessionData->CacheDirectoryChanges;
  222. PreserveDirectoryChangesCheck->Checked = aSessionData->PreserveDirectoryChanges;
  223. ResolveSymlinksCheck->Checked = aSessionData->ResolveSymlinks;
  224. // Environment tab
  225. ConsiderDSTOnCheck->Checked = aSessionData->ConsiderDST;
  226. ConsiderDSTOffCheck->Checked = !aSessionData->ConsiderDST;
  227. if (aSessionData->EOLType == eolLF)
  228. {
  229. EOLTypeLFButton->Checked = true;
  230. }
  231. else
  232. {
  233. EOLTypeCRLFButton->Checked = true;
  234. }
  235. DeleteToRecycleBinCheck->Checked = aSessionData->DeleteToRecycleBin;
  236. OverwrittenToRecycleBinCheck->Checked = aSessionData->OverwrittenToRecycleBin;
  237. RecycleBinPathEdit->Text = aSessionData->RecycleBinPath;
  238. // SFTP tab
  239. #define LOAD_SFTP_BUG_COMBO(BUG) \
  240. SFTPBug ## BUG ## Combo->ItemIndex = 2 - aSessionData->SFTPBug[sb ## BUG]; \
  241. if (SFTPBug ## BUG ## Combo->ItemIndex < 0) SFTPBug ## BUG ## Combo->ItemIndex = 0
  242. LOAD_SFTP_BUG_COMBO(Symlink);
  243. LOAD_SFTP_BUG_COMBO(Utf);
  244. LOAD_SFTP_BUG_COMBO(SignedTS);
  245. #undef LOAD_SFTP_BUG_COMBO
  246. SFTPMaxVersionCombo->ItemIndex = aSessionData->SFTPMaxVersion;
  247. // Authentication tab
  248. AuthTISCheck->Checked = aSessionData->AuthTIS;
  249. AuthKICheck->Checked = aSessionData->AuthKI;
  250. AuthKIPasswordCheck->Checked = aSessionData->AuthKIPassword;
  251. AuthGSSAPICheck->Checked = aSessionData->AuthGSSAPI;
  252. AgentFwdCheck->Checked = aSessionData->AgentFwd;
  253. // SSH tab
  254. Ssh2LegacyDESCheck->Checked = aSessionData->Ssh2DES;
  255. CompressionCheck->Checked = aSessionData->Compression;
  256. switch (aSessionData->SshProt) {
  257. case ssh1only: SshProt1onlyButton->Checked = true; break;
  258. case ssh1: SshProt1Button->Checked = true; break;
  259. case ssh2: SshProt2Button->Checked = true; break;
  260. case ssh2only: SshProt2onlyButton->Checked = true; break;
  261. }
  262. CipherListBox->Items->Clear();
  263. assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_DES);
  264. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  265. {
  266. CipherListBox->Items->AddObject(
  267. LoadStr(CIPHER_NAME_WARN+aSessionData->Cipher[Index]),
  268. (TObject*)aSessionData->Cipher[Index]);
  269. }
  270. // KEX tab
  271. KexListBox->Items->Clear();
  272. assert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_DHGEX);
  273. for (int Index = 0; Index < KEX_COUNT; Index++)
  274. {
  275. KexListBox->Items->AddObject(
  276. LoadStr(KEX_NAME_WARN+aSessionData->Kex[Index]),
  277. (TObject*)aSessionData->Kex[Index]);
  278. }
  279. RekeyTimeEdit->AsInteger = aSessionData->RekeyTime;
  280. RekeyDataEdit->Text = aSessionData->RekeyData;
  281. // Connection tab
  282. switch (aSessionData->PingType)
  283. {
  284. case ptNullPacket:
  285. PingNullPacketButton->Checked = true;
  286. break;
  287. case ptDummyCommand:
  288. PingDummyCommandButton->Checked = true;
  289. break;
  290. default:
  291. PingOffButton->Checked = true;
  292. break;
  293. }
  294. PingIntervalSecEdit->AsInteger = aSessionData->PingInterval;
  295. TimeoutEdit->AsInteger = aSessionData->Timeout;
  296. switch (aSessionData->AddressFamily)
  297. {
  298. case afIPv4:
  299. IPv4Button->Checked = true;
  300. break;
  301. case afIPv6:
  302. IPv6Button->Checked = true;
  303. break;
  304. case afAuto:
  305. default:
  306. IPAutoButton->Checked = true;
  307. break;
  308. }
  309. // Shell tab
  310. if (aSessionData->DefaultShell)
  311. DefaultShellButton->Checked = true;
  312. else
  313. ShellEnterButton->Checked = true;
  314. ShellEdit->Text = aSessionData->Shell;
  315. if (aSessionData->DetectReturnVar)
  316. ReturnVarAutodetectButton->Checked = true;
  317. else
  318. ReturnVarEnterButton->Checked = true;
  319. ReturnVarEdit->Text = aSessionData->ReturnVar;
  320. LookupUserGroupsCheck->Checked = aSessionData->LookupUserGroups;
  321. ClearAliasesCheck->Checked = aSessionData->ClearAliases;
  322. IgnoreLsWarningsCheck->Checked = aSessionData->IgnoreLsWarnings;
  323. Scp1CompatibilityCheck->Checked = aSessionData->Scp1Compatibility;
  324. UnsetNationalVarsCheck->Checked = aSessionData->UnsetNationalVars;
  325. AliasGroupListCheck->Checked = aSessionData->AliasGroupList;
  326. SCPLsFullTimeAutoCheck->Checked = (aSessionData->SCPLsFullTime != asOff);
  327. int TimeDifferenceMin = DateTimeToTimeStamp(aSessionData->TimeDifference).Time / 60000;
  328. if (double(aSessionData->TimeDifference) < 0)
  329. {
  330. TimeDifferenceMin = -TimeDifferenceMin;
  331. }
  332. TimeDifferenceEdit->AsInteger = TimeDifferenceMin / 60;
  333. TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % 60;
  334. // Proxy tab
  335. switch (aSessionData->ProxyMethod) {
  336. case pmHTTP: ProxyHTTPButton->Checked = true; break;
  337. case pmSocks4: ProxySocks4Button->Checked = true; break;
  338. case pmSocks5: ProxySocks5Button->Checked = true; break;
  339. case pmTelnet: ProxyTelnetButton->Checked = true; break;
  340. default: ProxyNoneButton->Checked = true; break;
  341. }
  342. ProxyHostEdit->Text = aSessionData->ProxyHost;
  343. ProxyPortEdit->AsInteger = aSessionData->ProxyPort;
  344. ProxyUsernameEdit->Text = aSessionData->ProxyUsername;
  345. ProxyPasswordEdit->Text = aSessionData->ProxyPassword;
  346. ProxyTelnetCommandEdit->Text = aSessionData->ProxyTelnetCommand;
  347. ProxyLocalhostCheck->Checked = aSessionData->ProxyLocalhost;
  348. switch (aSessionData->ProxyDNS) {
  349. case asOn: ProxyDNSOnButton->Checked = true; break;
  350. case asOff: ProxyDNSOffButton->Checked = true; break;
  351. default: ProxyDNSAutoButton->Checked = true; break;
  352. }
  353. // Bugs tab
  354. #define LOAD_BUG_COMBO(BUG) \
  355. Bug ## BUG ## Combo->ItemIndex = 2 - aSessionData->Bug[sb ## BUG]; \
  356. if (Bug ## BUG ## Combo->ItemIndex < 0) Bug ## BUG ## Combo->ItemIndex = 0
  357. LOAD_BUG_COMBO(Ignore1);
  358. LOAD_BUG_COMBO(PlainPW1);
  359. LOAD_BUG_COMBO(RSA1);
  360. LOAD_BUG_COMBO(HMAC2);
  361. LOAD_BUG_COMBO(DeriveKey2);
  362. LOAD_BUG_COMBO(RSAPad2);
  363. LOAD_BUG_COMBO(Rekey2);
  364. LOAD_BUG_COMBO(PKSessID2);
  365. #undef LOAD_BUG_COMBO
  366. }
  367. __finally
  368. {
  369. NoUpdate--;
  370. UpdateControls();
  371. }
  372. FCurrentSessionName = aSessionData->Name;
  373. }
  374. //---------------------------------------------------------------------
  375. void __fastcall TLoginDialog::SaveSession(TSessionData * aSessionData)
  376. {
  377. aSessionData->Name = FCurrentSessionName;
  378. // Basic tab
  379. aSessionData->UserName = UserNameEdit->Text.Trim();
  380. aSessionData->PortNumber = PortNumberEdit->AsInteger;
  381. // must be loaded after UserName, because HostName may be in format user@host
  382. aSessionData->HostName = HostNameEdit->Text.Trim();
  383. aSessionData->Password = PasswordEdit->Text;
  384. aSessionData->PublicKeyFile = PrivateKeyEdit->Text;
  385. aSessionData->Color = FColor;
  386. if (SCPonlyButton->Checked) aSessionData->FSProtocol = fsSCPonly;
  387. else
  388. if (SFTPButton->Checked) aSessionData->FSProtocol = fsSFTP;
  389. else
  390. if (ExternalSFTPButton->Checked) aSessionData->FSProtocol = fsExternalSFTP;
  391. else
  392. if (ExternalSSHButton->Checked) aSessionData->FSProtocol = fsExternalSSH;
  393. else aSessionData->FSProtocol = fsSFTPonly;
  394. // SSH tab
  395. aSessionData->Compression = CompressionCheck->Checked;
  396. aSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
  397. if (SshProt1onlyButton->Checked) aSessionData->SshProt = ssh1only;
  398. else
  399. if (SshProt1Button->Checked) aSessionData->SshProt = ssh1;
  400. else
  401. if (SshProt2Button->Checked) aSessionData->SshProt = ssh2;
  402. else aSessionData->SshProt = ssh2only;
  403. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  404. {
  405. aSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
  406. }
  407. // Kex tab
  408. for (int Index = 0; Index < KEX_COUNT; Index++)
  409. {
  410. aSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
  411. }
  412. aSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
  413. aSessionData->RekeyData = RekeyDataEdit->Text;
  414. // Authentication tab
  415. aSessionData->AuthTIS = AuthTISCheck->Checked;
  416. aSessionData->AuthKI = AuthKICheck->Checked;
  417. aSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
  418. aSessionData->AuthGSSAPI = AuthGSSAPICheck->Checked;
  419. aSessionData->AgentFwd = AgentFwdCheck->Checked;
  420. // Connection tab
  421. if (PingNullPacketButton->Checked)
  422. {
  423. aSessionData->PingType = ptNullPacket;
  424. }
  425. else if (PingDummyCommandButton->Checked)
  426. {
  427. aSessionData->PingType = ptDummyCommand;
  428. }
  429. else
  430. {
  431. aSessionData->PingType = ptOff;
  432. }
  433. aSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
  434. aSessionData->Timeout = TimeoutEdit->AsInteger;
  435. if (IPv4Button->Checked)
  436. {
  437. aSessionData->AddressFamily = afIPv4;
  438. }
  439. else if (IPv6Button->Checked)
  440. {
  441. aSessionData->AddressFamily = afIPv6;
  442. }
  443. else
  444. {
  445. aSessionData->AddressFamily = afAuto;
  446. }
  447. // Directories tab
  448. aSessionData->LocalDirectory = LocalDirectoryEdit->Text;
  449. aSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
  450. aSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
  451. aSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
  452. aSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
  453. aSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
  454. aSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
  455. // Environment tab
  456. aSessionData->ConsiderDST = ConsiderDSTOnCheck->Checked;
  457. if (EOLTypeLFButton->Checked) aSessionData->EOLType = eolLF;
  458. else aSessionData->EOLType = eolCRLF;
  459. aSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
  460. aSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
  461. aSessionData->RecycleBinPath = RecycleBinPathEdit->Text;
  462. // SCP tab
  463. aSessionData->DefaultShell = DefaultShellButton->Checked;
  464. if (ShellEnterButton->Checked)
  465. aSessionData->Shell = ShellEdit->Text;
  466. aSessionData->DetectReturnVar = ReturnVarAutodetectButton->Checked;
  467. if (ReturnVarEnterButton->Checked)
  468. aSessionData->ReturnVar = ReturnVarEdit->Text;
  469. aSessionData->LookupUserGroups = LookupUserGroupsCheck->Checked;
  470. aSessionData->ClearAliases = ClearAliasesCheck->Checked;
  471. aSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
  472. aSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
  473. aSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
  474. aSessionData->AliasGroupList = AliasGroupListCheck->Checked;
  475. aSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
  476. aSessionData->TimeDifference =
  477. (double(TimeDifferenceEdit->AsInteger) / 24) +
  478. (double(TimeDifferenceMinutesEdit->AsInteger) / 24 / 60);
  479. // SFTP tab
  480. #define SAVE_SFTP_BUG_COMBO(BUG) aSessionData->SFTPBug[sb ## BUG] = (TAutoSwitch)(2 - SFTPBug ## BUG ## Combo->ItemIndex);
  481. SAVE_SFTP_BUG_COMBO(Symlink);
  482. SAVE_SFTP_BUG_COMBO(Utf);
  483. SAVE_SFTP_BUG_COMBO(SignedTS);
  484. #undef SAVE_SFTP_BUG_COMBO
  485. aSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
  486. // Proxy tab
  487. if (ProxyHTTPButton->Checked) aSessionData->ProxyMethod = pmHTTP;
  488. else
  489. if (ProxySocks4Button->Checked) aSessionData->ProxyMethod = pmSocks4;
  490. else
  491. if (ProxySocks5Button->Checked) aSessionData->ProxyMethod = pmSocks5;
  492. else
  493. if (ProxyTelnetButton->Checked) aSessionData->ProxyMethod = pmTelnet;
  494. else aSessionData->ProxyMethod = pmNone;
  495. aSessionData->ProxyHost = ProxyHostEdit->Text;
  496. aSessionData->ProxyPort = ProxyPortEdit->AsInteger;
  497. aSessionData->ProxyUsername = ProxyUsernameEdit->Text;
  498. aSessionData->ProxyPassword = ProxyPasswordEdit->Text;
  499. aSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
  500. aSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
  501. if (ProxyDNSOnButton->Checked) aSessionData->ProxyDNS = asOn;
  502. else
  503. if (ProxyDNSOffButton->Checked) aSessionData->ProxyDNS = asOff;
  504. else aSessionData->ProxyDNS = asAuto;
  505. // Bugs tab
  506. #define SAVE_BUG_COMBO(BUG) aSessionData->Bug[sb ## BUG] = (TAutoSwitch)(2 - Bug ## BUG ## Combo->ItemIndex);
  507. SAVE_BUG_COMBO(Ignore1);
  508. SAVE_BUG_COMBO(PlainPW1);
  509. SAVE_BUG_COMBO(RSA1);
  510. SAVE_BUG_COMBO(HMAC2);
  511. SAVE_BUG_COMBO(DeriveKey2);
  512. SAVE_BUG_COMBO(RSAPad2);
  513. SAVE_BUG_COMBO(Rekey2);
  514. SAVE_BUG_COMBO(PKSessID2);
  515. #undef SAVE_BUG_COMBO
  516. }
  517. //---------------------------------------------------------------------
  518. void __fastcall TLoginDialog::UpdateControls()
  519. {
  520. if (Visible)
  521. {
  522. NoUpdate++;
  523. try
  524. {
  525. bool ExternalProtocol = ExternalSSHButton->Checked || ExternalSFTPButton->Checked;
  526. #define SHOW_NAVIGATION(TREE, SHOW) if ((TREE)->Visible != (SHOW)) { \
  527. (TREE)->Visible = (SHOW); PageControlChange(PageControl); }
  528. SHOW_NAVIGATION(SimpleNavigationTree, !ShowAdvancedLoginOptionsCheck->Checked);
  529. SHOW_NAVIGATION(AdvancedNavigationTree, ShowAdvancedLoginOptionsCheck->Checked);
  530. #undef SHOW_NAVIGATION
  531. EnableControl(ExternalSSHButton,
  532. !GUIConfiguration->PuttyPath.Trim().IsEmpty());
  533. EnableControl(ExternalSFTPButton,
  534. !GUIConfiguration->PSftpPath.Trim().IsEmpty());
  535. EnableControl(ShellIconsButton, SessionListView->Selected);
  536. EnableControl(PingIntervalSecEdit, !PingOffButton->Checked);
  537. EnableControl(PingIntervalLabel, PingIntervalSecEdit->Enabled);
  538. EnableControl(SessionListView, SessionListView->Items->Count);
  539. AdjustListColumnsWidth(SessionListView);
  540. SessionListView->Columns->Items[0]->Width -= 2;
  541. EnableControl(AuthTISCheck, !SshProt2onlyButton->Checked);
  542. EnableControl(AuthKICheck, !SshProt1onlyButton->Checked);
  543. EnableControl(AuthKIPasswordCheck,
  544. AuthTISCheck->Checked || AuthKICheck->Checked);
  545. EnableControl(AuthGSSAPICheck, !SshProt1onlyButton->Checked);
  546. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  547. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  548. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  549. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  550. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  551. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  552. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  553. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  554. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  555. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  556. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  557. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  558. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  559. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  560. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  561. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  562. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  563. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  564. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  565. EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
  566. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  567. EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
  568. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  569. EnableControl(ScpSheet, !ExternalProtocol);
  570. EnableControl(ShellEdit, ShellEnterButton->Checked && ScpSheet->Enabled);
  571. EnableControl(ReturnVarEdit, ReturnVarEnterButton->Checked && ScpSheet->Enabled);
  572. EnableControl(ProxyHostEdit, !ProxyNoneButton->Checked);
  573. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  574. EnableControl(ProxyPortEdit, !ProxyNoneButton->Checked);
  575. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  576. EnableControl(ProxyUsernameEdit, !ProxyNoneButton->Checked);
  577. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  578. EnableControl(ProxyPasswordEdit, !ProxyNoneButton->Checked &&
  579. !ProxySocks4Button->Checked);
  580. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  581. EnableControl(ProxySettingsGroup, !ProxyNoneButton->Checked);
  582. EnableControl(ProxyTelnetCommandEdit, ProxyTelnetButton->Checked);
  583. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  584. EnableControl(DirectoriesSheet, !ExternalProtocol);
  585. DirectoryOptionsGroup->Visible = ShowAdvancedLoginOptionsCheck->Checked;
  586. EnableControl(CacheDirectoryChangesCheck,
  587. (!SCPonlyButton->Checked || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  588. EnableControl(PreserveDirectoryChangesCheck,
  589. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  590. DirectoriesSheet->Enabled);
  591. EnableControl(EnvironmentSheet, !ExternalProtocol);
  592. RecycleBinGroup->Visible = ShowAdvancedLoginOptionsCheck->Checked;
  593. EnableControl(OverwrittenToRecycleBinCheck, !SCPonlyButton->Checked &&
  594. EnvironmentSheet->Enabled);
  595. EnableControl(RecycleBinPathEdit,
  596. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  597. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  598. EnvironmentSheet->Enabled);
  599. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  600. EnvironmentSheet->Enabled);
  601. EnableControl(SftpSheet, !SCPonlyButton->Checked && !ExternalProtocol);
  602. EnableControl(KexSheet, !SshProt1onlyButton->Checked);
  603. AboutButton->Visible = (Options & loAbout);
  604. LanguagesButton->Visible = (Options & loLanguage);
  605. ShellIconsButton->Visible = (Options & loTools);
  606. ToolsMenuButton->Visible = (Options & loTools);
  607. LoggingFrame->EnableLogWindow = (Options & loLogWindow);
  608. }
  609. __finally
  610. {
  611. NoUpdate--;
  612. }
  613. }
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
  617. {
  618. if (!NoUpdate) UpdateControls();
  619. }
  620. //---------------------------------------------------------------------------
  621. void __fastcall TLoginDialog::PrepareNavigationTree(TTreeView * Tree, bool ClearHints)
  622. {
  623. Tree->FullExpand();
  624. int i = 0;
  625. while (i < Tree->Items->Count)
  626. {
  627. if ((Tree->Items->Item[i]->StateIndex > 0) &&
  628. ((Options & Tree->Items->Item[i]->StateIndex) == 0))
  629. {
  630. Tree->Items->Delete(Tree->Items->Item[i]);
  631. }
  632. else
  633. {
  634. for (int pi = 0; pi < PageControl->PageCount; pi++)
  635. {
  636. if (PageControl->Pages[pi]->Tag == Tree->Items->Item[i]->SelectedIndex)
  637. {
  638. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  639. if (ClearHints)
  640. {
  641. PageControl->Pages[pi]->Hint = "";
  642. }
  643. break;
  644. }
  645. }
  646. i++;
  647. }
  648. }
  649. }
  650. //---------------------------------------------------------------------------
  651. void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
  652. {
  653. if (!FInitialized)
  654. {
  655. FInitialized = true;
  656. Init();
  657. TSessionData * Data = GetSessionData();
  658. if (Data == FSessionData)
  659. {
  660. LoadSession(Data);
  661. }
  662. else
  663. {
  664. Default();
  665. }
  666. }
  667. if (FLocaleChanging)
  668. {
  669. Init();
  670. LoadSession(FSessionData);
  671. ChangePage(FSavedTab);
  672. SessionListView->ItemIndex = FSavedSession;
  673. LoadConfiguration();
  674. }
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TLoginDialog::SessionListViewSelectItem(TObject * /*Sender*/,
  678. TListItem * /*Item*/, bool /*Selected*/)
  679. {
  680. UpdateControls();
  681. }
  682. //---------------------------------------------------------------------------
  683. void __fastcall TLoginDialog::StoreSessions()
  684. {
  685. StoredSessions->Save();
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
  689. {
  690. FSessionData->Assign(value);
  691. FSessionData->Special = false;
  692. LoadSession(FSessionData);
  693. }
  694. //---------------------------------------------------------------------------
  695. TSessionData * __fastcall TLoginDialog::GetSessionData()
  696. {
  697. if (PageControl->ActivePage == SessionListSheet)
  698. {
  699. return SelectedSession;
  700. }
  701. else
  702. {
  703. SaveSession(FSessionData);
  704. return FSessionData;
  705. }
  706. }
  707. //---------------------------------------------------------------------------
  708. void __fastcall TLoginDialog::SetStoredSessions(TStoredSessionList * value)
  709. {
  710. if (FStoredSessions != value)
  711. {
  712. FStoredSessions = value;
  713. LoadSessions();
  714. }
  715. }
  716. //---------------------------------------------------------------------------
  717. void __fastcall TLoginDialog::LoadSessionItem(TListItem * Item)
  718. {
  719. Item->Data = StoredSessions->AtObject(Item->Index);
  720. Item->Caption = ((TSessionData*)Item->Data)->Name;
  721. }
  722. //---------------------------------------------------------------------------
  723. void __fastcall TLoginDialog::SessionListViewDblClick(TObject * /*Sender*/)
  724. {
  725. if (SelectedSession)
  726. {
  727. if (SelectedSession->CanLogin) ModalResult = mrOk;
  728. else
  729. {
  730. SessionData = SelectedSession;
  731. ChangePage(BasicSheet);
  732. if (HostNameEdit->Text.IsEmpty()) HostNameEdit->SetFocus();
  733. else
  734. if (UserNameEdit->Text.IsEmpty()) UserNameEdit->SetFocus();
  735. }
  736. }
  737. }
  738. //---------------------------------------------------------------------------
  739. void __fastcall TLoginDialog::SetSelectedSession(TSessionData * value)
  740. {
  741. if (value)
  742. {
  743. int Index = StoredSessions->IndexOf(value);
  744. if (Index >= 0)
  745. {
  746. TListItem *Item = SessionListView->Items->Item[Index];
  747. Item->Focused = true;
  748. Item->Selected = true;
  749. Item->MakeVisible(false);
  750. }
  751. }
  752. else
  753. {
  754. SessionListView->Selected = NULL;
  755. }
  756. }
  757. //---------------------------------------------------------------------------
  758. TSessionData * __fastcall TLoginDialog::GetSelectedSession()
  759. {
  760. if (SessionListView->Selected)
  761. return (TSessionData *)SessionListView->Selected->Data;
  762. else
  763. return NULL;
  764. }
  765. //---------------------------------------------------------------------------
  766. void __fastcall TLoginDialog::SessionListViewInfoTip(TObject * /*Sender*/,
  767. TListItem * Item, AnsiString & InfoTip)
  768. {
  769. InfoTip = ((TSessionData*)Item->Data)->InfoTip;
  770. }
  771. //---------------------------------------------------------------------------
  772. void __fastcall TLoginDialog::SessionListViewKeyDown(TObject * /*Sender*/,
  773. WORD & Key, TShiftState /*Shift*/)
  774. {
  775. if (!SessionListView->IsEditing())
  776. {
  777. if (Key == VK_DELETE)
  778. {
  779. DeleteSessionAction->Execute();
  780. Key = 0;
  781. }
  782. else if (Key == VK_F2)
  783. {
  784. RenameSessionAction->Execute();
  785. Key = 0;
  786. }
  787. }
  788. }
  789. //---------------------------------------------------------------------------
  790. void __fastcall TLoginDialog::LoadSessionActionExecute(TObject * /*Sender*/)
  791. {
  792. if (SelectedSession)
  793. {
  794. SessionData = SelectedSession;
  795. ChangePage(BasicSheet);
  796. }
  797. }
  798. //---------------------------------------------------------------------------
  799. void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
  800. {
  801. AnsiString SessionName;
  802. SaveSession(FSessionData);
  803. if (FSessionData->Password.IsEmpty() ||
  804. Configuration->DisablePasswordStoring ||
  805. (MessageDialog(LoadStr(SAVE_PASSWORD), qtWarning, qaOK | qaCancel,
  806. HELP_SESSION_SAVE_PASSWORD) == qaOK))
  807. {
  808. SessionName = DoSaveSessionDialog(FSessionData->SessionName);
  809. if (!SessionName.IsEmpty())
  810. {
  811. TListItem * Item;
  812. TSessionData *NewSession =
  813. StoredSessions->NewSession(SessionName, FSessionData);
  814. StoredSessions->Save();
  815. // by now list must contais same number of items or one less
  816. assert(StoredSessions->Count == SessionListView->Items->Count ||
  817. StoredSessions->Count == SessionListView->Items->Count+1);
  818. if (StoredSessions->Count > SessionListView->Items->Count)
  819. Item = SessionListView->Items->Insert(StoredSessions->IndexOf(NewSession));
  820. else
  821. Item = SessionListView->Items->Item[StoredSessions->IndexOf(NewSession)];
  822. LoadSessionItem(Item);
  823. SelectedSession = NewSession;
  824. SessionData = NewSession;
  825. ChangePage(SessionListSheet);
  826. SessionListView->SetFocus();
  827. }
  828. }
  829. }
  830. //---------------------------------------------------------------------------
  831. void __fastcall TLoginDialog::DeleteSessionActionExecute(TObject * /*Sender*/)
  832. {
  833. if (SelectedSession &&
  834. (MessageDialog(FMTLOAD(CONFIRM_DELETE_SESSION, (SelectedSession->SessionName)),
  835. qtConfirmation, qaOK | qaCancel, HELP_DELETE_SESSION) == qaOK))
  836. {
  837. int PrevSelectedIndex = SessionListView->Selected->Index;
  838. SelectedSession->Remove();
  839. StoredSessions->Remove(SelectedSession);
  840. SessionListView->Selected->Delete();
  841. if (SessionListView->Items->Count)
  842. {
  843. if (PrevSelectedIndex >= SessionListView->Items->Count)
  844. PrevSelectedIndex = SessionListView->Items->Count - 1;
  845. SelectedSession =
  846. (TSessionData *)StoredSessions->AtObject(PrevSelectedIndex);
  847. }
  848. }
  849. }
  850. //---------------------------------------------------------------------------
  851. void __fastcall TLoginDialog::ImportSessionsActionExecute(TObject * /*Sender*/)
  852. {
  853. if (DoImportSessionsDialog(StoredSessions))
  854. {
  855. LoadSessions();
  856. if (SessionListView->Items->Count)
  857. SessionListView->Items->Item[0]->MakeVisible(False);
  858. }
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TLoginDialog::CleanUpActionExecute(TObject * /*Sender*/)
  862. {
  863. if (DoCleanupDialog(StoredSessions, Configuration))
  864. LoadSessions();
  865. }
  866. //---------------------------------------------------------------------------
  867. void __fastcall TLoginDialog::AboutActionExecute(TObject * /*Sender*/)
  868. {
  869. DoAboutDialog(Configuration);
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TLoginDialog::ActionListUpdate(TBasicAction *Action,
  873. bool &Handled)
  874. {
  875. if (Action == LoadSessionAction)
  876. {
  877. LoadSessionAction->Enabled = SessionListView->Selected;
  878. }
  879. else if (Action == DeleteSessionAction)
  880. {
  881. TSessionData * Data = SessionData;
  882. DeleteSessionAction->Enabled =
  883. SessionListView->Selected && Data && !Data->Special;
  884. }
  885. else if (Action == RenameSessionAction)
  886. {
  887. TSessionData * Data = SessionData;
  888. RenameSessionAction->Enabled =
  889. SessionListView->Selected && Data && !Data->Special;
  890. }
  891. else if (Action == DesktopIconAction)
  892. {
  893. DesktopIconAction->Enabled = SessionListView->Selected;
  894. }
  895. else if (Action == SendToHookAction)
  896. {
  897. SendToHookAction->Enabled = SessionListView->Selected;
  898. }
  899. else if (Action == LoginAction)
  900. {
  901. TSessionData * Data = SessionData;
  902. LoginAction->Enabled = Data && Data->CanLogin;
  903. }
  904. else if (Action == SaveSessionAction)
  905. {
  906. SaveSessionAction->Enabled = (PageControl->ActivePage != SessionListSheet);
  907. }
  908. Handled = true;
  909. if (!LoginButton->Default && !SessionListView->IsEditing())
  910. {
  911. LoginButton->Default = true;
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915. bool __fastcall TLoginDialog::Execute()
  916. {
  917. LoadConfiguration();
  918. bool Result = (ShowModal() == mrOk);
  919. if (Result)
  920. {
  921. SaveConfiguration();
  922. }
  923. return Result;
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TLoginDialog::SaveConfiguration()
  927. {
  928. assert(CustomWinConfiguration);
  929. CustomWinConfiguration->BeginUpdate();
  930. try
  931. {
  932. LoggingFrame->SaveConfiguration();
  933. GeneralSettingsFrame->SaveConfiguration();
  934. CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
  935. }
  936. __finally
  937. {
  938. CustomWinConfiguration->EndUpdate();
  939. }
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TLoginDialog::LoadConfiguration()
  943. {
  944. assert(CustomWinConfiguration);
  945. LoggingFrame->LoadConfiguration();
  946. GeneralSettingsFrame->LoadConfiguration();
  947. ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
  948. UpdateControls();
  949. }
  950. //---------------------------------------------------------------------------
  951. void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
  952. {
  953. ShowPreferencesDialog();
  954. UpdateControls();
  955. }
  956. //---------------------------------------------------------------------------
  957. void __fastcall TLoginDialog::ShowPreferencesDialog()
  958. {
  959. DoPreferencesDialog(pmLogin);
  960. }
  961. //---------------------------------------------------------------------------
  962. void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
  963. {
  964. Default();
  965. ChangePage(BasicSheet);
  966. }
  967. //---------------------------------------------------------------------------
  968. void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
  969. TTreeNode *Node)
  970. {
  971. if (Node->SelectedIndex)
  972. {
  973. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  974. {
  975. if (PageControl->Pages[Index]->Tag == Node->SelectedIndex)
  976. {
  977. PageControl->ActivePage = PageControl->Pages[Index];
  978. // reshow the accelerators, etc
  979. ResetSystemSettings(this);
  980. return;
  981. }
  982. }
  983. }
  984. assert(false);
  985. }
  986. //---------------------------------------------------------------------------
  987. void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
  988. {
  989. PageControl->ActivePage = Tab;
  990. PageControlChange(PageControl);
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
  994. {
  995. bool Found = false;
  996. if (PageControl->ActivePage->Tag)
  997. {
  998. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  999. {
  1000. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1001. PageControl->ActivePage->Tag)
  1002. {
  1003. NavigationTree->Items->Item[Index]->Selected = true;
  1004. Found = true;
  1005. }
  1006. }
  1007. }
  1008. if (!Found)
  1009. {
  1010. ChangePage(BasicSheet);
  1011. }
  1012. else
  1013. {
  1014. DataChange(Sender);
  1015. }
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. TTreeView * __fastcall TLoginDialog::GetNavigationTree()
  1019. {
  1020. return (ShowAdvancedLoginOptionsCheck->Checked ?
  1021. AdvancedNavigationTree : SimpleNavigationTree);
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
  1025. {
  1026. if (Message.CharCode == VK_TAB)
  1027. {
  1028. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1029. if (Shift.Contains(ssCtrl))
  1030. {
  1031. TTreeNode * Node = NavigationTree->Selected;
  1032. if (!Shift.Contains(ssShift))
  1033. {
  1034. Node = Node->GetNext();
  1035. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1036. }
  1037. else
  1038. {
  1039. if (Node->GetPrev()) Node = Node->GetPrev();
  1040. else
  1041. while (Node->GetNext()) Node = Node->GetNext();
  1042. }
  1043. Node->Selected = True;
  1044. Message.Result = 1;
  1045. return;
  1046. }
  1047. }
  1048. TForm::Dispatch(&Message);
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. void __fastcall TLoginDialog::Dispatch(void *Message)
  1052. {
  1053. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1054. assert(M);
  1055. if (M->Msg == CM_DIALOGKEY)
  1056. {
  1057. CMDialogKey(*((TWMKeyDown *)Message));
  1058. }
  1059. else if (M->Msg == WM_LOCALE_CHANGE)
  1060. {
  1061. if (M->WParam == 0)
  1062. {
  1063. SaveConfiguration();
  1064. SaveSession(FSessionData);
  1065. FSavedTab = PageControl->ActivePage;
  1066. FSavedSession = SessionListView->ItemIndex;
  1067. assert(FSystemSettings);
  1068. RevokeSystemSettings(this, FSystemSettings);
  1069. FSystemSettings = NULL;
  1070. ShowTabs(true);
  1071. Hide();
  1072. }
  1073. else
  1074. {
  1075. FLocaleChanging = true;
  1076. try
  1077. {
  1078. Show();
  1079. }
  1080. __finally
  1081. {
  1082. FLocaleChanging = false;
  1083. }
  1084. }
  1085. }
  1086. else
  1087. {
  1088. TForm::Dispatch(Message);
  1089. }
  1090. }
  1091. //---------------------------------------------------------------------------
  1092. void __fastcall TLoginDialog::AlgListBoxStartDrag(TObject * Sender,
  1093. TDragObject *& /*DragObject*/)
  1094. {
  1095. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1096. FAlgDragDest = -1;
  1097. }
  1098. //---------------------------------------------------------------------------
  1099. void __fastcall TLoginDialog::AlgListBoxDragOver(TObject * Sender,
  1100. TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
  1101. {
  1102. if (Source == Sender)
  1103. {
  1104. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1105. }
  1106. }
  1107. //---------------------------------------------------------------------------
  1108. void __fastcall TLoginDialog::AlgListBoxDragDrop(TObject * Sender,
  1109. TObject *Source, int X, int Y)
  1110. {
  1111. if (Source == Sender)
  1112. {
  1113. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1114. if (AllowAlgDrag(AlgListBox, X, Y))
  1115. {
  1116. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1117. }
  1118. }
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
  1122. {
  1123. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1124. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TLoginDialog::KexButtonClick(TObject *Sender)
  1128. {
  1129. AlgMove(KexListBox, KexListBox->ItemIndex,
  1130. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1131. }
  1132. //---------------------------------------------------------------------------
  1133. bool __fastcall TLoginDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1134. {
  1135. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1136. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1137. }
  1138. //---------------------------------------------------------------------------
  1139. void __fastcall TLoginDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1140. {
  1141. if (Source >= 0 && Source < AlgListBox->Items->Count &&
  1142. Dest >= 0 && Dest < AlgListBox->Items->Count)
  1143. {
  1144. AlgListBox->Items->Move(Source, Dest);
  1145. AlgListBox->ItemIndex = Dest;
  1146. AlgListBox->SetFocus();
  1147. }
  1148. UpdateControls();
  1149. }
  1150. //---------------------------------------------------------------------------
  1151. void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
  1152. TObject * /*Sender*/)
  1153. {
  1154. if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
  1155. qaOK | qaCancel, HELP_SESSION_SAVE_DEFAULT) == qaOK)
  1156. {
  1157. SaveSession(FSessionData);
  1158. StoredSessions->DefaultSettings = FSessionData;
  1159. }
  1160. }
  1161. //---------------------------------------------------------------------------
  1162. void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
  1163. {
  1164. TPoint PopupPoint = ToolsMenuButton->ClientToScreen(TPoint(0, ToolsMenuButton->Height));
  1165. ToolsPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. void __fastcall TLoginDialog::ShellIconsButtonClick(TObject * /*Sender*/)
  1169. {
  1170. TPoint PopupPoint = ShellIconsButton->ClientToScreen(TPoint(0, ShellIconsButton->Height));
  1171. IconsPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
  1175. {
  1176. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SHORTCUT, (SelectedSession->Name)),
  1177. qtConfirmation, qaYes | qaNo, HELP_CREATE_SHORTCUT) == qaYes)
  1178. {
  1179. assert(SelectedSession);
  1180. CreateDesktopShortCut(SelectedSession->Name, Application->ExeName,
  1181. FORMAT("\"%s\" /UploadIfAny", (SelectedSession->Name)),
  1182. FMTLOAD(SHORTCUT_INFO_TIP, (SelectedSession->Name, SelectedSession->InfoTip)));
  1183. }
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
  1187. {
  1188. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
  1189. qtConfirmation, qaYes | qaNo, HELP_CREATE_SENDTO) == qaYes)
  1190. {
  1191. assert(SelectedSession);
  1192. CreateDesktopShortCut(FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->Name)),
  1193. Application->ExeName,
  1194. FORMAT("\"%s\" /Upload", (SelectedSession->Name)), "",
  1195. CSIDL_SENDTO);
  1196. }
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TLoginDialog::SessionListViewCustomDrawItem(
  1200. TCustomListView *Sender, TListItem *Item, TCustomDrawState /*State*/,
  1201. bool &DefaultDraw)
  1202. {
  1203. TSessionData * Data = (TSessionData *)Item->Data;
  1204. TFontStyles Styles = Sender->Canvas->Font->Style;
  1205. if (Data->Special) Styles = Styles /*< fsItalic*/ << fsBold << fsUnderline;
  1206. else Styles = Styles /*>> fsItalic*/ >> fsBold >> fsUnderline;
  1207. Sender->Canvas->Font->Style = Styles;
  1208. DefaultDraw = true;
  1209. }
  1210. //---------------------------------------------------------------------------
  1211. void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
  1212. {
  1213. CheckForUpdates(false);
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TLoginDialog::SetOptions(int value)
  1217. {
  1218. if (Options != value)
  1219. {
  1220. FOptions = value;
  1221. UpdateControls();
  1222. }
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
  1226. {
  1227. TPoint PopupPoint = LanguagesButton->ClientToScreen(TPoint(0, LanguagesButton->Height));
  1228. delete FLanguagesPopupMenu;
  1229. FLanguagesPopupMenu = new TPopupMenu(this);
  1230. TMenuItem * Item;
  1231. TStrings * Locales = GUIConfiguration->Locales;
  1232. for (int Index = 0; Index < Locales->Count; Index++)
  1233. {
  1234. Item = new TMenuItem(FLanguagesPopupMenu);
  1235. FLanguagesPopupMenu->Items->Add(Item);
  1236. Item->Caption = Locales->Strings[Index];
  1237. Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
  1238. Item->OnClick = LocaleClick;
  1239. Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
  1240. GUIConfiguration->Locale);
  1241. }
  1242. Item = new TMenuItem(FLanguagesPopupMenu);
  1243. FLanguagesPopupMenu->Items->Add(Item);
  1244. Item->Caption = "-";
  1245. Item = new TMenuItem(FLanguagesPopupMenu);
  1246. FLanguagesPopupMenu->Items->Add(Item);
  1247. Item->Caption = LoadStr(LOGIN_GET_LOCALES);
  1248. Item->OnClick = LocaleGetClick;
  1249. FLanguagesPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  1250. }
  1251. //---------------------------------------------------------------------------
  1252. void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
  1253. {
  1254. assert(Sender);
  1255. GUIConfiguration->Locale =
  1256. static_cast<LCID>(dynamic_cast<TMenuItem*>(Sender)->Tag);
  1257. LanguagesButton->SetFocus();
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TLoginDialog::LocaleGetClick(TObject * /*Sender*/)
  1261. {
  1262. OpenBrowser(LoadStr(LOCALES_URL));
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall TLoginDialog::AuthGSSAPICheckClick(TObject * /*Sender*/)
  1266. {
  1267. if (!NoUpdate)
  1268. {
  1269. UpdateControls();
  1270. if (AuthGSSAPICheck->Checked && !Configuration->GSSAPIInstalled)
  1271. {
  1272. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED));
  1273. }
  1274. }
  1275. }
  1276. //---------------------------------------------------------------------------
  1277. void __fastcall TLoginDialog::HelpButtonClick(TObject * /*Sender*/)
  1278. {
  1279. FormHelp(this, PageControl->ActivePage);
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. void __fastcall TLoginDialog::FormKeyDown(TObject * /*Sender*/, WORD &Key,
  1283. TShiftState /*Shift*/)
  1284. {
  1285. // we don't have "cancel" button, so we must handle "esc" ourselves
  1286. if (Key == VK_ESCAPE)
  1287. {
  1288. ModalResult = mrCancel;
  1289. }
  1290. }
  1291. //---------------------------------------------------------------------------
  1292. void __fastcall TLoginDialog::VerifyKey(AnsiString FileName, bool TypeOnly)
  1293. {
  1294. if (!FileName.Trim().IsEmpty())
  1295. {
  1296. TKeyType Type = KeyType(FileName);
  1297. AnsiString Message;
  1298. switch (Type)
  1299. {
  1300. case ktOpenSSH:
  1301. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "OpenSSH SSH-2"));
  1302. break;
  1303. case ktSSHCom:
  1304. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "ssh.com SSH-2"));
  1305. break;
  1306. case ktSSH1:
  1307. case ktSSH2:
  1308. // on file select do not check for SSH version as user may
  1309. // intend to change it only after he/she selects key file
  1310. if (!TypeOnly)
  1311. {
  1312. TSessionData * Data = SessionData;
  1313. if ((Type == ktSSH1) !=
  1314. ((Data->SshProt == ssh1only) || (Data->SshProt == ssh1)))
  1315. {
  1316. Message = FMTLOAD(KEY_TYPE_DIFFERENT_SSH,
  1317. (FileName, (Type == ktSSH1 ? "SSH-1" : "PuTTY SSH-2")));
  1318. }
  1319. }
  1320. break;
  1321. default:
  1322. assert(false);
  1323. // fallthru
  1324. case ktUnopenable:
  1325. case ktUnknown:
  1326. Message = FMTLOAD(KEY_TYPE_UNKNOWN, (FileName));
  1327. break;
  1328. }
  1329. if (!Message.IsEmpty())
  1330. {
  1331. if (MessageDialog(Message, qtWarning, qaIgnore | qaAbort,
  1332. HELP_LOGIN_KEY_TYPE) == qaAbort)
  1333. {
  1334. Abort();
  1335. }
  1336. }
  1337. }
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TLoginDialog::PrivateKeyEditAfterDialog(TObject * /*Sender*/,
  1341. AnsiString & Name, bool & /*Action*/)
  1342. {
  1343. if (Name != PrivateKeyEdit->Text)
  1344. {
  1345. VerifyKey(Name, true);
  1346. }
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TLoginDialog::FormCloseQuery(TObject * /*Sender*/,
  1350. bool & /*CanClose*/)
  1351. {
  1352. if (ModalResult != mrCancel)
  1353. {
  1354. VerifyKey(SessionData->PublicKeyFile, false);
  1355. }
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. void __fastcall TLoginDialog::ColorButtonClick(TObject * /*Sender*/)
  1359. {
  1360. ColorDefaultItem->Checked = (FColor == 0);
  1361. PickColorItem->Checked = (FColor != 0);
  1362. PickColorItem->ImageIndex = (FColor != 0 ? 0 : -1);
  1363. ColorImageList->BkColor = FColor;
  1364. TPoint PopupPoint = ColorButton->ClientToScreen(TPoint(0, ColorButton->Height));
  1365. ColorPopupMenu->Popup(PopupPoint.x, PopupPoint.y);
  1366. }
  1367. //---------------------------------------------------------------------------
  1368. void __fastcall TLoginDialog::ColorDefaultItemClick(TObject * /*Sender*/)
  1369. {
  1370. FColor = (TColor)0;
  1371. }
  1372. //---------------------------------------------------------------------------
  1373. void __fastcall TLoginDialog::PickColorItemClick(TObject * /*Sender*/)
  1374. {
  1375. TColorDialog * Dialog = new TColorDialog(this);
  1376. try
  1377. {
  1378. Dialog->Options = Dialog->Options << cdFullOpen;
  1379. Dialog->Color = (FColor != 0 ? FColor : clSkyBlue);
  1380. if (Dialog->Execute())
  1381. {
  1382. FColor = Dialog->Color;
  1383. }
  1384. }
  1385. __finally
  1386. {
  1387. delete Dialog;
  1388. }
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. void __fastcall TLoginDialog::SessionListViewEditing(TObject * /*Sender*/,
  1392. TListItem * Item, bool & AllowEdit)
  1393. {
  1394. TSessionData * Data = static_cast<TSessionData *>(Item->Data);
  1395. AllowEdit = !Data->Special;
  1396. if (AllowEdit)
  1397. {
  1398. LoginButton->Default = false;
  1399. }
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TLoginDialog::RenameSessionActionExecute(TObject * /*Sender*/)
  1403. {
  1404. if (SessionListView->Selected != NULL)
  1405. {
  1406. SessionListView->Selected->EditCaption();
  1407. }
  1408. }
  1409. //---------------------------------------------------------------------------
  1410. void __fastcall TLoginDialog::SessionListViewEdited(TObject * /*Sender*/,
  1411. TListItem * Item, AnsiString & S)
  1412. {
  1413. if (Item->Caption != S)
  1414. {
  1415. SaveSessionInputValidate(S);
  1416. TSessionData * Session = SelectedSession;
  1417. // remove from storage
  1418. Session->Remove();
  1419. int PrevCount = StoredSessions->Count;
  1420. TSessionData * NewSession = StoredSessions->NewSession(S, Session);
  1421. StoredSessions->Save();
  1422. SessionListView->Selected->Data = NewSession;
  1423. // if we overwrite editing session, remove the original item
  1424. // (we must preserve the one we are editing)
  1425. if (PrevCount == StoredSessions->Count)
  1426. {
  1427. int Index = StoredSessions->IndexOf(NewSession);
  1428. TListItem * OldItem = SessionListView->Items->Item[Index];
  1429. assert(OldItem->Data == NewSession);
  1430. OldItem->Delete();
  1431. }
  1432. // should always be true as the name have changed
  1433. if (Session != NewSession)
  1434. {
  1435. StoredSessions->Remove(Session);
  1436. }
  1437. // sort items to the same order as in the container
  1438. SessionListView->AlphaSort();
  1439. SessionData = NewSession;
  1440. }
  1441. }
  1442. //---------------------------------------------------------------------------
  1443. void __fastcall TLoginDialog::SessionListViewCompare(TObject * /*Sender*/,
  1444. TListItem * Item1, TListItem * Item2, int /*Data*/, int & Compare)
  1445. {
  1446. int Index1 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item1->Data));
  1447. int Index2 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item2->Data));
  1448. if (Index1 < Index2)
  1449. {
  1450. Compare = -1;
  1451. }
  1452. else if (Index1 > Index2)
  1453. {
  1454. Compare = 1;
  1455. }
  1456. else
  1457. {
  1458. Compare = 0;
  1459. }
  1460. }
  1461. //---------------------------------------------------------------------------