converge/pkg/server/templates/usageinputs.go
Erik Brakkee b4b962d859 remove some console logs in the javascript
prometheus now listening on separate port
fixed powershell command for setting up authorized keys.
2024-09-08 11:16:49 +02:00

87 lines
1.9 KiB
Go

package templates
import (
"fmt"
)
type UsageInputs struct {
Id string
SshKeys []string
ErrorMessages []string
RemoteShells map[string]bool
LocalShells map[string]bool
DownloadCommand string
CertificateValidation bool
}
func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, localShells []string,
downloadCommand string,
certificateValidation bool) UsageInputs {
inputs := UsageInputs{
Id: id,
SshKeys: sshPublicKeys,
RemoteShells: make(map[string]bool),
LocalShells: make(map[string]bool),
DownloadCommand: downloadCommand,
CertificateValidation: certificateValidation,
}
for _, remoteShell := range remoteShells {
inputs.RemoteShells[remoteShell] = true
}
for _, localShell := range localShells {
inputs.LocalShells[localShell] = true
}
return inputs
}
func addSshKeys(shell string, keys []string) string {
quote := `"`
if shell == CMD {
quote = ""
}
res := ""
for index, key := range keys {
operator := ">>"
if index == 0 {
operator = ">"
}
if shell == POWERSHELL {
res += fmt.Sprintf(`"%s" | Out-File -FilePath ".authorized_keys" -Encoding ASCII<br/>`, key)
} else {
res += fmt.Sprintf(" echo %s%s%s %s .authorized_keys<br/>", quote, key, quote,
operator)
}
}
return res + " "
}
func formControlTextClass(message string) string {
if message == "" {
return "form-control"
}
return "form-control is-invalid"
}
func GetDownloadSecureOption(inputs UsageInputs) string {
switch inputs.DownloadCommand {
case CURL:
if !inputs.CertificateValidation {
return "-k"
}
case WGET:
if !inputs.CertificateValidation {
return "--no-check-certificate"
}
}
return ""
}
func GetAgentSecureOption(inputs UsageInputs) string {
if inputs.CertificateValidation {
return ""
}
return "--insecure"
}