Pārlūkot izejas kodu

Fixed agi interface to work under non sudo mode

Toby Chui 1 gadu atpakaļ
vecāks
revīzija
e2b5dc5791
1 mainītis faili ar 12 papildinājumiem un 6 dzēšanām
  1. 12 6
      mod/agi/agi.go

+ 12 - 6
mod/agi/agi.go

@@ -17,6 +17,7 @@ import (
 	"imuslab.com/arozos/mod/agi/static"
 	apt "imuslab.com/arozos/mod/apt"
 	"imuslab.com/arozos/mod/filesystem"
+	"imuslab.com/arozos/mod/filesystem/arozfs"
 	metadata "imuslab.com/arozos/mod/filesystem/metadata"
 	"imuslab.com/arozos/mod/iot"
 	"imuslab.com/arozos/mod/share"
@@ -197,8 +198,8 @@ func (g *Gateway) APIHandler(w http.ResponseWriter, r *http.Request, thisuser *u
 // Handle user requests
 func (g *Gateway) InterfaceHandler(w http.ResponseWriter, r *http.Request, thisuser *user.User) {
 	//Get user object from the request
-	startupRoot := g.Option.StartupRoot
-	startupRoot = filepath.ToSlash(filepath.Clean(startupRoot))
+	//startupRoot := g.Option.StartupRoot
+	//startupRoot = filepath.ToSlash(filepath.Clean(startupRoot))
 
 	//Get the script files for the plugin
 	scriptFile, err := utils.GetPara(r, "script")
@@ -212,11 +213,12 @@ func (g *Gateway) InterfaceHandler(w http.ResponseWriter, r *http.Request, thisu
 	scriptExists := false
 	scriptScope := "./web/"
 	for _, thisScope := range g.Option.ActivateScope {
-		thisScope = filepath.ToSlash(filepath.Clean(thisScope))
-		if utils.FileExists(thisScope + "/" + scriptFile) {
+		thisScope = arozfs.ToSlash(filepath.Clean(thisScope))
+		if utils.FileExists(arozfs.ToSlash(filepath.Join(thisScope, scriptFile))) {
 			scriptExists = true
-			scriptFile = thisScope + "/" + scriptFile
+			scriptFile = arozfs.ToSlash(filepath.Join(thisScope, scriptFile))
 			scriptScope = thisScope
+			break
 		}
 	}
 
@@ -252,7 +254,11 @@ func (g *Gateway) InterfaceHandler(w http.ResponseWriter, r *http.Request, thisu
 	}
 
 	//Get the content of the script
-	scriptContentByte, _ := os.ReadFile(scriptFile)
+	scriptContentByte, err := os.ReadFile(scriptFile)
+	if err != nil {
+		w.Write([]byte("Script load error: " + err.Error()))
+		return
+	}
 	scriptContent := string(scriptContentByte)
 
 	g.ExecuteAGIScript(scriptContent, nil, scriptFile, scriptScope, w, r, thisuser)