From 73b3cfa555af23f47141304361f11c1587311ea3 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Mon, 11 Nov 2024 10:54:17 -0500 Subject: [PATCH] hide powershell on prompt input --- cmd/windows_agent/service.go | 13 ++++--------- cmd/windows_agent/systray.go | 24 ------------------------ go.mod | 7 +++++-- go.sum | 4 ++-- internal/utils/windows_prompts.go | 3 +++ 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/cmd/windows_agent/service.go b/cmd/windows_agent/service.go index 377e2d5..2e41308 100644 --- a/cmd/windows_agent/service.go +++ b/cmd/windows_agent/service.go @@ -35,11 +35,9 @@ type agentService struct { cancel context.CancelFunc pingCancel context.CancelFunc wg sync.WaitGroup - exit chan struct{} } func (p *agentService) Start(s service.Service) error { - p.exit = make(chan struct{}) p.ctx, p.cancel = context.WithCancel(context.Background()) p.pingCtx, p.pingCancel = context.WithCancel(context.Background()) @@ -71,11 +69,6 @@ func (p *agentService) startPing() { } func (p *agentService) runLoop() { - defer func() { - p.cancel() - close(p.exit) - }() - logger, err := syslog.InitializeLogger(p.svc) if err != nil { utils.SetEnvironment("PBS_AGENT_STATUS", fmt.Sprintf("Failed to initialize logger -> %s", err.Error())) @@ -87,7 +80,7 @@ func (p *agentService) runLoop() { wgDone := utils.WaitChan(&p.wg) select { - case <-p.exit: + case <-p.ctx.Done(): snapshots.CloseAllSnapshots() return case <-wgDone: @@ -95,6 +88,8 @@ func (p *agentService) runLoop() { logger.Error("SSH endpoints stopped unexpectedly. Restarting...") p.wg = sync.WaitGroup{} } + + time.Sleep(5 * time.Second) } } @@ -149,10 +144,10 @@ waitUrl: } func (p *agentService) Stop(s service.Service) error { - close(p.exit) p.cancel() p.pingCancel() p.wg.Wait() + return nil } diff --git a/cmd/windows_agent/systray.go b/cmd/windows_agent/systray.go index 4953372..1c18e69 100644 --- a/cmd/windows_agent/systray.go +++ b/cmd/windows_agent/systray.go @@ -96,30 +96,6 @@ func (p *agentTray) onReady(url string) func() { } }(p.ctx, serverIP, &url) - status := systray.AddMenuItem("Status: Connecting...", "Connectivity status") - status.Disable() - - go func(ctx context.Context, status *systray.MenuItem, url *string) { - for { - select { - case <-ctx.Done(): - return - default: - if url != nil && *url != "" { - svcStatus, ok := os.LookupEnv("PBS_AGENT_STATUS") - if !ok { - status.SetTitle("Status: Agent service not running") - continue - } - status.SetTitle(fmt.Sprintf("Status: %s", svcStatus)) - } else { - status.SetTitle("Status: Server URL needs to be set.") - } - time.Sleep(5 * time.Second) - } - } - }(p.ctx, status, &url) - systray.AddSeparator() changeUrl := systray.AddMenuItem("Change Server", "Change Server URL") diff --git a/go.mod b/go.mod index a45bbdd..5b57bb2 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ module github.com/sonroyaalmerol/pbs-plus -go 1.23.0 +go 1.23.2 + +toolchain go1.23.3 require ( github.com/getlantern/systray v1.2.2 - github.com/go-ole/go-ole v1.3.0 github.com/kardianos/service v1.2.2 github.com/mattn/go-sqlite3 v1.14.24 github.com/mxk/go-vss v1.2.0 @@ -20,7 +21,9 @@ require ( github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/kr/fs v0.1.0 // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect + github.com/stretchr/testify v1.9.0 // indirect ) diff --git a/go.sum b/go.sum index 285dbab..0b74ad0 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,8 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/internal/utils/windows_prompts.go b/internal/utils/windows_prompts.go index 91ac804..28cb6b5 100644 --- a/internal/utils/windows_prompts.go +++ b/internal/utils/windows_prompts.go @@ -23,6 +23,9 @@ func PromptInput(title, prompt string) string { $input = [Microsoft.VisualBasic.Interaction]::InputBox('%s', '%s'); $input`, prompt, title)) + // Set SysProcAttr to hide the PowerShell window + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + output, err := cmd.Output() if err != nil { fmt.Println("Failed to get input:", err)