1
0

tasks.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package self_check
  2. import (
  3. "github.com/0xJacky/Nginx-UI/internal/helper"
  4. "github.com/0xJacky/Nginx-UI/internal/translation"
  5. "github.com/elliotchance/orderedmap/v3"
  6. "github.com/uozi-tech/cosy"
  7. )
  8. type Task struct {
  9. Key string
  10. Name *translation.Container
  11. Description *translation.Container
  12. CheckFunc func() error
  13. FixFunc func() error
  14. }
  15. type ReportStatus string
  16. const (
  17. ReportStatusSuccess ReportStatus = "success"
  18. ReportStatusWarning ReportStatus = "warning"
  19. ReportStatusError ReportStatus = "error"
  20. )
  21. type Report struct {
  22. Key string `json:"key"`
  23. Name *translation.Container `json:"name"`
  24. Description *translation.Container `json:"description,omitempty"`
  25. Fixable bool `json:"fixable"`
  26. Err *cosy.Error `json:"err,omitempty"`
  27. Status ReportStatus `json:"status"`
  28. }
  29. type Reports []*Report
  30. var selfCheckTasks = []*Task{
  31. {
  32. Key: "Directory-Sites",
  33. Name: translation.C("Sites directory exists"),
  34. Description: translation.C("Check if the " +
  35. "sites-available and sites-enabled directories are " +
  36. "under the nginx configuration directory"),
  37. CheckFunc: CheckSitesDirectory,
  38. FixFunc: FixSitesDirectory,
  39. },
  40. {
  41. Key: "Directory-Streams",
  42. Name: translation.C("Streams directory exists"),
  43. Description: translation.C("Check if the " +
  44. "streams-available and streams-enabled directories are " +
  45. "under the nginx configuration directory"),
  46. CheckFunc: CheckStreamDirectory,
  47. FixFunc: FixStreamDirectory,
  48. },
  49. {
  50. Key: "NginxConf-Sites-Enabled",
  51. Name: translation.C("Nginx.conf includes sites-enabled directory"),
  52. Description: translation.C("Check if the nginx.conf includes the " +
  53. "sites-enabled directory"),
  54. CheckFunc: CheckNginxConfIncludeSites,
  55. FixFunc: FixNginxConfIncludeSites,
  56. },
  57. {
  58. Key: "NginxConf-Streams-Enabled",
  59. Name: translation.C("Nginx.conf includes streams-enabled directory"),
  60. Description: translation.C("Check if the nginx.conf includes the " +
  61. "streams-enabled directory"),
  62. CheckFunc: CheckNginxConfIncludeStreams,
  63. FixFunc: FixNginxConfIncludeStreams,
  64. },
  65. {
  66. Key: "NginxConf-ConfD",
  67. Name: translation.C("Nginx.conf includes conf.d directory"),
  68. Description: translation.C("Check if the nginx.conf includes the " +
  69. "conf.d directory"),
  70. CheckFunc: CheckNginxConfIncludeConfD,
  71. FixFunc: FixNginxConfIncludeConfD,
  72. },
  73. {
  74. Key: "NginxConf-Directory",
  75. Name: translation.C("Nginx configuration directory exists"),
  76. Description: translation.C("Check if the nginx configuration directory exists"),
  77. CheckFunc: CheckConfigDir,
  78. },
  79. {
  80. Key: "NginxConf-Entry-File",
  81. Name: translation.C("Nginx configuration entry file exists"),
  82. Description: translation.C("Check if the nginx configuration entry file exists"),
  83. CheckFunc: CheckConfigEntryFile,
  84. },
  85. {
  86. Key: "NginxPID-Path",
  87. Name: translation.C("Nginx PID path exists"),
  88. Description: translation.C("Check if the nginx PID path exists"),
  89. CheckFunc: CheckPIDPath,
  90. },
  91. {
  92. Key: "NginxAccessLog-Path",
  93. Name: translation.C("Nginx access log path exists"),
  94. Description: translation.C("Check if the nginx access log path exists"),
  95. CheckFunc: CheckAccessLogPath,
  96. },
  97. {
  98. Key: "NginxErrorLog-Path",
  99. Name: translation.C("Nginx error log path exists"),
  100. Description: translation.C("Check if the nginx error log path exists"),
  101. CheckFunc: CheckErrorLogPath,
  102. },
  103. }
  104. var selfCheckTaskMap = orderedmap.NewOrderedMap[string, *Task]()
  105. func init() {
  106. for _, task := range selfCheckTasks {
  107. selfCheckTaskMap.Set(task.Key, task)
  108. }
  109. if helper.InNginxUIOfficialDocker() {
  110. selfCheckTasks = append(selfCheckTasks, &Task{
  111. Name: translation.C("Docker socket exists"),
  112. Description: translation.C("Check if the docker socket exists."),
  113. CheckFunc: CheckDockerSocket,
  114. })
  115. }
  116. }