about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Karl <akarl@darknebu.la>2019-02-13 22:28:50 +0100
committerAlexander Karl <akarl@darknebu.la>2019-02-13 22:28:50 +0100
commitb0ac27c3c943e4db6c23e780f0e9829c1bdefcaf (patch)
treee7e1cb272546ff2d2b328515e5e354573b67e7b2
Init commit - welcome ftp-grab-password
-rw-r--r--auth.go27
-rw-r--r--main.go53
2 files changed, 80 insertions, 0 deletions
diff --git a/auth.go b/auth.go
new file mode 100644
index 0000000..d056f1b
--- /dev/null
+++ b/auth.go
@@ -0,0 +1,27 @@
+package main
+
+import(
+  "log"
+)
+
+// Auth is an interface to auth your ftp user login.
+type Auth interface {
+	CheckPasswd(string, string) (bool, error)
+}
+
+var (
+	_ Auth = &FakeAuth{}
+)
+
+// FakeAuth implements Auth interface to provide a memory user login auth
+type FakeAuth struct {
+	Name     string
+	Password string
+}
+
+// CheckPasswd will check user's password
+func (a *FakeAuth) CheckPasswd(name, pass string) (bool, error) {
+    metrics_num_passwords++
+    log.Printf("%s@ftp - %s", name, pass)
+    return false, nil
+}
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..28db957
--- /dev/null
+++ b/main.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+    "fmt"
+    "net/http"
+    "log"
+    "github.com/goftp/server"
+    filedriver "github.com/goftp/file-driver"
+)
+
+var(
+    metrics_num_passwords int
+)
+
+
+func main() {
+    log.Println("Starting FTP listener")
+
+
+    go func() {
+
+        factory := &filedriver.FileDriverFactory{
+      		RootPath: "",
+      		Perm:     server.NewSimplePerm("user", "group"),
+        }
+
+        opts := &server.ServerOpts{
+          Factory:  factory,
+          Port:     21,
+          Hostname: "::",
+          Auth:     &FakeAuth{Name: "", Password: ""},
+          Logger:   &server.DiscardLogger{},
+        }
+
+        server := server.NewServer(opts)
+        err := server.ListenAndServe()
+        if err != nil {
+          log.Fatal("Error starting server:", err)
+        }
+    }()
+
+    log.Println("Starting HTTP metrics listener")
+    http.HandleFunc("/metrics", metricsHandler)
+    listenErr := http.ListenAndServe(":48081", nil) // set listen port
+    if listenErr != nil {
+        log.Fatalln(listenErr.Error())
+    }
+}
+
+// Handle HTTP /metrics requests
+func metricsHandler(w http.ResponseWriter, req *http.Request) {
+    fmt.Fprintf(w, "metrics_num_passwords %d\n", metrics_num_passwords)
+}