133 lines
5.1 KiB
C#
133 lines
5.1 KiB
C#
using CPM;
|
|
using MLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using UI;
|
|
|
|
namespace UI
|
|
{
|
|
public partial class SshClienteCadastroPanel : FormularioModelo
|
|
{
|
|
private ModeloSshCliente _ssh = new ModeloSshCliente();
|
|
|
|
// Controles - Identificação e Conexão
|
|
private LV_TEXTBOX1 txtId, txtNome, txtHost, txtPorta, txtUsuario;
|
|
|
|
// Controles - Autenticação
|
|
private LV_TEXTBOX1 txtSenha, txtPassphrase, txtCaminhoChave;
|
|
private ComboBox cbTipoAutenticacao;
|
|
private CheckBox chkUsarChave, chkAtivo;
|
|
private Button btnSelecionarChave;
|
|
|
|
// Controles - Informações Técnicas
|
|
private LV_TEXTBOX1 txtFingerprint, txtCriadoEm, txtAtualizadoEm;
|
|
|
|
public SshClienteCadastroPanel()
|
|
{
|
|
this.Titulo = "Configuração de Conexão SSH";
|
|
MontarInterface();
|
|
}
|
|
|
|
private void MontarInterface()
|
|
{
|
|
// --- SEÇÃO 1: Endereçamento ---
|
|
content.Controls.Add(CreateSectionHeader("SERVIDOR DESTINO", 20));
|
|
|
|
txtId = AddInput(content, "ID", 20, 50, 70, 30, true);
|
|
txtNome = AddInput(content, "NOME DA CONEXÃO (EX: SERVER CLOUD)", 100, 50, 350, 30);
|
|
txtHost = AddInput(content, "HOST / IP", 20, 105, 330, 30);
|
|
txtPorta = AddInput(content, "PORTA", 360, 105, 90, 30);
|
|
txtUsuario = AddInput(content, "USUÁRIO SSH", 460, 105, 180, 30);
|
|
|
|
chkAtivo = new CheckBox { Text = "ATIVO", Location = new Point(660, 121), AutoSize = true, Checked = true };
|
|
content.Controls.Add(chkAtivo);
|
|
|
|
// --- SEÇÃO 2: Autenticação ---
|
|
content.Controls.Add(CreateSectionHeader("SEGURANÇA E ACESSO", 165));
|
|
|
|
// ✅ Usando AddComboBox — label e input no mesmo padrão do AddInput
|
|
cbTipoAutenticacao = AddComboBox(content, "MÉTODO", 20, 195, 150);
|
|
cbTipoAutenticacao.Items.AddRange(new object[] { "Senha", "Chave Privada" });
|
|
cbTipoAutenticacao.SelectedIndex = 0;
|
|
|
|
// ✅ Y=195 no AddInput → label em 195, input em 211 — alinhado com o ComboBox
|
|
txtSenha = AddInput(content, "SENHA", 180, 195, 200, 30);
|
|
txtSenha.PasswordChar = '●';
|
|
|
|
chkUsarChave = new CheckBox
|
|
{
|
|
Text = "USAR CHAVE (.PEM / .PPK)",
|
|
Location = new Point(400, 213),
|
|
AutoSize = true
|
|
};
|
|
content.Controls.Add(chkUsarChave);
|
|
|
|
txtCaminhoChave = AddInput(content, "CAMINHO DA CHAVE PRIVADA", 20, 260, 580, 30);
|
|
|
|
btnSelecionarChave = new Button
|
|
{
|
|
Text = "...",
|
|
Location = new Point(610, 276),
|
|
Size = new Size(40, 30),
|
|
BackColor = Color.Gainsboro,
|
|
FlatStyle = FlatStyle.Flat
|
|
};
|
|
new ToolTip().SetToolTip(btnSelecionarChave, "Selecionar arquivo de chave (.PEM / .PPK)");
|
|
btnSelecionarChave.Click += (s, e) =>
|
|
{
|
|
using var ofd = new OpenFileDialog
|
|
{
|
|
Filter = "Arquivos de Chave (*.pem;*.ppk)|*.pem;*.ppk|Todos (*.*)|*.*"
|
|
};
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
txtCaminhoChave.Text = ofd.FileName;
|
|
};
|
|
content.Controls.Add(btnSelecionarChave);
|
|
|
|
txtPassphrase = AddInput(content, "PASSPHRASE DA CHAVE", 660, 260, 175, 30);
|
|
txtPassphrase.PasswordChar = '●';
|
|
|
|
// --- SEÇÃO 3: Metadados ---
|
|
content.Controls.Add(CreateSectionHeader("DADOS TÉCNICOS", 330));
|
|
txtFingerprint = AddInput(content, "SSH FINGERPRINT (AUTOMÁTICO)", 20, 360, 430, 30, true);
|
|
txtCriadoEm = AddInput(content, "CRIADO EM", 460, 360, 185, 30, true);
|
|
txtAtualizadoEm = AddInput(content, "ÚLT. ATUALIZAÇÃO", 655, 360, 185, 30, true);
|
|
|
|
content.Height = 420;
|
|
}
|
|
|
|
private void PreencherModel()
|
|
{
|
|
_ssh.Nome = txtNome.Text;
|
|
_ssh.Host = txtHost.Text;
|
|
_ssh.Porta = int.TryParse(txtPorta.Text, out int p) ? p : 22;
|
|
_ssh.Usuario = txtUsuario.Text;
|
|
_ssh.TipoAutenticacao = cbTipoAutenticacao.Text;
|
|
_ssh.Senha = txtSenha.Text;
|
|
_ssh.CaminhoChave = txtCaminhoChave.Text;
|
|
_ssh.Passphrase = txtPassphrase.Text;
|
|
_ssh.UsarChave = chkUsarChave.Checked;
|
|
_ssh.Ativo = chkAtivo.Checked;
|
|
}
|
|
|
|
protected override void OnNovo()
|
|
{
|
|
_ssh = new ModeloSshCliente();
|
|
txtPorta.Text = "22";
|
|
cbTipoAutenticacao.SelectedIndex = 0;
|
|
txtNome.Focus();
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
PreencherModel();
|
|
MessageBox.Show("Configuração de conexão SSH salva!", "LevelOS Network", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnAlterar() { }
|
|
protected override void OnExcluir() { }
|
|
protected override void OnLocalizar() { }
|
|
protected override void OnCancelar() { }
|
|
}
|
|
} |