Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apparrayhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"log"
"strings"
"sync"
"os/exec"
"runtime"
)

type AppArrayHub struct {
Expand Down Expand Up @@ -56,6 +58,7 @@ func (h *AppArrayHub) OnConnected(string) {
h.InitializeConnections()
}
}

}

func (h *AppArrayHub) RunCommand(cmd string, client *ssh.Client) (int, string) {
Expand Down Expand Up @@ -84,6 +87,29 @@ func (h *AppArrayHub) RunCommand(cmd string, client *ssh.Client) (int, string) {
io.Copy(buf, stdout)
return res, buf.String()
}
// open browser with url
func (h *AppArrayHub) OpenUrl(url string) (int, string) {
var err error
res := 0

switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
res = 1
}

buf := new(strings.Builder)

return res, buf.String()
}

func (h *AppArrayHub) DownloadFile(path string, client *ssh.Client) (int, string, string) {
sftpClient, err := sftp.NewClient(client)
Expand Down Expand Up @@ -113,6 +139,9 @@ func (h *AppArrayHub) SendCommand(message string) {
if req.CommandId == model.CommandDownload {
status, res, filename = h.DownloadFile(req.Command, client)
h.SendResponseCaller(NewCommandDownloadResponse(status, res, filename, req), CommandResultListener)
} else if req.CommandId == model.CommandWebsite {
status, res = h.OpenUrl(req.Command)
h.SendResponseCaller(NewCommandResponse(status, res, req), CommandResultListener)
} else {
status, res = h.RunCommand(req.Command, client)
h.SendResponseCaller(NewCommandResponse(status, res, req), CommandResultListener)
Expand Down