enhance(wip): error handle

This commit is contained in:
Jacky 2025-01-24 16:37:45 +08:00
parent 3f95ae5d90
commit 650196d06a
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
93 changed files with 5228 additions and 3738 deletions

View file

@ -0,0 +1,14 @@
package nginx_log
import "github.com/uozi-tech/cosy"
var (
e = cosy.NewErrorScope("nginx_log")
ErrLogPathIsNotUnderTheLogDirWhiteList = e.New(50001, "the log path is not under the paths in settings.NginxSettings.LogDirWhiteList")
ErrServerIdxOutOfRange = e.New(50002, "serverIdx out of range")
ErrDirectiveIdxOutOfRange = e.New(50003, "directiveIdx out of range")
ErrLogDirective = e.New(50004, "directive.Params neither access_log nor error_log")
ErrDirectiveParamsIsEmpty = e.New(50005, "directive params is empty")
ErrErrorLogPathIsEmpty = e.New(50006, "settings.NginxLogSettings.ErrorLogPath is empty, refer to https://nginxui.com/guide/config-nginx.html for more information")
ErrAccessLogPathIsEmpty = e.New(50007, "settings.NginxLogSettings.AccessLogPath is empty, refer to https://nginxui.com/guide/config-nginx.html for more information")
)

View file

@ -0,0 +1,41 @@
package nginx_log
import (
"fmt"
"github.com/0xJacky/Nginx-UI/internal/cache"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/settings"
"path/filepath"
)
// IsLogPathUnderWhiteList checks if the log path is under one of the paths in LogDirWhiteList
func IsLogPathUnderWhiteList(path string) bool {
cacheKey := fmt.Sprintf("isLogPathUnderWhiteList:%s", path)
res, ok := cache.Get(cacheKey)
// deep copy
logDirWhiteList := append([]string{}, settings.NginxSettings.LogDirWhiteList...)
accessLogPath := nginx.GetAccessLogPath()
errorLogPath := nginx.GetErrorLogPath()
if accessLogPath != "" {
logDirWhiteList = append(logDirWhiteList, filepath.Dir(accessLogPath))
}
if errorLogPath != "" {
logDirWhiteList = append(logDirWhiteList, filepath.Dir(errorLogPath))
}
// no cache, check it
if !ok {
for _, whitePath := range logDirWhiteList {
if helper.IsUnderDirectory(path, whitePath) {
cache.Set(cacheKey, true, 0)
return true
}
}
return false
}
return res.(bool)
}