-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
45 lines (38 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
//TODO
// make a configuration file that we can change http port and IP
// select different home routers to emulate
// toggle console logging
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
console_log := 1
port := ":8080"
logPath := "access.log"
writeLogFile(logPath)
fmt.Println("WAPot v1.0\n\n[+] Listening on port", port)
http.Handle("/", http.FileServer(http.Dir("./http")))
if err := http.ListenAndServe(port, logRequest(http.DefaultServeMux, console_log)); err != nil {
panic(err)
}
}
func logRequest(handler http.Handler, clog int) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
log.Printf("%s %s %s \"%s\" \"%s\" \n", req.RemoteAddr, req.Header.Get("X-Forwarded-For"), req.Method, req.URL.RequestURI(), req.UserAgent())
fmt.Printf("%s %s %s \"%s\" \"%s\" \n", req.RemoteAddr, req.Header.Get("X-Forwarded-For"), req.Method, req.URL.RequestURI(), req.UserAgent())
handler.ServeHTTP(w, req)
})
}
func writeLogFile(logfile string) {
if logfile != "" {
line, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
if err != nil {
log.Fatal("OpenLogfile: os.OpenFile:", err)
}
log.SetOutput(line)
}
}