Jacky 4 년 전
부모
커밋
c164cd16d6

+ 2 - 0
README.md

@@ -1,2 +1,4 @@
 # Nginx UI
+Yet another Nginx Web UI
 
+Version: 0.1

+ 2 - 1
nginx-ui-frontend/.env.development

@@ -1,2 +1,3 @@
 VUE_APP_API_ROOT = /
-VUE_APP_API_WSS_ROOT =
+VUE_APP_API_WSS_ROOT = 
+VUE_APP_API_WSS_TOKEN =

+ 1 - 0
nginx-ui-frontend/.env.production

@@ -1,2 +1,3 @@
 VUE_APP_API_ROOT = /api
 VUE_APP_API_WSS_ROOT =
+VUE_APP_API_WSS_TOKEN =

+ 10 - 5
nginx-ui-frontend/src/views/DashBoard.vue

@@ -111,7 +111,8 @@ export default {
         }
     },
     created() {
-        this.websocket = new WebSocket(process.env["VUE_APP_API_WSS_ROOT"] + "/analytic")
+        this.websocket = new WebSocket(process.env["VUE_APP_API_WSS_ROOT"] + "/analytic?token="
+            + process.env["VUE_APP_API_WSS_TOKEN"])
         this.websocket.onmessage = this.wsOnMessage
         this.websocket.onopen = this.wsOpen
         this.websocket.onerror = this.wsOnError
@@ -167,21 +168,25 @@ export default {
 <style lang="less" scoped>
 .ant-card {
     margin: 10px;
-    @media (max-width: 512px) {
-        margin: 10px 0;
-    }
 
     .chart {
         max-height: 300px;
     }
 
     .chart_dashboard {
-        padding: 50px;
+        padding: 60px;
         .description {
             width: 120px;
             text-align: center
         }
     }
+
+    @media (max-width: 512px) {
+        margin: 10px 0;
+        .chart_dashboard {
+            padding: 20px;
+        }
+    }
 }
 </style>
 

+ 1 - 1
nginx-ui-frontend/src/views/DomainEdit.vue

@@ -6,7 +6,7 @@
             </a-card>
         </a-col>
         <a-col :md="12" :sm="24">
-            <a-card title="配置文件实时编辑">
+            <a-card title="配置文件编辑">
                 <a-textarea
                     v-model="configText"
                     :rows="36"

+ 1 - 4
nginx-ui-frontend/version.json

@@ -1,4 +1 @@
-{
-    "version": "0.1.0",
-    "build_id": 1
-}
+{"version":"0.1.0","build_id":9}

+ 1 - 1
nginx-ui-frontend/vue.config.js

@@ -18,7 +18,7 @@ module.exports = {
         },
     },
     devServer: {
-        proxy: 'https://nginx.jackyu.cn/'
+        proxy: 'https://nginx.jackyu.cn/api'
     },
 
     productionSourceMap: false,

+ 10 - 1
server/api/analytic.go

@@ -3,14 +3,15 @@ package api
 import (
     "encoding/json"
     "fmt"
+    "github.com/0xJacky/Nginx-UI/settings"
     "github.com/0xJacky/Nginx-UI/tool"
     "github.com/dustin/go-humanize"
     "github.com/gin-gonic/gin"
     "github.com/gorilla/websocket"
     "github.com/mackerelio/go-osstat/cpu"
+    "github.com/mackerelio/go-osstat/loadavg"
     "github.com/mackerelio/go-osstat/memory"
     "github.com/mackerelio/go-osstat/uptime"
-    "github.com/mackerelio/go-osstat/loadavg"
     "net/http"
     "strconv"
     "time"
@@ -23,6 +24,14 @@ var upGrader = websocket.Upgrader{
 }
 
 func Analytic(c *gin.Context) {
+    token := c.Query("token")
+    if token != settings.ServerSettings.WebSocketToken {
+        c.JSON(http.StatusForbidden, gin.H{
+            "message": "auth fail",
+        })
+        return
+    }
+
     // upgrade http to websocket
     ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
     if err != nil {

+ 1 - 0
server/app.ini

@@ -1,3 +1,4 @@
 [server]
 HttpPort = 9000
 RunMode = debug
+WebSocketToken =

+ 1 - 0
server/settings/settings.go

@@ -10,6 +10,7 @@ var Conf *ini.File
 type Server struct {
 	HttpPort string
 	RunMode  string
+	WebSocketToken string
 }
 
 var ServerSettings = &Server{}

+ 0 - 5
server/tool/analytic.go

@@ -13,11 +13,6 @@ func DiskUsage(path string) (string, string, float64, error) {
         return "", "", 0, 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,
-    )
     percentage, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", percentage), 64)
 
     return humanize.Bytes(di.Total-di.Free), humanize.Bytes(di.Total),