|
@@ -2,7 +2,6 @@ package agi
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
- "io/ioutil"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"path/filepath"
|
|
@@ -61,19 +60,18 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // read the file and store it into scriptContent
|
|
|
- scriptContentByte, err := ioutil.ReadFile(realPath)
|
|
|
- if err != nil {
|
|
|
- common.SendErrorResponse(w, "Bad file I/O")
|
|
|
- return
|
|
|
- }
|
|
|
- scriptContent := string(scriptContentByte)
|
|
|
-
|
|
|
// execute!
|
|
|
start := time.Now()
|
|
|
- g.ExecuteAGIScript(scriptContent, "", "", w, r, userInfo)
|
|
|
+ //g.ExecuteAGIScript(scriptContent, "", "", w, r, userInfo)
|
|
|
+ result, err := g.ExecuteAGIScriptAsUser(realPath, userInfo)
|
|
|
duration := time.Since(start)
|
|
|
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ common.SendTextResponse(w, result)
|
|
|
+
|
|
|
log.Println("[Remote AGI] IP:", r.RemoteAddr, " executed the script ", pathFromDb, "(", realPath, ")", " on behalf of", userInfo.Username, "with total duration: ", duration)
|
|
|
|
|
|
}
|