Skip to content

Commit

Permalink
feat: If the configuration file is empty, access from the public netw…
Browse files Browse the repository at this point in the history
…ork is prohibited for more than 3 hours (#646)
  • Loading branch information
jeessy2 authored Mar 24, 2023
1 parent 9f7ee01 commit ce1a4b0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions web/basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func BasicAuth(f ViewFunc) ViewFunc {
return func(w http.ResponseWriter, r *http.Request) {
conf, err := config.GetConfigCached()

// 配置文件为空, 超过2天禁止从公网访问
if err != nil && time.Now().Unix()-startTime > 2*24*60*60 &&
// 配置文件为空, 启动时间超过3小时禁止从公网访问
if err != nil && time.Now().Unix()-startTime > 3*60*60 &&
(!util.IsPrivateNetwork(r.RemoteAddr) || !util.IsPrivateNetwork(r.Host)) {
w.WriteHeader(http.StatusForbidden)
log.Printf("%q 配置文件为空, 超过2天禁止从公网访问\n", util.GetRequestIPStr(r))
log.Printf("%q 配置文件为空, 超过3小时禁止从公网访问\n", util.GetRequestIPStr(r))
return
}

// 禁止公网访问
if conf.NotAllowWanAccess {
if !util.IsPrivateNetwork(r.RemoteAddr) || !util.IsPrivateNetwork(r.Host) {
w.WriteHeader(http.StatusForbidden)
log.Printf("%q 禁止从公网访问!\n", util.GetRequestIPStr(r))
log.Printf("%q 被禁止从公网访问!\n", util.GetRequestIPStr(r))
return
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func BasicAuth(f ViewFunc) ViewFunc {
}

ld.FailTimes = ld.FailTimes + 1
log.Printf("%q 登陆失败!\n", util.GetRequestIPStr(r))
log.Printf("%q 帐号密码不正确!\n", util.GetRequestIPStr(r))
}

// 认证失败,提示 401 Unauthorized
Expand Down

0 comments on commit ce1a4b0

Please sign in to comment.