feat: print command aprsing error

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Henrique Dias 2019-01-02 19:33:35 +00:00
parent 88effa0889
commit 1470ec8629

View File

@ -21,7 +21,6 @@ var upgrader = websocket.Upgrader{
}
var (
cmdNotImplemented = []byte("Command not implemented.")
cmdNotAllowed = []byte("Command not allowed.")
)
@ -63,6 +62,15 @@ func (e *Env) commandsHandler(w http.ResponseWriter, r *http.Request) {
}
command, err := e.Settings.ParseCommand(raw)
if err != nil {
err := conn.WriteMessage(websocket.TextMessage, []byte(err.Error()))
if err != nil {
wsErr(conn, r, http.StatusInternalServerError, err)
}
return
}
path := strings.TrimPrefix(r.URL.Path, "/api/command")
dir := afero.FullBaseFsPath(user.Fs.(*afero.BasePathFs), path)
cmd := exec.Command(command[0], command[1:]...)