feat: wireguard / vproxy configuration
This commit is contained in:
+101
-6
@@ -9,8 +9,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
imageName = "hub.davinti.com.br:443/app-dono/app-cliente:latest"
|
||||
configPath = "config.toml"
|
||||
imageName = "hub.davinti.com.br:443/app-dono/app-cliente:latest"
|
||||
wireguardImageName = "hub.davinti.com.br:443/davinti-vproxy:latest"
|
||||
configPath = "config.toml"
|
||||
wireguardConfigPath = "envs"
|
||||
)
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@@ -49,10 +51,32 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, cmd
|
||||
case StepDownloadImage:
|
||||
return m.updateDownloadImage(msg)
|
||||
|
||||
// Ip & Wireguard
|
||||
case StepIPQuestion:
|
||||
return m.updateIPQuestion(msg)
|
||||
//case StepInstallWireguard
|
||||
// return m.updateInstallWireguard(msg)
|
||||
case StepWireguardConfig:
|
||||
done, cmd := m.wireguardForm.Update(msg)
|
||||
|
||||
if done {
|
||||
m.configValues.Wireguard = m.wireguardForm.Values()
|
||||
|
||||
m.downloadDone = false
|
||||
m.downloadMessage = ""
|
||||
m.downloadError = nil
|
||||
m.currentStep = StepGenerateWireguardFile
|
||||
|
||||
return m, GenerateWireguardConfigFile(m.configValues, wireguardConfigPath)
|
||||
}
|
||||
|
||||
return m, cmd
|
||||
case StepGenerateWireguardFile:
|
||||
return m.updateGenerateWireguardFile(msg)
|
||||
case StepDownloadWireguard:
|
||||
return m.updateDownloadWireguard(msg)
|
||||
case StepRunWireguard:
|
||||
return m.updateRunWireguardDocker(msg)
|
||||
|
||||
case StepServerConfig:
|
||||
done, cmd := m.serverForm.Update(msg)
|
||||
|
||||
@@ -78,6 +102,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.configValues.Cert = m.certForm.Values()
|
||||
m.currentStep = StepGenerateFile
|
||||
|
||||
m.finishedFile = false
|
||||
m.configFileError = nil
|
||||
|
||||
return m, GenerateConfigFile(m.configValues, configPath)
|
||||
}
|
||||
|
||||
@@ -169,8 +196,73 @@ func (m Model) updateIPQuestion(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
m.currentStep = StepInstallWireguard
|
||||
return m, nil
|
||||
m.currentStep = StepWireguardConfig
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateDownloadWireguard(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case ImageDownloadFinishedMsg:
|
||||
m.downloadDone = true
|
||||
m.downloadMessage = msg.Message
|
||||
m.downloadError = msg.Err
|
||||
|
||||
if m.downloadError == nil {
|
||||
m.currentStep = StepRunWireguard
|
||||
|
||||
return m, RunWireguardContainer(wireguardConfigPath, m.configValues)
|
||||
}
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
if m.downloadDone && m.downloadError == nil {
|
||||
m.currentStep = StepRunWireguard
|
||||
} else if m.downloadDone {
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateGenerateWireguardFile(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case ConfigFileMsg:
|
||||
m.finishedFile = true
|
||||
m.configFileError = msg.Err
|
||||
|
||||
if msg.Err == nil {
|
||||
m.currentStep = StepDownloadWireguard
|
||||
|
||||
return m, DownloadWireguardImageCmd(m.configValues.Login["user"], m.configValues.Login["password"])
|
||||
}
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
if m.finishedFile && m.configFileError != nil {
|
||||
return m, tea.Quit
|
||||
} else if m.finishedFile && m.configFileError == nil {
|
||||
m.currentStep = StepDownloadWireguard
|
||||
|
||||
return m, DownloadWireguardImageCmd(m.configValues.Login["user"], m.configValues.Login["password"])
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateRunWireguardDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case DockerRunMsg:
|
||||
m.finishedDockerRun = true
|
||||
m.dockerRunError = msg.Err
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
if m.finishedDockerRun && m.dockerRunError != nil {
|
||||
return m, tea.Quit
|
||||
} else if m.finishedDockerRun && m.dockerRunError == nil {
|
||||
m.currentStep = StepServerConfig
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +281,9 @@ func (m Model) updateGenerateFile(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
} else if m.finishedFile && m.configFileError == nil {
|
||||
m.currentStep = StepRunDocker
|
||||
|
||||
m.finishedDockerRun = false
|
||||
m.dockerRunError = nil
|
||||
|
||||
return m, RunAppContainer(
|
||||
imageName,
|
||||
"app-dono-cliente",
|
||||
|
||||
Reference in New Issue
Block a user