@@ -3,6 +3,7 @@ package sandbox
33import (
44 "fmt"
55 "io/ioutil"
6+ "os"
67 "strings"
78
89 "github.com/alessio/shellescape"
@@ -33,6 +34,23 @@ func GenerateCommand(extension *models.Extension, credentials *models.Credential
3334 return "" , err
3435 }
3536
37+ extJson , err := liman .GetExtensionJSON (extension )
38+ if err != nil {
39+ return "" , err
40+ }
41+
42+ requiredList := []string {}
43+ if extJson ["functions" ] != nil {
44+ for _ , function := range extJson ["functions" ].([]interface {}) {
45+ fn := function .(map [string ]any )
46+ requiredList = append (requiredList , fn ["name" ].(string ))
47+ }
48+ }
49+
50+ if user .Status != 1 && ! helpers .Contains (permissions , params .TargetFunction ) && helpers .Contains (requiredList , params .TargetFunction ) {
51+ return "" , logger .FiberError (fiber .StatusForbidden , "you have no permission to do this" )
52+ }
53+
3654 if credentials .Username != "" && credentials .Key != "" {
3755 settings ["clientUsername" ] = credentials .Username
3856 settings ["clientPassword" ] = credentials .Key
@@ -68,7 +86,7 @@ func GenerateCommand(extension *models.Extension, credentials *models.Credential
6886 "license" : licenceData ,
6987 "token" : params .Token ,
7088 "locale" : params .Locale ,
71- "log_id" : "0000000" , // TODO: add log handlers
89+ "log_id" : params . LogID ,
7290 "ajax" : "true" ,
7391 "apiRoute" : "/extensionRun" ,
7492 }
@@ -81,22 +99,22 @@ func GenerateCommand(extension *models.Extension, credentials *models.Credential
8199 extensionDataJson , _ := sonic .Marshal (extensionData )
82100 encryptedData := aes256 .Encrypt (string (extensionDataJson ), string (secureKey ))
83101
84- // TODO: extJsonfile
85- // TODO: required param tester
86- // TODO: targetFunction and permission match check
87- // TODO: so file handler
102+ soPath := "/liman/extensions/" + strings .ToLower (extension .Name ) + "/liman.so"
103+ soCommand := ""
104+ if _ , err := os .Stat (soPath ); err == nil {
105+ soCommand = "-dextension=" + shellescape .Quote (soPath ) + " "
106+ }
88107
89108 command := fmt .Sprintf (
90- "runuser %s -c 'timeout %s /usr/bin/php -d display_errors=on %s %s %s'" ,
109+ "runuser %s -c 'timeout %s /usr/bin/php %s -d display_errors=on %s %s %s'" ,
91110 strings .Replace (extension .ID , "-" , "" , - 1 ),
92111 helpers .Env ("EXTENSION_TIMEOUT" , "30" ),
112+ soCommand ,
93113 constants .SANDBOX_PATH ,
94114 constants .KEYS_PATH + "/" + extension .ID ,
95115 encryptedData ,
96116 )
97117
98- // TODO: complete the command generator
99-
100118 return command , nil
101119}
102120
0 commit comments