diff --git a/core/cli.py b/core/cli.py index 709f93f..3a1770a 100644 --- a/core/cli.py +++ b/core/cli.py @@ -253,17 +253,35 @@ def uninstall_warp(): @click.option('--popular-sites', '-p', is_flag=True, help='Use WARP for popular sites like Google, OpenAI, etc') @click.option('--domestic-sites', '-d', is_flag=True, help='Use WARP for Iran domestic sites') @click.option('--block-adult-sites', '-x', is_flag=True, help='Block adult content (porn)') -def configure_warp(all: bool, popular_sites: bool, domestic_sites: bool, block_adult_sites: bool): - options = { - "all": all, - "popular_sites": popular_sites, - "domestic_sites": domestic_sites, - "block_adult_sites": block_adult_sites - } +@click.option('--warp-option', '-w', type=click.Choice(['warp', 'warp plus'], case_sensitive=False), help='Specify whether to use WARP or WARP Plus') +@click.option('--warp-key', '-k', help='WARP Plus key (required if warp-option is "warp plus")') +def configure_warp(all: bool, popular_sites: bool, domestic_sites: bool, block_adult_sites: bool, warp_option: str, warp_key: str): + if warp_option == 'warp plus' and not warp_key: + print("Error: WARP Plus key is required when 'warp plus' is selected.") + return - options = {k: 'true' if v else 'false' for k, v in options.items()} - run_cmd(['bash', Command.CONFIGURE_WARP.value, - options['all'], options['popular_sites'], options['domestic_sites'], options['block_adult_sites']]) + options = { + "all": 'true' if all else 'false', + "popular_sites": 'true' if popular_sites else 'false', + "domestic_sites": 'true' if domestic_sites else 'false', + "block_adult_sites": 'true' if block_adult_sites else 'false', + "warp_option": warp_option or '', + "warp_key": warp_key or '' + } + + cmd_args = [ + 'bash', Command.CONFIGURE_WARP.value, + options['all'], + options['popular_sites'], + options['domestic_sites'], + options['block_adult_sites'], + options['warp_option'] + ] + + if options['warp_key']: + cmd_args.append(options['warp_key']) + + run_cmd(cmd_args) @cli.command('telegram') @click.option('--action', '-a', required=True, help='Action to perform: start or stop', type=click.Choice(['start', 'stop'], case_sensitive=False)) diff --git a/core/scripts/hysteria2/server_info.sh b/core/scripts/hysteria2/server_info.sh index 853f4c9..4eeb9bd 100644 --- a/core/scripts/hysteria2/server_info.sh +++ b/core/scripts/hysteria2/server_info.sh @@ -1,7 +1,6 @@ #!/bin/bash source /etc/hysteria/core/scripts/path.sh -ONLINE_API_URL='http://127.0.0.1:25413/online' get_secret() { if [ ! -f "$CONFIG_FILE" ]; then @@ -19,15 +18,25 @@ get_secret() { echo $secret } -cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') +convert_bytes() { + local bytes=$1 + if (( bytes < 1048576 )); then + echo "$(echo "scale=2; $bytes / 1024" | bc) KB" + elif (( bytes < 1073741824 )); then + echo "$(echo "scale=2; $bytes / 1048576" | bc) MB" + elif (( bytes < 1099511627776 )); then + echo "$(echo "scale=2; $bytes / 1073741824" | bc) GB" + else + echo "$(echo "scale=2; $bytes / 1099511627776" | bc) TB" + fi +} +cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') total_ram=$(free -m | awk '/Mem:/ {print $2}') used_ram=$(free -m | awk '/Mem:/ {print $3}') secret=$(get_secret) - online_users=$(curl -s -H "Authorization: $secret" $ONLINE_API_URL) - online_user_count=$(echo $online_users | jq 'add') if [ "$online_user_count" == "null" ] || [ "$online_user_count" == "0" ]; then @@ -38,3 +47,24 @@ echo "CPU Usage: $cpu_usage" echo "Total RAM: ${total_ram}MB" echo "Used RAM: ${used_ram}MB" echo "Online Users: $online_user_count" +echo +echo "Total Traffic: " + +if [ -f "$TRAFFIC_FILE" ]; then + total_upload=0 + total_download=0 + + while IFS= read -r line; do + upload=$(echo $line | jq -r '.upload_bytes') + download=$(echo $line | jq -r '.download_bytes') + total_upload=$(echo "$total_upload + $upload" | bc) + total_download=$(echo "$total_download + $download" | bc) + done <<< "$(jq -c '.[]' $TRAFFIC_FILE)" + + total_upload_human=$(convert_bytes $total_upload) + total_download_human=$(convert_bytes $total_download) + + echo "${total_upload_human} uploaded" + + echo "${total_download_human} downloaded" +fi diff --git a/core/scripts/path.sh b/core/scripts/path.sh index 8c0b5fc..6218d00 100644 --- a/core/scripts/path.sh +++ b/core/scripts/path.sh @@ -4,3 +4,4 @@ TRAFFIC_FILE="/etc/hysteria/traffic_data.json" CONFIG_FILE="/etc/hysteria/config.json" TELEGRAM_ENV="/etc/hysteria/core/scripts/telegrambot/.env" SINGBOX_ENV="/etc/hysteria/core/scripts/singbox/.env" +ONLINE_API_URL="http://127.0.0.1:25413/online" diff --git a/core/scripts/warp/configure.sh b/core/scripts/warp/configure.sh index 439409c..6aaddab 100644 --- a/core/scripts/warp/configure.sh +++ b/core/scripts/warp/configure.sh @@ -7,6 +7,8 @@ warp_configure_handler() { local popular_sites=$2 local domestic_sites=$3 local block_adult_sites=$4 + local warp_option=$5 + local warp_key=$6 if [ "$all" == "true" ]; then if [ "$(jq -r 'if .acl.inline | index("warps(all)") then "WARP active" else "Direct" end' "$CONFIG_FILE")" == "WARP active" ]; then @@ -50,7 +52,27 @@ warp_configure_handler() { fi fi + if [ "$warp_option" == "warp plus" ]; then + if [ -z "$warp_key" ]; then + echo "Error: WARP Plus key is required. Exiting." + exit 1 + fi + cd /etc/warp/ || { echo "Failed to change directory to /etc/warp/"; exit 1; } + + WGCF_LICENSE_KEY="$warp_key" wgcf update + + if [ $? -ne 0 ]; then + echo "Error: Failed to update WARP Plus configuration." + exit 1 + fi + + elif [ "$warp_option" == "warp" ]; then + cd /etc/warp/ || { echo "Failed to change directory to /etc/warp/"; exit 1; } + rm wgcf-account.toml && yes | wgcf register + echo "WARP configured with a new account." + fi + python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 } -warp_configure_handler "$1" "$2" "$3" "$4" +warp_configure_handler "$1" "$2" "$3" "$4" "$5" "$6" diff --git a/core/scripts/warp/uninstall.sh b/core/scripts/warp/uninstall.sh index c51aedf..8ce8b0a 100644 --- a/core/scripts/warp/uninstall.sh +++ b/core/scripts/warp/uninstall.sh @@ -1,14 +1,11 @@ #!/bin/bash -# Source the path.sh script to load the CONFIG_FILE and CLI_PATH variables source /etc/hysteria/core/scripts/path.sh -# Check if WARP is active if systemctl is-active --quiet wg-quick@wgcf.service; then echo "Uninstalling WARP..." bash <(curl -fsSL git.io/warp.sh) dwg - # Check if the config file exists if [ -f "$CONFIG_FILE" ]; then default_config='["reject(geosite:ir)", "reject(geoip:ir)", "reject(geosite:category-ads-all)", "reject(geoip:private)", "reject(geosite:google@ads)"]' @@ -28,6 +25,14 @@ if systemctl is-active --quiet wg-quick@wgcf.service; then jq 'del(.outbounds[] | select(.name == "warps" and .type == "direct" and .direct.mode == 4 and .direct.bindDevice == "wgcf"))' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" + if [ "$(jq -r 'if .acl.inline | index("reject(geosite:category-porn)") then "Blocked" else "Not blocked" end' "$CONFIG_FILE")" == "Blocked" ]; then + jq 'del(.acl.inline[] | select(. == "reject(geosite:category-porn)"))' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" + echo "Adult content blocking removed." + fi + + jq '.resolver.tls.addr = "1.1.1.1:853"' "$CONFIG_FILE" > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json "$CONFIG_FILE" + echo "DNS resolver address changed to 1.1.1.1:853." + python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 echo "WARP uninstalled and configurations reset to default." else diff --git a/menu.sh b/menu.sh index b5a7367..1b1f9b1 100644 --- a/menu.sh +++ b/menu.sh @@ -240,6 +240,10 @@ warp_configure_handler() { echo "2. Use WARP for popular sites" echo "3. Use WARP for domestic sites" echo "4. Block adult content" + echo "5. WARP (Plus) Profile" + echo "6. WARP (Normal) Profile" + echo "7. WARP Status Profile" + echo "8. Change IP address" echo "0. Cancel" read -p "Select an option: " option @@ -249,11 +253,30 @@ warp_configure_handler() { 2) python3 $CLI_PATH configure-warp --popular-sites ;; 3) python3 $CLI_PATH configure-warp --domestic-sites ;; 4) python3 $CLI_PATH configure-warp --block-adult-sites ;; + 5) + echo "Please enter your WARP Plus key:" + read -r warp_key + if [ -z "$warp_key" ]; then + echo "Error: WARP Plus key cannot be empty. Exiting." + return + fi + python3 $CLI_PATH configure-warp --warp-option "warp plus" --warp-key "$warp_key" + ;; + 6) python3 $CLI_PATH configure-warp --warp-option "warp" ;; + 7) cd /etc/warp/ && wgcf status ;; + 8) + old_ip=$(curl -s --interface wgcf --connect-timeout 0.5 http://v4.ident.me) + echo "Current IP address: $old_ip" + echo "Restarting $service_name..." + systemctl restart "$service_name" + sleep 5 + new_ip=$(curl -s --interface wgcf --connect-timeout 0.5 http://v4.ident.me) + echo "New IP address: $new_ip" + ;; 0) echo "WARP configuration canceled." ;; *) echo "Invalid option. Please try again." ;; esac else - # Notify user if the service is not active echo "$service_name is not active. Please start the service before configuring WARP." fi }