mkdir.go 842 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package config
  2. import (
  3. "github.com/0xJacky/Nginx-UI/api"
  4. "github.com/0xJacky/Nginx-UI/internal/helper"
  5. "github.com/0xJacky/Nginx-UI/internal/nginx"
  6. "github.com/gin-gonic/gin"
  7. "github.com/uozi-tech/cosy"
  8. "net/http"
  9. "os"
  10. )
  11. func Mkdir(c *gin.Context) {
  12. var json struct {
  13. BasePath string `json:"base_path"`
  14. FolderName string `json:"folder_name"`
  15. }
  16. if !cosy.BindAndValid(c, &json) {
  17. return
  18. }
  19. fullPath := nginx.GetConfPath(json.BasePath, json.FolderName)
  20. if !helper.IsUnderDirectory(fullPath, nginx.GetConfPath()) {
  21. c.JSON(http.StatusForbidden, gin.H{
  22. "message": "You are not allowed to create a folder " +
  23. "outside of the nginx configuration directory",
  24. })
  25. return
  26. }
  27. err := os.Mkdir(fullPath, 0755)
  28. if err != nil {
  29. api.ErrHandler(c, err)
  30. return
  31. }
  32. c.JSON(http.StatusOK, gin.H{
  33. "message": "ok",
  34. })
  35. }