From a130a27a20b043e71bd9fecc566405eb7ad260e9 Mon Sep 17 00:00:00 2001 From: maride Date: Tue, 12 Feb 2019 16:45:14 +0100 Subject: Init --- main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..1517c79 --- /dev/null +++ b/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + "github.com/gliderlabs/ssh" + "net/http" + "log" +) + +var( + metrics_num_passwords int +) + +func main() { + log.Println("Starting SSH listener") + go func() { + listenErr := ssh.ListenAndServe(":2222", nil, ssh.PasswordAuth(handlePass)) + if listenErr != nil { + log.Fatalln(listenErr.Error()) + } + }() + + log.Println("Starting HTTP metrics listener") + http.HandleFunc("/metrics", metricsHandler) + listenErr := http.ListenAndServe(":8080", nil) + if listenErr != nil { + log.Fatalln(listenErr.Error()) + } +} + +// Handling incoming SSH connections +func handlePass(ctx ssh.Context, pass string) bool { + metrics_num_passwords++ + log.Printf("%s@%s: '%s'", ctx.User(), ctx.RemoteAddr().String(), pass) + return false +} + +// Handle HTTP /metrics requests +func metricsHandler(w http.ResponseWriter, req *http.Request) { + fmt.Fprintf(w, "num_passwords %d\n", metrics_num_passwords) +} + -- cgit 1.4.1