+
+
@@ -231,7 +288,9 @@
{
+ if (JSON.stringify(info.which) === JSON.stringify(x.which)) {
+ for (const k in info) {
+ if (k === "which" || !info.hasOwnProperty(k)) {
+ continue;
+ }
+ x.info[k] = info[k];
+ }
+ return true;
+ }
+ return false;
+ });
+ }
+ let minDelay = 99999;
+ let index = -1;
+ this.connectedServerInfo.forEach((x, i) => {
+ x.selected = false;
+ if (x.info.delay && x.info.delay < minDelay) {
+ minDelay = x.info.delay;
+ index = i;
+ }
+ });
+ if (index >= 0) {
+ this.connectedServerInfo[index].selected = true;
+ }
}
},
created() {
@@ -738,6 +846,53 @@ export default {
});
},
methods: {
+ handleClickConnectedServer(which) {
+ const that = this;
+ this.locateTabToConnected(which);
+ let tabIndex = -1;
+ if (which._type === "server") {
+ tabIndex = 1;
+ } else {
+ tabIndex = 2 + which.sub;
+ }
+
+ let tryCnt = 0;
+ const maxTry = 5;
+ const tryInterval = 500;
+ function waitingAndLocate() {
+ let nodes = document.querySelectorAll(".main-tabs .tabs li");
+ if (!nodes[tabIndex].classList.contains("is-active")) {
+ tryCnt++;
+ if (tryCnt > maxTry) {
+ return;
+ }
+ setTimeout(waitingAndLocate, tryInterval);
+ return;
+ }
+ console.log("ok");
+ that.$nextTick(() => {
+ let nodes = document.querySelectorAll(".main-tabs .b-table");
+ if (which._type === "subscriptionServer") {
+ // solid
+ tabIndex = 2;
+ }
+ nodes = nodes[tabIndex].querySelectorAll("tbody tr");
+ const node = nodes[which.id - 1];
+ node.scrollIntoView({ block: "end", inline: "center" });
+ node.classList.add("highlight-row");
+ setTimeout(() => {
+ node.classList.remove("highlight-row");
+ setTimeout(() => {
+ node.classList.add("highlight-row");
+ setTimeout(() => {
+ node.classList.remove("highlight-row");
+ }, 200);
+ }, 50);
+ }, 200);
+ });
+ }
+ waitingAndLocate();
+ },
handleClickImportInBatch() {
this.showModalImportInBatch = true;
},
@@ -865,12 +1020,41 @@ export default {
}
} else {
server.connected = true;
+ server = [server];
}
+ if (this.observatorySidebarValid) {
+ this.connectedServerInfo = [];
+ for (const i in server) {
+ let subscription_name = null;
+ if (connectedServer[i]._type === "subscriptionServer") {
+ subscription_name = this.tableData.subscriptions[
+ connectedServer[i].sub
+ ].host.toUpperCase();
+ }
+ this.connectedServerInfo.push({
+ info: {
+ ...server[i],
+ subscription_name,
+ alive: null,
+ delay: null,
+ outbound_tag: null,
+ last_seen_time: null,
+ last_error_reason: null,
+ last_try_time: null
+ },
+ which: connectedServer[i],
+ showContent: true,
+ selected: false
+ });
+ }
+ }
+ } else {
+ this.connectedServerInfo = [];
}
- this.connectedServer.server = false;
- for (const i in this.connectedServer.subscriptionServer) {
- this.connectedServer.subscriptionServer[i] = false;
+ this.connectedServerInTab.server = false;
+ for (const i in this.connectedServerInTab.subscriptionServer) {
+ this.connectedServerInTab.subscriptionServer[i] = false;
}
if (connectedServer) {
let servers = connectedServer;
@@ -879,16 +1063,19 @@ export default {
}
for (const s of servers) {
if (s._type === "server") {
- this.connectedServer.server = true;
+ this.connectedServerInTab.server = true;
} else if (s._type === "subscriptionServer") {
- this.connectedServer.subscriptionServer[s.sub] = true;
+ this.connectedServerInTab.subscriptionServer[s.sub] = true;
}
}
}
this.$emit("input", this.runningState);
},
- locateTabToConnected() {
- let whichServer = this.runningState.connectedServer;
+ locateTabToConnected(which) {
+ let whichServer = which;
+ if (!whichServer) {
+ whichServer = this.runningState.connectedServer;
+ }
if (!whichServer) {
return;
}
@@ -1367,14 +1554,6 @@ export default {
queue: false
});
this.showModalSubscription = false;
- this.tableData = res.data.data.touch;
- this.runningState = {
- running: res.data.data.running
- ? this.$t("common.isRunning")
- : this.$t("common.notRunning"),
- connectedServer: this.tableData.connectedServer
- };
- this.updateConnectView();
});
});
}
@@ -1557,4 +1736,43 @@ $coverBackground: rgba(0, 0, 0, 0.6);
font-size: 0.75rem;
}
}
+.b-sidebar.node-status-sidebar-reduced > .sidebar-content.is-fixed {
+ left: 1px;
+ top: 4.25rem;
+ background-color: white;
+ width: unset;
+ line-height: 0;
+ border-radius: 4px;
+}
+.b-sidebar.node-status-sidebar > .sidebar-content.is-fixed {
+ left: 1px;
+ top: 4.25rem;
+ background-color: white;
+ max-height: calc(100vh - 5rem);
+ overflow-y: scroll;
+ .message {
+ cursor: pointer;
+ }
+ .tabs:not(:last-child),
+ .pagination:not(:last-child),
+ .message:not(:last-child),
+ .level:not(:last-child),
+ .breadcrumb:not(:last-child),
+ .highlight:not(:last-child),
+ .block:not(:last-child),
+ .title:not(:last-child),
+ .subtitle:not(:last-child),
+ .table-container:not(:last-child),
+ .table:not(:last-child),
+ .progress:not(:last-child),
+ .notification:not(:last-child),
+ .content:not(:last-child),
+ .box:not(:last-child) {
+ margin-bottom: 0.25rem;
+ }
+}
+tr.highlight-row {
+ transition: background-color 0.05s linear;
+ background-color: #a8cff0;
+}
diff --git a/gui/yarn.lock b/gui/yarn.lock
index 8114cc12..5f9dc9c6 100644
--- a/gui/yarn.lock
+++ b/gui/yarn.lock
@@ -3108,10 +3108,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"
-dayjs@^1.8.16:
- version "1.10.2"
- resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.2.tgz#8f3a424ceb944a8193506804b0045a773d2d0672"
- integrity sha512-h/YtykNNTR8Qgtd1Fxl5J1/SFP1b7SOk/M1P+Re+bCdFMV0IMkuKNgHPN7rlvvuhfw24w0LX78iYKt4YmePJNQ==
+dayjs@^1.10.6:
+ version "1.10.6"
+ resolved "https://registry.nlark.com/dayjs/download/dayjs-1.10.6.tgz?cache=0&sync_timestamp=1625557417200&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fdayjs%2Fdownload%2Fdayjs-1.10.6.tgz#288b2aa82f2d8418a6c9d4df5898c0737ad02a63"
+ integrity sha1-KIsqqC8thBimydTfWJjAc3rQKmM=
de-indent@^1.0.2:
version "1.0.2"
diff --git a/service/common/jwt/jwtTools.go b/service/common/jwt/jwtTools.go
index 3b708ec5..8dd74204 100644
--- a/service/common/jwt/jwtTools.go
+++ b/service/common/jwt/jwtTools.go
@@ -1,7 +1,6 @@
package jwt
import (
- "github.com/v2rayA/v2rayA/common"
"encoding/base64"
"fmt"
"github.com/dgrijalva/jwt-go"
@@ -9,22 +8,44 @@ import (
"github.com/gin-gonic/gin"
"github.com/json-iterator/go"
"github.com/pkg/errors"
+ "github.com/v2rayA/v2rayA/common"
"strconv"
"strings"
"time"
)
+// stripBearerPrefixFromTokenString strips 'Bearer ' prefix from bearer token string
+func stripBearerPrefixFromTokenString(tok string) (string, error) {
+ // Should be a bearer token
+ if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
+ return tok[7:], nil
+ }
+ return tok, nil
+}
+
+// AuthorizationArgumentExtractor extracts bearer token from Argument header
+// Uses PostExtractionFilter to strip "Bearer " prefix from header
+var AuthorizationArgumentExtractor = &request.PostExtractionFilter{
+ request.ArgumentExtractor{"Authorization"},
+ stripBearerPrefixFromTokenString,
+}
+
func JWTAuth(Admin bool) gin.HandlerFunc {
return func(ctx *gin.Context) {
token, err := request.ParseFromRequest(ctx.Request, request.AuthorizationHeaderExtractor,
func(token *jwt.Token) (interface{}, error) {
- // 我们使用固定的secret,直接返回就好
return getSecret(), nil
})
if err != nil {
- common.Response(ctx, common.UNAUTHORIZED, err.Error())
- ctx.Abort()
- return
+ token, err = request.ParseFromRequest(ctx.Request, AuthorizationArgumentExtractor,
+ func(token *jwt.Token) (interface{}, error) {
+ return getSecret(), nil
+ });
+ if err != nil {
+ common.Response(ctx, common.UNAUTHORIZED, err.Error())
+ ctx.Abort()
+ return
+ }
}
//如果需要Admin权限
mapClaims := token.Claims.(jwt.MapClaims)
diff --git a/service/core/v2ray/api.go b/service/core/v2ray/api.go
index 352ff667..9687f76b 100644
--- a/service/core/v2ray/api.go
+++ b/service/core/v2ray/api.go
@@ -23,16 +23,19 @@ var (
ApiFeed *Feed
)
-const ApiFeedBoxSize = 10
+const (
+ ApiFeedBoxSize = 10
+ ApiFeedInterval = 3 * time.Second
+)
type OutboundStatus struct {
- Alive bool `json:"alive,omitempty"`
- Delay int64 `json:"delay,omitempty"`
- LastErrorReason string `json:"last_error_reason,omitempty"`
- OutboundTag string `json:"outbound_tag,omitempty"`
- Which *configure.Which `json:"which,omitempty"`
- LastSeenTime int64 `json:"last_seen_time,omitempty"`
- LastTryTime int64 `json:"last_try_time,omitempty"`
+ Alive bool `json:"alive"`
+ Delay int64 `json:"delay"`
+ LastErrorReason string `json:"last_error_reason"`
+ OutboundTag string `json:"outbound_tag"`
+ Which *configure.Which `json:"which"`
+ LastSeenTime int64 `json:"last_seen_time"`
+ LastTryTime int64 `json:"last_try_time"`
}
func init() {
@@ -62,7 +65,7 @@ func observatoryProducer() {
var conn *grpc.ClientConn
for {
if ApiPort() == 0 {
- time.Sleep(5 * time.Second)
+ time.Sleep(ApiFeedInterval)
continue
}
// Set up a connection to the server.
@@ -92,6 +95,6 @@ func observatoryProducer() {
}
ApiFeed.ProductMessage(product, os)
}
- time.Sleep(5 * time.Second)
+ time.Sleep(ApiFeedInterval)
}
}
diff --git a/service/core/v2ray/feed.go b/service/core/v2ray/feed.go
index 9e824c4f..3b7408cb 100644
--- a/service/core/v2ray/feed.go
+++ b/service/core/v2ray/feed.go
@@ -11,7 +11,7 @@ type Feed struct {
boxSize int
}
type Message struct {
- ProduceTime time.Time
+ ProduceTime int64
Product string
Body interface{}
}
@@ -50,6 +50,8 @@ func (s *Feed) SubscribeMessage(product string) (box *Box) {
s.boxes[product] = append(s.boxes[product], &messages)
index := len(s.boxes[product]) - 1
cancel := func() {
+ s.mu.Lock()
+ defer s.mu.Unlock()
if index >= len(s.boxes[product]) || s.boxes[product][index] != &messages {
index = -1
for i := range s.boxes[product] {
@@ -74,7 +76,7 @@ func (s *Feed) SubscribeMessage(product string) (box *Box) {
func (s *Feed) ProductMessage(product string, message interface{}) (numConsumer int) {
msg := Message{
- ProduceTime: time.Now(),
+ ProduceTime: time.Now().Unix(),
Body: message,
Product: product,
}
diff --git a/service/server/controller/message.go b/service/server/controller/message.go
index e4a37125..d69ae036 100644
--- a/service/server/controller/message.go
+++ b/service/server/controller/message.go
@@ -4,16 +4,21 @@ import (
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/v2rayA/v2rayA/server/service"
+ "net/http"
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
+ CheckOrigin: func(r *http.Request) bool {
+ return true
+ },
}
func WsMessage(ctx *gin.Context) {
conn, err := upgrader.Upgrade(ctx.Writer, ctx.Request, nil)
if err != nil {
+ logError(err)
return
}
h := service.NewMessageHandler(conn)
diff --git a/service/server/router/index.go b/service/server/router/index.go
index 87ef0b29..92d13bfa 100644
--- a/service/server/router/index.go
+++ b/service/server/router/index.go
@@ -63,6 +63,7 @@ func nocache(c *gin.Context) {
c.Header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate")
c.Header("Pragma", "no-cache")
c.Header("Expires", "0")
+ c.Next()
}
func Run() error {
@@ -74,6 +75,8 @@ func Run() error {
corsConfig.AllowMethods = []string{
"GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD",
}
+ corsConfig.AllowWebSockets = true
+ corsConfig.AllowCredentials = true
corsConfig.AddAllowHeaders("Authorization")
engine.Use(cors.New(corsConfig))
noAuth := engine.Group("api", nocache)
diff --git a/service/server/service/message.go b/service/server/service/message.go
index 900fdedf..f70b4d76 100644
--- a/service/server/service/message.go
+++ b/service/server/service/message.go
@@ -2,15 +2,13 @@ package service
import (
"github.com/gorilla/websocket"
- jsoniter "github.com/json-iterator/go"
"github.com/v2rayA/v2rayA/core/v2ray"
- "log"
"sync"
"time"
)
const (
- writeWait = 5 * time.Second
+ writeWait = v2ray.ApiFeedInterval
)
type MessageHandler struct {
@@ -18,7 +16,7 @@ type MessageHandler struct {
boxes map[string]*v2ray.Box
}
type Message struct {
- ProductTime time.Time `json:"product_time"`
+ ProduceTime int64 `json:"produce_time"`
Type string `json:"type"`
Body interface{} `json:"body"`
}
@@ -45,7 +43,7 @@ func (h *MessageHandler) Read() {
}()
for {
if _, _, err := h.conn.ReadMessage(); err != nil {
- log.Println(err)
+ //log.Println(err)
break
}
}
@@ -62,16 +60,12 @@ func (h *MessageHandler) Write() {
go func(box *v2ray.Box) {
defer wg.Done()
for msg := range box.Messages {
- b, err := jsoniter.Marshal(Message{
- ProductTime: msg.ProduceTime,
+ _ = h.conn.SetWriteDeadline(time.Now().Add(writeWait))
+ if err := h.conn.WriteJSON(Message{
+ ProduceTime: msg.ProduceTime,
Type: msg.Product,
Body: msg.Body,
- })
- if err != nil {
- log.Printf("[Warning] %v", err)
- }
- _ = h.conn.SetWriteDeadline(time.Now().Add(writeWait))
- if err := h.conn.WriteMessage(websocket.TextMessage, b); err != nil {
+ }); err != nil {
return
}
}