|
@@ -1,8 +1,8 @@
|
|
|
package api
|
|
|
|
|
|
import (
|
|
|
- "github.com/0xJacky/Nginx-UI/model"
|
|
|
- "github.com/0xJacky/Nginx-UI/tool"
|
|
|
+ "github.com/0xJacky/Nginx-UI/server/model"
|
|
|
+ tool2 "github.com/0xJacky/Nginx-UI/server/tool"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
@@ -20,14 +20,14 @@ func GetDomains(c *gin.Context) {
|
|
|
"modify": "time",
|
|
|
}
|
|
|
|
|
|
- configFiles, err := ioutil.ReadDir(tool.GetNginxConfPath("sites-available"))
|
|
|
+ configFiles, err := ioutil.ReadDir(tool2.GetNginxConfPath("sites-available"))
|
|
|
|
|
|
if err != nil {
|
|
|
ErrHandler(c, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- enabledConfig, err := ioutil.ReadDir(filepath.Join(tool.GetNginxConfPath("sites-enabled")))
|
|
|
+ enabledConfig, err := ioutil.ReadDir(filepath.Join(tool2.GetNginxConfPath("sites-enabled")))
|
|
|
|
|
|
enabledConfigMap := make(map[string]bool)
|
|
|
for i := range enabledConfig {
|
|
@@ -53,7 +53,7 @@ func GetDomains(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- configs = tool.Sort(orderBy, sort, mySort[orderBy], configs)
|
|
|
+ configs = tool2.Sort(orderBy, sort, mySort[orderBy], configs)
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
"configs": configs,
|
|
@@ -62,10 +62,10 @@ func GetDomains(c *gin.Context) {
|
|
|
|
|
|
func GetDomain(c *gin.Context) {
|
|
|
name := c.Param("name")
|
|
|
- path := filepath.Join(tool.GetNginxConfPath("sites-available"), name)
|
|
|
+ path := filepath.Join(tool2.GetNginxConfPath("sites-available"), name)
|
|
|
|
|
|
enabled := true
|
|
|
- if _, err := os.Stat(filepath.Join(tool.GetNginxConfPath("sites-enabled"), name)); os.IsNotExist(err) {
|
|
|
+ if _, err := os.Stat(filepath.Join(tool2.GetNginxConfPath("sites-enabled"), name)); os.IsNotExist(err) {
|
|
|
enabled = false
|
|
|
}
|
|
|
|
|
@@ -98,7 +98,7 @@ func EditDomain(c *gin.Context) {
|
|
|
name := c.Param("name")
|
|
|
request := make(gin.H)
|
|
|
err = c.BindJSON(&request)
|
|
|
- path := filepath.Join(tool.GetNginxConfPath("sites-available"), name)
|
|
|
+ path := filepath.Join(tool2.GetNginxConfPath("sites-available"), name)
|
|
|
|
|
|
err = ioutil.WriteFile(path, []byte(request["content"].(string)), 0644)
|
|
|
if err != nil {
|
|
@@ -106,10 +106,10 @@ func EditDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), name)
|
|
|
+ enabledConfigFilePath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), name)
|
|
|
if _, err = os.Stat(enabledConfigFilePath); err == nil {
|
|
|
// 测试配置文件
|
|
|
- err = tool.TestNginxConf(enabledConfigFilePath)
|
|
|
+ err = tool2.TestNginxConf(enabledConfigFilePath)
|
|
|
if err != nil {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
"message": err.Error(),
|
|
@@ -117,7 +117,7 @@ func EditDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output := tool.ReloadNginx()
|
|
|
+ output := tool2.ReloadNginx()
|
|
|
|
|
|
if output != "" {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
@@ -131,8 +131,8 @@ func EditDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func EnableDomain(c *gin.Context) {
|
|
|
- configFilePath := filepath.Join(tool.GetNginxConfPath("sites-available"), c.Param("name"))
|
|
|
- enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
|
|
+ configFilePath := filepath.Join(tool2.GetNginxConfPath("sites-available"), c.Param("name"))
|
|
|
+ enabledConfigFilePath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
|
|
|
|
|
_, err := os.Stat(configFilePath)
|
|
|
|
|
@@ -149,7 +149,7 @@ func EnableDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
// 测试配置文件,不通过则撤回启用
|
|
|
- err = tool.TestNginxConf(enabledConfigFilePath)
|
|
|
+ err = tool2.TestNginxConf(enabledConfigFilePath)
|
|
|
if err != nil {
|
|
|
_ = os.Remove(enabledConfigFilePath)
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
@@ -158,7 +158,7 @@ func EnableDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output := tool.ReloadNginx()
|
|
|
+ output := tool2.ReloadNginx()
|
|
|
|
|
|
if output != "" {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
@@ -173,7 +173,7 @@ func EnableDomain(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func DisableDomain(c *gin.Context) {
|
|
|
- enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
|
|
+ enabledConfigFilePath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
|
|
|
|
|
_, err := os.Stat(enabledConfigFilePath)
|
|
|
|
|
@@ -189,7 +189,7 @@ func DisableDomain(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- output := tool.ReloadNginx()
|
|
|
+ output := tool2.ReloadNginx()
|
|
|
|
|
|
if output != "" {
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
@@ -206,8 +206,8 @@ func DisableDomain(c *gin.Context) {
|
|
|
func DeleteDomain(c *gin.Context) {
|
|
|
var err error
|
|
|
name := c.Param("name")
|
|
|
- availablePath := filepath.Join(tool.GetNginxConfPath("sites-available"), name)
|
|
|
- enabledPath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), name)
|
|
|
+ availablePath := filepath.Join(tool2.GetNginxConfPath("sites-available"), name)
|
|
|
+ enabledPath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), name)
|
|
|
|
|
|
if _, err = os.Stat(availablePath); os.IsNotExist(err) {
|
|
|
c.JSON(http.StatusNotFound, gin.H{
|