diff options
author | Emile <hanemile@protonmail.com> | 2019-02-17 21:39:46 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-02-17 21:39:46 +0100 |
commit | 683ee67889db2bd6112df955af79b77aaeee3033 (patch) | |
tree | 1c4f11b946dd55555bae6f8867b3230a87f8a57f | |
parent | d9cdae9fda434e977ad280cfb94e2d90c4cab7bc (diff) |
optimized the empty behaviour
-rw-r--r-- | main.go | 18 |
1 files 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 <C-c> 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) } - |