Browse Source

Added more blacklist code

Toby Chui 3 năm trước cách đây
mục cha
commit
9a59bd1345
1 tập tin đã thay đổi với 16 bổ sung1 xóa
  1. 16 1
      mod/auth/blacklist/blacklist.go

+ 16 - 1
mod/auth/blacklist/blacklist.go

@@ -33,23 +33,38 @@ func NewBlacklistManager(sysdb *db.Database) *BlackList {
 	}
 }
 
+//Check if a given IP is banned
 func (bl *BlackList) IsBanned(ip string) bool {
+	if bl.Enabled == false {
+		return false
+	}
 	if bl.database.KeyExists("ipblacklist", ip) {
 		return true
 	}
 	return false
 }
 
-func (bl *BlackList) SetBan(ipRange string) error {
+//Set the ban state of a ip or ip range
+func (bl *BlackList) Ban(ipRange string) error {
 	//Check if the IP range is correct
 	err := validateIpRange(ipRange)
 	if err != nil {
 		return err
 	}
 
+	//Push it to the ban list
+	ipRange = strings.TrimSpace(ipRange)
+	ipRange = strings.ReplaceAll(ipRange, " ", "")
+	return bl.database.Write("ipblacklist", ipRange, true)
+}
+
+func (bl *BlackList) UnBan(ipRange string) error {
+	//Check if the IP range is correct
 	return nil
+
 }
 
+//Check if an given ip in the given range
 func ipInRange(ip string, ipRange string) bool {
 	ip = strings.TrimSpace(ip)
 	ipRange = strings.TrimSpace(ipRange)