Login.cpp 64 KB

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