fix: wildcard on commands

This commit is contained in:
Henrique Dias 2018-08-05 14:21:00 +01:00 committed by 1138-4EB
parent 69a3f853bd
commit 9690ec1b00

View File

@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"time"
@ -26,6 +27,22 @@ var (
cmdNotAllowed = []byte("Command not allowed.")
)
var commandShell []string
func init() {
if runtime.GOOS != "windows" {
path, err := exec.LookPath("bash")
if err != nil {
path, err = exec.LookPath("sh")
}
if err != nil {
commandShell = []string{path, "-c"}
}
}
}
// command handles the requests for VCS related commands: git, svn and mercurial
func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error) {
// Upgrades the connection to a websocket and checks for fb.Errors.
@ -87,6 +104,10 @@ func command(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error)
path = filepath.Clean(path)
buff := new(bytes.Buffer)
if len(commandShell) == 0 {
command = append(commandShell, command...)
}
// Sets up the command executation.
cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = path