SSHShortcutLoginDialog.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:22k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: SSHShortcutLoginDialog.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.Collections;
  9. using System.Collections.Specialized;
  10. using System.ComponentModel;
  11. using System.Windows.Forms;
  12. using System.IO;
  13. using Granados.SSHC;
  14. using Poderosa.Toolkit;
  15. using Poderosa.Connection;
  16. using Poderosa.ConnectionParam;
  17. using EnumDescAttributeT = Poderosa.Toolkit.EnumDescAttribute;
  18. using Poderosa.Terminal;
  19. using Poderosa.Communication;
  20. using Poderosa.SSH;
  21. namespace Poderosa.Forms
  22. {
  23. internal class SSHShortcutLoginDialog : System.Windows.Forms.Form, ISocketWithTimeoutClient
  24.     {
  25.         #region fields
  26.         private SSHTerminalParam _terminalParam;
  27. private ConnectionTag _result;
  28. private SocketWithTimeout _connector;
  29. private string _errorMessage;
  30. private TextBox _privateKeyBox;
  31. private TextBox _passphraseBox;
  32. private Button _privateKeySelect;
  33. private System.Windows.Forms.Label _hostLabel;
  34. private System.Windows.Forms.Label _hostBox;
  35. private System.Windows.Forms.Label _methodLabel;
  36. private System.Windows.Forms.Label _methodBox;
  37. private System.Windows.Forms.Label _accountLabel;
  38. private System.Windows.Forms.Label _accountBox;
  39. private System.Windows.Forms.Label _authTypeLabel;
  40. private System.Windows.Forms.Label _authTypeBox;
  41. private System.Windows.Forms.Label _encodingLabel;
  42. private System.Windows.Forms.Label _encodingBox;
  43. private ComboBox _logFileBox;
  44. private Button _selectlogButton;
  45. private System.Windows.Forms.Button _cancelButton;
  46. private System.Windows.Forms.Button _loginButton;
  47. private System.Windows.Forms.Label _privateKeyLabel;
  48. private System.Windows.Forms.Label _passphraseLabel;
  49. private System.Windows.Forms.Label _logFileLabel;
  50. private ComboBox _logTypeBox;
  51. private System.Windows.Forms.Label _logTypeLabel;
  52.         #endregion
  53. private System.ComponentModel.Container components = null;
  54. public SSHShortcutLoginDialog(SSHTerminalParam param)
  55. {
  56. //
  57. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  58. //
  59. InitializeComponent();
  60. this._privateKeyLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._privateKeyLabel");
  61. this._passphraseLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._passphraseLabel");
  62. this._logFileLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._logFileLabel");
  63. this._hostLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._hostLabel");
  64. this._methodLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._methodLabel");
  65. this._accountLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._accountLabel");
  66. this._authTypeLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._authTypeLabel");
  67. this._encodingLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._encodingLabel");
  68. this._logTypeLabel.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog._logTypeLabel");
  69. this.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog.Text");
  70. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  71. this._loginButton.Text = GApp.Strings.GetString("Common.OK");
  72. //
  73. // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
  74. //
  75. _terminalParam = param;
  76. InitUI();
  77. }
  78. protected override void Dispose( bool disposing )
  79. {
  80. if( disposing )
  81. {
  82. if(components != null)
  83. {
  84. components.Dispose();
  85. }
  86. }
  87. base.Dispose( disposing );
  88. }
  89. public ConnectionTag Result {
  90. get {
  91. return _result;
  92. }
  93. }
  94. #region Windows Form Designer generated code
  95. /// <summary>
  96. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  97. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  98. /// this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  99. /// </summary>
  100. private void InitializeComponent()
  101. {
  102. this._privateKeyBox = new TextBox();
  103. this._privateKeyLabel = new System.Windows.Forms.Label();
  104. this._passphraseBox = new TextBox();
  105. this._passphraseLabel = new System.Windows.Forms.Label();
  106. this._privateKeySelect = new Button();
  107. this._logFileBox = new ComboBox();
  108. this._logFileLabel = new System.Windows.Forms.Label();
  109. this._selectlogButton = new Button();
  110. this._cancelButton = new System.Windows.Forms.Button();
  111. this._loginButton = new System.Windows.Forms.Button();
  112. this._hostLabel = new System.Windows.Forms.Label();
  113. this._hostBox = new System.Windows.Forms.Label();
  114. this._methodLabel = new System.Windows.Forms.Label();
  115. this._methodBox = new System.Windows.Forms.Label();
  116. this._accountLabel = new System.Windows.Forms.Label();
  117. this._accountBox = new System.Windows.Forms.Label();
  118. this._authTypeLabel = new System.Windows.Forms.Label();
  119. this._authTypeBox = new System.Windows.Forms.Label();
  120. this._encodingLabel = new System.Windows.Forms.Label();
  121. this._encodingBox = new System.Windows.Forms.Label();
  122. this._logTypeBox = new ComboBox();
  123. this._logTypeLabel = new System.Windows.Forms.Label();
  124. this.SuspendLayout();
  125. // 
  126. // _privateKeyBox
  127. // 
  128. this._privateKeyBox.Location = new System.Drawing.Point(104, 128);
  129. this._privateKeyBox.Name = "_privateKeyBox";
  130. this._privateKeyBox.Size = new System.Drawing.Size(160, 19);
  131. this._privateKeyBox.TabIndex = 3;
  132. this._privateKeyBox.Text = "";
  133. // 
  134. // _privateKeyLabel
  135. // 
  136. this._privateKeyLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  137. this._privateKeyLabel.Location = new System.Drawing.Point(8, 128);
  138. this._privateKeyLabel.Name = "_privateKeyLabel";
  139. this._privateKeyLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  140. this._privateKeyLabel.Size = new System.Drawing.Size(72, 16);
  141. this._privateKeyLabel.TabIndex = 2;
  142. this._privateKeyLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  143. // 
  144. // _passphraseBox
  145. // 
  146. this._passphraseBox.Location = new System.Drawing.Point(104, 104);
  147. this._passphraseBox.Name = "_passphraseBox";
  148. this._passphraseBox.PasswordChar = '*';
  149. this._passphraseBox.Size = new System.Drawing.Size(184, 19);
  150. this._passphraseBox.TabIndex = 1;
  151. this._passphraseBox.Text = "";
  152. // 
  153. // _passphraseLabel
  154. // 
  155. this._passphraseLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  156. this._passphraseLabel.Location = new System.Drawing.Point(8, 104);
  157. this._passphraseLabel.Name = "_passphraseLabel";
  158. this._passphraseLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  159. this._passphraseLabel.Size = new System.Drawing.Size(80, 16);
  160. this._passphraseLabel.TabIndex = 0;
  161. this._passphraseLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  162. // 
  163. // _privateKeySelect
  164. // 
  165. this._privateKeySelect.FlatStyle = System.Windows.Forms.FlatStyle.System;
  166. this._privateKeySelect.ImageIndex = 0;
  167. this._privateKeySelect.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  168. this._privateKeySelect.Location = new System.Drawing.Point(272, 128);
  169. this._privateKeySelect.Name = "_privateKeySelect";
  170. this._privateKeySelect.RightToLeft = System.Windows.Forms.RightToLeft.No;
  171. this._privateKeySelect.Size = new System.Drawing.Size(19, 19);
  172. this._privateKeySelect.TabIndex = 4;
  173. this._privateKeySelect.Text = "...";
  174. this._privateKeySelect.Click += new System.EventHandler(this.OnOpenPrivateKey);
  175. // 
  176. // _logFileBox
  177. // 
  178. this._logFileBox.Location = new System.Drawing.Point(104, 176);
  179. this._logFileBox.Name = "_logFileBox";
  180. this._logFileBox.Size = new System.Drawing.Size(160, 20);
  181. this._logFileBox.TabIndex = 8;
  182. // 
  183. // _logFileLabel
  184. // 
  185. this._logFileLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  186. this._logFileLabel.Location = new System.Drawing.Point(8, 176);
  187. this._logFileLabel.Name = "_logFileLabel";
  188. this._logFileLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  189. this._logFileLabel.Size = new System.Drawing.Size(88, 16);
  190. this._logFileLabel.TabIndex = 7;
  191. this._logFileLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  192. // 
  193. // _selectlogButton
  194. // 
  195. this._selectlogButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
  196. this._selectlogButton.ImageIndex = 0;
  197. this._selectlogButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  198. this._selectlogButton.Location = new System.Drawing.Point(272, 176);
  199. this._selectlogButton.Name = "_selectlogButton";
  200. this._selectlogButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  201. this._selectlogButton.Size = new System.Drawing.Size(19, 19);
  202. this._selectlogButton.TabIndex = 9;
  203. this._selectlogButton.Text = "...";
  204. this._selectlogButton.Click += new System.EventHandler(this.SelectLog);
  205. // 
  206. // _cancelButton
  207. // 
  208. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  209. this._cancelButton.ImageIndex = 0;
  210. this._cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  211. this._cancelButton.Location = new System.Drawing.Point(216, 208);
  212. this._cancelButton.Name = "_cancelButton";
  213. this._cancelButton.FlatStyle = FlatStyle.System;
  214. this._cancelButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  215. this._cancelButton.Size = new System.Drawing.Size(72, 25);
  216. this._cancelButton.TabIndex = 11;
  217. // 
  218. // _loginButton
  219. // 
  220. this._loginButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  221. this._loginButton.ImageIndex = 0;
  222. this._loginButton.FlatStyle = FlatStyle.System;
  223. this._loginButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  224. this._loginButton.Location = new System.Drawing.Point(128, 208);
  225. this._loginButton.Name = "_loginButton";
  226. this._loginButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  227. this._loginButton.Size = new System.Drawing.Size(72, 25);
  228. this._loginButton.TabIndex = 10;
  229. this._loginButton.Click += new System.EventHandler(this.OnOK);
  230. // 
  231. // _hostLabel
  232. // 
  233. this._hostLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  234. this._hostLabel.Location = new System.Drawing.Point(8, 8);
  235. this._hostLabel.Name = "_hostLabel";
  236. this._hostLabel.Size = new System.Drawing.Size(80, 16);
  237. this._hostLabel.TabIndex = 0;
  238. this._hostLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  239. // 
  240. // _hostBox
  241. // 
  242. this._hostBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  243. this._hostBox.Location = new System.Drawing.Point(104, 8);
  244. this._hostBox.Name = "_hostBox";
  245. this._hostBox.Size = new System.Drawing.Size(144, 16);
  246. this._hostBox.TabIndex = 35;
  247. this._hostBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  248. // 
  249. // _methodLabel
  250. // 
  251. this._methodLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  252. this._methodLabel.Location = new System.Drawing.Point(8, 24);
  253. this._methodLabel.Name = "_methodLabel";
  254. this._methodLabel.Size = new System.Drawing.Size(80, 16);
  255. this._methodLabel.TabIndex = 0;
  256. this._methodLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  257. // 
  258. // _methodBox
  259. // 
  260. this._methodBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  261. this._methodBox.Location = new System.Drawing.Point(104, 24);
  262. this._methodBox.Name = "_methodBox";
  263. this._methodBox.Size = new System.Drawing.Size(144, 16);
  264. this._methodBox.TabIndex = 0;
  265. this._methodBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  266. // 
  267. // _accountLabel
  268. // 
  269. this._accountLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  270. this._accountLabel.Location = new System.Drawing.Point(8, 40);
  271. this._accountLabel.Name = "_accountLabel";
  272. this._accountLabel.Size = new System.Drawing.Size(80, 16);
  273. this._accountLabel.TabIndex = 0;
  274. this._accountLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  275. // 
  276. // _accountBox
  277. // 
  278. this._accountBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  279. this._accountBox.Location = new System.Drawing.Point(104, 40);
  280. this._accountBox.Name = "_accountBox";
  281. this._accountBox.Size = new System.Drawing.Size(144, 16);
  282. this._accountBox.TabIndex = 0;
  283. this._accountBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  284. // 
  285. // _authTypeLabel
  286. // 
  287. this._authTypeLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  288. this._authTypeLabel.Location = new System.Drawing.Point(8, 56);
  289. this._authTypeLabel.Name = "_authTypeLabel";
  290. this._authTypeLabel.Size = new System.Drawing.Size(80, 16);
  291. this._authTypeLabel.TabIndex = 0;
  292. this._authTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  293. // 
  294. // _authTypeBox
  295. // 
  296. this._authTypeBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  297. this._authTypeBox.Location = new System.Drawing.Point(104, 56);
  298. this._authTypeBox.Name = "_authTypeBox";
  299. this._authTypeBox.Size = new System.Drawing.Size(144, 16);
  300. this._authTypeBox.TabIndex = 0;
  301. this._authTypeBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  302. // 
  303. // _encodingLabel
  304. // 
  305. this._encodingLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  306. this._encodingLabel.Location = new System.Drawing.Point(8, 72);
  307. this._encodingLabel.Name = "_encodingLabel";
  308. this._encodingLabel.Size = new System.Drawing.Size(80, 16);
  309. this._encodingLabel.TabIndex = 0;
  310. this._encodingLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  311. // 
  312. // _encodingBox
  313. // 
  314. this._encodingBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  315. this._encodingBox.Location = new System.Drawing.Point(104, 72);
  316. this._encodingBox.Name = "_encodingBox";
  317. this._encodingBox.Size = new System.Drawing.Size(144, 16);
  318. this._encodingBox.TabIndex = 0;
  319. this._encodingBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  320. // 
  321. // _logTypeBox
  322. // 
  323. this._logTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  324. this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  325. this._logTypeBox.Location = new System.Drawing.Point(104, 152);
  326. this._logTypeBox.Name = "_logTypeBox";
  327. this._logTypeBox.Size = new System.Drawing.Size(96, 20);
  328. this._logTypeBox.TabIndex = 6;
  329. this._logTypeBox.SelectionChangeCommitted += new System.EventHandler(this.OnLogTypeChanged);
  330. // 
  331. // _logTypeLabel
  332. // 
  333. this._logTypeLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  334. this._logTypeLabel.Location = new System.Drawing.Point(8, 152);
  335. this._logTypeLabel.Name = "_logTypeLabel";
  336. this._logTypeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  337. this._logTypeLabel.Size = new System.Drawing.Size(80, 16);
  338. this._logTypeLabel.TabIndex = 5;
  339. this._logTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  340. // 
  341. // SSHShortcutLoginDialog
  342. // 
  343. this.AcceptButton = this._loginButton;
  344. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  345. this.CancelButton = this._cancelButton;
  346. this.ClientSize = new System.Drawing.Size(298, 239);
  347. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  348.   this._logTypeBox,
  349.   this._logTypeLabel,
  350.   this._cancelButton,
  351.   this._loginButton,
  352.   this._logFileBox,
  353.   this._logFileLabel,
  354.   this._selectlogButton,
  355.   this._hostLabel,
  356.   this._hostBox,
  357.   this._methodLabel,
  358.   this._methodBox,
  359.   this._accountLabel,
  360.   this._accountBox,
  361.   this._authTypeLabel,
  362.   this._authTypeBox,
  363.   this._encodingLabel,
  364.   this._encodingBox,
  365.   this._privateKeyBox,
  366.   this._privateKeyLabel,
  367.   this._passphraseBox,
  368.   this._passphraseLabel,
  369.   this._privateKeySelect});
  370. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  371. this.MaximizeBox = false;
  372. this.MinimizeBox = false;
  373. this.Name = "SSHShortcutLoginDialog";
  374. this.ShowInTaskbar = false;
  375. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  376. this.ResumeLayout(false);
  377. }
  378. #endregion
  379. private void InitUI() {
  380. _hostBox.Text = _terminalParam.Host;
  381. _methodBox.Text = _terminalParam.Method.ToString();
  382. if(_terminalParam.Port!=22) _methodBox.Text += String.Format(GApp.Strings.GetString("Caption.SSHShortcutLoginDialog.NotStandardPort"), _terminalParam.Port);
  383. _accountBox.Text = _terminalParam.Account;
  384. _authTypeBox.Text = EnumDescAttributeT.For(typeof(AuthType)).GetDescription(_terminalParam.AuthType);
  385. _encodingBox.Text = EnumDescAttributeT.For(typeof(EncodingType)).GetDescription(_terminalParam.EncodingProfile.Type);
  386. if(_terminalParam.AuthType==AuthType.Password) {
  387. _privateKeyBox.Enabled = false;
  388. _privateKeySelect.Enabled = false;
  389. }
  390. else if(_terminalParam.AuthType==AuthType.PublicKey) {
  391. _privateKeyBox.Text = _terminalParam.IdentityFile;
  392. }
  393. else if(_terminalParam.AuthType==AuthType.KeyboardInteractive) {
  394. _privateKeyBox.Enabled = false;
  395. _privateKeySelect.Enabled = false;
  396. _passphraseBox.Enabled = false;
  397. }
  398. _passphraseBox.Text = _terminalParam.Passphrase;
  399. StringCollection c = GApp.ConnectionHistory.LogPaths;
  400. foreach(string p in c) _logFileBox.Items.Add(p);
  401. if(GApp.Options.DefaultLogType!=LogType.None) {
  402. _logTypeBox.SelectedIndex = (int)GApp.Options.DefaultLogType;
  403. string t = GUtil.CreateLogFileName(_terminalParam.Host);
  404. _logFileBox.Items.Add(t);
  405. _logFileBox.Text = t;
  406. }
  407. else
  408. _logTypeBox.SelectedIndex = 0;
  409. AdjustUI();
  410. }
  411. private void AdjustUI() {
  412. _passphraseBox.Enabled = _terminalParam.AuthType!=AuthType.KeyboardInteractive;
  413. bool e = _logTypeBox.SelectedIndex!=(int)LogType.None;
  414. _logFileBox.Enabled = e;
  415. _selectlogButton.Enabled = e;
  416. }
  417. private void OnOK(object sender, System.EventArgs e) {
  418. this.DialogResult = DialogResult.None;
  419. TCPTerminalParam param = ValidateContent();
  420. if(param==null) return;  //僷儔儊乕僞偵岆傝偑偁傟偽懄扙弌
  421. _loginButton.Enabled = false;
  422. _cancelButton.Enabled = false;
  423. this.Cursor = Cursors.WaitCursor;
  424. this.Text = GApp.Strings.GetString("Caption.SSHShortcutLoginDialog.Connecting");
  425. HostKeyCheckCallback checker = new HostKeyCheckCallback(new HostKeyChecker(this, (SSHTerminalParam)param).CheckHostKeyCallback);
  426. _connector = CommunicationUtil.StartNewConnection(this, param, _passphraseBox.Text, checker);
  427. if(_connector==null) ClearConnectingState();
  428. }
  429. private SSHTerminalParam ValidateContent() {
  430. SSHTerminalParam p = _terminalParam;
  431. string msg = null;
  432. try {
  433. p.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
  434. if(p.LogType!=LogType.None) {
  435. p.LogPath = _logFileBox.Text;
  436. LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this);
  437. if(r==LogFileCheckResult.Cancel || r==LogFileCheckResult.Error) return null;
  438. p.LogAppend = (r==LogFileCheckResult.Append);
  439. }
  440. if(p.AuthType==AuthType.PublicKey) {
  441. if(!File.Exists(_privateKeyBox.Text))
  442. msg = GApp.Strings.GetString("Message.SSHShortcutLoginDialog.KeyFileNotExist");
  443. else
  444. p.IdentityFile = _privateKeyBox.Text;
  445. }
  446. if(msg!=null) {
  447. GUtil.Warning(this, msg);
  448. return null;
  449. }
  450. else
  451. return p;
  452. }
  453. catch(Exception ex) {
  454. GUtil.Warning(this, ex.Message);
  455. return null;
  456. }
  457. }
  458. private void OnOpenPrivateKey(object sender, System.EventArgs e) {
  459. string fn = GCUtil.SelectPrivateKeyFileByDialog(this);
  460. if(fn!=null) _privateKeyBox.Text = fn;
  461. }
  462. private void SelectLog(object sender, System.EventArgs e) {
  463. string fn = GCUtil.SelectLogFileByDialog(this);
  464. if(fn!=null) _logFileBox.Text = fn;
  465. }
  466. private void OnLogTypeChanged(object sender, System.EventArgs args) {
  467. AdjustUI();
  468. }
  469. private void ShowError(string msg) {
  470. GUtil.Warning(this, msg, GApp.Strings.GetString("Message.SSHShortcutLoginDialog.ConnectionError"));
  471. }
  472. protected override bool ProcessDialogKey(Keys key) {
  473. if(_connector!=null && key==(Keys.Control | Keys.C)) {
  474. _connector.Interrupt();
  475. ClearConnectingState();
  476. return true;
  477. }
  478. else
  479. return base.ProcessDialogKey(key);
  480. }
  481. private void ClearConnectingState() {
  482. _loginButton.Enabled = true;
  483. _cancelButton.Enabled = true;
  484. this.Cursor = Cursors.Default;
  485. this.Text = GApp.Strings.GetString("Form.SSHShortcutLoginDialog.Text");
  486. _connector = null;
  487. }
  488. protected override void WndProc(ref Message msg) {
  489. base.WndProc(ref msg);
  490. if(msg.Msg==GConst.WMG_ASYNCCONNECT) {
  491. if(msg.LParam.ToInt32()==1) {
  492. this.DialogResult = DialogResult.OK;
  493. Close();
  494. }
  495. else {
  496. ClearConnectingState();
  497. ShowError(_errorMessage);
  498. }
  499. }
  500. }
  501. public void SuccessfullyExit(object result) {
  502. _result = (ConnectionTag)result;
  503. //_result.SetServerInfo(((TCPTerminalParam)_result.Param).Host, swt.IPAddress);
  504. Win32.SendMessage(this.Handle, GConst.WMG_ASYNCCONNECT, IntPtr.Zero, new IntPtr(1));
  505. }
  506. public void ConnectionFailed(string message) {
  507. _errorMessage = message;
  508. Win32.SendMessage(this.Handle, GConst.WMG_ASYNCCONNECT, IntPtr.Zero, IntPtr.Zero);
  509. }
  510. public void CancelTimer() {
  511. }
  512. public IWin32Window GetWindow() {
  513. return this;
  514. }
  515. }
  516. }