fix(limit): Ensure IP removal on disconnect for all users
This commit is contained in:
@ -122,16 +122,6 @@ check_expired_blocks() {
|
|||||||
check_ip_limit() {
|
check_ip_limit() {
|
||||||
local username="$1"
|
local username="$1"
|
||||||
|
|
||||||
local is_unlimited
|
|
||||||
is_unlimited=$(mongosh "$DB_NAME" --quiet --eval "
|
|
||||||
db.users.findOne({_id: '$username'}, {_id: 0, unlimited_user: 1})?.unlimited_user || false;
|
|
||||||
")
|
|
||||||
|
|
||||||
if [ "$is_unlimited" == "true" ]; then
|
|
||||||
log_message "INFO" "User $username is exempt from IP limit. Skipping check."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local ip_count
|
local ip_count
|
||||||
ip_count=$(mongosh "$DB_NAME" --quiet --eval "
|
ip_count=$(mongosh "$DB_NAME" --quiet --eval "
|
||||||
db.getCollection('$CONNECTIONS_COLLECTION').findOne({_id: '$username'})?.ips?.length || 0;
|
db.getCollection('$CONNECTIONS_COLLECTION').findOne({_id: '$username'})?.ips?.length || 0;
|
||||||
@ -160,7 +150,17 @@ parse_log_line() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
add_ip_to_db "$username" "$ip_address"
|
add_ip_to_db "$username" "$ip_address"
|
||||||
check_ip_limit "$username"
|
|
||||||
|
local is_unlimited
|
||||||
|
is_unlimited=$(mongosh "$DB_NAME" --quiet --eval "
|
||||||
|
db.users.findOne({_id: '$username'}, {_id: 0, unlimited_user: 1})?.unlimited_user || false;
|
||||||
|
")
|
||||||
|
|
||||||
|
if [ "$is_unlimited" == "true" ]; then
|
||||||
|
log_message "INFO" "User $username is exempt from IP limit. Skipping check."
|
||||||
|
else
|
||||||
|
check_ip_limit "$username"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
elif echo "$log_line" | grep -q "client disconnected"; then
|
elif echo "$log_line" | grep -q "client disconnected"; then
|
||||||
remove_ip_from_db "$username" "$ip_address"
|
remove_ip_from_db "$username" "$ip_address"
|
||||||
|
|||||||
Reference in New Issue
Block a user