template.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package api
  2. import (
  3. "github.com/0xJacky/Nginx-UI/server/pkg/nginx"
  4. "github.com/0xJacky/Nginx-UI/server/settings"
  5. "github.com/gin-gonic/gin"
  6. "net/http"
  7. "strings"
  8. )
  9. func GetTemplate(c *gin.Context) {
  10. content := `proxy_set_header Host $host;
  11. proxy_set_header X-Real_IP $remote_addr;
  12. proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
  13. proxy_pass http://127.0.0.1:{{ HTTP01PORT }};
  14. `
  15. content = strings.ReplaceAll(content, "{{ HTTP01PORT }}",
  16. settings.ServerSettings.HTTPChallengePort)
  17. var ngxConfig *nginx.NgxConfig
  18. ngxConfig = &nginx.NgxConfig{
  19. Servers: []*nginx.NgxServer{
  20. {
  21. Directives: []*nginx.NgxDirective{
  22. {
  23. Directive: "listen",
  24. Params: "80",
  25. },
  26. {
  27. Directive: "listen",
  28. Params: "[::]:80",
  29. },
  30. {
  31. Directive: "server_name",
  32. },
  33. {
  34. Directive: "root",
  35. },
  36. {
  37. Directive: "index",
  38. },
  39. },
  40. Locations: []*nginx.NgxLocation{
  41. {
  42. Path: "/.well-known/acme-challenge",
  43. Content: content,
  44. },
  45. },
  46. },
  47. },
  48. }
  49. c.JSON(http.StatusOK, gin.H{
  50. "message": "ok",
  51. "template": ngxConfig.BuildConfig(),
  52. "tokenized": ngxConfig,
  53. })
  54. }