Login.cpp 48 KB

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