fix: Windows handler liest params statt data, exec via PowerShell (winget-kompatibel)
This commit is contained in:
parent
5eae071bf9
commit
557e59bfc5
@ -15,7 +15,8 @@ type Message struct {
|
|||||||
Command string `json:"command,omitempty"`
|
Command string `json:"command,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
Data interface{} `json:"data,omitempty"`
|
Params map[string]interface{} `json:"params,omitempty"` // Backend -> Agent
|
||||||
|
Data interface{} `json:"data,omitempty"` // Agent -> Backend (Response)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler struct{}
|
type Handler struct{}
|
||||||
@ -65,7 +66,10 @@ func (h *Handler) Handle(raw []byte) []byte {
|
|||||||
func (h *Handler) handleExec(msg Message) Message {
|
func (h *Handler) handleExec(msg Message) Message {
|
||||||
resp := Message{Type: "response", ID: msg.ID}
|
resp := Message{Type: "response", ID: msg.ID}
|
||||||
|
|
||||||
data, _ := msg.Data.(map[string]interface{})
|
data := msg.Params
|
||||||
|
if data == nil {
|
||||||
|
data, _ = msg.Data.(map[string]interface{})
|
||||||
|
}
|
||||||
command, _ := data["command"].(string)
|
command, _ := data["command"].(string)
|
||||||
if command == "" {
|
if command == "" {
|
||||||
resp.Status = "error"
|
resp.Status = "error"
|
||||||
@ -107,7 +111,8 @@ func (h *Handler) handleWingetList(msg Message) Message {
|
|||||||
// handleWingetInstall installiert ein Paket
|
// handleWingetInstall installiert ein Paket
|
||||||
func (h *Handler) handleWingetInstall(msg Message) Message {
|
func (h *Handler) handleWingetInstall(msg Message) Message {
|
||||||
resp := Message{Type: "response", ID: msg.ID}
|
resp := Message{Type: "response", ID: msg.ID}
|
||||||
data, _ := msg.Data.(map[string]interface{})
|
data := msg.Params
|
||||||
|
if data == nil { data, _ = msg.Data.(map[string]interface{}) }
|
||||||
pkg, _ := data["package"].(string)
|
pkg, _ := data["package"].(string)
|
||||||
if pkg == "" {
|
if pkg == "" {
|
||||||
resp.Status = "error"
|
resp.Status = "error"
|
||||||
@ -130,7 +135,8 @@ func (h *Handler) handleWingetInstall(msg Message) Message {
|
|||||||
// handleWingetUpgrade aktualisiert ein Paket
|
// handleWingetUpgrade aktualisiert ein Paket
|
||||||
func (h *Handler) handleWingetUpgrade(msg Message) Message {
|
func (h *Handler) handleWingetUpgrade(msg Message) Message {
|
||||||
resp := Message{Type: "response", ID: msg.ID}
|
resp := Message{Type: "response", ID: msg.ID}
|
||||||
data, _ := msg.Data.(map[string]interface{})
|
data := msg.Params
|
||||||
|
if data == nil { data, _ = msg.Data.(map[string]interface{}) }
|
||||||
pkg, _ := data["package"].(string)
|
pkg, _ := data["package"].(string)
|
||||||
if pkg == "" {
|
if pkg == "" {
|
||||||
resp.Status = "error"
|
resp.Status = "error"
|
||||||
@ -229,8 +235,9 @@ func (h *Handler) handleReboot(msg Message) Message {
|
|||||||
// Hilfsfunktionen
|
// Hilfsfunktionen
|
||||||
|
|
||||||
func runWithTimeout(command string, timeoutSecs int) (string, error) {
|
func runWithTimeout(command string, timeoutSecs int) (string, error) {
|
||||||
cmd := exec.Command("cmd", "/C", command)
|
// PowerShell verwenden — unterstuetzt winget, UTF-8, moderne Windows-Befehle
|
||||||
cmd.SysProcAttr = nil
|
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive",
|
||||||
|
"-OutputEncoding", "UTF8", "-Command", command)
|
||||||
out, err := withTimeout(cmd, time.Duration(timeoutSecs)*time.Second)
|
out, err := withTimeout(cmd, time.Duration(timeoutSecs)*time.Second)
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user