1
0

nginx_log.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package nginx_log
  2. import (
  3. "fmt"
  4. "github.com/0xJacky/Nginx-UI/internal/cache"
  5. "github.com/0xJacky/Nginx-UI/internal/helper"
  6. "github.com/0xJacky/Nginx-UI/internal/nginx"
  7. "github.com/0xJacky/Nginx-UI/settings"
  8. "path/filepath"
  9. )
  10. // IsLogPathUnderWhiteList checks if the log path is under one of the paths in LogDirWhiteList
  11. func IsLogPathUnderWhiteList(path string) bool {
  12. cacheKey := fmt.Sprintf("isLogPathUnderWhiteList:%s", path)
  13. res, ok := cache.Get(cacheKey)
  14. // deep copy
  15. logDirWhiteList := append([]string{}, settings.NginxSettings.LogDirWhiteList...)
  16. accessLogPath := nginx.GetAccessLogPath()
  17. errorLogPath := nginx.GetErrorLogPath()
  18. if accessLogPath != "" {
  19. logDirWhiteList = append(logDirWhiteList, filepath.Dir(accessLogPath))
  20. }
  21. if errorLogPath != "" {
  22. logDirWhiteList = append(logDirWhiteList, filepath.Dir(errorLogPath))
  23. }
  24. // no cache, check it
  25. if !ok {
  26. for _, whitePath := range logDirWhiteList {
  27. if helper.IsUnderDirectory(path, whitePath) {
  28. cache.Set(cacheKey, true, 0)
  29. return true
  30. }
  31. }
  32. return false
  33. }
  34. return res.(bool)
  35. }