gh-7 Log failed authentications. Forked rocketlaunchr/https-go to add CN to the generated certifcate
This commit is contained in:
parent
0e10c9d925
commit
468bc33f7e
|
@ -3,6 +3,7 @@ module github.com/0ranki/enervent-ctrl/enervent-ctrl-go
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/0ranki/https-go v0.0.0-20230314064508-ba9a558db433
|
||||||
github.com/goburrow/modbus v0.1.0
|
github.com/goburrow/modbus v0.1.0
|
||||||
github.com/gorilla/handlers v1.5.1
|
github.com/gorilla/handlers v1.5.1
|
||||||
)
|
)
|
||||||
|
@ -12,5 +13,4 @@ require golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||||
require (
|
require (
|
||||||
github.com/felixge/httpsnoop v1.0.1 // indirect
|
github.com/felixge/httpsnoop v1.0.1 // indirect
|
||||||
github.com/goburrow/serial v0.1.0 // indirect
|
github.com/goburrow/serial v0.1.0 // indirect
|
||||||
github.com/rocketlaunchr/https-go v0.0.0-20200218083740-ba6c48f29f4d
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
github.com/0ranki/https-go v0.0.0-20230314064508-ba9a558db433 h1:QT2IRJnhIdCSr26LJktnZnBpHdiLfTrUFzLSdP3h9Wo=
|
||||||
|
github.com/0ranki/https-go v0.0.0-20230314064508-ba9a558db433/go.mod h1:r4Jb05+PuiVKHDYwSsSBuSz4LpOlC2DgOY4N58+K8Hk=
|
||||||
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
|
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
|
||||||
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
github.com/goburrow/modbus v0.1.0 h1:DejRZY73nEM6+bt5JSP6IsFolJ9dVcqxsYbpLbeW/ro=
|
github.com/goburrow/modbus v0.1.0 h1:DejRZY73nEM6+bt5JSP6IsFolJ9dVcqxsYbpLbeW/ro=
|
||||||
|
@ -6,7 +8,5 @@ github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA
|
||||||
github.com/goburrow/serial v0.1.0/go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA=
|
github.com/goburrow/serial v0.1.0/go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA=
|
||||||
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
|
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
|
||||||
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
|
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
|
||||||
github.com/rocketlaunchr/https-go v0.0.0-20200218083740-ba6c48f29f4d h1:bL0c7wxznxDDQ+ebCpGN5T20ATeYDXedomXbQHwFwHA=
|
|
||||||
github.com/rocketlaunchr/https-go v0.0.0-20200218083740-ba6c48f29f4d/go.mod h1:kDbnFcjPe/2KqPfycPSq0Ripnddx0DtCC2M1k95myWQ=
|
|
||||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
|
||||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/0ranki/enervent-ctrl/enervent-ctrl-go/pingvinKL"
|
"github.com/0ranki/enervent-ctrl/enervent-ctrl-go/pingvinKL"
|
||||||
|
"github.com/0ranki/https-go"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/rocketlaunchr/https-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Remember to dereference the symbolic links under ./static/html
|
// Remember to dereference the symbolic links under ./static/html
|
||||||
|
@ -26,7 +26,7 @@ import (
|
||||||
var static embed.FS
|
var static embed.FS
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "0.0.20"
|
version = "0.0.21"
|
||||||
pingvin pingvinKL.PingvinKL
|
pingvin pingvinKL.PingvinKL
|
||||||
DEBUG *bool
|
DEBUG *bool
|
||||||
INTERVAL *int
|
INTERVAL *int
|
||||||
|
@ -50,6 +50,10 @@ func authHandlerFunc(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(user) == 0 {
|
||||||
|
user = "-"
|
||||||
|
}
|
||||||
|
log.Println("Authentication failed: IP:", r.RemoteAddr, "URI:", r.RequestURI, "username:", user)
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
})
|
})
|
||||||
|
@ -69,6 +73,10 @@ func authHandler(next http.Handler) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(user) == 0 {
|
||||||
|
user = "-"
|
||||||
|
}
|
||||||
|
log.Println("Authentication failed: IP:", r.RemoteAddr, "URI:", r.RequestURI, "username:", user)
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
})
|
})
|
||||||
|
@ -201,6 +209,7 @@ func generateCertificate(certpath, cert, key string) {
|
||||||
}
|
}
|
||||||
opts := https.GenerateOptions{Host: "enervent-ctrl.local", RSABits: 4096, ValidFor: 10 * 365 * 24 * time.Hour}
|
opts := https.GenerateOptions{Host: "enervent-ctrl.local", RSABits: 4096, ValidFor: 10 * 365 * 24 * time.Hour}
|
||||||
log.Println("Generating new self-signed SSL keypair to ", certpath)
|
log.Println("Generating new self-signed SSL keypair to ", certpath)
|
||||||
|
log.Println("This may take a while...")
|
||||||
pub, priv, err := https.GenerateKeys(opts)
|
pub, priv, err := https.GenerateKeys(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error generating SSL certificate: ", err)
|
log.Fatal("Error generating SSL certificate: ", err)
|
||||||
|
|
Loading…
Reference in New Issue