|
@@ -1,19 +1,19 @@
|
|
|
package api
|
|
|
|
|
|
import (
|
|
|
- "github.com/0xJacky/Nginx-UI/server/internal/cert"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/internal/config_list"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/internal/helper"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/internal/logger"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/internal/nginx"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/model"
|
|
|
- "github.com/0xJacky/Nginx-UI/server/query"
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
- "github.com/sashabaranov/go-openai"
|
|
|
- "net/http"
|
|
|
- "os"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "github.com/0xJacky/Nginx-UI/internal/cert"
|
|
|
+ "github.com/0xJacky/Nginx-UI/internal/config_list"
|
|
|
+ helper2 "github.com/0xJacky/Nginx-UI/internal/helper"
|
|
|
+ "github.com/0xJacky/Nginx-UI/internal/logger"
|
|
|
+ nginx2 "github.com/0xJacky/Nginx-UI/internal/nginx"
|
|
|
+ "github.com/0xJacky/Nginx-UI/model"
|
|
|
+ "github.com/0xJacky/Nginx-UI/query"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "github.com/sashabaranov/go-openai"
|
|
|
+ "net/http"
|
|
|
+ "os"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
func GetDomains(c *gin.Context) {
|
|
@@ -27,14 +27,14 @@ func GetDomains(c *gin.Context) {
|
|
|
"modify": "time",
|
|
|
}
|
|
|
|
|
|
- configFiles, err := os.ReadDir(nginx.GetConfPath("sites-available"))
|
|
|
+ configFiles, err := os.ReadDir(nginx2.GetConfPath("sites-available"))
|
|
|
|
|
|
if err != nil {
|
|
|
ErrHandler(c, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- enabledConfig, err := os.ReadDir(nginx.GetConfPath("sites-enabled"))
|
|
|
+ enabledConfig, err := os.ReadDir(nginx2.GetConfPath("sites-enabled"))
|
|
|
|
|
|
if err != nil {
|
|
|
ErrHandler(c, err)
|
|
@@ -88,7 +88,7 @@ func GetDomain(c *gin.Context) {
|
|
|
name = rewriteName.(string)
|
|
|
}
|
|
|
|
|
|
- path := nginx.GetConfPath("sites-available", name)
|
|
|
+ path := nginx2.GetConfPath("sites-available", name)
|
|
|
file, err := os.Stat(path)
|
|
|
if os.IsNotExist(err) {
|
|
|
c.JSON(http.StatusNotFound, gin.H{
|
|
@@ -99,7 +99,7 @@ func GetDomain(c *gin.Context) {
|
|
|
|
|
|
enabled := true
|
|
|
|
|
|
- if _, err := os.Stat(nginx.GetConfPath("sites-enabled", name)); os.IsNotExist(err) {
|
|
|
+ if _, err := os.Stat(nginx2.GetConfPath("sites-enabled", name)); os.IsNotExist(err) {
|
|
|
enabled = false
|
|
|
}
|
|
|
|
|
@@ -149,7 +149,7 @@ func GetDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
c.Set("maybe_error", "nginx_config_syntax_error")
|
|
|
- config, err := nginx.ParseNgxConfig(path)
|
|
|
+ config, err := nginx2.ParseNgxConfig(path)
|
|
|
|
|
|
if err != nil {
|
|
|
ErrHandler(c, err)
|
|
@@ -218,9 +218,9 @@ func SaveDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- path := nginx.GetConfPath("sites-available", name)
|
|
|
+ path := nginx2.GetConfPath("sites-available", name)
|
|
|
|
|
|
- if !json.Overwrite && helper.FileExists(path) {
|
|
|
+ if !json.Overwrite && helper2.FileExists(path) {
|
|
|
c.JSON(http.StatusNotAcceptable, gin.H{
|
|
|
"message": "File exists",
|
|
|
})
|
|
@@ -232,24 +232,24 @@ func SaveDomain(c *gin.Context) {
|
|
|
ErrHandler(c, err)
|
|
|
return
|
|
|
}
|
|
|
- enabledConfigFilePath := nginx.GetConfPath("sites-enabled", name)
|
|
|
+ enabledConfigFilePath := nginx2.GetConfPath("sites-enabled", name)
|
|
|
// rename the config file if needed
|
|
|
if name != json.Name {
|
|
|
- newPath := nginx.GetConfPath("sites-available", json.Name)
|
|
|
+ newPath := nginx2.GetConfPath("sites-available", json.Name)
|
|
|
s := query.Site
|
|
|
_, err = s.Where(s.Path.Eq(path)).Update(s.Path, newPath)
|
|
|
|
|
|
// check if dst file exists, do not rename
|
|
|
- if helper.FileExists(newPath) {
|
|
|
+ if helper2.FileExists(newPath) {
|
|
|
c.JSON(http.StatusNotAcceptable, gin.H{
|
|
|
"message": "File exists",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
// recreate soft link
|
|
|
- if helper.FileExists(enabledConfigFilePath) {
|
|
|
+ if helper2.FileExists(enabledConfigFilePath) {
|
|
|
_ = os.Remove(enabledConfigFilePath)
|
|
|
- enabledConfigFilePath = nginx.GetConfPath("sites-enabled", json.Name)
|
|
|
+ enabledConfigFilePath = nginx2.GetConfPath("sites-enabled", json.Name)
|
|
|
err = os.Symlink(newPath, enabledConfigFilePath)
|
|
|
|
|
|
if err != nil {
|
|
@@ -268,12 +268,12 @@ func SaveDomain(c *gin.Context) {
|
|
|
c.Set("rewriteConfigFileName", name)
|
|
|
}
|
|
|
|
|
|
- enabledConfigFilePath = nginx.GetConfPath("sites-enabled", name)
|
|
|
- if helper.FileExists(enabledConfigFilePath) {
|
|
|
+ enabledConfigFilePath = nginx2.GetConfPath("sites-enabled", name)
|
|
|
+ if helper2.FileExists(enabledConfigFilePath) {
|
|
|
// Test nginx configuration
|
|
|
- output := nginx.TestConf()
|
|
|
+ output := nginx2.TestConf()
|
|
|
|
|
|
- if nginx.GetLogLevel(output) > nginx.Warn {
|
|
|
+ if nginx2.GetLogLevel(output) > nginx2.Warn {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": output,
|
|
|
"error": "nginx_config_syntax_error",
|
|
@@ -281,9 +281,9 @@ func SaveDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output = nginx.Reload()
|
|
|
+ output = nginx2.Reload()
|
|
|
|
|
|
- if nginx.GetLogLevel(output) > nginx.Warn {
|
|
|
+ if nginx2.GetLogLevel(output) > nginx2.Warn {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": output,
|
|
|
})
|
|
@@ -295,8 +295,8 @@ func SaveDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func EnableDomain(c *gin.Context) {
|
|
|
- configFilePath := nginx.GetConfPath("sites-available", c.Param("name"))
|
|
|
- enabledConfigFilePath := nginx.GetConfPath("sites-enabled", c.Param("name"))
|
|
|
+ configFilePath := nginx2.GetConfPath("sites-available", c.Param("name"))
|
|
|
+ enabledConfigFilePath := nginx2.GetConfPath("sites-enabled", c.Param("name"))
|
|
|
|
|
|
_, err := os.Stat(configFilePath)
|
|
|
|
|
@@ -315,9 +315,9 @@ func EnableDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
// Test nginx config, if not pass then disable the site.
|
|
|
- output := nginx.TestConf()
|
|
|
+ output := nginx2.TestConf()
|
|
|
|
|
|
- if nginx.GetLogLevel(output) > nginx.Warn {
|
|
|
+ if nginx2.GetLogLevel(output) > nginx2.Warn {
|
|
|
_ = os.Remove(enabledConfigFilePath)
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": output,
|
|
@@ -325,9 +325,9 @@ func EnableDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output = nginx.Reload()
|
|
|
+ output = nginx2.Reload()
|
|
|
|
|
|
- if nginx.GetLogLevel(output) > nginx.Warn {
|
|
|
+ if nginx2.GetLogLevel(output) > nginx2.Warn {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": output,
|
|
|
})
|
|
@@ -340,7 +340,7 @@ func EnableDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func DisableDomain(c *gin.Context) {
|
|
|
- enabledConfigFilePath := nginx.GetConfPath("sites-enabled", c.Param("name"))
|
|
|
+ enabledConfigFilePath := nginx2.GetConfPath("sites-enabled", c.Param("name"))
|
|
|
|
|
|
_, err := os.Stat(enabledConfigFilePath)
|
|
|
|
|
@@ -364,9 +364,9 @@ func DisableDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output := nginx.Reload()
|
|
|
+ output := nginx2.Reload()
|
|
|
|
|
|
- if nginx.GetLogLevel(output) > nginx.Warn {
|
|
|
+ if nginx2.GetLogLevel(output) > nginx2.Warn {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": output,
|
|
|
})
|
|
@@ -381,8 +381,8 @@ func DisableDomain(c *gin.Context) {
|
|
|
func DeleteDomain(c *gin.Context) {
|
|
|
var err error
|
|
|
name := c.Param("name")
|
|
|
- availablePath := nginx.GetConfPath("sites-available", name)
|
|
|
- enabledPath := nginx.GetConfPath("sites-enabled", name)
|
|
|
+ availablePath := nginx2.GetConfPath("sites-available", name)
|
|
|
+ enabledPath := nginx2.GetConfPath("sites-enabled", name)
|
|
|
|
|
|
if _, err = os.Stat(availablePath); os.IsNotExist(err) {
|
|
|
c.JSON(http.StatusNotFound, gin.H{
|
|
@@ -418,7 +418,7 @@ func AddDomainToAutoCert(c *gin.Context) {
|
|
|
name := c.Param("name")
|
|
|
|
|
|
var json struct {
|
|
|
- model.Cert
|
|
|
+ model.Cert
|
|
|
Domains []string `json:"domains"`
|
|
|
}
|
|
|
|
|
@@ -480,17 +480,17 @@ func DuplicateSite(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- src := nginx.GetConfPath("sites-available", name)
|
|
|
- dst := nginx.GetConfPath("sites-available", json.Name)
|
|
|
+ src := nginx2.GetConfPath("sites-available", name)
|
|
|
+ dst := nginx2.GetConfPath("sites-available", json.Name)
|
|
|
|
|
|
- if helper.FileExists(dst) {
|
|
|
+ if helper2.FileExists(dst) {
|
|
|
c.JSON(http.StatusNotAcceptable, gin.H{
|
|
|
"message": "File exists",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- _, err := helper.CopyFile(src, dst)
|
|
|
+ _, err := helper2.CopyFile(src, dst)
|
|
|
|
|
|
if err != nil {
|
|
|
ErrHandler(c, err)
|
|
@@ -512,7 +512,7 @@ func DomainEditByAdvancedMode(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
name := c.Param("name")
|
|
|
- path := nginx.GetConfPath("sites-available", name)
|
|
|
+ path := nginx2.GetConfPath("sites-available", name)
|
|
|
|
|
|
s := query.Site
|
|
|
|