about summary refs log tree commit diff
path: root/main.go
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-02-17 21:15:56 +0100
committerEmile <hanemile@protonmail.com>2019-02-17 21:15:56 +0100
commitce32d97155533c6b3531a0958aa60004f8b93d21 (patch)
tree273666172148d751b88cc0cfe2e92dd6c22e605d /main.go
parentd9cdae9fda434e977ad280cfb94e2d90c4cab7bc (diff)
minor updates
Diffstat (limited to 'main.go')
-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)
 }