Skip to content

Commit 5b0567d

Browse files
committed
First prototype
1 parent 49bcced commit 5b0567d

16 files changed

+2052
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
.vs
3+
.packages
4+
bin
5+
obj
6+
*.sln

Keys/CreateKeyForm.cs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Xml.Linq;
7+
8+
namespace RishWinTools.Keys
9+
{
10+
public partial class CreateKeyForm : System.Windows.Forms.Form
11+
{
12+
private Label NameLabel;
13+
private TextBox NameInput;
14+
public string NameValue => NameInput.Text;
15+
private Label CommentLabel;
16+
private TextBox CommentInput;
17+
public string CommentValue => CommentInput.Text;
18+
private Button GenerateButton;
19+
20+
public CreateKeyForm()
21+
{
22+
// Window
23+
Name = "CreateKeyForm";
24+
Text = "Создание SSH ключа";
25+
AutoScaleDimensions = new SizeF(6F, 13F);
26+
AutoScaleMode = AutoScaleMode.Font;
27+
ClientSize = new Size(640, 0);
28+
StartPosition = FormStartPosition.CenterParent;
29+
30+
// NameLabel
31+
NameLabel = new Label();
32+
NameLabel.Name = "NameLabel";
33+
NameLabel.Text = "Имя ключа";
34+
NameLabel.AutoSize = true;
35+
NameLabel.Location = new Point(10, 20);
36+
Controls.Add(NameLabel);
37+
38+
// NameInput
39+
NameInput = new TextBox();
40+
NameInput.Name = "NameInput";
41+
NameInput.Text = "id_ed25519";
42+
NameInput.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
43+
NameInput.Size = new Size(ClientSize.Width - 20, 20);
44+
NameInput.Location = new Point(10, NameLabel.Bottom + 5);
45+
Controls.Add(NameInput);
46+
47+
// CommentLabel
48+
CommentLabel = new Label();
49+
CommentLabel.Name = "CommentLabel";
50+
CommentLabel.Text = "Комментарий к ключу";
51+
CommentLabel.AutoSize = true;
52+
CommentLabel.Location = new Point(10, NameInput.Bottom + 10);
53+
Controls.Add(CommentLabel);
54+
55+
// CommentInput
56+
CommentInput = new TextBox();
57+
CommentInput.Name = "CommentInput";
58+
CommentInput.Text = "Youre.Name";
59+
CommentInput.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
60+
CommentInput.Size = new Size(ClientSize.Width - 20, 20);
61+
CommentInput.Location = new Point(10, CommentLabel.Bottom + 5);
62+
Controls.Add(CommentInput);
63+
64+
// GenerateButton
65+
GenerateButton = new Button();
66+
GenerateButton.Name = "GenerateButton";
67+
GenerateButton.Text = "Сгенировать ключ";
68+
GenerateButton.AutoSize = true;
69+
GenerateButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
70+
GenerateButton.Location = new Point(10, CommentInput.Bottom + 10);
71+
GenerateButton.UseVisualStyleBackColor = true;
72+
GenerateButton.Click += OnGenerateButtonClick;
73+
Controls.Add(GenerateButton);
74+
75+
// Layout
76+
int FormHeight = 0;
77+
foreach (Control control in Controls)
78+
{
79+
int controlBottom = control.Bottom;
80+
if (controlBottom > FormHeight)
81+
{
82+
FormHeight = controlBottom;
83+
}
84+
}
85+
ClientSize = new Size(ClientSize.Width, FormHeight + 20);
86+
}
87+
88+
protected void OnGenerateButtonClick(object? sender, EventArgs e)
89+
{
90+
if (string.IsNullOrWhiteSpace(NameValue))
91+
{
92+
MessageBox.Show("Пожалуйста заполните поле Имя", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
93+
return;
94+
}
95+
if (string.IsNullOrWhiteSpace(CommentValue))
96+
{
97+
MessageBox.Show("Пожалуйста заполните поле Комментарий.", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
98+
return;
99+
}
100+
101+
if (KeysManager.GenerateKey(NameValue, CommentValue))
102+
{
103+
KeysManager.GetKeys(true);
104+
DialogResult = DialogResult.OK;
105+
Close();
106+
}
107+
else
108+
{
109+
DialogResult = DialogResult.None;
110+
}
111+
}
112+
}
113+
}

Keys/InsertKeyForm.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Xml.Linq;
7+
8+
namespace RishWinTools.Keys
9+
{
10+
public partial class InsertKeyForm : System.Windows.Forms.Form
11+
{
12+
private Label NameLabel;
13+
private TextBox NameInput;
14+
public string NameValue => NameInput.Text;
15+
private Label SecretKeyLabel;
16+
private TextBox SecretKeyInput;
17+
public string SecretKeyValue => SecretKeyInput.Text;
18+
private Button InsertButton;
19+
20+
public InsertKeyForm()
21+
{
22+
// Window
23+
Name = "InsertKeyForm";
24+
Text = "Вставка SSH ключа";
25+
AutoScaleDimensions = new SizeF(6F, 13F);
26+
AutoScaleMode = AutoScaleMode.Font;
27+
ClientSize = new Size(640, 0);
28+
StartPosition = FormStartPosition.CenterParent;
29+
30+
// NameLabel
31+
NameLabel = new Label();
32+
NameLabel.Name = "NameLabel";
33+
NameLabel.Text = "Имя ключа";
34+
NameLabel.AutoSize = true;
35+
NameLabel.Location = new Point(10, 20);
36+
Controls.Add(NameLabel);
37+
38+
// NameInput
39+
NameInput = new TextBox();
40+
NameInput.Name = "NameInput";
41+
NameInput.Text = "id_ed25519";
42+
NameInput.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
43+
NameInput.Size = new Size(ClientSize.Width - 20, 20);
44+
NameInput.Location = new Point(10, 40);
45+
Controls.Add(NameInput);
46+
47+
// SecretKeyLabel
48+
SecretKeyLabel = new Label();
49+
SecretKeyLabel.Name = "SecretKeyLabel";
50+
SecretKeyLabel.Text = "Секретный ключ";
51+
SecretKeyLabel.AutoSize = true;
52+
SecretKeyLabel.Location = new Point(10, NameInput.Bottom + 10);
53+
Controls.Add(SecretKeyLabel);
54+
55+
// SecretKeyInput
56+
SecretKeyInput = new TextBox();
57+
SecretKeyInput.Name = "SecretKeyInput";
58+
SecretKeyInput.Text = "";
59+
SecretKeyInput.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
60+
SecretKeyInput.Size = new Size(ClientSize.Width - 20, 140);
61+
SecretKeyInput.Location = new Point(10, SecretKeyLabel.Bottom + 5);
62+
SecretKeyInput.Multiline = true;
63+
Controls.Add(SecretKeyInput);
64+
65+
// InsertButton
66+
InsertButton = new Button();
67+
InsertButton.Name = "InsertButton";
68+
InsertButton.Text = "Вставить ключ";
69+
InsertButton.AutoSize = true;
70+
InsertButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
71+
InsertButton.Location = new Point(10, SecretKeyInput.Bottom + 10);
72+
InsertButton.UseVisualStyleBackColor = true;
73+
InsertButton.Click += OnInsertButtonClick;
74+
Controls.Add(InsertButton);
75+
76+
// Layout
77+
int FormHeight = 0;
78+
foreach (Control control in Controls)
79+
{
80+
int controlBottom = control.Bottom;
81+
if (controlBottom > FormHeight)
82+
{
83+
FormHeight = controlBottom;
84+
}
85+
}
86+
ClientSize = new Size(ClientSize.Width, FormHeight + 20);
87+
}
88+
89+
protected void OnInsertButtonClick(object? sender, EventArgs e)
90+
{
91+
if (string.IsNullOrWhiteSpace(NameValue))
92+
{
93+
MessageBox.Show("Пожалуйста заполните поле Имя", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
94+
return;
95+
}
96+
if (string.IsNullOrWhiteSpace(SecretKeyValue))
97+
{
98+
MessageBox.Show("Пожалуйста заполните поле Секретный ключ.", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Error);
99+
return;
100+
}
101+
102+
if (KeysManager.InsertKey(NameValue, SecretKeyValue))
103+
{
104+
KeysManager.GetKeys(true);
105+
if (KeysManager.CreatePubKey(NameValue, false, true))
106+
{
107+
KeysManager.GetKeys(true);
108+
}
109+
DialogResult = DialogResult.OK;
110+
Close();
111+
}
112+
else
113+
{
114+
DialogResult = DialogResult.None;
115+
}
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)