fix desktop
This commit is contained in:
@@ -24,10 +24,13 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
ConfigYaml string `json:"config_yaml"`
|
||||
}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
// fmt.Printf("bad json: %v\n", err)
|
||||
c.JSON(400, gin.H{"error": fmt.Sprintf("bad json: %v", err)})
|
||||
return
|
||||
}
|
||||
|
||||
// fmt.Printf("req: %+v\n", req)
|
||||
|
||||
knocker := internal.NewPortKnocker()
|
||||
|
||||
// Определяем режим: inline или YAML
|
||||
@@ -39,6 +42,8 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("config: %+v\n", config)
|
||||
|
||||
// Применяем дополнительные параметры из запроса
|
||||
if req.Gateway != "" {
|
||||
for i := range config.Targets {
|
||||
@@ -47,7 +52,8 @@ func setupKnockRoutes(api *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
if err := knocker.ExecuteWithConfig(config, req.Verbose, req.WaitConnection); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
fmt.Printf("error: %v\n", err)
|
||||
c.JSON(400, gin.H{"status": "error","error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{"status": "ok"})
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -100,13 +100,17 @@ func parseInlineTargets(targetsStr, delayStr string) (*internal.Config, error) {
|
||||
|
||||
// Разбираем формат [proto]:[host]:[port]
|
||||
parts := strings.Split(targetStr, ":")
|
||||
if len(parts) != 3 {
|
||||
return nil, fmt.Errorf("неверный формат цели '%s', ожидается [proto]:[host]:[port]", targetStr)
|
||||
if len(parts) != 3 && len(parts) != 4 {
|
||||
return nil, fmt.Errorf("неверный формат цели '%s', ожидается [proto]:[host]:[port] или [proto]:[host]:[port]:[gateway]", targetStr)
|
||||
}
|
||||
|
||||
protocol := strings.TrimSpace(parts[0])
|
||||
host := strings.TrimSpace(parts[1])
|
||||
portStr := strings.TrimSpace(parts[2])
|
||||
gateway := ""
|
||||
if len(parts) == 4 {
|
||||
gateway = strings.TrimSpace(parts[3])
|
||||
}
|
||||
|
||||
// Проверяем протокол
|
||||
if protocol != "tcp" && protocol != "udp" {
|
||||
@@ -130,7 +134,7 @@ func parseInlineTargets(targetsStr, delayStr string) (*internal.Config, error) {
|
||||
Protocol: protocol,
|
||||
Delay: internal.Duration(delay),
|
||||
WaitConnection: false,
|
||||
Gateway: "",
|
||||
Gateway: gateway,
|
||||
}
|
||||
|
||||
config.Targets = append(config.Targets, target)
|
||||
|
@@ -43,11 +43,16 @@ func runServe(cmd *cobra.Command, args []string) error {
|
||||
port = "8888"
|
||||
}
|
||||
|
||||
host := os.Getenv("GO_KNOCKER_SERVE_HOST")
|
||||
if strings.TrimSpace(port) == "" {
|
||||
host = ""
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
// CORS: разрешаем для локальной разработки
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"http://localhost:4200", "http://127.0.0.1:8888", "http://localhost:8888"},
|
||||
AllowOrigins: []string{"http://localhost:4200", "http://127.0.0.1:8888", "http://localhost:" + port},
|
||||
AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
||||
AllowHeaders: []string{"Authorization", "Content-Type"},
|
||||
AllowCredentials: true,
|
||||
@@ -65,6 +70,6 @@ func runServe(cmd *cobra.Command, args []string) error {
|
||||
setupCryptoRoutes(api, passHash)
|
||||
setupStaticRoutes(r, embeddedFS)
|
||||
|
||||
fmt.Printf("Serving on :%s\n", port)
|
||||
return r.Run(":" + port)
|
||||
fmt.Printf("Serving on %s:%s\n", host, port)
|
||||
return r.Run(host + ":" + port)
|
||||
}
|
||||
|
Reference in New Issue
Block a user