feat(backend): Add telnet protocol support

This commit is contained in:
pycook
2025-05-13 22:55:40 +08:00
parent 0a6e060149
commit e4903551b3
13 changed files with 442 additions and 55 deletions

View File

@@ -0,0 +1,34 @@
package db
import (
"fmt"
"os"
"strings"
"github.com/veops/oneterm/internal/model"
)
// getPostgreSQLConfig returns PostgreSQL client configuration
func getPostgreSQLConfig(ip string, port int, account *model.Account) DBClientConfig {
// Set PGPASSWORD environment variable instead of using -W
os.Setenv("PGPASSWORD", account.Password)
args := []string{
"-h", ip,
"-p", fmt.Sprintf("%d", port),
"-U", account.Account,
"postgres", // Default database name
}
// Add database name if specified in the account.Account field (username/database format)
parts := strings.Split(account.Account, "/")
if len(parts) > 1 {
args = append(args, "-d", parts[1])
}
return DBClientConfig{
Command: "psql",
Args: args,
ExitAliases: []string{"\\q", "exit", "quit"},
}
}