diff options
author | maride <maride@darknebu.la> | 2019-02-12 16:45:14 +0100 |
---|---|---|
committer | maride <maride@darknebu.la> | 2019-02-12 16:45:14 +0100 |
commit | a130a27a20b043e71bd9fecc566405eb7ad260e9 (patch) | |
tree | 9c672af227057f288c6cee593d88f2ab9e51de1f /main.go |
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 42 |
1 files changed, 42 insertions, 0 deletions
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) +} + |