about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--main.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/main.go b/main.go
index 2928196..57a77a6 100644
--- a/main.go
+++ b/main.go
@@ -16,31 +16,24 @@ var (
 )
 
 func main() {
-	log.Println("Starting SSH listener")
-
-	//// start the ssh server
-	//go func() {
-	//	listenErr := ssh.ListenAndServe(":2222", nil, ssh.PasswordAuth(handlePass))
-	//	if listenErr != nil {
-	//		log.Fatalln(listenErr.Error())
-	//	}
-	//}()
+	log.Println("Starting SSH listener (:22)")
 
 	go func() {
 		// star the metrics listener
-		log.Println("Starting HTTP metrics listener")
+		log.Println("Starting HTTP metrics listener (:8033)")
 		http.HandleFunc("/metrics", metricsHandler)
-		listenErr := http.ListenAndServe(":8080", nil)
+		listenErr := http.ListenAndServe(":8033", nil)
 		if listenErr != nil {
 			log.Fatalln(listenErr.Error())
 		}
 	}()
 
 	ssh.Handle(handleConnection)
-	log.Fatal(ssh.ListenAndServe(":2222", nil, ssh.PasswordAuth(handlePass)))
+	log.Fatal(ssh.ListenAndServe(":22", nil, ssh.PasswordAuth(handlePass)))
 }
 
 func handleConnection(s ssh.Session) {
+    log.Println("handling a connection!")
 	cmd := exec.Command("bash")
 	p, _ := pty.Start(cmd)
 
@@ -53,16 +46,20 @@ func handleConnection(s ssh.Session) {
 			commandBuffer := make([]byte, 0)
 
 			// the current char
-			var char string
+			//var char string
 
 			// read until ENTER is pressed
-			for char != "\x0d"{
+			//for char != "\x0d"{
+            for {
 
 				// read the char inserted by the user into the buffer
 				_, readErr = s.Read(buf)
 
 				// trim the char and append it to the commandBuffer
+                log.Printf("--> %v", bytes.Trim(buf, "\x00"))
 				char1 := bytes.Trim(buf, "\x00")[0]
+                log.Printf("%x -> %s", char1, char1)
+
 				if char1 == []byte("\x03")[0] {
 					s.Close()
 					return
@@ -70,7 +67,7 @@ func handleConnection(s ssh.Session) {
 				commandBuffer = append(commandBuffer, char1)
 
 				// write the char to stdout
-				char = string(bytes.Trim(buf, "\x00"))
+				//char := string(bytes.Trim(buf, "\x00"))
 				input := string(bytes.Trim(buf, "\x00"))
 				io.WriteString(s, input)
 			}
@@ -83,7 +80,7 @@ func handleConnection(s ssh.Session) {
 
 			// write the string to the commandHandler
 			io.WriteString(p, filteredInput)
-			s.Close()
+			//s.Close()
 			return
 		}
 	}()
@@ -111,6 +108,7 @@ func handlePass(ctx ssh.Context, pass string) bool {
 
 // Handle HTTP /metrics requests
 func metricsHandler(w http.ResponseWriter, req *http.Request) {
+    log.Println("The metricsHandler was acessed")
 	fmt.Fprintf(w, "num_passwords %d\n", metrics_num_passwords)
 }