enhance: clean filepath

This commit is contained in:
Jacky 2024-10-08 09:59:42 +08:00
parent 46a9ccbdf1
commit abd76ff930
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
2 changed files with 8 additions and 2 deletions

View file

@ -18,7 +18,6 @@ func GetConfigs(c *gin.Context) {
dir := c.DefaultQuery("dir", "/")
configFiles, err := os.ReadDir(nginx.GetConfPath(dir))
if err != nil {
api.ErrHandler(c, err)
return

View file

@ -1,6 +1,7 @@
package nginx
import (
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/0xJacky/Nginx-UI/settings"
"os/exec"
@ -31,7 +32,13 @@ func GetConfPath(dir ...string) (confPath string) {
confPath = settings.NginxSettings.ConfigDir
}
return filepath.Join(confPath, filepath.Join(dir...))
joined := filepath.Clean(filepath.Join(confPath, filepath.Join(dir...)))
if !helper.IsUnderDirectory(confPath, joined) {
return confPath
}
return
}
func GetPIDPath() (path string) {