Skip to content

Commit

Permalink
hide powershell on prompt input
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 11, 2024
1 parent 4db3f24 commit 73b3cfa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
13 changes: 4 additions & 9 deletions cmd/windows_agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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()))
Expand All @@ -87,14 +80,16 @@ func (p *agentService) runLoop() {
wgDone := utils.WaitChan(&p.wg)

select {
case <-p.exit:
case <-p.ctx.Done():
snapshots.CloseAllSnapshots()
return
case <-wgDone:
utils.SetEnvironment("PBS_AGENT_STATUS", "Unexpected shutdown - restarting SSH endpoints")
logger.Error("SSH endpoints stopped unexpectedly. Restarting...")
p.wg = sync.WaitGroup{}
}

time.Sleep(5 * time.Second)
}
}

Expand Down Expand Up @@ -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
}
24 changes: 0 additions & 24 deletions cmd/windows_agent/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions internal/utils/windows_prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 73b3cfa

Please sign in to comment.