#!/usr/bin/env bash set -u URL_INPUT=${1:-} CONFIG_FILE="client.json" if [[ -z "$URL_INPUT" ]]; then echo "Usage: ./menu.sh " exit 1 fi # Function to decode URL params specially for VLESS decode_url() { local encoded="$1" # Basic URL decode echo -e "${encoded//%/\\x}" } # 1. Detect type if [[ "$URL_INPUT" =~ ^vless:// ]]; then echo "Direct VLESS URL detected. Applying..." ./gen-client-from-url.sh "$URL_INPUT" "$CONFIG_FILE" echo "Triggering reload..." curl -s http://localhost:9090/reload echo "Done." exit 0 fi # 2. It's likely a subscription echo "Fetching subscription..." SUB_CONTENT=$(curl -sSL "$URL_INPUT") if [[ -z "$SUB_CONTENT" ]]; then echo "Error: Empty response." exit 1 fi # Try Base64 decode if DECODED=$(echo "$SUB_CONTENT" | base64 -d 2>/dev/null); then echo "Subscription is Base64 encoded." RAW_LIST="$DECODED" else echo "Subscription is plain text." RAW_LIST="$SUB_CONTENT" fi # 3. Parse VLESS links # We will use an array to store links and names declare -a LINKS declare -a NAMES i=0 while IFS= read -r line; do # trimming line=$(echo "$line" | xargs) if [[ "$line" =~ ^vless:// ]]; then LINKS[$i]="$line" # Extract name from hash #Name if [[ "$line" =~ \#(.*)$ ]]; then NAME=$(decode_url "${BASH_REMATCH[1]}") else NAME="Config_$((i+1))" fi NAMES[$i]="$NAME" ((i++)) fi done <<< "$RAW_LIST" COUNT=${#LINKS[@]} if [[ "$COUNT" -eq 0 ]]; then echo "No VLESS configs found in subscription." exit 1 fi # 4. Display Menu echo "Found $COUNT configurations:" echo "--------------------------------" for (( j=0; j