From 683ee67889db2bd6112df955af79b77aaeee3033 Mon Sep 17 00:00:00 2001 From: Emile Date: Sun, 17 Feb 2019 21:39:46 +0100 Subject: optimized the empty behaviour --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 2928196..2ebc6fa 100644 --- a/main.go +++ b/main.go @@ -56,18 +56,27 @@ func handleConnection(s ssh.Session) { var char string // read until ENTER is pressed - for char != "\x0d"{ + for char != "\x0d" { // read the char inserted by the user into the buffer _, readErr = s.Read(buf) + if len(bytes.Trim(buf, "\x00")) == 0 { + buf[0] = []byte("\x108\x105")[0] + } + // trim the char and append it to the commandBuffer - char1 := bytes.Trim(buf, "\x00")[0] - if char1 == []byte("\x03")[0] { + currentChar := bytes.Trim(buf, "\x00")[0] + log.Println(currentChar) + + // if ist pressed, close the connection + if currentChar == []byte("\x03")[0] { s.Close() return } - commandBuffer = append(commandBuffer, char1) + + // append the current char to the command buffer + commandBuffer = append(commandBuffer, currentChar) // write the char to stdout char = string(bytes.Trim(buf, "\x00")) @@ -113,4 +122,3 @@ func handlePass(ctx ssh.Context, pass string) bool { func metricsHandler(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "num_passwords %d\n", metrics_num_passwords) } - -- cgit 1.4.1