-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProfileEditForm.cs
374 lines (342 loc) · 22.6 KB
/
ProfileEditForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
* Copyright 2015-2016 yoshikixxxx.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
using System;
using System.IO;
using System.Windows.Forms;
using Poderosa.ConnectionParam;
using Poderosa.Terminal;
using Poderosa.UI;
using Poderosa.Util;
using Poderosa.View;
namespace Contrib.ConnectProfile {
/// <summary>
/// プロファイルの追加/編集フォームクラス
/// </summary>
public partial class ProfileEditForm : Form {
private ConnectProfileStruct _result = new ConnectProfileStruct();
private RenderProfile _renderProfile;
private bool _Initialized = false;
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="prof">プロファイル</param>
public ProfileEditForm(ConnectProfileStruct prof) {
InitializeComponent();
InitializeComponentValue();
// オブジェクト初期値設定
if (prof == null) {
// 新規作成時はデフォルト値を設定
_protocolBox.SelectedItem = ConnectionMethod.SSH2;
_portBox.Value = ConnectProfileStruct.DEFAULT_SSH_PORT;
_authTypeBox.SelectedItem = AuthType.Password;
_charCodeBox.SelectedItem = EncodingType.UTF8;
_newLineTypeBox.SelectedItem = NewLine.CR;
_telnetNewLineCheck.Checked = true;
_terminalTypeBox.SelectedItem = TerminalType.XTerm;
_commandSendIntBox.Value = ConnectProfileStruct.DEFAULT_CMD_SEND_INTERVAL;
_promptRecvTimeoutBox.Value = ConnectProfileStruct.DEFAULT_PROMPT_RECV_TIMEOUT;
// コンソール表示オブジェクトはターミナルオプション値を反映
_renderProfile = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
} else {
// 編集時は対象プロファイル値を設定
_hostNameBox.Text = prof.HostName;
_protocolBox.SelectedItem = prof.Protocol;
_portBox.Value = prof.Port;
_authTypeBox.SelectedItem = prof.AuthType;
_keyFileBox.Text = prof.KeyFile;
_userNameBox.Text = prof.UserName;
_passwordBox.Text = prof.Password;
_autoLoginCheck.Checked = prof.AutoLogin;
_loginPromptBox.Text = prof.LoginPrompt;
_passwordPromptBox.Text = prof.PasswordPrompt;
_execCommandBox.Text = prof.ExecCommand;
_suUserNameBox.Text = prof.SUUserName;
_suPasswordBox.Text = prof.SUPassword;
if (prof.SUType == _suTypeRadio1.Text) _suTypeRadio1.Checked = true;
else if (prof.SUType == _suTypeRadio2.Text) _suTypeRadio2.Checked = true;
else if (prof.SUType == _suTypeRadio3.Text) _suTypeRadio3.Checked = true;
else if (prof.SUType == _suTypeRadio4.Text) _suTypeRadio4.Checked = true;
else if (prof.SUType == _suTypeRadio5.Text) _suTypeRadio5.Checked = true;
else if (prof.SUType == _suTypeRadio6.Text) _suTypeRadio6.Checked = true;
_charCodeBox.SelectedItem = prof.CharCode;
_newLineTypeBox.SelectedItem = prof.NewLine;
_telnetNewLineCheck.Checked = prof.TelnetNewLine;
_terminalTypeBox.SelectedItem = prof.TerminalType;
_commandSendIntBox.Value = prof.CommandSendInterval;
_promptRecvTimeoutBox.Value = prof.PromptRecvTimeout;
_profileItemColorButton.SelectedColor = prof.ProfileItemColor;
_descriptionBox.Text = prof.Description;
_renderProfile = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
_renderProfile = prof.RenderProfile;
}
_Initialized = true;
EnableValidControls(this, EventArgs.Empty);
}
/// <summary>
/// オブジェクトの各値を設定
/// </summary>
private void InitializeComponentValue() {
// テキスト
this.Text = ConnectProfilePlugin.Strings.GetString("Caption.AddProfile");
this._accountGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._accountGroup");
this._authTypeLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._authTypeLabel");
this._autoLoginCheck.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._autoLoginCheck");
this._autoLoginGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._autoLoginGroup");
this._basicGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._basicGroup");
this._cancelButton.Text = ConnectProfilePlugin.Strings.GetString("Form.Common._cancelButton");
this._charCodeLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._charCodeLabel");
this._commandSendIntLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._commandSendIntLabel");
this._descriptionLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._descriptionLabel");
this._etcGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._etcGroup");
this._execCommandLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._execCommandLabel");
this._hostNameLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._hostNameLabel");
this._keyFileLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._keyFileLabel");
this._loginPromptLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._loginPromptLabel");
this._newLineTypeLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._newLineTypeLabel");
this._okButton.Text = ConnectProfilePlugin.Strings.GetString("Form.Common._okButton");
this._openKeyFileButton.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._openKeyFileButton");
this._passwordLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._passwordLabel");
this._passwordPromptLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._passwordPromptLabel");
this._portLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._portLabel");
this._profileItemColorLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._profileItemColorLabel");
this._promptRecvTimeoutLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._promptRecvTimeoutLabel");
this._protocolLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._protocolLabel");
this._sshGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._sshGroup");
this._showPasswordCheck.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._showPasswordCheck");
this._suGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suGroup");
this._suPasswordLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suPasswordLabel");
this._suTypeLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeLabel");
this._suTypeRadio1.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio1");
this._suTypeRadio2.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio2");
this._suTypeRadio3.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio3");
this._suTypeRadio4.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio4");
this._suTypeRadio5.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio5");
this._suTypeRadio6.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio6");
this._suUserNameLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suUserNameLabel");
this._telnetNewLineCheck.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._telnetNewLineCheck");
this._editRenderButton.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._editRenderButton");
this._editRenderLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._editRenderLabel");
this._terminalGroup.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._terminalGroup");
this._terminalTypeLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._terminalTypeLabel");
this._userNameLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._userNameLabel");
// コンボボックス
this._charCodeBox.Items.AddRange(EnumListItem<EncodingType>.GetListItems());
this._authTypeBox.Items.AddRange(EnumListItem<AuthType>.GetListItems());
this._newLineTypeBox.Items.AddRange(EnumListItem<NewLine>.GetListItems());
this._terminalTypeBox.Items.AddRange(EnumListItem<TerminalType>.GetListItems());
this._protocolBox.Items.AddRange(new object[] {
new ListItem<ConnectionMethod>(ConnectionMethod.Telnet,ConnectionMethod.Telnet.ToString()),
new ListItem<ConnectionMethod>(ConnectionMethod.SSH1, ConnectionMethod.SSH1.ToString()),
new ListItem<ConnectionMethod>(ConnectionMethod.SSH2, ConnectionMethod.SSH2.ToString()),
});
}
/// <summary>
/// オブジェクトを有効/無効化(オブジェクト共通)
/// </summary>
private void EnableValidControls(object sender, EventArgs e) {
if (_Initialized == true) {
ConnectionMethod protocol = ((ListItem<ConnectionMethod>)_protocolBox.SelectedItem).Value;
EnumListItem<AuthType> authTypeItem = (EnumListItem<AuthType>)_authTypeBox.SelectedItem;
EnumListItem<NewLine> newLineItem = (EnumListItem<NewLine>)_newLineTypeBox.SelectedItem;
bool autologin = (_autoLoginCheck.Checked);
bool ssh = (protocol == ConnectionMethod.SSH1 || protocol == ConnectionMethod.SSH2);
bool pubkey = (authTypeItem != null && authTypeItem.Value == AuthType.PublicKey);
bool kbd = (authTypeItem != null && authTypeItem.Value == AuthType.KeyboardInteractive);
bool newline = (newLineItem != null && newLineItem.Value == NewLine.CRLF);
bool su = (_suUserNameBox.Text != "");
// ユーザ名/パスワード
_userNameBox.Enabled = (ssh || autologin);
_passwordBox.Enabled = autologin;
// 自動ログイン用プロンプト
_loginPromptBox.Enabled = (autologin && !ssh);
_passwordPromptBox.Enabled = ((autologin && !ssh) || (autologin && su));
// 秘密鍵ファイル
_authTypeBox.Enabled = ssh;
_keyFileBox.Enabled = (ssh && pubkey);
_openKeyFileButton.Enabled = (ssh && pubkey);
// 実行コマンド
_execCommandBox.Enabled = autologin;
// SU
_suUserNameBox.Enabled = autologin;
_suPasswordBox.Enabled = (su && autologin);
_suTypeRadio1.Enabled = (su && autologin);
_suTypeRadio2.Enabled = (su && autologin);
_suTypeRadio3.Enabled = (su && autologin);
_suTypeRadio4.Enabled = (su && autologin);
_suTypeRadio5.Enabled = (su && autologin);
_suTypeRadio6.Enabled = (su && autologin);
// TelnetNewLine
_telnetNewLineCheck.Enabled = (!ssh && newline);
// コマンド発行間隔/プロンプト受信タイムアウト
_commandSendIntBox.Enabled = autologin;
_promptRecvTimeoutBox.Enabled = autologin;
// ポート番号
//_portBox.Value = ssh ? ConnectProfileStruct.DEFAULT_SSH_PORT : ConnectProfileStruct.DEFAULT_TELNET_PORT;
}
}
/// <summary>
/// 説明文を表示(オブジェクト共通)
/// </summary>
private void ShowHint(object sender, EventArgs e) {
if (sender == _hostNameBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._hostNameBox");
} else if (sender == _protocolBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._protocolBox");
} else if (sender == _portBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._portBox");
} else if (sender == _authTypeBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._authTypeBox");
} else if (sender == _keyFileBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._keyFileBox");
} else if (sender == _userNameBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._userNameBox");
} else if (sender == _passwordBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._passwordBox");
} else if (sender == _autoLoginCheck) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._autoLoginCheck");
} else if (sender == _loginPromptBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._loginPromptBox");
} else if (sender == _passwordPromptBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._passwordPromptBox");
} else if (sender == _execCommandBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._execCommandBox");
} else if (sender == _suUserNameBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._suUserNameBox");
} else if (sender == _suPasswordBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._suPasswordBox");
} else if ((sender == _suTypeRadio1) || (sender == _suTypeRadio2) || (sender == _suTypeRadio3) || (sender == _suTypeRadio4) || (sender == _suTypeRadio5) || (sender == _suTypeRadio6)) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._suTypeRadio");
} else if (sender == _charCodeBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._charCodeBox");
} else if (sender == _newLineTypeBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._newLineTypeBox");
} else if (sender == _telnetNewLineCheck) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._telnetNewLineCheck");
} else if (sender == _terminalTypeBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._terminalTypeBox");
} else if (sender == _editRenderButton) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._editRenderButton");
} else if (sender == _commandSendIntBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._commandSendIntBox");
} else if (sender == _promptRecvTimeoutBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._promptRecvTimeoutBox");
} else if (sender == _profileItemColorButton) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._profileItemColorButton");
} else if (sender == _descriptionBox) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._descriptionBox");
} else if (sender == _showPasswordCheck) {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint._showPasswordCheck");
} else {
this._hintLabel.Text = ConnectProfilePlugin.Strings.GetString("Form.AddProfile.Hint.None");
}
}
/// <summary>
/// OKボタンクリックイベント
/// </summary>
private void _okButton_Click(object sender, EventArgs e) {
this.DialogResult = DialogResult.None;
// 入力チェック
try {
// 初期化
_result.HostName = _hostNameBox.Text;
_result.Protocol = ((ListItem<ConnectionMethod>)_protocolBox.SelectedItem).Value;
_result.Port = (int)_portBox.Value;
_result.AuthType = ((EnumListItem<AuthType>)_authTypeBox.SelectedItem).Value;
_result.KeyFile = "";
_result.UserName = "";
_result.Password = _passwordBox.Text;
_result.AutoLogin = _autoLoginCheck.Checked;
_result.LoginPrompt = "";
_result.PasswordPrompt = "";
_result.ExecCommand = "";
_result.SUUserName = "";
_result.SUPassword = "";
_result.SUType = "";
_result.CharCode = ((EnumListItem<EncodingType>)_charCodeBox.SelectedItem).Value;
_result.NewLine = ((EnumListItem<NewLine>)_newLineTypeBox.SelectedItem).Value;
_result.TelnetNewLine = _telnetNewLineCheck.Checked;
_result.TerminalType = ((EnumListItem<TerminalType>)_terminalTypeBox.SelectedItem).Value;
_result.CommandSendInterval = (int)_commandSendIntBox.Value;
_result.PromptRecvTimeout = (int)_promptRecvTimeoutBox.Value;
_result.ProfileItemColor = _profileItemColorButton.SelectedColor;
_result.Description = _descriptionBox.Text;
_result.RenderProfile = _renderProfile;
// ホスト名
if (_hostNameBox.Text == "") throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyHostName"));
// 秘密鍵ファイル
if (_keyFileBox.Enabled == true) {
if (_keyFileBox.Text != "") {
if (File.Exists(_keyFileBox.Text)) _result.KeyFile = _keyFileBox.Text;
else throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.KeyFileNotExist"));
} else {
throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyKeyFile"));
}
}
// ユーザ名
if (_userNameBox.Enabled == true) {
if (_userNameBox.Text != "") _result.UserName = _userNameBox.Text;
else throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyUserName"));
}
// ログインプロンプト
if (_loginPromptBox.Enabled == true) {
if (_loginPromptBox.Text != "") _result.LoginPrompt = _loginPromptBox.Text;
else throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyLoginPrompt"));
}
// パスワードプロンプト
if (_passwordPromptBox.Enabled == true) _result.PasswordPrompt = _passwordPromptBox.Text;
// 実行コマンド
if ((_execCommandBox.Enabled == true) && _execCommandBox.Text != "") _result.ExecCommand = _execCommandBox.Text;
// SU
if ((_suUserNameBox.Enabled == true) && _suUserNameBox.Text != "") {
_result.SUUserName = _suUserNameBox.Text;
_result.SUPassword = _suPasswordBox.Text;
if (_suTypeRadio1.Checked == true) _result.SUType = _suTypeRadio1.Text;
else if (_suTypeRadio2.Checked == true) _result.SUType = _suTypeRadio2.Text;
else if (_suTypeRadio3.Checked == true) _result.SUType = _suTypeRadio3.Text;
else if (_suTypeRadio4.Checked == true) _result.SUType = _suTypeRadio4.Text;
else if (_suTypeRadio5.Checked == true) _result.SUType = _suTypeRadio5.Text;
else if (_suTypeRadio6.Checked == true) _result.SUType = _suTypeRadio6.Text;
else throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.SUTypeNotSelect"));
}
this.DialogResult = DialogResult.OK;
} catch (Exception ex) {
ConnectProfilePlugin.MessageBoxInvoke(ex.Message, MessageBoxIcon.Warning);
}
}
/// <summary>
/// 秘密鍵ファイル選択ボタンクリックイベント
/// </summary>
private void _openKeyFileButton_Click(object sender, EventArgs e) {
string fn = TerminalUtil.SelectPrivateKeyFileByDialog(this);
if (fn != null) _keyFileBox.Text = fn;
_keyFileBox.Focus();
}
/// <summary>
/// 表示オプションボタンクリックイベント
/// </summary>
private void _editRenderButton_Click(object sender, EventArgs e) {
EditRenderProfile dlg = new EditRenderProfile(_renderProfile);
if (dlg.ShowDialog() == DialogResult.OK) {
_renderProfile = dlg.Result;
}
}
/// <summary>
/// パスワード表示チェックボックスクリックイベント
/// </summary>
private void _showPasswordCheck_CheckedChanged(object sender, EventArgs e) {
if (_showPasswordCheck.Checked == true) _passwordBox.UseSystemPasswordChar = _suPasswordBox.UseSystemPasswordChar = false;
else _passwordBox.UseSystemPasswordChar = _suPasswordBox.UseSystemPasswordChar = true;
}
/// <summary>
/// 設定済みプロファイル
/// </summary>
public ConnectProfileStruct ResultProfile {
get { return _result; }
}
}
}