feat: Add per-user IP limit exemption
Introduces a new 'unlimited_user' flag for users. When set to true, the user is exempt from the concurrent IP limit enforcement by `limit.sh`. - `core/scripts/hysteria2/add_user.py`: - Adds an optional `unlimited_user` argument (defaults to false). - Stores the `unlimited_user` boolean in the `users.json` file when adding a user. - `core/scripts/hysteria2/limit.sh`: - Modifies `check_ip_limit` function to first check the `unlimited_user` flag for the connecting user in `users.json`. - If the flag is true, the script bypasses the IP limit check for that user. - Uses `jq` for reliable parsing and includes a `grep` fallback for systems without `jq`. - Existing users without the flag are treated as limited (default behavior).
This commit is contained in:
@ -183,6 +183,23 @@ check_ip_limit() {
|
||||
local username="$1"
|
||||
local ips=()
|
||||
|
||||
local is_unlimited="false"
|
||||
if [ -f "$USERS_FILE" ]; then
|
||||
if command -v jq &>/dev/null; then
|
||||
is_unlimited=$(jq -r --arg user "$username" '.[$user].unlimited_user // "false"' "$USERS_FILE" 2>/dev/null)
|
||||
else
|
||||
if grep -q "\"$username\"" "$USERS_FILE" && \
|
||||
grep -A 5 "\"$username\"" "$USERS_FILE" | grep -q '"unlimited_user": true'; then
|
||||
is_unlimited="true"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$is_unlimited" = "true" ]; then
|
||||
log_message "INFO" "User $username is exempt from IP limit. Skipping check."
|
||||
return
|
||||
fi
|
||||
|
||||
# Get all IPs for this user
|
||||
if command -v jq &>/dev/null; then
|
||||
readarray -t ips < <(jq -r --arg user "$username" '.[$user][]' "$CONNECTIONS_FILE" 2>/dev/null)
|
||||
@ -364,4 +381,4 @@ case "$1" in
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
exit 0
|
||||
Reference in New Issue
Block a user