Skip to content

Commit b731d58

Browse files
committed
feature: Logger log id support
1 parent f5599a0 commit b731d58

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

app/middleware/app_logger/new.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ func New() fiber.Handler {
1717
user_id = c.Locals("user_id").(string)
1818
}
1919

20+
c.Locals("log_id", uuid.NewString())
21+
2022
logger.Sugar().WithOptions(
2123
zap.WithCaller(false),
2224
).Infow(
2325
"render engine request",
2426
"lmn_level", "request",
25-
"log_id", uuid.NewString(),
27+
"log_id", c.Locals("log_id").(string),
2628
"user_id", user_id,
2729
"route", c.Path(),
2830
"ip_address", c.IP(),

app/models/php_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ type CommandParams struct {
99
Token string
1010
BaseURL string
1111
Locale string
12+
LogID string
1213
}

internal/sandbox/command_generator.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sandbox
33
import (
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

Comments
 (0)