Skip to content

Commit f6b9d3b

Browse files
committed
fix #704
1 parent 44bc236 commit f6b9d3b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"github.com/tidwall/pretty"
77
"github.com/tidwall/sjson"
8-
"io/ioutil"
8+
"os"
99
)
1010

1111
var configPath = "/usr/local/etc/trojan/config.json"
@@ -40,7 +40,7 @@ func Load(path string) []byte {
4040
if path == "" {
4141
path = configPath
4242
}
43-
data, err := ioutil.ReadFile(path)
43+
data, err := os.ReadFile(path)
4444
if err != nil {
4545
fmt.Println(err)
4646
return nil
@@ -53,7 +53,7 @@ func Save(data []byte, path string) bool {
5353
if path == "" {
5454
path = configPath
5555
}
56-
if err := ioutil.WriteFile(path, pretty.Pretty(data), 0644); err != nil {
56+
if err := os.WriteFile(path, pretty.Pretty(data), 0644); err != nil {
5757
fmt.Println(err)
5858
return false
5959
}

web/controller/trojan.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/gin-gonic/gin"
99
ws "github.com/gorilla/websocket"
1010
"io"
11-
"log"
1211
"strconv"
1312
"strings"
1413
"time"
@@ -81,6 +80,10 @@ func Log(c *gin.Context) {
8180
}
8281
defer wsConn.WsClose()
8382
param := c.DefaultQuery("line", "300")
83+
if !websocket.IsInteger(param) {
84+
fmt.Println("invalid param: " + param)
85+
return
86+
}
8487
if param == "-1" {
8588
param = "--no-tail"
8689
} else {
@@ -89,12 +92,11 @@ func Log(c *gin.Context) {
8992
result, err := websocket.LogChan("trojan", param, wsConn.CloseChan)
9093
if err != nil {
9194
fmt.Println(err)
92-
wsConn.WsClose()
9395
return
9496
}
9597
for line := range result {
9698
if err := wsConn.WsWrite(ws.TextMessage, []byte(line+"\n")); err != nil {
97-
log.Println("can't send: ", line)
99+
fmt.Println("can't send: ", line)
98100
break
99101
}
100102
}

0 commit comments

Comments
 (0)