Login.cpp 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  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. EnableControl(ShellIconsButton, SessionListView->Selected);
  773. // ssh/authentication sheet
  774. AuthSheet->Enabled = SshProtocol && Advanced;
  775. EnableControl(AuthTISCheck, !SshProt2onlyButton->Checked);
  776. EnableControl(AuthKICheck, !SshProt1onlyButton->Checked);
  777. EnableControl(AuthKIPasswordCheck,
  778. (AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
  779. (AuthKICheck->Enabled && AuthKICheck->Checked));
  780. EnableControl(AuthGSSAPICheck, !SshProt1onlyButton->Checked);
  781. EnableControl(GSSAPIFwdTGTCheck,
  782. AuthGSSAPICheck->Enabled && AuthGSSAPICheck->Checked);
  783. EnableControl(GSSAPIServerRealmEdit,
  784. AuthGSSAPICheck->Enabled && AuthGSSAPICheck->Checked);
  785. EnableControl(GSSAPIServerRealmLabel, GSSAPIServerRealmEdit->Enabled);
  786. // ssh sheet
  787. AdvancedSheet->Enabled = SshProtocol;
  788. EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
  789. EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
  790. CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
  791. EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
  792. // ssh/kex sheet
  793. KexSheet->Enabled = SshProtocol && Advanced && !SshProt1onlyButton->Checked &&
  794. (BugRekey2Combo->ItemIndex != 2);
  795. EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
  796. EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
  797. KexListBox->ItemIndex < KexListBox->Items->Count-1);
  798. // ssh/bugs sheet
  799. BugsSheet->Enabled = SshProtocol && Advanced;
  800. EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
  801. EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
  802. EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
  803. EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
  804. EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
  805. EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
  806. EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
  807. EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
  808. EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
  809. EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
  810. EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
  811. EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
  812. EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
  813. EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
  814. EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
  815. EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
  816. // environment/scp/shell sheet
  817. ScpSheet->Enabled = Advanced && InternalSshProtocol;
  818. // connection/proxy sheet
  819. ProxySheet->Enabled = Advanced;
  820. EnableControl(ProxyTelnetButton, SshProtocol);
  821. bool Proxy = !ProxyNoneButton->Checked &&
  822. (!ProxyTelnetButton->Checked || ProxyTelnetButton->Enabled);
  823. EnableControl(ProxyHostEdit, Proxy);
  824. EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
  825. EnableControl(ProxyPortEdit, Proxy);
  826. EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
  827. EnableControl(ProxyUsernameEdit, Proxy &&
  828. // FZAPI does not support username for SOCKS4
  829. ((ProxySocks4Button->Checked && SshProtocol) ||
  830. (ProxySocks5Button->Checked) ||
  831. (ProxyHTTPButton->Checked) ||
  832. (ProxyTelnetButton->Checked &&
  833. AnsiContainsText(ProxyTelnetCommandEdit->Text, "%user"))));
  834. EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
  835. EnableControl(ProxyPasswordEdit, Proxy &&
  836. (!ProxySocks4Button->Checked &&
  837. (!ProxyTelnetButton->Checked ||
  838. AnsiContainsText(ProxyTelnetCommandEdit->Text, "%pass"))));
  839. EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
  840. EnableControl(ProxySettingsGroup, Proxy && SshProtocol);
  841. EnableControl(ProxyTelnetCommandEdit, Proxy && ProxyTelnetButton->Checked);
  842. EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
  843. // environment/directories sheet
  844. DirectoriesSheet->Enabled = !ExternalProtocol;
  845. DirectoryOptionsGroup->Visible = Advanced;
  846. EnableControl(CacheDirectoryChangesCheck,
  847. ((FSProtocol != fsSCPonly) || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
  848. EnableControl(PreserveDirectoryChangesCheck,
  849. CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
  850. DirectoriesSheet->Enabled);
  851. EnableControl(ResolveSymlinksCheck, (FSProtocol != fsFTP) && DirectoriesSheet->Enabled);
  852. // environment sheet
  853. EnvironmentSheet->Enabled = !ExternalProtocol;
  854. EnableControl(DSTModeGroup, (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  855. UnixEnvironmentButton->Visible = !ShowAdvancedLoginOptionsCheck->Checked;
  856. WindowsEnvironmentButton->Visible = !ShowAdvancedLoginOptionsCheck->Checked;
  857. RecycleBinGroup->Visible = ShowAdvancedLoginOptionsCheck->Checked;
  858. EnableControl(OverwrittenToRecycleBinCheck, (FSProtocol != fsSCPonly) &&
  859. (FSProtocol != fsFTP) && EnvironmentSheet->Enabled);
  860. EnableControl(RecycleBinPathEdit,
  861. (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
  862. (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
  863. EnvironmentSheet->Enabled);
  864. EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
  865. EnvironmentSheet->Enabled);
  866. // environment/sftp sheet
  867. SftpSheet->Enabled = Advanced && ((FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP));
  868. // tunnel sheet
  869. TunnelSheet->Enabled = Advanced && InternalSshProtocol;
  870. EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
  871. EnableControl(TunnelOptionsGroup, TunnelCheck->Enabled && TunnelSessionGroup->Enabled);
  872. // preferences sheet
  873. GeneralSheet->Enabled = FLAGSET(Options, loPreferences);
  874. AboutButton->Visible = (Options & loAbout);
  875. LanguagesButton->Visible = (Options & loLanguage);
  876. ShellIconsButton->Visible = (Options & loTools);
  877. ToolsMenuButton->Visible = (Options & loTools);
  878. LoggingFrame->EnableLogWindow = (Options & loLogWindow);
  879. UpdateNavigationTree();
  880. }
  881. __finally
  882. {
  883. NoUpdate--;
  884. }
  885. }
  886. }
  887. //---------------------------------------------------------------------------
  888. void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
  889. {
  890. if (!NoUpdate) UpdateControls();
  891. }
  892. //---------------------------------------------------------------------------
  893. void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
  894. {
  895. if (!FInitialized)
  896. {
  897. FInitialized = true;
  898. Init();
  899. TSessionData * Data = GetSessionData();
  900. if (Data == FSessionData)
  901. {
  902. LoadSession(Data);
  903. }
  904. else
  905. {
  906. Default();
  907. }
  908. }
  909. if (FLocaleChanging)
  910. {
  911. Init();
  912. LoadSession(FSessionData);
  913. ChangePage(FSavedTab);
  914. SessionListView->ItemIndex = FSavedSession;
  915. LoadConfiguration();
  916. }
  917. }
  918. //---------------------------------------------------------------------------
  919. void __fastcall TLoginDialog::SessionListViewSelectItem(TObject * /*Sender*/,
  920. TListItem * /*Item*/, bool /*Selected*/)
  921. {
  922. UpdateControls();
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
  926. {
  927. FSessionData->Assign(value);
  928. FSessionData->Special = false;
  929. FEditingSessionData = value;
  930. LoadSession(FSessionData);
  931. }
  932. //---------------------------------------------------------------------------
  933. TSessionData * __fastcall TLoginDialog::GetSessionData()
  934. {
  935. if (PageControl->ActivePage == SessionListSheet)
  936. {
  937. return SelectedSession;
  938. }
  939. else
  940. {
  941. SaveSession(FSessionData);
  942. return FSessionData;
  943. }
  944. }
  945. //---------------------------------------------------------------------------
  946. void __fastcall TLoginDialog::SetStoredSessions(TStoredSessionList * value)
  947. {
  948. if (FStoredSessions != value)
  949. {
  950. FStoredSessions = value;
  951. LoadSessions();
  952. }
  953. }
  954. //---------------------------------------------------------------------------
  955. void __fastcall TLoginDialog::LoadSessionItem(TListItem * Item)
  956. {
  957. Item->Data = StoredSessions->AtObject(Item->Index);
  958. Item->Caption = ((TSessionData*)Item->Data)->Name;
  959. }
  960. //---------------------------------------------------------------------------
  961. void __fastcall TLoginDialog::SessionListViewDblClick(TObject * /*Sender*/)
  962. {
  963. if (SelectedSession)
  964. {
  965. if (SelectedSession->CanLogin) ModalResult = mrOk;
  966. else
  967. {
  968. SessionData = SelectedSession;
  969. EditSession();
  970. }
  971. }
  972. }
  973. //---------------------------------------------------------------------------
  974. void __fastcall TLoginDialog::SetSelectedSession(TSessionData * value)
  975. {
  976. if (value)
  977. {
  978. int Index = StoredSessions->IndexOf(value);
  979. if (Index >= 0)
  980. {
  981. TListItem *Item = SessionListView->Items->Item[Index];
  982. Item->Focused = true;
  983. Item->Selected = true;
  984. Item->MakeVisible(false);
  985. }
  986. }
  987. else
  988. {
  989. SessionListView->Selected = NULL;
  990. }
  991. }
  992. //---------------------------------------------------------------------------
  993. TSessionData * __fastcall TLoginDialog::GetSelectedSession()
  994. {
  995. if (SessionListView->Selected)
  996. return (TSessionData *)SessionListView->Selected->Data;
  997. else
  998. return NULL;
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TLoginDialog::SessionListViewInfoTip(TObject * /*Sender*/,
  1002. TListItem * Item, AnsiString & InfoTip)
  1003. {
  1004. InfoTip = ((TSessionData*)Item->Data)->InfoTip;
  1005. }
  1006. //---------------------------------------------------------------------------
  1007. void __fastcall TLoginDialog::SessionListViewKeyDown(TObject * /*Sender*/,
  1008. WORD & Key, TShiftState /*Shift*/)
  1009. {
  1010. if (!SessionListView->IsEditing())
  1011. {
  1012. if (Key == VK_DELETE)
  1013. {
  1014. DeleteSessionAction->Execute();
  1015. Key = 0;
  1016. }
  1017. else if (Key == VK_F2)
  1018. {
  1019. RenameSessionAction->Execute();
  1020. Key = 0;
  1021. }
  1022. }
  1023. }
  1024. //---------------------------------------------------------------------------
  1025. void __fastcall TLoginDialog::EditSession()
  1026. {
  1027. ChangePage(BasicSheet);
  1028. HostNameEdit->SetFocus();
  1029. }
  1030. //---------------------------------------------------------------------------
  1031. void __fastcall TLoginDialog::EditSessionActionExecute(TObject * /*Sender*/)
  1032. {
  1033. if (SelectedSession)
  1034. {
  1035. SessionData = SelectedSession;
  1036. EditSession();
  1037. }
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
  1041. {
  1042. AnsiString SessionName;
  1043. SaveSession(FSessionData);
  1044. if (FSessionData->Password.IsEmpty() ||
  1045. Configuration->DisablePasswordStoring ||
  1046. (MessageDialog(LoadStr(SAVE_PASSWORD), qtWarning, qaOK | qaCancel,
  1047. HELP_SESSION_SAVE_PASSWORD) == qaOK))
  1048. {
  1049. SessionName = DoSaveSessionDialog(FSessionData->SessionName, FEditingSessionData);
  1050. if (!SessionName.IsEmpty())
  1051. {
  1052. TListItem * Item;
  1053. TSessionData *NewSession =
  1054. StoredSessions->NewSession(SessionName, FSessionData);
  1055. StoredSessions->Save();
  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. Handled = true;
  1155. if (!LoginButton->Default && !SessionListView->IsEditing())
  1156. {
  1157. LoginButton->Default = true;
  1158. }
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. bool __fastcall TLoginDialog::Execute()
  1162. {
  1163. LoadConfiguration();
  1164. bool Result = (ShowModal() == mrOk);
  1165. if (Result)
  1166. {
  1167. SaveConfiguration();
  1168. }
  1169. return Result;
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TLoginDialog::SaveConfiguration()
  1173. {
  1174. assert(CustomWinConfiguration);
  1175. CustomWinConfiguration->BeginUpdate();
  1176. try
  1177. {
  1178. LoggingFrame->SaveConfiguration();
  1179. GeneralSettingsFrame->SaveConfiguration();
  1180. CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
  1181. }
  1182. __finally
  1183. {
  1184. CustomWinConfiguration->EndUpdate();
  1185. }
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TLoginDialog::LoadConfiguration()
  1189. {
  1190. assert(CustomWinConfiguration);
  1191. LoggingFrame->LoadConfiguration();
  1192. GeneralSettingsFrame->LoadConfiguration();
  1193. ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
  1194. UpdateControls();
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
  1198. {
  1199. ShowPreferencesDialog();
  1200. UpdateControls();
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TLoginDialog::ShowPreferencesDialog()
  1204. {
  1205. DoPreferencesDialog(pmLogin);
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
  1209. {
  1210. Default();
  1211. EditSession();
  1212. }
  1213. //---------------------------------------------------------------------------
  1214. void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
  1215. TTreeNode *Node)
  1216. {
  1217. if (NoUpdate == 0)
  1218. {
  1219. TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
  1220. // should happen only while loading language
  1221. // (UpdateNavigationTree may not be called yet)
  1222. if (Tab != NULL)
  1223. {
  1224. PageControl->ActivePage = Tab;
  1225. // reshow the accelerators, etc
  1226. ResetSystemSettings(this);
  1227. }
  1228. }
  1229. }
  1230. //---------------------------------------------------------------------------
  1231. void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
  1232. {
  1233. PageControl->ActivePage = Tab;
  1234. PageControlChange(PageControl);
  1235. }
  1236. //---------------------------------------------------------------------------
  1237. void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
  1238. {
  1239. bool Found = false;
  1240. if (PageControl->ActivePage)
  1241. {
  1242. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1243. {
  1244. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1245. reinterpret_cast<int>(PageControl->ActivePage))
  1246. {
  1247. NavigationTree->Items->Item[Index]->Selected = true;
  1248. Found = true;
  1249. }
  1250. }
  1251. }
  1252. if (!Found)
  1253. {
  1254. assert(false);
  1255. ChangePage(BasicSheet);
  1256. }
  1257. else
  1258. {
  1259. DataChange(Sender);
  1260. }
  1261. }
  1262. //---------------------------------------------------------------------------
  1263. void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
  1264. {
  1265. if (Message.CharCode == VK_TAB)
  1266. {
  1267. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1268. if (Shift.Contains(ssCtrl))
  1269. {
  1270. TTreeNode * Node = NavigationTree->Selected;
  1271. if (!Shift.Contains(ssShift))
  1272. {
  1273. Node = Node->GetNext();
  1274. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1275. }
  1276. else
  1277. {
  1278. if (Node->GetPrev()) Node = Node->GetPrev();
  1279. else
  1280. while (Node->GetNext()) Node = Node->GetNext();
  1281. }
  1282. Node->Selected = True;
  1283. Message.Result = 1;
  1284. return;
  1285. }
  1286. }
  1287. TForm::Dispatch(&Message);
  1288. }
  1289. //---------------------------------------------------------------------------
  1290. void __fastcall TLoginDialog::WMHelp(TWMHelp & Message)
  1291. {
  1292. assert(Message.HelpInfo != NULL);
  1293. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1294. {
  1295. // invoke help for active page (not for whole form), regardless of focus
  1296. // (e.g. even if focus is on control outside pagecontrol)
  1297. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1298. }
  1299. TForm::Dispatch(&Message);
  1300. }
  1301. //---------------------------------------------------------------------------
  1302. void __fastcall TLoginDialog::Dispatch(void *Message)
  1303. {
  1304. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1305. assert(M);
  1306. if (M->Msg == CM_DIALOGKEY)
  1307. {
  1308. CMDialogKey(*((TWMKeyDown *)Message));
  1309. }
  1310. else if (M->Msg == WM_LOCALE_CHANGE)
  1311. {
  1312. if (M->WParam == 0)
  1313. {
  1314. SaveConfiguration();
  1315. SaveSession(FSessionData);
  1316. FSavedTab = PageControl->ActivePage;
  1317. FSavedSession = SessionListView->ItemIndex;
  1318. assert(FSystemSettings);
  1319. RevokeSystemSettings(this, FSystemSettings);
  1320. FSystemSettings = NULL;
  1321. ShowTabs(true);
  1322. Hide();
  1323. }
  1324. else
  1325. {
  1326. FLocaleChanging = true;
  1327. try
  1328. {
  1329. Show();
  1330. }
  1331. __finally
  1332. {
  1333. FLocaleChanging = false;
  1334. }
  1335. }
  1336. }
  1337. else if (M->Msg == WM_HELP)
  1338. {
  1339. WMHelp(*((TWMHelp *)Message));
  1340. }
  1341. else
  1342. {
  1343. TForm::Dispatch(Message);
  1344. }
  1345. }
  1346. //---------------------------------------------------------------------------
  1347. void __fastcall TLoginDialog::AlgListBoxStartDrag(TObject * Sender,
  1348. TDragObject *& /*DragObject*/)
  1349. {
  1350. FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
  1351. FAlgDragDest = -1;
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TLoginDialog::AlgListBoxDragOver(TObject * Sender,
  1355. TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
  1356. {
  1357. if (Source == Sender)
  1358. {
  1359. Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
  1360. }
  1361. }
  1362. //---------------------------------------------------------------------------
  1363. void __fastcall TLoginDialog::AlgListBoxDragDrop(TObject * Sender,
  1364. TObject *Source, int X, int Y)
  1365. {
  1366. if (Source == Sender)
  1367. {
  1368. TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
  1369. if (AllowAlgDrag(AlgListBox, X, Y))
  1370. {
  1371. AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
  1372. }
  1373. }
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
  1377. {
  1378. AlgMove(CipherListBox, CipherListBox->ItemIndex,
  1379. CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. void __fastcall TLoginDialog::KexButtonClick(TObject *Sender)
  1383. {
  1384. AlgMove(KexListBox, KexListBox->ItemIndex,
  1385. KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
  1386. }
  1387. //---------------------------------------------------------------------------
  1388. bool __fastcall TLoginDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
  1389. {
  1390. FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
  1391. return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
  1392. }
  1393. //---------------------------------------------------------------------------
  1394. void __fastcall TLoginDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
  1395. {
  1396. if (Source >= 0 && Source < AlgListBox->Items->Count &&
  1397. Dest >= 0 && Dest < AlgListBox->Items->Count)
  1398. {
  1399. AlgListBox->Items->Move(Source, Dest);
  1400. AlgListBox->ItemIndex = Dest;
  1401. AlgListBox->SetFocus();
  1402. }
  1403. UpdateControls();
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
  1407. TObject * /*Sender*/)
  1408. {
  1409. if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
  1410. qaOK | qaCancel, HELP_SESSION_SAVE_DEFAULT) == qaOK)
  1411. {
  1412. SaveSession(FSessionData);
  1413. StoredSessions->DefaultSettings = FSessionData;
  1414. }
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
  1418. {
  1419. MenuPopup(ToolsPopupMenu, ToolsMenuButton);
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TLoginDialog::ShellIconsButtonClick(TObject * /*Sender*/)
  1423. {
  1424. MenuPopup(IconsPopupMenu, ShellIconsButton);
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
  1428. {
  1429. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SHORTCUT, (SelectedSession->Name)),
  1430. qtConfirmation, qaYes | qaNo, HELP_CREATE_SHORTCUT) == qaYes)
  1431. {
  1432. assert(SelectedSession);
  1433. CreateDesktopShortCut(SelectedSession->Name, Application->ExeName,
  1434. FORMAT("\"%s\" /UploadIfAny", (SelectedSession->Name)),
  1435. FMTLOAD(SHORTCUT_INFO_TIP, (SelectedSession->Name, SelectedSession->InfoTip)));
  1436. }
  1437. }
  1438. //---------------------------------------------------------------------------
  1439. void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
  1440. {
  1441. if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
  1442. qtConfirmation, qaYes | qaNo, HELP_CREATE_SENDTO) == qaYes)
  1443. {
  1444. assert(SelectedSession);
  1445. CreateDesktopShortCut(FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->Name)),
  1446. Application->ExeName,
  1447. FORMAT("\"%s\" /Upload", (SelectedSession->Name)), "",
  1448. CSIDL_SENDTO);
  1449. }
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TLoginDialog::SessionListViewCustomDrawItem(
  1453. TCustomListView *Sender, TListItem *Item, TCustomDrawState /*State*/,
  1454. bool &DefaultDraw)
  1455. {
  1456. TSessionData * Data = (TSessionData *)Item->Data;
  1457. TFontStyles Styles = Sender->Canvas->Font->Style;
  1458. if (Data->Special) Styles = Styles /*< fsItalic*/ << fsBold << fsUnderline;
  1459. else Styles = Styles /*>> fsItalic*/ >> fsBold >> fsUnderline;
  1460. Sender->Canvas->Font->Style = Styles;
  1461. DefaultDraw = true;
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
  1465. {
  1466. CheckForUpdates(false);
  1467. }
  1468. //---------------------------------------------------------------------------
  1469. void __fastcall TLoginDialog::SetOptions(int value)
  1470. {
  1471. if (Options != value)
  1472. {
  1473. FOptions = value;
  1474. UpdateControls();
  1475. }
  1476. }
  1477. //---------------------------------------------------------------------------
  1478. void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
  1479. {
  1480. delete FLanguagesPopupMenu;
  1481. FLanguagesPopupMenu = new TPopupMenu(this);
  1482. TMenuItem * Item;
  1483. TStrings * Locales = GUIConfiguration->Locales;
  1484. for (int Index = 0; Index < Locales->Count; Index++)
  1485. {
  1486. Item = new TMenuItem(FLanguagesPopupMenu);
  1487. FLanguagesPopupMenu->Items->Add(Item);
  1488. Item->Caption = Locales->Strings[Index];
  1489. Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
  1490. Item->OnClick = LocaleClick;
  1491. Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
  1492. GUIConfiguration->Locale);
  1493. }
  1494. Item = new TMenuItem(FLanguagesPopupMenu);
  1495. FLanguagesPopupMenu->Items->Add(Item);
  1496. Item->Caption = "-";
  1497. Item = new TMenuItem(FLanguagesPopupMenu);
  1498. FLanguagesPopupMenu->Items->Add(Item);
  1499. Item->Caption = LoadStr(LOGIN_GET_LOCALES);
  1500. Item->OnClick = LocaleGetClick;
  1501. MenuPopup(FLanguagesPopupMenu, LanguagesButton);
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
  1505. {
  1506. assert(Sender);
  1507. GUIConfiguration->Locale =
  1508. static_cast<LCID>(dynamic_cast<TComponent*>(Sender)->Tag);
  1509. LanguagesButton->SetFocus();
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. void __fastcall TLoginDialog::LocaleGetClick(TObject * /*Sender*/)
  1513. {
  1514. OpenBrowser(LoadStr(LOCALES_URL));
  1515. }
  1516. //---------------------------------------------------------------------------
  1517. void __fastcall TLoginDialog::AuthGSSAPICheckClick(TObject * /*Sender*/)
  1518. {
  1519. if (!NoUpdate)
  1520. {
  1521. UpdateControls();
  1522. if (AuthGSSAPICheck->Checked && !Configuration->GSSAPIInstalled)
  1523. {
  1524. throw Exception(LoadStr(GSSAPI_NOT_INSTALLED));
  1525. }
  1526. }
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TLoginDialog::HelpButtonClick(TObject * /*Sender*/)
  1530. {
  1531. FormHelp(this);
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. void __fastcall TLoginDialog::FormKeyDown(TObject * /*Sender*/, WORD &Key,
  1535. TShiftState /*Shift*/)
  1536. {
  1537. // we don't have "cancel" button, so we must handle "esc" ourselves
  1538. if (Key == VK_ESCAPE)
  1539. {
  1540. ModalResult = mrCancel;
  1541. }
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. void __fastcall TLoginDialog::VerifyKey(AnsiString FileName, bool TypeOnly)
  1545. {
  1546. if (!FileName.Trim().IsEmpty())
  1547. {
  1548. FileName = ExpandEnvironmentVariables(FileName);
  1549. TKeyType Type = KeyType(FileName);
  1550. AnsiString Message;
  1551. switch (Type)
  1552. {
  1553. case ktOpenSSH:
  1554. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "OpenSSH SSH-2"));
  1555. break;
  1556. case ktSSHCom:
  1557. Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, "ssh.com SSH-2"));
  1558. break;
  1559. case ktSSH1:
  1560. case ktSSH2:
  1561. // on file select do not check for SSH version as user may
  1562. // intend to change it only after he/she selects key file
  1563. if (!TypeOnly)
  1564. {
  1565. TSessionData * Data = SessionData;
  1566. if ((Type == ktSSH1) !=
  1567. ((Data->SshProt == ssh1only) || (Data->SshProt == ssh1)))
  1568. {
  1569. Message = FMTLOAD(KEY_TYPE_DIFFERENT_SSH,
  1570. (FileName, (Type == ktSSH1 ? "SSH-1" : "PuTTY SSH-2")));
  1571. }
  1572. }
  1573. break;
  1574. default:
  1575. assert(false);
  1576. // fallthru
  1577. case ktUnopenable:
  1578. case ktUnknown:
  1579. Message = FMTLOAD(KEY_TYPE_UNKNOWN, (FileName));
  1580. break;
  1581. }
  1582. if (!Message.IsEmpty())
  1583. {
  1584. if (MessageDialog(Message, qtWarning, qaIgnore | qaAbort,
  1585. HELP_LOGIN_KEY_TYPE) == qaAbort)
  1586. {
  1587. Abort();
  1588. }
  1589. }
  1590. }
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. void __fastcall TLoginDialog::PrivateKeyEditAfterDialog(TObject * Sender,
  1594. AnsiString & Name, bool & /*Action*/)
  1595. {
  1596. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1597. {
  1598. Name = FBeforeDialogPath;
  1599. }
  1600. TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
  1601. if (Name != Edit->Text)
  1602. {
  1603. VerifyKey(Name, true);
  1604. }
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TLoginDialog::FormCloseQuery(TObject * /*Sender*/,
  1608. bool & /*CanClose*/)
  1609. {
  1610. if (ModalResult != mrCancel)
  1611. {
  1612. VerifyKey(SessionData->PublicKeyFile, false);
  1613. // for tunnel key do not check SSH version as it is not configurable
  1614. VerifyKey(SessionData->TunnelPublicKeyFile, true);
  1615. }
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TLoginDialog::ColorButtonClick(TObject * /*Sender*/)
  1619. {
  1620. ColorDefaultItem->Checked = (FColor == 0);
  1621. PickColorItem->Checked = (FColor != 0);
  1622. PickColorItem->ImageIndex = (FColor != 0 ? 0 : -1);
  1623. ColorImageList->BkColor = FColor;
  1624. MenuPopup(ColorPopupMenu, ColorButton);
  1625. }
  1626. //---------------------------------------------------------------------------
  1627. void __fastcall TLoginDialog::ColorDefaultItemClick(TObject * /*Sender*/)
  1628. {
  1629. FColor = (TColor)0;
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. void __fastcall TLoginDialog::PickColorItemClick(TObject * /*Sender*/)
  1633. {
  1634. TColorDialog * Dialog = new TColorDialog(this);
  1635. try
  1636. {
  1637. Dialog->Options = Dialog->Options << cdFullOpen;
  1638. Dialog->Color = (FColor != 0 ? FColor : clSkyBlue);
  1639. if (Dialog->Execute())
  1640. {
  1641. FColor = Dialog->Color;
  1642. }
  1643. }
  1644. __finally
  1645. {
  1646. delete Dialog;
  1647. }
  1648. }
  1649. //---------------------------------------------------------------------------
  1650. void __fastcall TLoginDialog::SessionListViewEditing(TObject * /*Sender*/,
  1651. TListItem * Item, bool & AllowEdit)
  1652. {
  1653. TSessionData * Data = static_cast<TSessionData *>(Item->Data);
  1654. AllowEdit = !Data->Special;
  1655. if (AllowEdit)
  1656. {
  1657. LoginButton->Default = false;
  1658. }
  1659. }
  1660. //---------------------------------------------------------------------------
  1661. void __fastcall TLoginDialog::RenameSessionActionExecute(TObject * /*Sender*/)
  1662. {
  1663. if (SessionListView->Selected != NULL)
  1664. {
  1665. SessionListView->Selected->EditCaption();
  1666. }
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TLoginDialog::SessionListViewEdited(TObject * /*Sender*/,
  1670. TListItem * Item, AnsiString & S)
  1671. {
  1672. if (Item->Caption != S)
  1673. {
  1674. TSessionData * Session = SelectedSession;
  1675. SessionNameValidate(S, Session);
  1676. // remove from storage
  1677. Session->Remove();
  1678. int PrevCount = StoredSessions->Count;
  1679. TSessionData * NewSession = StoredSessions->NewSession(S, Session);
  1680. StoredSessions->Save();
  1681. // the session may be the same, if only letter case has changed
  1682. if (Session != NewSession)
  1683. {
  1684. SessionListView->Selected->Data = NewSession;
  1685. // if we overwrite editing session, remove the original item
  1686. // (we must preserve the one we are editing)
  1687. if (PrevCount == StoredSessions->Count)
  1688. {
  1689. int Index = StoredSessions->IndexOf(NewSession);
  1690. TListItem * OldItem = SessionListView->Items->Item[Index];
  1691. assert(OldItem->Data == NewSession);
  1692. OldItem->Delete();
  1693. }
  1694. StoredSessions->Remove(Session);
  1695. }
  1696. // sort items to the same order as in the container
  1697. SessionListView->AlphaSort();
  1698. SessionData = NewSession;
  1699. }
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. void __fastcall TLoginDialog::SessionListViewCompare(TObject * /*Sender*/,
  1703. TListItem * Item1, TListItem * Item2, int /*Data*/, int & Compare)
  1704. {
  1705. int Index1 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item1->Data));
  1706. int Index2 = StoredSessions->IndexOf(static_cast<TSessionData*>(Item2->Data));
  1707. if (Index1 < Index2)
  1708. {
  1709. Compare = -1;
  1710. }
  1711. else if (Index1 > Index2)
  1712. {
  1713. Compare = 1;
  1714. }
  1715. else
  1716. {
  1717. Compare = 0;
  1718. }
  1719. }
  1720. //---------------------------------------------------------------------------
  1721. void __fastcall TLoginDialog::UnixEnvironmentButtonClick(TObject * /*Sender*/)
  1722. {
  1723. EOLTypeLFButton->Checked = true;
  1724. DSTModeUnixCheck->Checked = true;
  1725. }
  1726. //---------------------------------------------------------------------------
  1727. void __fastcall TLoginDialog::WindowsEnvironmentButtonClick(
  1728. TObject * /*Sender*/)
  1729. {
  1730. EOLTypeCRLFButton->Checked = true;
  1731. DSTModeWinCheck->Checked = true;
  1732. }
  1733. //---------------------------------------------------------------------------
  1734. void __fastcall TLoginDialog::PathEditBeforeDialog(TObject * /*Sender*/,
  1735. AnsiString & Name, bool & /*Action*/)
  1736. {
  1737. FBeforeDialogPath = Name;
  1738. Name = ExpandEnvironmentVariables(Name);
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. int __fastcall TLoginDialog::FSProtocolToIndex(TFSProtocol FSProtocol,
  1742. bool & AllowScpFallback)
  1743. {
  1744. if (FSProtocol == fsSFTP)
  1745. {
  1746. AllowScpFallback = true;
  1747. bool Dummy;
  1748. return FSProtocolToIndex(fsSFTPonly, Dummy);
  1749. }
  1750. else
  1751. {
  1752. AllowScpFallback = false;
  1753. for (int Index = 0; Index < LENOF(FSOrder); Index++)
  1754. {
  1755. if ((FSOrder[Index] == FSProtocol) &&
  1756. (Index < TransferProtocolCombo->Items->Count))
  1757. {
  1758. return Index;
  1759. }
  1760. }
  1761. // SFTP is always present
  1762. return FSProtocolToIndex(fsSFTP, AllowScpFallback);
  1763. }
  1764. }
  1765. //---------------------------------------------------------------------------
  1766. TFSProtocol __fastcall TLoginDialog::IndexToFSProtocol(int Index, bool AllowScpFallback)
  1767. {
  1768. bool InBounds = (Index >= 0) && (Index < LENOF(FSOrder));
  1769. // can be temporary "unselected" while new language is being loaded
  1770. assert(InBounds || (Index == -1));
  1771. TFSProtocol Result = fsSFTP;
  1772. if (InBounds)
  1773. {
  1774. Result = FSOrder[Index];
  1775. if ((Result == fsSFTPonly) && AllowScpFallback)
  1776. {
  1777. Result = fsSFTP;
  1778. }
  1779. }
  1780. return Result;
  1781. }
  1782. //---------------------------------------------------------------------------
  1783. void __fastcall TLoginDialog::TransferProtocolComboChange(TObject * Sender)
  1784. {
  1785. if (!NoUpdate)
  1786. {
  1787. SavePing(FSessionData);
  1788. FFSProtocol = IndexToFSProtocol(
  1789. TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
  1790. LoadPing(FSessionData);
  1791. if (FFSProtocol == fsFTP)
  1792. {
  1793. if (PortNumberEdit->AsInteger == 22)
  1794. {
  1795. PortNumberEdit->AsInteger = 21;
  1796. }
  1797. }
  1798. else
  1799. {
  1800. if (PortNumberEdit->AsInteger == 21)
  1801. {
  1802. PortNumberEdit->AsInteger = 22;
  1803. }
  1804. }
  1805. }
  1806. DataChange(Sender);
  1807. }
  1808. //---------------------------------------------------------------------------
  1809. void __fastcall TLoginDialog::NavigationTreeCollapsing(
  1810. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1811. {
  1812. AllowCollapse = false;
  1813. }
  1814. //---------------------------------------------------------------------------