Skip to content

Kill and restart the browser #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 29, 2016
Prev Previous commit
Next Next commit
Add a bit of safeguard against malicious attacks
  • Loading branch information
matteosuppo committed Jan 29, 2016
commit 2ba1652653e620671e75694ac3dbcf3d36315f5e
12 changes: 9 additions & 3 deletions killbrowser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"log"
"errors"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -17,25 +17,31 @@ func killBrowserHandler(c *gin.Context) {

c.BindJSON(&data)

command, err := findBrowser(data.Process)
if data.Process != "chrome" && data.Process != "chrom" {
c.JSON(http.StatusBadRequest, errors.New("You can't kill the process"+data.Process))
return
}

log.Println(command)
command, err := findBrowser(data.Process)

if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}

if data.Action == "kill" || data.Action == "restart" {
_, err := killBrowser(data.Process)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}
}

if data.Action == "restart" {
_, err := startBrowser(command, data.URL)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}
}

Expand Down