mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
Clean codes.
This commit is contained in:
parent
830351985c
commit
584cbd745c
4 changed files with 42 additions and 42 deletions
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
tool2 "github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
"log"
|
||||
|
@ -13,7 +13,7 @@ import (
|
|||
func CertInfo(c *gin.Context) {
|
||||
domain := c.Param("domain")
|
||||
|
||||
key := tool2.GetCertInfo(domain)
|
||||
key := tool.GetCertInfo(domain)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"subject_name": key.Subject.CommonName,
|
||||
|
@ -55,7 +55,7 @@ func IssueCert(c *gin.Context) {
|
|||
if string(message) == "go" {
|
||||
var m []byte
|
||||
|
||||
err = tool2.IssueCert(domain)
|
||||
err = tool.IssueCert(domain)
|
||||
if err != nil {
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "error",
|
||||
|
@ -78,7 +78,7 @@ func IssueCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
sslCertificatePath := tool2.GetNginxConfPath("ssl/" + domain + "/fullchain.cer")
|
||||
sslCertificatePath := tool.GetNginxConfPath("ssl/" + domain + "/fullchain.cer")
|
||||
_, err = os.Stat(sslCertificatePath)
|
||||
|
||||
if err != nil {
|
||||
|
@ -104,7 +104,7 @@ func IssueCert(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
sslCertificateKeyPath := tool2.GetNginxConfPath("ssl/" + domain + "/" + domain + ".key")
|
||||
sslCertificateKeyPath := tool.GetNginxConfPath("ssl/" + domain + "/" + domain + ".key")
|
||||
_, err = os.Stat(sslCertificateKeyPath)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
tool2 "github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -19,7 +19,7 @@ func GetConfigs(c *gin.Context) {
|
|||
"modify": "time",
|
||||
}
|
||||
|
||||
configFiles, err := ioutil.ReadDir(tool2.GetNginxConfPath("/"))
|
||||
configFiles, err := ioutil.ReadDir(tool.GetNginxConfPath("/"))
|
||||
|
||||
if err != nil {
|
||||
ErrHandler(c, err)
|
||||
|
@ -40,7 +40,7 @@ func GetConfigs(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
configs = tool2.Sort(orderBy, sort, mySort[orderBy], configs)
|
||||
configs = tool.Sort(orderBy, sort, mySort[orderBy], configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"configs": configs,
|
||||
|
@ -49,7 +49,7 @@ func GetConfigs(c *gin.Context) {
|
|||
|
||||
func GetConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
path := filepath.Join(tool2.GetNginxConfPath("/"), name)
|
||||
path := filepath.Join(tool.GetNginxConfPath("/"), name)
|
||||
|
||||
content, err := ioutil.ReadFile(path)
|
||||
|
||||
|
@ -80,7 +80,7 @@ func AddConfig(c *gin.Context) {
|
|||
name := request.Name
|
||||
content := request.Content
|
||||
|
||||
path := filepath.Join(tool2.GetNginxConfPath("/"), name)
|
||||
path := filepath.Join(tool.GetNginxConfPath("/"), name)
|
||||
|
||||
log.Println(path)
|
||||
if _, err = os.Stat(path); err == nil {
|
||||
|
@ -98,7 +98,7 @@ func AddConfig(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
output := tool2.ReloadNginx()
|
||||
output := tool.ReloadNginx()
|
||||
|
||||
if output != "" {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
|
@ -126,7 +126,7 @@ func EditConfig(c *gin.Context) {
|
|||
ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
path := filepath.Join(tool2.GetNginxConfPath("/"), name)
|
||||
path := filepath.Join(tool.GetNginxConfPath("/"), name)
|
||||
content := request.Content
|
||||
|
||||
origContent, err := ioutil.ReadFile(path)
|
||||
|
@ -144,7 +144,7 @@ func EditConfig(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
output := tool2.ReloadNginx()
|
||||
output := tool.ReloadNginx()
|
||||
|
||||
if output != "" {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
|
|
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
tool2 "github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"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(tool2.GetNginxConfPath("sites-available"))
|
||||
configFiles, err := ioutil.ReadDir(tool.GetNginxConfPath("sites-available"))
|
||||
|
||||
if err != nil {
|
||||
ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
enabledConfig, err := ioutil.ReadDir(filepath.Join(tool2.GetNginxConfPath("sites-enabled")))
|
||||
enabledConfig, err := ioutil.ReadDir(filepath.Join(tool.GetNginxConfPath("sites-enabled")))
|
||||
|
||||
enabledConfigMap := make(map[string]bool)
|
||||
for i := range enabledConfig {
|
||||
|
@ -53,7 +53,7 @@ func GetDomains(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
configs = tool2.Sort(orderBy, sort, mySort[orderBy], configs)
|
||||
configs = tool.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(tool2.GetNginxConfPath("sites-available"), name)
|
||||
path := filepath.Join(tool.GetNginxConfPath("sites-available"), name)
|
||||
|
||||
enabled := true
|
||||
if _, err := os.Stat(filepath.Join(tool2.GetNginxConfPath("sites-enabled"), name)); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filepath.Join(tool.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(tool2.GetNginxConfPath("sites-available"), name)
|
||||
path := filepath.Join(tool.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(tool2.GetNginxConfPath("sites-enabled"), name)
|
||||
enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), name)
|
||||
if _, err = os.Stat(enabledConfigFilePath); err == nil {
|
||||
// 测试配置文件
|
||||
err = tool2.TestNginxConf(enabledConfigFilePath)
|
||||
err = tool.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 := tool2.ReloadNginx()
|
||||
output := tool.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(tool2.GetNginxConfPath("sites-available"), c.Param("name"))
|
||||
enabledConfigFilePath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
||||
configFilePath := filepath.Join(tool.GetNginxConfPath("sites-available"), c.Param("name"))
|
||||
enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
||||
|
||||
_, err := os.Stat(configFilePath)
|
||||
|
||||
|
@ -149,7 +149,7 @@ func EnableDomain(c *gin.Context) {
|
|||
}
|
||||
|
||||
// 测试配置文件,不通过则撤回启用
|
||||
err = tool2.TestNginxConf(enabledConfigFilePath)
|
||||
err = tool.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 := tool2.ReloadNginx()
|
||||
output := tool.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(tool2.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
||||
enabledConfigFilePath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), c.Param("name"))
|
||||
|
||||
_, err := os.Stat(enabledConfigFilePath)
|
||||
|
||||
|
@ -189,7 +189,7 @@ func DisableDomain(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
output := tool2.ReloadNginx()
|
||||
output := tool.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(tool2.GetNginxConfPath("sites-available"), name)
|
||||
enabledPath := filepath.Join(tool2.GetNginxConfPath("sites-enabled"), name)
|
||||
availablePath := filepath.Join(tool.GetNginxConfPath("sites-available"), name)
|
||||
enabledPath := filepath.Join(tool.GetNginxConfPath("sites-enabled"), name)
|
||||
|
||||
if _, err = os.Stat(availablePath); os.IsNotExist(err) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
|
|
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"errors"
|
||||
model2 "github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
@ -10,9 +10,9 @@ import (
|
|||
)
|
||||
|
||||
func GetUsers(c *gin.Context) {
|
||||
curd := model2.NewCurd(&model2.Auth{})
|
||||
curd := model.NewCurd(&model.Auth{})
|
||||
|
||||
var list []model2.Auth
|
||||
var list []model.Auth
|
||||
err := curd.GetList(&list)
|
||||
|
||||
if err != nil {
|
||||
|
@ -25,10 +25,10 @@ func GetUsers(c *gin.Context) {
|
|||
}
|
||||
|
||||
func GetUser(c *gin.Context) {
|
||||
curd := model2.NewCurd(&model2.Auth{})
|
||||
curd := model.NewCurd(&model.Auth{})
|
||||
id := c.Param("id")
|
||||
|
||||
var user model2.Auth
|
||||
var user model.Auth
|
||||
err := curd.First(&user, id)
|
||||
|
||||
if err != nil {
|
||||
|
@ -49,7 +49,7 @@ func AddUser(c *gin.Context) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
curd := model2.NewCurd(&model2.Auth{})
|
||||
curd := model.NewCurd(&model.Auth{})
|
||||
|
||||
pwd, err := bcrypt.GenerateFromPassword([]byte(json.Password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
|
@ -58,7 +58,7 @@ func AddUser(c *gin.Context) {
|
|||
}
|
||||
json.Password = string(pwd)
|
||||
|
||||
user := model2.Auth{
|
||||
user := model.Auth{
|
||||
Name: json.Name,
|
||||
Password: json.Password,
|
||||
}
|
||||
|
@ -80,9 +80,9 @@ func EditUser(c *gin.Context) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
curd := model2.NewCurd(&model2.Auth{})
|
||||
curd := model.NewCurd(&model.Auth{})
|
||||
|
||||
var user, edit model2.Auth
|
||||
var user, edit model.Auth
|
||||
|
||||
err := curd.First(&user, c.Param("id"))
|
||||
|
||||
|
@ -120,8 +120,8 @@ func DeleteUser(c *gin.Context) {
|
|||
ErrHandler(c, errors.New("不允许删除默认账户"))
|
||||
return
|
||||
}
|
||||
curd := model2.NewCurd(&model2.Auth{})
|
||||
err := curd.Delete(&model2.Auth{}, "id", id)
|
||||
curd := model.NewCurd(&model.Auth{})
|
||||
err := curd.Delete(&model.Auth{}, "id", id)
|
||||
if err != nil {
|
||||
ErrHandler(c, err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue