From deca713acc66069132df06f055a177606119b4ef Mon Sep 17 00:00:00 2001 From: Super User Date: Wed, 8 May 2024 15:42:47 +0300 Subject: [PATCH] Fix ping2 --- cmpSnipper/cmpSnipperHttpWsHandle.go | 10 ++++---- cmpSnipper/cmpSnipperSnipPing.go | 35 ++++++---------------------- static/default.js | 16 ++++++------- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/cmpSnipper/cmpSnipperHttpWsHandle.go b/cmpSnipper/cmpSnipperHttpWsHandle.go index 6fce4fe..792acc6 100644 --- a/cmpSnipper/cmpSnipperHttpWsHandle.go +++ b/cmpSnipper/cmpSnipperHttpWsHandle.go @@ -12,7 +12,7 @@ type cmpWbsCliStruct struct { W http.ResponseWriter Connect *websocket.Conn - Mutex sync.Mutex + Mutex *sync.Mutex HostPort string } @@ -51,7 +51,7 @@ var cmpWbsCli cmpWbsCliStruct = cmpWbsCliStruct{ w, conn, - Mutex, + &Mutex, HostPort, } @@ -132,14 +132,14 @@ func (app *App) HttpWebSockSendRawTo(cmpWbsCli cmpWbsCliStruct, raw map[string]interface{}) { var err error - app.Log("LOCK") + // app.Log("LOCK") cmpWbsCli.Mutex.Lock() - defer cmpWbsCli.Mutex.Unlock() - err = cmpWbsCli.Connect.WriteJSON(raw) + cmpWbsCli.Mutex.Unlock() + if err != nil { app.Log(err) return diff --git a/cmpSnipper/cmpSnipperSnipPing.go b/cmpSnipper/cmpSnipperSnipPing.go index a334930..d3c3a9a 100644 --- a/cmpSnipper/cmpSnipperSnipPing.go +++ b/cmpSnipper/cmpSnipperSnipPing.go @@ -78,31 +78,6 @@ }, nil } - -func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) { - var out []byte - buf := make([]byte, 1024, 1024) - for { - n, err := r.Read(buf[:]) - if n > 0 { - d := buf[:n] - out = append(out, d...) - str := strings.Trim(string(d), "\n\r") - - app.Log("Std: %s", str) - - app.Ping2SendStr(str) - } - if err != nil { - // Read returns io.EOF at the end of file, which is not an error for us - if err == io.EOF { - err = nil - } - return out, err - } - } -} - func (app *App) Ping2SendObj(obj map[string]interface{}) (error) { if app.CliCur == nil { app.Log("No cli") @@ -113,14 +88,14 @@ func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) { return nil } - +/* func (app *App) Ping2SendStr(str string) (error) { return app.Ping2SendObj(map[string]interface{}{ "data" : "stdout", "string": str, }) } - +*/ @@ -136,7 +111,11 @@ func (app *App) ping2Capture(r io.Reader, strWin string) ([]byte, error) { app.Log("Std: %s", str) - app.Ping2SendStr(str) + app.Ping2SendObj(map[string]interface{}{ + "data" : "stdout", + "win" : strWin, + "string": str, + }) } if err != nil { // Read returns io.EOF at the end of file, which is not an error for us diff --git a/static/default.js b/static/default.js index be6bb44..11cbb80 100644 --- a/static/default.js +++ b/static/default.js @@ -285,7 +285,7 @@ if(!this.blobPing2Wind[w].nodeAddrList) { this.blobPing2Wind[w].nodeAddrList = dcrt({ tag : "div", - style: "display:block; visibility:hidden; position:absolute; top:32px; left:110px; background-color:#222; overflow:auto; border:1px solid grey; padding:15px;", + style: "display:block; visibility:hidden; position:absolute; top:100px; left:30px; background-color:#222; overflow:auto; border:1px solid grey; padding:15px;", parn : this.blobPing2Wind[w].nodeRoot }); @@ -334,14 +334,14 @@ this.blobPing2Wind[w].nodeAddr = dcrt({ tag : "div", - style: "display:block; position:absolute; top:-2px; left:125px;", + style: "display:block; position:absolute; top:125px; left:1px;", click: this.ping2Addr.bind(this, w), html : "8.8.8.8" }); this.blobPing2Wind[w].nodeHead = dcrt({ tag : "div", - style: "display:block; position:absolute; top:1px; height:32px; left:1px; right:1px; overflow:auto; border:0px solid red; padding:0;", + style: "display:block; position:absolute; top:1px; width:32px; /* height:32px; right:1px; */ left:1px; bottom:1px; overflow:auto; border:0px solid red; padding:0;", parn : this.blobPing2Wind[w].nodeRoot, child: [ { @@ -352,19 +352,19 @@ }, { tag : "div", - style: "display:block; position:absolute; top:0px; left:25px;", + style: "display:block; position:absolute; top:25px; left:1px;", click: this.ping2Snip.bind(this, w, "stat"), html : '' }, { tag : "div", - style: "display:block; position:absolute; top:0px; left:50px;", + style: "display:block; position:absolute; top:50px; left:1px;", click: this.ping2Snip.bind(this, w, "stop"), html : '' }, { tag : "div", - style: "display:block; position:absolute; top:0px; left:100px;", + style: "display:block; position:absolute; top:100px; left:1px;", click: this.ping2Addr.bind(this, w), html : '' }, @@ -374,7 +374,7 @@ this.blobPing2Wind[w].nodeBody = dcrt({ tag : "div", - style: "display:block; position:absolute; top:26px; bottom:1px; left:1px; right:1px; overflow:auto; border:1px solid grey;", + style: "display:block; position:absolute; top:1px; bottom:1px; left:26px; right:1px; overflow:auto; border:1px solid grey;", parn : this.blobPing2Wind[w].nodeRoot }); @@ -454,7 +454,7 @@ return; } - var w = 0; + var w = obj.win; this.blobPing2Wind[w].list.push(dcrt({ tag : "pre",