diff options
author | Emile <hanemile@protonmail.com> | 2019-02-17 22:20:39 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-02-17 22:20:39 +0100 |
commit | 879b831f7c01c2cdbaaf67703967f3a2be5cd7f7 (patch) | |
tree | bd17427ad50c7596d54e74b46d8fccc639bc27fa | |
parent | 5f2d16e634d51f75114a47016f826942f6ef46b9 (diff) |
'small steps' ~maride
-rw-r--r-- | main.go | 38 |
1 files changed, 2 insertions, 36 deletions
diff --git a/main.go b/main.go index 2ebc6fa..a3fd2a6 100644 --- a/main.go +++ b/main.go @@ -50,48 +50,14 @@ func handleConnection(s ssh.Session) { // create two buffers, one for storing the char input (buf) // and the other for storing complete commands (commandBuffer) buf := make([]byte, 1024) - commandBuffer := make([]byte, 0) - // the current char - var char string - - // read until ENTER is pressed - for char != "\x0d" { - - // read the char inserted by the user into the buffer + for { _, 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 - 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 - } - - // append the current char to the command buffer - commandBuffer = append(commandBuffer, currentChar) - - // write the char to stdout - char = string(bytes.Trim(buf, "\x00")) input := string(bytes.Trim(buf, "\x00")) + log.Println(input) io.WriteString(s, input) } - // prepare the command for execution - input := string(bytes.Trim(commandBuffer, "\x00")) - - // filter out unwanted commands - filteredInput := filter(input) - - // write the string to the commandHandler - io.WriteString(p, filteredInput) s.Close() return } |