mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
bug fix
This commit is contained in:
parent
43b490669e
commit
c164cd16d6
11 changed files with 30 additions and 18 deletions
|
@ -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,3 +1,4 @@
|
|||
[server]
|
||||
HttpPort = 9000
|
||||
RunMode = debug
|
||||
WebSocketToken =
|
||||
|
|
|
@ -10,6 +10,7 @@ var Conf *ini.File
|
|||
type Server struct {
|
||||
HttpPort string
|
||||
RunMode string
|
||||
WebSocketToken string
|
||||
}
|
||||
|
||||
var ServerSettings = &Server{}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue