Skip to content

Commit

Permalink
添加 auth_alone_otp 开关
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Nov 7, 2024
1 parent c7d6a76 commit 9ef2954
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 143 deletions.
1 change: 1 addition & 0 deletions server/base/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ServerConfig struct {

DisplayError bool `json:"display_error"`
ExcludeExportIp bool `json:"exclude_export_ip"`
AuthAloneOtp bool `json:"auth_alone_otp"`

AntiBruteForce bool `json:"anti_brute_force"`
IPWhitelist string `json:"ip_whitelist"`
Expand Down
1 change: 1 addition & 0 deletions server/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var configs = []config{

{Typ: cfgBool, Name: "display_error", Usage: "客户端显示详细错误信息(线上环境慎开启)", ValBool: false},
{Typ: cfgBool, Name: "exclude_export_ip", Usage: "排除出口ip路由(出口ip不加密传输)", ValBool: true},
{Typ: cfgBool, Name: "auth_alone_otp", Usage: "登录单独验证OTP窗口", ValBool: false},

{Typ: cfgBool, Name: "anti_brute_force", Usage: "是否开启防爆功能", ValBool: true},
{Typ: cfgStr, Name: "ip_whitelist", Usage: "全局IP白名单,多个用逗号分隔,支持单IP和CIDR范围", ValStr: "192.168.90.1,172.16.0.0/24"},
Expand Down
37 changes: 37 additions & 0 deletions server/conf/server-sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,40 @@ display_error = false

#排除出口ip路由(出口ip不加密传输)
exclude_export_ip = true

#登录单独验证OTP窗口
auth_alone_otp = false


#防爆破全局开关
anti_brute_force = true
#全局IP白名单,多个用逗号分隔,支持单IP和CIDR范围
ip_whitelist = "192.168.90.1,172.16.0.0/24"

#锁定时间最好不要超过单位时间
#单位时间内最大尝试次数,0为关闭该功能
max_ban_score = 5
#设置单位时间(秒),超过则重置计数
ban_reset_time = 600
#超过最大尝试次数后的锁定时长(秒)
lock_time = 300

#全局用户单位时间内最大尝试次数,0为关闭该功能
max_global_user_ban_count = 20
#全局用户设置单位时间(秒)
global_user_ban_reset_time = 600
#全局用户锁定时间(秒)
global_user_lock_time = 300

#全局IP单位时间内最大尝试次数,0为关闭该功能
max_global_ip_ban_count = 40
#全局IP设置单位时间(秒)
global_ip_ban_reset_time = 1200
#全局IP锁定时间(秒)
global_ip_lock_time = 300

#全局锁定状态的保存生命周期(秒),超过则删除记录
global_lock_state_expiration_time = 3600



30 changes: 0 additions & 30 deletions server/conf/server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,5 @@ ipv4_end = "192.168.90.200"
#是否自动添加nat
iptables_nat = true

#防爆破全局开关
anti_brute_force = true
#全局IP白名单,多个用逗号分隔,支持单IP和CIDR范围
ip_whitelist = "192.168.90.1,172.16.0.0/24"

#锁定时间最好不要超过单位时间
#单位时间内最大尝试次数,0为关闭该功能
max_ban_score = 5
#设置单位时间(秒),超过则重置计数
ban_reset_time = 600
#超过最大尝试次数后的锁定时长(秒)
lock_time = 300

#全局用户单位时间内最大尝试次数,0为关闭该功能
max_global_user_ban_count = 20
#全局用户设置单位时间(秒)
global_user_ban_reset_time = 600
#全局用户锁定时间(秒)
global_user_lock_time = 300

#全局IP单位时间内最大尝试次数,0为关闭该功能
max_global_ip_ban_count = 40
#全局IP设置单位时间(秒)
global_ip_ban_reset_time = 1200
#全局IP锁定时间(秒)
global_ip_lock_time = 300

#全局锁定状态的保存生命周期(秒),超过则删除记录
global_lock_state_expiration_time = 3600

#客户端显示详细错误信息(线上环境慎开启)
display_error = true
26 changes: 15 additions & 11 deletions server/dbdata/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,29 @@ func checkLocalUser(name, pwd, group string) error {
if !utils.InArrStr(v.Groups, group) {
return fmt.Errorf("%s %s", name, "用户组错误")
}
// 判断otp信息
// pinCode := pwd
// if !v.DisableOtp {
// pinCode = pwd[:pl-6]
// otp := pwd[pl-6:]
// if !CheckOtp(name, otp, v.OtpSecret) {
// return fmt.Errorf("%s %s", name, "动态码错误")
// }
// }

pinCode := pwd
if base.Cfg.AuthAloneOtp == false {
// 判断otp信息
if !v.DisableOtp {
pinCode = pwd[:pl-6]
otp := pwd[pl-6:]
if !CheckOtp(name, otp, v.OtpSecret) {
return fmt.Errorf("%s %s", name, "动态码错误")
}
}
}

// 判断用户密码
// 兼容明文密码
if len(v.PinCode) != 60 {
if pwd != v.PinCode {
if pinCode != v.PinCode {
return fmt.Errorf("%s %s", name, "密码错误")
}
return nil
}
// 密文密码
if !utils.PasswordVerify(pwd, v.PinCode) {
if !utils.PasswordVerify(pinCode, v.PinCode) {
return fmt.Errorf("%s %s", name, "密码错误")
}

Expand Down
Loading

0 comments on commit 9ef2954

Please sign in to comment.