1
0

mkdir.go 812 B

12345678910111213141516171819202122232425262728293031323334353637
  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. "net/http"
  8. "os"
  9. )
  10. func Mkdir(c *gin.Context) {
  11. var json struct {
  12. BasePath string `json:"base_path"`
  13. FolderName string `json:"folder_name"`
  14. }
  15. if !api.BindAndValid(c, &json) {
  16. return
  17. }
  18. fullPath := nginx.GetConfPath(json.BasePath, json.FolderName)
  19. if !helper.IsUnderDirectory(fullPath, nginx.GetConfPath()) {
  20. c.JSON(http.StatusForbidden, gin.H{
  21. "message": "You are not allowed to create a folder " +
  22. "outside of the nginx configuration directory",
  23. })
  24. return
  25. }
  26. err := os.Mkdir(fullPath, 0755)
  27. if err != nil {
  28. api.ErrHandler(c, err)
  29. return
  30. }
  31. c.JSON(http.StatusOK, gin.H{
  32. "message": "ok",
  33. })
  34. }