Fix some Warp ip access to ip.sb returned restricted.

This commit is contained in:
fs carmen
2024-08-19 04:05:49 +00:00
parent 2113865e8e
commit 55767e4a47
3 changed files with 246 additions and 230 deletions
+197 -183
View File
@@ -1,60 +1,60 @@
#!/usr/bin/env bash
# 只允许root运行
[[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
[[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1
# 帮助
help() {
echo -ne " Usage:\n\tbash api.sh\t-h/--help\t\thelp\n\t\t\t-f/--file string\tConfiguration file (default "warp-account.conf")\n\t\t\t-r/--register\t\tRegister an account\n\t\t\t-t/--token\t\tRegister with a team token\n\t\t\t-d/--device\t\tGet the devices information and plus traffic quota\n\t\t\t-a/--app\t\tFetch App information\n\t\t\t-b/--bind\t\tGet the account blinding devices\n\t\t\t-n/--name\t\tChange the device name\n\t\t\t-l/--license\t\tChange the license\n\t\t\t-u/--unbind\t\tUnbine a device from the account\n\t\t\t-c/--cancle\t\tCancle the account\n\t\t\t-i/--id\t\t\tShow the client id and reserved\n\n"
echo -ne " Usage:\n bash api.sh\n\t-h/--help\t\thelp\n\t-f/--file string\tConfiguration file\n\t-r/--register\t\tRegister an account\n\t-t/--token\t\tRegister with a team token\n\t-d/--device\t\tGet the devices information and plus traffic quota\n\t-a/--app\t\tFetch App information\n\t-b/--bind\t\tGet the account blinding devices\n\t-n/--name\t\tChange the device name\n\t-l/--license\t\tChange the license\n\t-u/--unbind\t\tUnbine a device from the account\n\t-c/--cancle\t\tCancle the account\n\t-i/--id\t\t\tShow the client id and reserved\n\n"
}
# 获取账户信息
fetch_account_information() {
# 如不使用账户信息文件,则手动填写 Device id 和 Api token
if [ -s "$register_path" ]; then
if [ -s "$REGISTER_PATH" ]; then
# Teams 账户文件
if grep -q 'xml version' $register_path; then
id=$(grep 'correlation_id' $register_path | sed "s#.*>\(.*\)<.*#\1#")
token=$(grep 'warp_token' $register_path | sed "s#.*>\(.*\)<.*#\1#")
client_id=$(grep 'client_id' $register_path | sed "s#.*client_id&quot;:&quot;\([^&]\{4\}\)&.*#\1#")
if grep -q 'xml version' $REGISTER_PATH; then
ID=$(grep 'correlation_id' $REGISTER_PATH | sed "s#.*>\(.*\)<.*#\1#")
TOKEN=$(grep 'warp_token' $REGISTER_PATH | sed "s#.*>\(.*\)<.*#\1#")
CLIENT_ID=$(grep 'client_id' $REGISTER_PATH | sed "s#.*client_id&quot;:&quot;\([^&]\{4\}\)&.*#\1#")
# 官方 api 文件
elif grep -q 'client_id' $register_path; then
id=$(grep -m1 '"id' "$register_path" | cut -d\" -f4)
token=$(grep '"token' "$register_path" | cut -d\" -f4)
client_id=$(grep 'client_id' "$register_path" | cut -d\" -f4)
elif grep -q 'client_id' $REGISTER_PATH; then
ID=$(grep -m1 '"id' "$REGISTER_PATH" | cut -d\" -f4)
TOKEN=$(grep '"token' "$REGISTER_PATH" | cut -d\" -f4)
CLIENT_ID=$(grep 'client_id' "$REGISTER_PATH" | cut -d\" -f4)
# client 文件,默认存放路径为 /var/lib/cloudflare-warp/reg.json
elif grep -q 'registration_id' $register_path; then
id=$(cut -d\" -f4 "$register_path")
token=$(cut -d\" -f8 "$register_path")
elif grep -q 'registration_id' $REGISTER_PATH; then
ID=$(cut -d\" -f4 "$REGISTER_PATH")
TOKEN=$(cut -d\" -f8 "$REGISTER_PATH")
# wgcf 文件,默认存放路径为 /etc/wireguard/wgcf-account.toml
elif grep -q 'access_token' $register_path; then
id=$(grep 'device_id' "$register_path" | cut -d\' -f2)
token=$(grep 'access_token' "$register_path" | cut -d\' -f2)
elif grep -q 'access_token' $REGISTER_PATH; then
ID=$(grep 'device_id' "$REGISTER_PATH" | cut -d\' -f2)
TOKEN=$(grep 'access_token' "$REGISTER_PATH" | cut -d\' -f2)
# warp-go 文件,默认存放路径为 /opt/warp-go/warp.conf
elif grep -q 'PrivateKey' $register_path; then
id=$(awk -F' *= *' '/^Device/{print $2}' "$register_path")
token=$(awk -F' *= *' '/^Token/{print $2}' "$register_path")
elif grep -q 'PrivateKey' $REGISTER_PATH; then
ID=$(awk -F' *= *' '/^Device/{print $2}' "$REGISTER_PATH")
TOKEN=$(awk -F' *= *' '/^Token/{print $2}' "$REGISTER_PATH")
else
echo " There is no registered account information, please check the content. " && exit 1
fi
else
read -rp " Input device id: " id
read -rp " Input device id: " ID
local i=5
until [[ "$id" =~ ^(t\.)?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}$ ]]; do
(( i-- )) || true
[ "$i" = 0 ] && echo " Input errors up to 5 times. The script is aborted. " && exit 1 || read -rp " Device id should be 36 or 38 characters, please re-enter (${i} times remaining): " id
until [[ "$ID" =~ ^(t\.)?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}$ ]]; do
((i--)) || true
[ "$i" = 0 ] && echo " Input errors up to 5 times. The script is aborted. " && exit 1 || read -rp " Device id should be 36 or 38 characters, please re-enter (${i} times remaining): " ID
done
read -rp " Input api token: " token
read -rp " Input api token: " TOKEN
local i=5
until [[ "$token" =~ ^[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}$ ]]; do
(( i-- )) || true
[ "$i" = 0 ] && echo " Input errors up to 5 times. The script is aborted. " && exit 1 || read -rp " Api token should be 36 characters, please re-enter (${i} times remaining): " token
until [[ "$TOKEN" =~ ^[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}$ ]]; do
((i--)) || true
[ "$i" = 0 ] && echo " Input errors up to 5 times. The script is aborted. " && exit 1 || read -rp " Api token should be 36 characters, please re-enter (${i} times remaining): " TOKEN
done
fi
}
@@ -62,219 +62,233 @@ fetch_account_information() {
# 注册warp账户
register_account() {
# 生成 wireguard 公私钥,并且补上 private key
if [ $(type -p wg) ]; then
private_key=$(wg genkey)
public_key=$(wg pubkey <<< "$private_key")
if [ -x "$(type -p wg)" ]; then
PRIVATE_KEY=$(wg genkey)
PUBLIC_KEY=$(wg pubkey <<<"$PRIVATE_KEY")
elif [[ -x "$(type -p openssl)" && -x "$(type -p xxd)" && -x "$(type -p base64)" ]]; then
KEY_PAIR=$(openssl genpkey -algorithm X25519 -text)
PRIVATE_KEY=$(echo $KEY_PAIR | sed 's/.*priv:\(.*\)pub.*/\1/' | xxd -r -p | base64)
PUBLIC_KEY=$(echo $KEY_PAIR | sed 's/.*pub://' | xxd -r -p | base64)
else
wg_api=$(curl -m5 -sSL https://wg-key.forvps.gq/)
private_key=$(awk 'NR==2 {print $2}' <<< "$wg_api")
public_key=$(awk 'NR==1 {print $2}' <<< "$wg_api")
WG_API=$(curl -m5 -sSL https://wg-key.forvps.gq/)
PRIVATE_KEY=$(awk 'NR==2 {print $2}' <<<"$WG_API")
PUBLIC_KEY=$(awk 'NR==1 {print $2}' <<<"$WG_API")
fi
register_path=${register_path:-warp-account.conf}
[[ "$(dirname "$register_path")" != '.' ]] && mkdir -p $(dirname "$register_path")
if [[ -n "$private_key" && -n "$public_key" ]]; then
install_id=$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 22)
fcm_token="${install_id}:APA91b$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 134)"
if grep -q . <<<"$PRIVATE_KEY" && grep -q . <<<"$PUBLIC_KEY"; then
INSTALL_ID=$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 22)
FCM_TOKEN="${INSTALL_ID}:APA91b$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 134)"
# 由于某些 IP 存在被限制注册,所以使用不停的注册来处理
until grep -q 'account' <<< "$account"; do
account=$(curl --request POST 'https://api.cloudflareclient.com/v0a2158/reg' \
--silent \
--location \
--tlsv1.3 \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Cf-Access-Jwt-Assertion: ${team_token}" \
--data '{"key":"'${public_key}'","install_id":"'${install_id}'","fcm_token":"'${fcm_token}'","tos":"'$(date +"%Y-%m-%dT%H:%M:%S.000Z")'","model":"PC","serial_number":"'${install_id}'","locale":"zh_CN"}')
until grep -q 'account' <<<"$ACCOUNT"; do
[ "$ACCOUNT" = 'error code: 1015' ] && sleep 10
ACCOUNT=$(curl --request POST 'https://api.cloudflareclient.com/v0a2158/reg' \
--silent \
--location \
--tlsv1.3 \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Cf-Access-Jwt-Assertion: $(sed 's/.*?token=//' <<<"$TEAM_TOKEN")" \
--data '{"key":"'${PUBLIC_KEY}'","install_id":"'${INSTALL_ID}'","fcm_token":"'${FCM_TOKEN}'","tos":"'$(date +"%Y-%m-%dT%H:%M:%S.000Z")'","model":"PC","serial_number":"'${INSTALL_ID}'","locale":"zh_CN"}')
done
client_id=$(sed 's/.*"client_id":"\([^\"]\+\)\".*/\1/' <<< "$account")
reserved=$(echo "$client_id" | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}')
account=$(python3 -m json.tool <<< "$account" 2>&1 | sed "/\"key\"/a\ \"private_key\": \"$private_key\","| sed "/\"client_id\"/a\ \"reserved\": $reserved,")
echo "$account" > $register_path 2>&1
CLIENT_ID=$(sed 's/.*"client_id":"\([^\"]\+\)\".*/\1/' <<<"$ACCOUNT")
RESERVED=$(echo "$CLIENT_ID" | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}')
ACCOUNT=$(python3 -m json.tool <<<"$ACCOUNT" 2>&1 | sed "/\"key\"/a\ \"private_key\": \"$PRIVATE_KEY\"," | sed "/\"client_id\"/a\ \"reserved\": $RESERVED,")
fi
[[ ! -s $register_path || $(grep 'error' $register_path) ]] && { rm -f $register_path; exit 1; } || { cat $register_path; exit 0; }
grep -q 'error' <<<"$ACCOUNT" && echo " Failed to register an account. " && exit 1
if [ -n "$REGISTER_PATH" ]; then
[ ! -d "$(dirname "$REGISTER_PATH")" ] && mkdir -p $(dirname "$REGISTER_PATH")
echo "$ACCOUNT" >$REGISTER_PATH 2>&1
cat $REGISTER_PATH
else
echo "$ACCOUNT"
fi
exit 0
}
# 获取设备信息
device_information() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request GET "https://api.cloudflareclient.com/v0a2158/reg/${id}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
| python3 -m json.tool | sed "/\"warp_enabled\"/i\ \"token\": \"${token}\","
curl --request GET "https://api.cloudflareclient.com/v0a2158/reg/${ID}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" |
python3 -m json.tool | sed "/\"warp_enabled\"/i\ \"token\": \"${TOKEN}\","
}
# 获取账户APP信息
app_information() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request GET "https://api.cloudflareclient.com/v0a2158/client_config" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
| python3 -m json.tool
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" |
python3 -m json.tool
}
# 查看账户绑定设备
account_binding_devices() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request GET "https://api.cloudflareclient.com/v0a2158/reg/${id}/account/devices" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
| python3 -m json.tool
curl --request GET "https://api.cloudflareclient.com/v0a2158/reg/${ID}/account/devices" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" |
python3 -m json.tool
}
# 添加或者更改设备名
change_device_name() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request PATCH "https://api.cloudflareclient.com/v0a2158/reg/${id}/account/reg/${id}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{"name":"'$device_name'"}' \
| python3 -m json.tool
curl --request PATCH "https://api.cloudflareclient.com/v0a2158/reg/${ID}/account/reg/${ID}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" \
--data '{"name":"'$DEVICE_NAME'"}' |
python3 -m json.tool
}
# 更换 license
change_license() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request PUT "https://api.cloudflareclient.com/v0a2158/reg/${id}/account" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{"license": "'$license'"}' \
| python3 -m json.tool
curl --request PUT "https://api.cloudflareclient.com/v0a2158/reg/${ID}/account" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" \
--data '{"license": "'$LICENSE'"}' |
python3 -m json.tool
}
# 删除绑定设备
unbind_devide() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
curl --request PATCH "https://api.cloudflareclient.com/v0a2158/reg/${id}/account/reg/${id}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" \
--data '{"active":false}' \
| python3 -m json.tool
curl --request PATCH "https://api.cloudflareclient.com/v0a2158/reg/${ID}/account/reg/${ID}" \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" \
--data '{"active":false}' |
python3 -m json.tool
}
# 删除账户
cancle_account() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
local result=$(curl --request DELETE "https://api.cloudflareclient.com/v0a2158/reg/${id}" \
--head \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${token}" | awk '/HTTP/{print $(NF-1)}')
local RESULT=$(curl --request DELETE "https://api.cloudflareclient.com/v0a2158/reg/${ID}" \
--head \
--silent \
--location \
--header 'User-Agent: okhttp/3.12.1' \
--header 'CF-Client-Version: a-6.10-2158' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer ${TOKEN}" | awk '/HTTP/{print $(NF-1)}')
grep -qw '204' <<< "$result" && echo " Success. The account has been cancelled. " || echo " Failure. The account is not available. "
grep -qw '204' <<<"$RESULT" && echo " Success. The account has been cancelled. " || echo " Failure. The account is not available. "
}
# reserved 解码
decode_reserved() {
[[ -z "$id" && -z "$token" ]] && fetch_account_information
[ -z "$client_id" ] && { fetch_client_id=$(device_information); client_id=$(expr " $fetch_client_id" | awk -F'"' '/client_id/{print $4}'); }
reserved=$(echo "$client_id" | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}')
echo -e "client id: $client_id\nreserved : $reserved"
[[ -z "$ID" && -z "$TOKEN" ]] && fetch_account_information
[ -z "$CLIENT_ID" ] && {
fetch_client_id=$(device_information)
CLIENT_ID=$(expr " $fetch_client_id" | awk -F'"' '/client_id/{print $4}')
}
RESERVED=$(echo "$CLIENT_ID" | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}')
echo -e "client id: $CLIENT_ID\nreserved : $RESERVED"
}
[[ "$#" -eq '0' ]] && help && exit;
[[ "$#" -eq '0' ]] && help && exit
while [[ $# -ge 1 ]]; do
case $1 in
-f|--file)
shift
register_path="$1"
shift
;;
-r|--register)
run=register_account
shift
;;
-d|--device)
run=device_information
shift
;;
-a|--app)
run=app_information
shift
;;
-b|--bind)
run=account_binding_devices
shift
;;
-n|--name)
shift
device_name="$1"
run=change_device_name
shift
;;
-l|--license)
shift
license="$1"
run=change_license
shift
;;
-u|--unbind)
run=unbind_devide
shift
;;
-c|--cancle)
run=cancle_account
shift
;;
-i|--id)
run=decode_reserved
shift
;;
-t|--token)
case "${1,,}" in
-f | --file)
shift
REGISTER_PATH="$1"
shift
;;
-r | --register)
RUN=register_account
shift
;;
-d | --device)
RUN=device_information
shift
;;
-a | --app)
RUN=app_information
shift
;;
-b | --bind)
RUN=account_binding_devices
shift
;;
-n | --name)
shift
DEVICE_NAME="$1"
RUN=change_device_name
shift
;;
-l | --license)
shift
LICENSE="$1"
RUN=change_license
shift
;;
-u | --unbind)
RUN=unbind_devide
shift
;;
-c | --cancle)
RUN=cancle_account
shift
;;
-i | --id)
RUN=decode_reserved
shift
;;
-t | --token)
shift
team_token="$1"
shift
;;
-h|--help)
help
exit
;;
*)
help
exit
;;
-h | --help)
help
exit
;;
*)
help
exit
;;
esac
done
# 根据参数运行
$run
$RUN
+5 -5
View File
@@ -620,7 +620,7 @@ warp_api(){
curl -m5 -sL "https://${WARP_API_URL}/?run=token&organization=${TEAM_ORGANIZATION}&A=${A}&S=${S}&N=${N}&code=${TEAM_CODE}"
;;
pluskey )
curl -m30 -sL "https://${WARP_API_URL}/?run=pluskey"
curl -m20 --retry 3 -sL "https://${WARP_API_URL}/?run=pluskey"
;;
esac
}
@@ -631,7 +631,7 @@ generate_pluskey() {
[ -n "$FILE_PATH" ] && warp_api pluskey | awk -F '"' '/licenseCode/{print $4}' > $FILE_PATH || warp_api pluskey | awk -F '"' '/licenseCode/{print $4}'
}
# 聚合 IP api 函数
# 聚合 IP api 函数。由于 ip.sb 会对某些 ip 访问报 error code: 1015,所以使用备用 IP api: ifconfig.co
ip_info() {
local CHECK_46="$1"
if [[ "$2" =~ ^[0-9]+$ ]]; then
@@ -646,7 +646,7 @@ ip_info() {
IP_TRACE=$(curl --retry 2 -ksm5 $INTERFACE_SOCK5 https://www.cloudflare.com/cdn-cgi/trace | awk -F '=' '/^warp=/{print $NF}')
if [ -n "$IP_TRACE" ]; then
[ "$IS_UNINSTALL" = 'is_uninstall' ] && local API_IP=$(curl -$CHECK_46 --retry 2 -ksm5 --user-agent Mozilla https://api.ip.sb/ip) || local API_IP=$(curl --retry 2 -ksm5 $INTERFACE_SOCK5 --user-agent Mozilla $CHOOSE_IP_API | sed 's/.*"ip":"\([^"]\+\)".*/\1/')
[ -n "$API_IP" ] && local IP_JSON=$(curl --retry 2 -ksm5 https://ip.forvps.gq/${API_IP}${IS_CHINESE})
[[ -n "$API_IP" && ! "$API_IP" =~ error[[:space:]]+code:[[:space:]]+1015 ]] && local IP_JSON=$(curl --retry 2 -ksm5 https://ip.forvps.gq/${API_IP}${IS_CHINESE}) || unset IP_JSON
IP_JSON=${IP_JSON:-"$(curl --retry 3 -ks${CHECK_46}m5 $INTERFACE_SOCK5 --user-agent Mozilla https://ifconfig.co/json)"}
if [ -n "$IP_JSON" ]; then
@@ -1772,14 +1772,14 @@ input_url_token() {
# 升级 WARP+ 账户(如有),限制位数为空或者26位以防输入错误,WARP interface 可以自定义设备名(不允许字符串间有空格,如遇到将会以_代替)
update_license() {
[ -z "$LICENSE" ] && reading " $(text 61) " LICENSE
hint " $(text 100) "
hint " $(text 100) "
wait
[ -z "$LICENSE" ] && [ -s /tmp/license-tmp ] && LICENSE=$(cat /tmp/license-tmp) && rm -f /tmp/license-tmp
i=5
until [[ "$LICENSE" =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do
(( i-- )) || true
[ "$i" = 0 ] && error " $(text 29) " || reading " $(text 30) " LICENSE
hint " $(text 100) "
hint " $(text 100) "
wait
[ -z "$LICENSE" ] && [ -s /tmp/license-tmp ] && LICENSE=$(cat /tmp/license-tmp) && rm -f /tmp/license-tmp
done
+44 -42
View File
@@ -495,7 +495,7 @@ warp_api(){
curl -m5 -sL "https://${WARP_API_URL}/?run=token&organization=${TEAM_ORGANIZATION}&A=${A}&S=${S}&N=${N}&code=${TEAM_CODE}"
;;
pluskey )
curl -m30 -sL "https://${WARP_API_URL}/?run=pluskey"
curl -m20 --retry 3 -sL "https://${WARP_API_URL}/?run=pluskey"
;;
esac
}
@@ -513,7 +513,7 @@ check_install() {
wget --no-check-certificate -T5 -qO- /tmp/warp-go.tar.gz https://gitlab.com/fscarmen/warp/-/raw/main/warp-go/warp-go_"$latest"_linux_"$ARCHITECTURE".tar.gz | tar xz -C /tmp/ warp-go
chmod +x /tmp/warp-go
}&
# 后台优选最佳 MTU
{
# 反复测试最佳 MTU。 Wireguard Header:IPv4=60 bytes,IPv6=80 bytes1280 ≤ MTU ≤ 1420。 ping = 8(ICMP回显示请求和回显应答报文格式长度) + 20(IP首部) 。
@@ -524,7 +524,7 @@ check_install() {
MTU=$((MTU-10))
[ "$IPV4$IPV6" = 01 ] && $PING6 -c1 -W1 -s $MTU -Mdo 2606:4700:d0::a29f:c001 >/dev/null 2>&1 || ping -c1 -W1 -s $MTU -Mdo 162.159.193.10 >/dev/null 2>&1
done
if [ "$MTU" -eq $((1500-28)) ]; then
MTU=$MTU
elif [ "$MTU" -le $((1280+80-28)) ]; then
@@ -536,9 +536,9 @@ check_install() {
done
(( MTU-- ))
fi
MTU=$((MTU+28-80))
echo "$MTU" > /tmp/warp-go-mtu
}&
@@ -546,33 +546,34 @@ check_install() {
{
wget $STACK -qO /tmp/endpoint https://gitlab.com/fscarmen/warp/-/raw/main/endpoint/warp-linux-${ARCHITECTURE//amd64*/amd64} && chmod +x /tmp/endpoint
[ "$IPV4$IPV6" = 01 ] && wget $STACK -qO /tmp/ip https://gitlab.com/fscarmen/warp/-/raw/main/endpoint/ipv6 || wget $STACK -qO /tmp/ip https://gitlab.com/fscarmen/warp/-/raw/main/endpoint/ipv4
if [[ -s /tmp/endpoint && -s /tmp/ip ]]; then
/tmp/endpoint -file /tmp/ip -output /tmp/endpoint_result >/dev/null 2>&1
# 如果全部是数据包丢失,LOSS = 100%,说明 UDP 被禁止,生成标志 /tmp/noudp
[ "$(grep -sE '[0-9]+[ ]+ms$' /tmp/endpoint_result | awk -F, 'NR==1 {print $2}')" = '100.00%' ] && touch /tmp/noudp || ENDPOINT=$(grep -sE '[0-9]+[ ]+ms$' /tmp/endpoint_result | awk -F, 'NR==1 {print $1}')
rm -f /tmp/{endpoint,ip,endpoint_result}
fi
# 如果失败,会有默认值 162.159.193.10:2408 或 [2606:4700:d0::a29f:c001]:2408
[ "$IPV4$IPV6" = 01 ] && ENDPOINT=${ENDPOINT:-'[2606:4700:d0::a29f:c001]:2408'} || ENDPOINT=${ENDPOINT:-'162.159.193.10:2408'}
echo "$ENDPOINT" > /tmp/warp-go-endpoint
}&
fi
}
# 检测 IPv4 IPv6 信息,WARP Ineterface 开启,普通还是 Plus账户 和 IP 信息
# 检测 IPv4 IPv6 信息,WARP Ineterface 开启,普通还是 Plus账户 和 IP 信息。由于 ip.sb 会对某些 ip 访问报 error code: 1015,所以使用备用 IP api: ifconfig.co
ip4_info() {
unset IP4_JSON COUNTRY4 ASNORG4 TRACE4 IS_UNINSTALL
IS_UNINSTALL="$1"
[ "$L" = 'C' ] && IS_CHINESE=${IS_CHINESE:-'?lang=zh-CN'}
TRACE4=$(curl --retry 2 -ks4m5 https://www.cloudflare.com/cdn-cgi/trace $INTERFACE4 | awk -F '=' '/^warp=/{print $NF}')
TRACE4=$(curl --retry 2 -ks4m5 https://www.cloudflare.com/cdn-cgi/trace $INTERFACE_4 | awk -F '=' '/^warp=/{print $NF}')
if [ -n "$TRACE4" ]; then
[ "$IS_UNINSTALL" = 'is_uninstall' ] && WAN4=$(curl -4 --retry 2 -ksm5 --user-agent Mozilla https://api.ip.sb/ip) || WAN4=$(curl --retry 2 -ks4m5 -A Mozilla https://api-ipv4.ip.sb/geoip $INTERFACE4 | sed 's/.*"ip":"\([^"]\+\)".*/\1/')
[ -n "$WAN4" ] && IP4_JSON=$(curl --retry 2 -ksm5 --user-agent Mozilla https://ip.forvps.gq/${WAN4}${IS_CHINESE})
IP4_JSON=${IP4_JSON:-"$(curl --retry 2 -ks4m3 --user-agent Mozilla https://ifconfig.co/json $INTERFACE4)"}
[ "$IS_UNINSTALL" = 'is_uninstall' ] && WAN4=$(curl -4 --retry 2 -ksm5 --user-agent Mozilla https://api.ip.sb/ip) || WAN4=$(curl --retry 2 -ks4m5 -A Mozilla https://api-ipv4.ip.sb/geoip $INTERFACE_4 | sed 's/.*"ip":"\([^"]\+\)".*/\1/')
[[ -n "$WAN4" && ! "$WAN4" =~ error[[:space:]]+code:[[:space:]]+1015 ]] && IP4_JSON=$(curl --retry 2 -ksm5 --user-agent Mozilla https://ip.forvps.gq/${WAN4}${IS_CHINESE}) || unset WAN4
IP4_JSON=${IP4_JSON:-"$(curl --retry 2 -ks4m3 --user-agent Mozilla https://ifconfig.co/json $INTERFACE_4)"}
if [ -n "$IP4_JSON" ]; then
WAN4=${WAN4:-"$(sed -En 's/.*"ip":[ ]*"([^"]+)".*/\1/p' <<< "$IP4_JSON")"}
COUNTRY4=$(sed -En 's/.*"country":[ ]*"([^"]+)".*/\1/p' <<< "$IP4_JSON")
ASNORG4=$(sed -En 's/.*"(isp|asn_org)":[ ]*"([^"]+)".*/\2/p' <<< "$IP4_JSON")
fi
@@ -583,12 +584,13 @@ ip6_info() {
unset IP6_JSON COUNTRY6 ASNORG6 TRACE6 IS_UNINSTALL
IS_UNINSTALL="$1"
[ "$L" = 'C' ] && IS_CHINESE=${IS_CHINESE:-'?lang=zh-CN'}
TRACE6=$(curl --retry 5 -ks6m5 https://www.cloudflare.com/cdn-cgi/trace $INTERFACE6 | awk -F '=' '/^warp=/{print $NF}')
TRACE6=$(curl --retry 5 -ks6m5 https://www.cloudflare.com/cdn-cgi/trace $INTERFACE_6 | awk -F '=' '/^warp=/{print $NF}')
if [ -n "$TRACE6" ]; then
[ "$IS_UNINSTALL" = 'is_uninstall' ] && WAN6=$(curl -6 --retry 2 -ksm5 --user-agent Mozilla https://api.ip.sb/ip) || WAN6=$(curl --retry 5 -ks6m5 -A Mozilla https://api-ipv6.ip.sb/geoip $INTERFACE6 | sed 's/.*"ip":"\([^"]\+\)".*/\1/')
[ -n "$WAN6" ] && IP6_JSON=$(curl --retry 2 -ksm5 --user-agent Mozilla https://ip.forvps.gq/${WAN6}${IS_CHINESE})
IP6_JSON=${IP6_JSON:-"$(curl --retry 2 -ks6m3 --user-agent Mozilla https://ifconfig.co/json $INTERFACE6)"}
[ "$IS_UNINSTALL" = 'is_uninstall' ] && WAN6=$(curl -6 --retry 2 -ksm5 --user-agent Mozilla https://api.ip.sb/ip) || WAN6=$(curl --retry 5 -ks6m5 -A Mozilla https://api-ipv6.ip.sb/geoip $INTERFACE_6 | sed 's/.*"ip":"\([^"]\+\)".*/\1/')
[[ -n "$WAN6" && ! "$WAN6" =~ error[[:space:]]+code:[[:space:]]+1015 ]] && IP6_JSON=$(curl --retry 2 -ksm5 --user-agent Mozilla https://ip.forvps.gq/${WAN6}${IS_CHINESE}) || unset WAN6
IP6_JSON=${IP6_JSON:-"$(curl --retry 2 -ks6m3 --user-agent Mozilla https://ifconfig.co/json $INTERFACE_6)"}
if [ -n "$IP6_JSON" ]; then
WAN6=${WAN6:-"$(sed -En 's/.*"ip":[ ]*"([^"]+)".*/\1/p' <<< "$IP6_JSON")"}
COUNTRY6=$(sed -En 's/.*"country":[ ]*"([^"]+)".*/\1/p' <<< "$IP6_JSON")
ASNORG6=$(sed -En 's/.*"(isp|asn_org)":[ ]*"([^"]+)".*/\2/p' <<< "$IP6_JSON")
fi
@@ -755,7 +757,7 @@ change_ip() {
# 关闭 WARP 网络接口,并删除 warp-go
uninstall() {
unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6 INTERFACE4 INTERFACE6
unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6 INTERFACE_4 INTERFACE_6
# 如已安装 warp_unlock 项目,先行卸载
[ -s /usr/bin/warp_unlock.sh ] && bash <(curl -sSL https://gitlab.com/fscarmen/warp_unlock/-/raw/main/unlock.sh) -U -$L
@@ -790,8 +792,8 @@ ver() {
net() {
unset IP4 IP6 WAN4 WAN6 COUNTRY4 COUNTRY6 ASNORG4 ASNORG6
i=1; j=5
grep -qE "^AllowedIPs[ ]+=.*0\.\0\/0|#AllowedIPs" 2>/dev/null /opt/warp-go/warp.conf && INTERFACE4='--interface WARP'
grep -qE "^AllowedIPs[ ]+=.*\:\:\/0|#AllowedIPs" 2>/dev/null /opt/warp-go/warp.conf && INTERFACE6='--interface WARP'
grep -qE "^AllowedIPs[ ]+=.*0\.\0\/0|#AllowedIPs" 2>/dev/null /opt/warp-go/warp.conf && INTERFACE_4='--interface WARP'
grep -qE "^AllowedIPs[ ]+=.*\:\:\/0|#AllowedIPs" 2>/dev/null /opt/warp-go/warp.conf && INTERFACE_6='--interface WARP'
hint " $(text_eval 20)\n $(text_eval 59) "
[ "$KEEP_FREE" != 1 ] && ${SYSTEMCTL_RESTART[int]}
grep -q "#AllowedIPs" /opt/warp-go/warp.conf && sleep 8 || sleep 1
@@ -949,7 +951,7 @@ check_stack() {
CONF1=("014" "104" "114" "11N4")
CONF2=("016" "106" "116" "11N6")
CONF3=("01D" "10D" "11D" "11ND")
elif [ "$m" = 8 ]; then
elif [ "$m" = 9 ]; then
error "\n $(text 108) \n"
fi
}
@@ -987,7 +989,7 @@ stack_switch() {
elif [[ "$SWITCHCHOOSE" = [46D] ]]; then
if [[ "$TO_GLOBAL" = [Yy] ]]; then
if [[ "$T4@$T6@$SWITCHCHOOSE" =~ '1@0@4'|'0@1@6'|'1@1@D' ]]; then
grep -q "^AllowedIPs.*0\.\0\/0" 2>/dev/null /opt/warp-go/warp.conf || unset INTERFACE4 INTERFACE6
grep -q "^AllowedIPs.*0\.\0\/0" 2>/dev/null /opt/warp-go/warp.conf || unset INTERFACE_4 INTERFACE_6
OPTION=o && net
exit 0
else
@@ -1017,13 +1019,13 @@ stack_switch() {
[ "${#TO}" != 3 ] && error " $(text 10) " || sed -i "$(eval echo "\$SWITCH$TO")" /opt/warp-go/warp.conf
case "$TO" in
014|114 )
INTERFACE4='--interface WARP'; unset INTERFACE6
INTERFACE_4='--interface WARP'; unset INTERFACE_6
;;
106|116 )
INTERFACE6='--interface WARP'; unset INTERFACE4
INTERFACE_6='--interface WARP'; unset INTERFACE_4
;;
01D|10D )
INTERFACE4='--interface WARP'; INTERFACE6='--interface WARP'
INTERFACE_4='--interface WARP'; INTERFACE_6='--interface WARP'
esac
OPTION=o && net
@@ -1080,25 +1082,25 @@ EOF
fi
fi
# 判断机器原生状态类型
IPV4=0; IPV6=0
LAN4=$(ip route get 192.168.193.10 2>/dev/null | awk '{for (i=0; i<NF; i++) if ($i=="src") {print $(i+1)}}')
LAN6=$(ip route get 2606:4700:d0::a29f:c001 2>/dev/null | awk '{for (i=0; i<NF; i++) if ($i=="src") {print $(i+1)}}')
[[ "$LAN4" =~ ^([0-9]{1,3}\.){3} ]] && INET4=1
[[ "$LAN6" != "::1" && "$LAN6" =~ ^[a-f0-9:]+$ ]] && INET6=1
[ "$INET6" = 1 ] && $PING6 -c2 -w10 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && STACK=-6
[ "$INET4" = 1 ] && ping -c2 -W3 162.159.193.10 >/dev/null 2>&1 && IPV4=1 && STACK=-4
if [ "$STATUS" != 0 ]; then
if grep -qE "^AllowedIPs.*\.0/0,::/0|^#AllowedIPs" 2>/dev/null /opt/warp-go/warp.conf; then
INTERFACE4='--interface WARP'; INTERFACE6='--interface WARP'
INTERFACE_4='--interface WARP'; INTERFACE_6='--interface WARP'; local IP_INTERFACE_4='dev WARP'; local IP_INTERFACE_6='dev WARP'; local PING_INTERFACE_4='-I WARP'; local PING_INTERFACE_6='-I WARP'
elif grep -q '^AllowedIPs.*\.0/0$' 2>/dev/null /opt/warp-go/warp.conf; then
INTERFACE4='--interface WARP'; unset INTERFACE6
INTERFACE_4='--interface WARP'; unset INTERFACE_6; local IP_INTERFACE_4='dev WARP'; unset IP_INTERFACE_6; local PING_INTERFACE_4='-I WARP'; unset PING_INTERFACE_6
elif grep -q '^AllowedIPs.*::/0$' 2>/dev/null /opt/warp-go/warp.conf; then
INTERFACE6='--interface WARP'; unset INTERFACE4
INTERFACE_6='--interface WARP'; unset INTERFACE_4; unset IP_INTERFACE_4; local IP_INTERFACE_6='dev WARP'; unset PING_INTERFACE_4; local PING_INTERFACE_6='-I WARP'
fi
fi
# 判断机器原生状态类型
IPV4=0; IPV6=0
LAN4=$(ip route get 192.168.193.10 $IP_INTERFACE_4 2>/dev/null | awk '{for (i=0; i<NF; i++) if ($i=="src") {print $(i+1)}}')
LAN6=$(ip route get 2606:4700:d0::a29f:c001 $IP_INTERFACE_6 2>/dev/null | awk '{for (i=0; i<NF; i++) if ($i=="src") {print $(i+1)}}')
[[ "$LAN4" =~ ^([0-9]{1,3}\.){3} ]] && local INET4=1
[[ "$LAN6" != "::1" && "$LAN6" =~ ^[a-f0-9:]+$ ]] && local INET6=1
[ "$INET6" = 1 ] && $PING6 -c2 -w10 2606:4700:d0::a29f:c001 $PING_INTERFACE_4 >/dev/null 2>&1 && IPV6=1 && STACK=-6
[ "$INET4" = 1 ] && ping -c2 -W3 162.159.193.10 $PING_INTERFACE_6 >/dev/null 2>&1 && IPV4=1 && STACK=-4
[ "$IPV4" = 1 ] && ip4_info
[ "$IPV6" = 1 ] && ip6_info
}
@@ -1153,7 +1155,7 @@ best_endpoint() {
input_license() {
[ -z "$LICENSE" ] && reading " $(text 38) " LICENSE
if [ -z "$LICENSE" ]; then
hint " $(text 43) "
hint " $(text 43) "
wait
[ -s /tmp/warp-go-license ] && LICENSE=$(cat /tmp/warp-go-license) && rm -f /tmp/warp-go-license
fi
@@ -1162,7 +1164,7 @@ input_license() {
(( i-- )) || true
[ "$i" = 0 ] && error "$(text 39)" || reading " $(text_eval 40) " LICENSE
if [ -z "$LICENSE" ]; then
hint " $(text 43) "
hint " $(text 43) "
wait
[ -s /tmp/warp-go-license ] && LICENSE=$(cat /tmp/warp-go-license) && rm -f /tmp/warp-go-license
fi
@@ -1174,14 +1176,14 @@ input_license() {
# 升级 WARP+ 账户(如有),限制位数为空或者26位以防输入错误,WARP interface 可以自定义设备名(不允许字符串间有空格,如遇到将会以_代替)
update_license() {
[ -z "$LICENSE" ] && reading " $(text 42) " LICENSE
hint " $(text 43) "
hint " $(text 43) "
wait
[ -z "$LICENSE" ] && [ -s /tmp/warp-go-license ] && LICENSE=$(cat /tmp/warp-go-license) && rm -f /tmp/warp-go-license
i=5
until [[ "$LICENSE" =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do
(( i-- )) || true
[ "$i" = 0 ] && error "$(text 39)" || reading " $(text_eval 40) " LICENSE
hint " $(text 43) "
hint " $(text 43) "
wait
[ -z "$LICENSE" ] && [ -s /tmp/warp-go-license ] && LICENSE=$(cat /tmp/warp-go-license) && rm -f /tmp/warp-go-license
done
@@ -1210,7 +1212,7 @@ get_token() {
unset TEAM_CODE TOKEN
(( ERROR_TIMES++ ))
if [[ "$ERROR_TIMES" > 5 ]]; then
error "\n $(text 39) \n"
error "\n $(text 39) \n"
else
[ "$ERROR_TIMES" = 1 ] && reading " $(text 110) " TEAM_CODE || reading " $(text 112) " TEAM_CODE
[[ "$TEAM_CODE" =~ ^[0-9]{6}$ ]] && local TEAM_TOKEN=$(warp_api "token-step2" "" "" "" "" "" "" "$TEAM_AUTH" "" "" "$TEAM_CODE")