Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,72 @@ func loop() {
for _, element := range portList {
log.Printf("\t%v\n", element)

r.Use(cors.Middleware(cors.Config{
Origins: *origins + ", " + extraOriginStr,
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 50 * time.Second,
Credentials: true,
ValidateHeaders: false,
}))

r.LoadHTMLFiles("templates/nofirefox.html")

r.GET("/", homeHandler)
r.GET("/certificate.crt", certHandler)
r.DELETE("/certificate.crt", deleteCertHandler)
r.POST("/upload", uploadHandler)
r.GET("/socket.io/", socketHandler)
r.POST("/socket.io/", socketHandler)
r.Handle("WS", "/socket.io/", socketHandler)
r.Handle("WSS", "/socket.io/", socketHandler)
r.GET("/info", infoHandler)
r.POST("/killbrowser", killBrowserHandler)
r.POST("/pause", pauseHandler)
r.POST("/update", updateHandler)

go func() {
// check if certificates exist; if not, use plain http
if _, err := os.Stat(filepath.Join(dest, "cert.pem")); os.IsNotExist(err) {
log.Error("Could not find HTTPS certificate. Using plain HTTP only.")
return
}

start := 8990
end := 9000
i := start
for i < end {
i = i + 1
portSSL = ":" + strconv.Itoa(i)
if err := r.RunTLS(*address+portSSL, filepath.Join(dest, "cert.pem"), filepath.Join(dest, "key.pem")); err != nil {
log.Printf("Error trying to bind to port: %v, so exiting...", err)
continue
} else {
log.Print("Starting server and websocket (SSL) on " + *address + "" + port)
break
}
}
}()

go func() {
start := 8990
end := 9000
i := start
for i < end {
i = i + 1
port = ":" + strconv.Itoa(i)
if err := r.Run(*address + port); err != nil {
log.Printf("Error trying to bind to port: %v, so exiting...", err)
continue
} else {
log.Print("Starting server and websocket on " + *address + "" + port)
break
}
}
}()

}()
}

if !*verbose {
Expand Down