mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
change work dir
This commit is contained in:
parent
b37c1e8eac
commit
ad421905a8
17 changed files with 231 additions and 618 deletions
|
@ -3,7 +3,7 @@ package api
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
|
|
|
@ -3,7 +3,7 @@ package api
|
|||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/unknwon/com"
|
||||
"net/http"
|
||||
|
@ -21,4 +21,4 @@ func GetFileBackup(c *gin.Context) {
|
|||
backup := model.GetBackup(com.StrTo(id).MustInt())
|
||||
|
||||
c.JSON(http.StatusOK, backup)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,183 +1,182 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func CertInfo(c *gin.Context) {
|
||||
domain := c.Param("domain")
|
||||
domain := c.Param("domain")
|
||||
|
||||
/*sslCertificatePath := tool.GetNginxConfPath("ssl/" + domain +"/fullchain.cer")
|
||||
/*sslCertificatePath := tool.GetNginxConfPath("ssl/" + domain +"/fullchain.cer")
|
||||
|
||||
content, err := ioutil.ReadFile(sslCertificatePath)
|
||||
content, err := ioutil.ReadFile(sslCertificatePath)
|
||||
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
certDERBlock, _ := pem.Decode(content)
|
||||
certDERBlock, _ := pem.Decode(content)
|
||||
|
||||
if certDERBlock == nil {
|
||||
ErrorHandler(c, errors.New("pem decode error"))
|
||||
return
|
||||
}
|
||||
if certDERBlock == nil {
|
||||
ErrorHandler(c, errors.New("pem decode error"))
|
||||
return
|
||||
}
|
||||
|
||||
var key *x509.Certificate
|
||||
key, err = x509.ParseCertificate(certDERBlock.Bytes)
|
||||
var key *x509.Certificate
|
||||
key, err = x509.ParseCertificate(certDERBlock.Bytes)
|
||||
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}*/
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}*/
|
||||
|
||||
ts := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
ts := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
|
||||
client := &http.Client{Transport: ts}
|
||||
client := &http.Client{Transport: ts}
|
||||
|
||||
response, err := client.Get("https://" + domain)
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err = Body.Close()
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
}(response.Body)
|
||||
response, err := client.Get("https://" + domain)
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
err = Body.Close()
|
||||
if err != nil {
|
||||
ErrorHandler(c, err)
|
||||
return
|
||||
}
|
||||
}(response.Body)
|
||||
|
||||
key := response.TLS.PeerCertificates[0]
|
||||
key := response.TLS.PeerCertificates[0]
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"subject_name": key.Subject.CommonName,
|
||||
"issuer_name": key.Issuer.CommonName,
|
||||
"not_after": key.NotAfter,
|
||||
"not_before": key.NotBefore,
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"subject_name": key.Subject.CommonName,
|
||||
"issuer_name": key.Issuer.CommonName,
|
||||
"not_after": key.NotAfter,
|
||||
"not_before": key.NotBefore,
|
||||
})
|
||||
}
|
||||
|
||||
func IssueCert(c *gin.Context) {
|
||||
domain := c.Param("domain")
|
||||
func IssueCert(c *gin.Context) {
|
||||
domain := c.Param("domain")
|
||||
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// upgrade http to websocket
|
||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer ws.Close()
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
// read
|
||||
mt, message, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if string(message) == "go" {
|
||||
var m []byte
|
||||
for {
|
||||
// read
|
||||
mt, message, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if string(message) == "go" {
|
||||
var m []byte
|
||||
|
||||
err = tool.IssueCert(domain)
|
||||
if err != nil {
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
})
|
||||
err = tool.IssueCert(domain)
|
||||
if err != nil {
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "error",
|
||||
"message": err.Error(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = ws.WriteMessage(mt, m)
|
||||
err = ws.WriteMessage(mt, m)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
sslCertificatePath := tool.GetNginxConfPath("ssl/" + domain + "/fullchain.cer")
|
||||
_, err = os.Stat(sslCertificatePath)
|
||||
sslCertificatePath := tool.GetNginxConfPath("ssl/" + domain + "/fullchain.cer")
|
||||
_, err = os.Stat(sslCertificatePath)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("[found]", "fullchain.cer")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "[found] fullchain.cer",
|
||||
})
|
||||
log.Println("[found]", "fullchain.cer")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "[found] fullchain.cer",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = ws.WriteMessage(mt, m)
|
||||
err = ws.WriteMessage(mt, m)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
sslCertificateKeyPath := tool.GetNginxConfPath("ssl/" + domain +"/" + domain + ".key")
|
||||
_, err = os.Stat(sslCertificateKeyPath)
|
||||
sslCertificateKeyPath := tool.GetNginxConfPath("ssl/" + domain + "/" + domain + ".key")
|
||||
_, err = os.Stat(sslCertificateKeyPath)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("[found]", "cert key")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "[found] cert key",
|
||||
})
|
||||
log.Println("[found]", "cert key")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "[found] cert key",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
err = ws.WriteMessage(mt, m)
|
||||
err = ws.WriteMessage(mt, m)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
log.Println("申请成功")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "申请成功",
|
||||
"ssl_certificate": sslCertificatePath,
|
||||
"ssl_certificate_key": sslCertificateKeyPath,
|
||||
})
|
||||
log.Println("申请成功")
|
||||
m, err = json.Marshal(gin.H{
|
||||
"status": "success",
|
||||
"message": "申请成功",
|
||||
"ssl_certificate": sslCertificatePath,
|
||||
"ssl_certificate_key": sslCertificateKeyPath,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
err = ws.WriteMessage(mt, m)
|
||||
err = ws.WriteMessage(mt, m)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/0xJacky/Nginx-UI/server/settings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
module github.com/0xJacky/Nginx-UI
|
||||
module github.com/0xJacky/Nginx-UI/server
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/gin-gonic/gin v1.7.2
|
||||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/go-acme/lego/v4 v4.4.0
|
||||
github.com/go-playground/validator/v10 v10.7.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/json-iterator/go v1.1.11 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mackerelio/go-osstat v0.1.0
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||
github.com/minio/minio v0.0.0-20210316030313-6160188bf32a
|
||||
github.com/mackerelio/go-osstat v0.2.0
|
||||
github.com/unknwon/com v1.0.1
|
||||
golang.org/x/sys v0.0.0-20210217105451-b926d437f341 // indirect
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
gopkg.in/ini.v1 v1.62.0
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/gorm v1.20.12
|
||||
gorm.io/gorm v1.21.14
|
||||
)
|
||||
|
|
422
server/go.sum
422
server/go.sum
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/router"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/0xJacky/Nginx-UI/server/router"
|
||||
"github.com/0xJacky/Nginx-UI/server/settings"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"log"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/0xJacky/Nginx-UI/server/settings"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -2,8 +2,8 @@ package router
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/server/api"
|
||||
"github.com/0xJacky/Nginx-UI/server/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ package test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
|
|
@ -1,62 +1,62 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/mackerelio/go-osstat/cpu"
|
||||
"github.com/mackerelio/go-osstat/memory"
|
||||
"github.com/minio/minio/pkg/disk"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
"fmt"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/mackerelio/go-osstat/cpu"
|
||||
"github.com/mackerelio/go-osstat/disk"
|
||||
"github.com/mackerelio/go-osstat/memory"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetArch(t *testing.T) {
|
||||
fmt.Println("os:", runtime.GOOS)
|
||||
fmt.Println("threads:", runtime.GOMAXPROCS(0))
|
||||
fmt.Println("os:", runtime.GOOS)
|
||||
fmt.Println("threads:", runtime.GOMAXPROCS(0))
|
||||
|
||||
memoryStat, err := memory.Get()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("memory total:", humanize.Bytes(memoryStat.Total))
|
||||
fmt.Println("memory used:", humanize.Bytes(memoryStat.Used))
|
||||
fmt.Println("memory cached:", humanize.Bytes(memoryStat.Cached))
|
||||
fmt.Println("memory free:", humanize.Bytes(memoryStat.Free))
|
||||
memoryStat, err := memory.Get()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("memory total:", humanize.Bytes(memoryStat.Total))
|
||||
fmt.Println("memory used:", humanize.Bytes(memoryStat.Used))
|
||||
fmt.Println("memory cached:", humanize.Bytes(memoryStat.Cached))
|
||||
fmt.Println("memory free:", humanize.Bytes(memoryStat.Free))
|
||||
|
||||
before, err := cpu.Get()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
after, err := cpu.Get()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
total := float64(after.Total - before.Total)
|
||||
fmt.Printf("cpu user: %f %%\n", float64(after.User-before.User)/total*100)
|
||||
fmt.Printf("cpu system: %f %%\n", float64(after.System-before.System)/total*100)
|
||||
fmt.Printf("cpu idle: %f %%\n", float64(after.Idle-before.Idle)/total*100)
|
||||
before, err := cpu.Get()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
after, err := cpu.Get()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
total := float64(after.Total - before.Total)
|
||||
fmt.Printf("cpu user: %f %%\n", float64(after.User-before.User)/total*100)
|
||||
fmt.Printf("cpu system: %f %%\n", float64(after.System-before.System)/total*100)
|
||||
fmt.Printf("cpu idle: %f %%\n", float64(after.Idle-before.Idle)/total*100)
|
||||
|
||||
err = diskUsage(".")
|
||||
err = diskUsage(".")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func diskUsage(path string) error {
|
||||
di, err := disk.GetInfo(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
|
||||
fmt.Printf("%s of %s disk space used (%0.2f%%)\n",
|
||||
humanize.Bytes(di.Total-di.Free),
|
||||
humanize.Bytes(di.Total),
|
||||
percentage,
|
||||
)
|
||||
return nil
|
||||
di, err := disk.GetInfo(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
|
||||
fmt.Printf("%s of %s disk space used (%0.2f%%)\n",
|
||||
humanize.Bytes(di.Total-di.Free),
|
||||
humanize.Bytes(di.Total),
|
||||
percentage,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/tool"
|
||||
"github.com/0xJacky/Nginx-UI/server/tool"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
|
@ -3,7 +3,7 @@ package tool
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/minio/pkg/disk"
|
||||
"github.com/mackerelio/go-osstat/disk"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,6 @@ func DiskUsage(path string) (string, string, float64, error) {
|
|||
}
|
||||
percentage := (float64(di.Total-di.Free) / float64(di.Total)) * 100
|
||||
percentage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", percentage), 64)
|
||||
|
||||
return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),
|
||||
percentage, nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/0xJacky/Nginx-UI/server/settings"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/go-acme/lego/v4/challenge/http01"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue