rcd: disable duplicate log
if running `rclone rcd --rc-user=admin --rc-pass=admin --rc-allow-origin="*"`, lots of duplicate warnings apperent in log Warning: Allow origin set to *. This can cause serious security problems. Warning: Allow origin set to *. This can cause serious security problems. .... This is not conducive to analyzing debugging info. Therefore, let's show it only once.
This commit is contained in:
parent
bdc91eda0f
commit
d119bfd934
1 changed files with 7 additions and 3 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -34,6 +35,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var promHandler http.Handler
|
var promHandler http.Handler
|
||||||
|
var onlyOnceWarningAllowOrigin sync.Once
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rcloneCollector := accounting.NewRcloneCollector()
|
rcloneCollector := accounting.NewRcloneCollector()
|
||||||
|
@ -187,9 +189,11 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
allowOrigin := rcflags.Opt.AccessControlAllowOrigin
|
allowOrigin := rcflags.Opt.AccessControlAllowOrigin
|
||||||
if allowOrigin != "" {
|
if allowOrigin != "" {
|
||||||
if allowOrigin == "*" {
|
onlyOnceWarningAllowOrigin.Do(func() {
|
||||||
fs.Logf(nil, "Warning: Allow origin set to *. This can cause serious security problems.")
|
if allowOrigin == "*" {
|
||||||
}
|
fs.Logf(nil, "Warning: Allow origin set to *. This can cause serious security problems.")
|
||||||
|
}
|
||||||
|
})
|
||||||
w.Header().Add("Access-Control-Allow-Origin", allowOrigin)
|
w.Header().Add("Access-Control-Allow-Origin", allowOrigin)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Add("Access-Control-Allow-Origin", s.URL())
|
w.Header().Add("Access-Control-Allow-Origin", s.URL())
|
||||||
|
|
Loading…
Add table
Reference in a new issue