This commit is contained in:
Jacky 2021-03-22 18:00:13 +08:00
parent 43b490669e
commit c164cd16d6
11 changed files with 30 additions and 18 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,14 +3,15 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/0xJacky/Nginx-UI/settings"
"github.com/0xJacky/Nginx-UI/tool" "github.com/0xJacky/Nginx-UI/tool"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/mackerelio/go-osstat/cpu" "github.com/mackerelio/go-osstat/cpu"
"github.com/mackerelio/go-osstat/loadavg"
"github.com/mackerelio/go-osstat/memory" "github.com/mackerelio/go-osstat/memory"
"github.com/mackerelio/go-osstat/uptime" "github.com/mackerelio/go-osstat/uptime"
"github.com/mackerelio/go-osstat/loadavg"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -23,6 +24,14 @@ var upGrader = websocket.Upgrader{
} }
func Analytic(c *gin.Context) { 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 // upgrade http to websocket
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil) ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
if err != nil { if err != nil {

View file

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

View file

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

View file

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