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
Yet another Nginx Web UI
Version: 0.1

View file

@ -1,2 +1,3 @@
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_WSS_ROOT =
VUE_APP_API_WSS_TOKEN =

View file

@ -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>

View file

@ -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"

View file

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

View file

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

View file

@ -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 {

View file

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

View file

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

View file

@ -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),