50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
package captiveportal
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type Liar interface {
|
||
|
Handle(os OS, w http.ResponseWriter, r *http.Request)
|
||
|
}
|
||
|
|
||
|
type LiarFunc func(os OS, w http.ResponseWriter, r *http.Request)
|
||
|
|
||
|
func (f LiarFunc) Handle(os OS, w http.ResponseWriter, r *http.Request) {
|
||
|
f(os, w, r)
|
||
|
}
|
||
|
|
||
|
func HandleAndroid(w http.ResponseWriter, r *http.Request) {
|
||
|
w.WriteHeader(http.StatusNoContent)
|
||
|
}
|
||
|
|
||
|
func HandleApple(w http.ResponseWriter, r *http.Request) {
|
||
|
w.WriteHeader(http.StatusOK)
|
||
|
// nolint: errcheck
|
||
|
w.Write([]byte("<HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>"))
|
||
|
}
|
||
|
|
||
|
func HandleWindows(w http.ResponseWriter, r *http.Request) {
|
||
|
w.WriteHeader(http.StatusOK)
|
||
|
// nolint: errcheck
|
||
|
w.Write([]byte("Microsoft NCSI"))
|
||
|
}
|
||
|
|
||
|
// nolint: gochecknoglobals
|
||
|
var defaultLiars = map[OS]http.HandlerFunc{
|
||
|
OSAndroid: http.HandlerFunc(HandleAndroid),
|
||
|
OSApple: http.HandlerFunc(HandleApple),
|
||
|
OSWindows: http.HandlerFunc(HandleWindows),
|
||
|
}
|
||
|
|
||
|
func DefaultLiar(os OS, w http.ResponseWriter, r *http.Request) {
|
||
|
liar, exists := defaultLiars[os]
|
||
|
if !exists {
|
||
|
w.WriteHeader(http.StatusNoContent)
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
liar.ServeHTTP(w, r)
|
||
|
}
|