Login.cpp 46 KB

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