diff --git a/killbrowser.go b/killbrowser.go deleted file mode 100644 index a3a1dc6ee..000000000 --- a/killbrowser.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2022 Arduino SA -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package main - -import ( - "errors" - "net/http" - - "github.com/arduino/arduino-create-agent/killbrowser" - "github.com/gin-gonic/gin" -) - -func killBrowserHandler(c *gin.Context) { - - var data struct { - Action string `json:"action"` - Process string `json:"process"` - URL string `json:"url"` - } - - c.BindJSON(&data) - - if data.Process != "chrome" && data.Process != "chrom" { - c.JSON(http.StatusBadRequest, errors.New("You can't kill the process"+data.Process)) - return - } - - command, err := browser.Find(data.Process) - - if err != nil { - c.JSON(http.StatusInternalServerError, err.Error()) - return - } - - if data.Action == "kill" || data.Action == "restart" { - _, err := browser.Kill(data.Process) - if err != nil { - c.JSON(http.StatusInternalServerError, err.Error()) - return - } - } - - if data.Action == "restart" { - _, err := browser.Start(command, data.URL) - if err != nil { - c.JSON(http.StatusInternalServerError, err.Error()) - return - } - } - -} diff --git a/killbrowser/killbrowser_darwin.go b/killbrowser/killbrowser_darwin.go deleted file mode 100644 index 2ff4c3e64..000000000 --- a/killbrowser/killbrowser_darwin.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2022 Arduino SA -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package browser - -// Find will find the browser -func Find(process string) ([]byte, error) { - return nil, nil -} - -// Kill will kill a process -func Kill(process string) ([]byte, error) { - return nil, nil -} - -// Start will start a command -func Start(command []byte, url string) ([]byte, error) { - return nil, nil -} diff --git a/killbrowser/killbrowser_linux.go b/killbrowser/killbrowser_linux.go deleted file mode 100644 index 4e4a1e987..000000000 --- a/killbrowser/killbrowser_linux.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 Arduino SA -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package browser - -import ( - "os/exec" - "strings" - - "github.com/arduino/arduino-create-agent/utilities" -) - -// Find will find the browser -func Find(process string) ([]byte, error) { - ps := exec.Command("ps", "-A", "-o", "command") - grep := exec.Command("grep", process) - head := exec.Command("head", "-n", "1") - - return utilities.PipeCommands(ps, grep, head) -} - -// Kill will kill a process -func Kill(process string) ([]byte, error) { - cmd := exec.Command("pkill", "-9", process) - return cmd.Output() -} - -// Start will start a command -func Start(command []byte, url string) ([]byte, error) { - parts := strings.Split(string(command), " ") - cmd := exec.Command(parts[0], url) - return cmd.Output() -} diff --git a/killbrowser/killbrowser_windows.go b/killbrowser/killbrowser_windows.go deleted file mode 100644 index 0f6628482..000000000 --- a/killbrowser/killbrowser_windows.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2022 Arduino SA -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package browser - -import "os/exec" - -// Find will find the browser -func Find(process string) ([]byte, error) { - return []byte(process), nil -} - -// Kill will kill a process -func Kill(process string) ([]byte, error) { - cmd := exec.Command("Taskkill", "/F", "/IM", process+".exe") - return cmd.Output() -} - -// Start will start a command -func Start(command []byte, url string) ([]byte, error) { - cmd := exec.Command("cmd", "/C", "start", string(command), url) - return cmd.Output() -} diff --git a/main.go b/main.go index 29f097112..e48272655 100755 --- a/main.go +++ b/main.go @@ -392,7 +392,6 @@ func loop() { r.Handle("WS", "/socket.io/", socketHandler) r.Handle("WSS", "/socket.io/", socketHandler) r.GET("/info", infoHandler) - r.POST("/killbrowser", killBrowserHandler) r.POST("/pause", pauseHandler) r.POST("/update", updateHandler)