feat: wireguard / vproxy configuration
This commit is contained in:
+140
-38
@@ -1,8 +1,14 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"charm.land/bubbles/v2/spinner"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
@@ -23,11 +29,12 @@ type Model struct {
|
||||
|
||||
isPublicIP bool
|
||||
|
||||
loginForm FormStep
|
||||
serverForm FormStep
|
||||
dbForm FormStep
|
||||
certForm FormStep
|
||||
configValues ConfigValues
|
||||
loginForm FormStep
|
||||
wireguardForm FormStep
|
||||
serverForm FormStep
|
||||
dbForm FormStep
|
||||
certForm FormStep
|
||||
configValues ConfigValues
|
||||
|
||||
finishedFile bool
|
||||
configFileError error
|
||||
@@ -43,13 +50,71 @@ type DockerLoginData struct {
|
||||
}
|
||||
|
||||
type ConfigValues struct {
|
||||
Login map[string]string
|
||||
Server map[string]string
|
||||
Database map[string]string
|
||||
Cert map[string]string
|
||||
Login map[string]string
|
||||
Wireguard map[string]string
|
||||
Server map[string]string
|
||||
Database map[string]string
|
||||
Cert map[string]string
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Server struct {
|
||||
Port int64 `toml:"port"`
|
||||
Timeout int64 `toml:"timeout_seconds"`
|
||||
Environment string `toml:"environment"`
|
||||
} `toml:"server"`
|
||||
Database struct {
|
||||
Type string `toml:"type"`
|
||||
URL string `toml:"url"`
|
||||
MaxConns int64 `toml:"max_conns"`
|
||||
MinConns int64 `toml:"min_conns"`
|
||||
} `toml:"database"`
|
||||
Certificates struct {
|
||||
DirPath string `toml:"mapped_dir"`
|
||||
CertName string `toml:"cert_path"`
|
||||
KeyName string `toml:"key_path"`
|
||||
CAName string `toml:"ca_path"`
|
||||
ServerName string `toml:"server_name"`
|
||||
} `toml:"certificate"`
|
||||
}
|
||||
|
||||
func loadConfig() AppConfig {
|
||||
var config AppConfig
|
||||
|
||||
config.Server.Port = 8081
|
||||
config.Server.Timeout = 30
|
||||
config.Server.Environment = "production"
|
||||
|
||||
config.Database.Type = "postgres"
|
||||
config.Database.URL = "postgres://usuario:senha@banco:5432/app_dono_db"
|
||||
config.Database.MaxConns = 10
|
||||
config.Database.MinConns = 2
|
||||
|
||||
config.Certificates.DirPath = "/caminho/para/diretorio"
|
||||
config.Certificates.CertName = "certificado.crt"
|
||||
config.Certificates.KeyName = "chave.key"
|
||||
config.Certificates.CAName = "chaveCA.crt"
|
||||
config.Certificates.ServerName = "client"
|
||||
|
||||
_, err := os.Stat("config.toml")
|
||||
if err == nil {
|
||||
if _, err := toml.DecodeFile("config.toml", &config); err != nil {
|
||||
fmt.Printf("Error loading config: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
config.Certificates.CertName = filepath.Base(config.Certificates.CertName)
|
||||
config.Certificates.KeyName = filepath.Base(config.Certificates.KeyName)
|
||||
config.Certificates.CAName = filepath.Base(config.Certificates.CAName)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func InitialModel() Model {
|
||||
cfg := loadConfig()
|
||||
|
||||
s := spinner.New()
|
||||
s.Spinner = spinner.Dot
|
||||
s.Style = SpinnerStyle
|
||||
@@ -70,12 +135,53 @@ func InitialModel() Model {
|
||||
Type: FieldTypePassword,
|
||||
},
|
||||
}),
|
||||
wireguardForm: NewFormStep("Configurações vproxy", []FormField{
|
||||
{
|
||||
Id: "privkey",
|
||||
Label: "Chave Privada",
|
||||
Placeholder: "",
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "vip",
|
||||
Label: "IP Virtual",
|
||||
Default: "127.0.0.1",
|
||||
Placeholder: "127.0.0.1",
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "psk",
|
||||
Label: "Pre-Shared Key",
|
||||
Placeholder: "",
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "proxy_edps",
|
||||
Label: "Proxy EDPS",
|
||||
Placeholder: "22:127.0.0.1:22",
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "mtu",
|
||||
Label: "MTU",
|
||||
Default: "1380",
|
||||
Placeholder: "1380",
|
||||
Type: FieldTypeNumber,
|
||||
},
|
||||
{
|
||||
Id: "proto",
|
||||
Label: "Protocolo",
|
||||
Default: "UDP",
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"UDP", "TCP"},
|
||||
},
|
||||
}),
|
||||
serverForm: NewFormStep("Servidor", []FormField{
|
||||
{
|
||||
Id: "port",
|
||||
Label: "Porta",
|
||||
Placeholder: "8081",
|
||||
Default: "8081",
|
||||
Default: strconv.FormatInt(cfg.Server.Port, 10),
|
||||
Type: FieldTypeNumber,
|
||||
CharLimit: 4,
|
||||
},
|
||||
@@ -83,14 +189,14 @@ func InitialModel() Model {
|
||||
Id: "timeout",
|
||||
Label: "Timeout (Segundos)",
|
||||
Placeholder: "30",
|
||||
Default: "30",
|
||||
Default: strconv.FormatInt(cfg.Server.Timeout, 10),
|
||||
Type: FieldTypeNumber,
|
||||
CharLimit: 3,
|
||||
},
|
||||
{
|
||||
Id: "environment",
|
||||
Label: "Ambiente",
|
||||
Default: "production",
|
||||
Default: cfg.Server.Environment,
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"development", "production"},
|
||||
},
|
||||
@@ -99,7 +205,7 @@ func InitialModel() Model {
|
||||
{
|
||||
Id: "database_type",
|
||||
Label: "Tipo do Banco",
|
||||
Default: "postgres",
|
||||
Default: cfg.Database.Type,
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"postgres", "oracle"},
|
||||
},
|
||||
@@ -107,59 +213,55 @@ func InitialModel() Model {
|
||||
Id: "database_url",
|
||||
Label: "URL de acesso",
|
||||
Placeholder: "postgres://usuario:senha@banco:5432/app_dono_db",
|
||||
Default: "postgres://usuario:senha@banco:5432/app_dono_db",
|
||||
Default: cfg.Database.URL,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "max_conns",
|
||||
Label: "Conexões ativas (máximo)",
|
||||
Placeholder: "10",
|
||||
Default: "10",
|
||||
Default: strconv.FormatInt(cfg.Database.MaxConns, 10),
|
||||
Type: FieldTypeNumber,
|
||||
},
|
||||
{
|
||||
Id: "min_conns",
|
||||
Label: "Conexões ativas (mínimo)",
|
||||
Placeholder: "2",
|
||||
Default: "2",
|
||||
Default: strconv.FormatInt(cfg.Database.MinConns, 10),
|
||||
Type: FieldTypeNumber,
|
||||
},
|
||||
}),
|
||||
certForm: NewFormStep("Certificado", []FormField{
|
||||
{
|
||||
Id: "cert_dir_path",
|
||||
Label: "Caminho para o diretório dos certificados (será montado no container)",
|
||||
Label: "Caminho para o diretório dos certificados",
|
||||
Placeholder: "/caminho/para/diretorio",
|
||||
Default: "/caminho/para/diretorio",
|
||||
Default: cfg.Certificates.DirPath,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "cert_name",
|
||||
Label: "Nome do arquivo do certificado",
|
||||
Placeholder: "certificado.crt",
|
||||
Default: "certificado.crt",
|
||||
Type: FieldTypeText,
|
||||
Id: "cert_name",
|
||||
Label: "Nome do arquivo do certificado",
|
||||
Default: cfg.Certificates.CertName,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "key_name",
|
||||
Label: "Nome do arquivo da chave",
|
||||
Placeholder: "chave.key",
|
||||
Default: "chave.key",
|
||||
Type: FieldTypeText,
|
||||
Id: "key_name",
|
||||
Label: "Nome do arquivo da chave",
|
||||
Default: cfg.Certificates.KeyName,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "ca_name",
|
||||
Label: "Nome do arquivo da autoridade certificadora",
|
||||
Placeholder: "chaveCA.crt",
|
||||
Default: "chaveCA.crt",
|
||||
Type: FieldTypeText,
|
||||
Id: "ca_name",
|
||||
Label: "Nome do arquivo da autoridade certificadora",
|
||||
Default: cfg.Certificates.CAName,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "server_name",
|
||||
Label: "Nome do servidor",
|
||||
Placeholder: "client",
|
||||
Default: "client",
|
||||
Type: FieldTypeText,
|
||||
Id: "server_name",
|
||||
Label: "Nome do servidor",
|
||||
Default: cfg.Certificates.ServerName,
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
}),
|
||||
spinner: s,
|
||||
|
||||
Reference in New Issue
Block a user