about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-11-02 21:10:41 +0100
committerEmile <hanemile@protonmail.com>2019-11-02 21:10:41 +0100
commit319ac3d30db83acdb1d46bfab042ee468e7b29b0 (patch)
tree25be70394ab8865708cf31f71f7bc06c4f6def10
parent0af71a7fe967f149b6ff2b1030c5544f1a336e3c (diff)
http server
-rw-r--r--src/http.go58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/http.go b/src/http.go
index 12a8a6d..1caa14a 100644
--- a/src/http.go
+++ b/src/http.go
@@ -1,35 +1,43 @@
 package main
 
 import (
+	"fmt"
 	"log"
 	"net/http"
-	"strings"
+
+	"github.com/gorilla/mux"
 )
 
-func httpRequest(wordlistChannel chan string, printChannel chan Response, doneChannel chan int, threadNr int) {
-	for {
-		// replace the first instance of "FUZZ" in the given url by the next
-		// value from the wordlistChannel
-		fuzzWord := <-wordlistChannel
-		requestURL := strings.Replace(url, "FUZZ", fuzzWord, 1)
-
-		// make the http get request
-		resp, err := http.Get("https://" + requestURL)
-		if err != nil {
-			log.Println(err)
-		}
-
-		// define the response
-		var response = Response{
-			StatusCode: resp.StatusCode,
-			FuzzWord:   fuzzWord,
-		}
-
-		// insert the response into the print channel for further printing
-		printChannel <- response
-	}
+// setupHTTPServer sets up a http server
+func setupHTTPServer() http.Server {
+	r := mux.NewRouter()
+
+	r.HandleFunc("/", indexHandler)
+	r.HandleFunc("/api/found", apiFoundHandler)
 
-	if doneChannel != nil {
-		doneChannel <- threadNr
+	return http.Server{
+		Addr:    fmt.Sprintf("0.0.0.0:%d", httpServerPort),
+		Handler: r,
 	}
 }
+
+// indexHandler handles requests to the / endpoint
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "%s", "FUZZ!")
+}
+
+// httpStartServer starts the http server
+func httpStartServer() {
+	log.Printf("%s Starting the http server", green("[i]"))
+
+	// setup the http server and start it
+	httpServer := setupHTTPServer()
+	log.Fatalln(httpServer.ListenAndServe())
+
+	log.Printf("%s Done starting the http server", boldGreen("[+]"))
+}
+
+// handle requests to the /api/found endpoint
+func apiFoundHandler() {
+	w.Header().Set("Content-Type", "application/json")
+}