File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 55 "fmt"
66 "github.com/tidwall/pretty"
77 "github.com/tidwall/sjson"
8- "io/ioutil "
8+ "os "
99)
1010
1111var 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 }
Original file line number Diff line number Diff line change 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 }
You can’t perform that action at this time.
0 commit comments