mirror of
https://gitlab.com/fscarmen/warp.git
synced 2026-06-15 03:25:42 +08:00
v3.0.10 Warp api: https://warp.cloudflare.now.cc/
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
- [WARP好处](README.md#WARP好处)
|
||||
- [warp 运行脚本](README.md#warp-运行脚本)
|
||||
- [warp-go 运行脚本](README.md#warp-go-运行脚本)
|
||||
- [Cloudflare api 运行脚本](README.md#cloudflare-api-运行脚本)
|
||||
- [Cloudflare api](README.md#cloudflare-api)
|
||||
- [通过 warp 解锁 chatGPT 的方法](README.md#通过-warp-解锁-chatgpt-的方法)
|
||||
- [刷 Netflix 解锁 WARP IP 的方法](README.md#刷-Netflix-解锁-WARP-IP-的方法)
|
||||
- [指定网站分流到 "socks5" 的 xray 配置模板 (适用于 WARP Client Proxy 和 WireProxy)](README.md#指定网站分流到-socks5-的-xray-配置模板-适用于-warp-client-proxy-和-wireproxy)
|
||||
@@ -23,20 +23,22 @@
|
||||
* * *
|
||||
|
||||
## 更新信息
|
||||
2024.7.8 menu.sh v3.0.10 / warp-go.sh v1.1.9 1. Publish warp api, you can register account, join Zero Trust, check account information and all other operations. Detailed instructions: https://warp.cloudflare.now.cc/ ; 2. Scripts to update the warp api; 1. 发布 warp api,可以注册账户,加入 Zero Trust,查账户信息等所有的操作。详细使用说明: https://warp.cloudflare.now.cc/; 2. 脚本更新 warp api
|
||||
|
||||
2024.6.30 menu.sh v3.0.9 1. By multithreading, parallel processing of optimal MTU, optimal endpoint, downloading wireguard-go and installing dependencies, the script runtime is reduced by more than half; 2. Reverse proxy http://ip-api.com/json and https://hits.seeyoufarm.com with cloudflare worker for better dual-stack support and faster fetching; 3. DNS Priority: Cloudflare 1.1.1.1 > Google 8.8.8.8; 1. 通过多线程,并行处理最优 MTU,最优 endpoint,下载 wireguard-go 和安装依赖, 脚本运行时间缩短一半以上; 2. 用 Cloudflare worker 反向代理 http://ip-api.com/json 和 https://hits.seeyoufarm.com,以更好支持双栈及提升获取速度; 3. DNS 优先级: Cloudflare 1.1.1.1 > Google 8.8.8.8
|
||||
|
||||
2024.6.28 menu.sh v3.0.8 The official WARP Linux Client supports arm64 systems and is available in both socks5 proxy and Warp interface modes; 官方 WARP Linux Client 支持 arm64 系统, Socks5 proxy 模式 和 Warp interface 模式均可用
|
||||
|
||||
2024.6.2 menu.sh v3.0.7 Support CentOS 9 / Alma Linux 9 / Rocky Linux 9 system; 支持 CentOS 9 / Alma Linux 9 / Rocky Linux 9 系统
|
||||
|
||||
2024.5.5 menu.sh v3.0.6 / warp-go.sh v1.1.8 Support Alpine edge system; 支持 Alpine edge 系统
|
||||
|
||||
2024.5.1 menu.sh v3.0.5 Deal with apt library changes for Debian 10 installations of wireguard-tools; 处理 Debian 10 安装 wireguard-tools 的 apt 库变更的问题
|
||||
|
||||
<details>
|
||||
<summary>历史更新 history(点击即可展开或收起)</summary>
|
||||
<br>
|
||||
|
||||
>2024.6.28 menu.sh v3.0.8 The official WARP Linux Client supports arm64 systems and is available in both socks5 proxy and Warp interface modes; 官方 WARP Linux Client 支持 arm64 系统, Socks5 proxy 模式 和 Warp interface 模式均可用
|
||||
>
|
||||
>2024.6.2 menu.sh v3.0.7 Support CentOS 9 / Alma Linux 9 / Rocky Linux 9 system; 支持 CentOS 9 / Alma Linux 9 / Rocky Linux 9 系统
|
||||
>
|
||||
>2024.5.5 menu.sh v3.0.6 / warp-go.sh v1.1.8 Support Alpine edge system; 支持 Alpine edge 系统
|
||||
>
|
||||
>2024.5.1 menu.sh v3.0.5 Deal with apt library changes for Debian 10 installations of wireguard-tools; 处理 Debian 10 安装 wireguard-tools 的 apt 库变更的问题
|
||||
>
|
||||
>2024.4.14 menu.sh v3.0.4 1. Alpine check and update the wget version; 2. Add a message for feedback when connect warp fails; 1. Alpine 检测并更新 wget 版本的; 2. 获取 IP 失败时增加提示信息以便反馈
|
||||
>
|
||||
>2024.3.21 menu.sh v3.0.3 / warp-go.sh 1.1.7 1. Update some commands according to warp-cli; 2. Remove the github cdn; 1. 根据 warp-cli 官方更新部分命令; 2. 去掉 Github cdn
|
||||
@@ -563,7 +565,25 @@ warp-go [option] [lisence]
|
||||
| 其他或空值| 菜单界面 |
|
||||
|
||||
|
||||
## Cloudflare api 运行脚本
|
||||
## Cloudflare api
|
||||
|
||||
### Warp 使用指南,使用 `curl` 命令可以执行 Warp API 请求。
|
||||
|
||||
| run 参数 | 作用描述 | 参数 | 示例 |
|
||||
|---|---|---|---|
|
||||
| | 使用指南 | | `https://warp.cloudflare.now.cc/` |
|
||||
| `register` | 注册新设备 | `team_token(可选)`, `format(可选)` | `https://warp.cloudflare.now.cc/?run=register&team_token=<Your-Team-Token>&format=<json\|yaml\|wireguard>` |
|
||||
| `device` | 获取特定设备的详细信息 | `device_id`, `token` | `https://warp.cloudflare.now.cc/?run=device&device_id=<Your-Device-ID>&token=<Your-Token>` |
|
||||
| `app` | 获取客户端配置 | `token` | `https://warp.cloudflare.now.cc/?run=app&token=<Your-Token>` |
|
||||
| `bind` | 将设备绑定到帐户 | `device_id`, `token` | `https://warp.cloudflare.now.cc/?run=bind&device_id=<Your-Device-ID>&token=<Your-Token>` |
|
||||
| `name` | 设置设备名称 | `device_id`, `token`, `device_name` | `https://warp.cloudflare.now.cc/?run=name&device_id=<Your-Device-ID>&token=<Your-Token>&device_name=<Your-Device-Name>` |
|
||||
| `license` | 设置设备许可证 | `device_id`, `token`, `license` | `https://warp.cloudflare.now.cc/?run=license&device_id=<Your-Device-ID>&token=<Your-Token>&license=<Your-License>` |
|
||||
| `unbind` | 从帐户中取消绑定设备 | `device_id`, `token` | `https://warp.cloudflare.now.cc/?run=unbind&device_id=<Your-Device-ID>&token=<Your-Token>` |
|
||||
| `cancel` | 取消设备注册 | `device_id`, `token` | `https://warp.cloudflare.now.cc/?run=cancel&device_id=<Your-Device-ID>&token=<Your-Token>` |
|
||||
| `id` | Client ID 与 Reserved 转换 | `convert` | `https://warp.cloudflare.now.cc/?run=id&convert=<4-char-string\|Numbers1,Numbers2,Numbers3>` |
|
||||
| `sum` | 获取总计和 24 小时运行计数 | | `https://warp.cloudflare.now.cc/?run=sum` |
|
||||
|
||||
### 运行脚本
|
||||
```
|
||||
wget -N https://gitlab.com/fscarmen/warp/-/raw/main/api.sh && bash api.sh [option]
|
||||
```
|
||||
@@ -664,6 +684,7 @@ https://github.com/acacia233/Project-WARP-Unlock
|
||||
* 所有的热心网友们
|
||||
|
||||
服务提供(排名不分先后):
|
||||
* fscarmen 的 Warp Api: https://warp.cloudflare.now.cc/
|
||||
* CloudFlare Warp(+): https://1.1.1.1/
|
||||
* WGCF 项目原作者: https://github.com/ViRb3/wgcf/
|
||||
* Coia 和 warp-go 团队: https://gitlab.com/ProjectWARP/warp-go
|
||||
@@ -675,10 +696,8 @@ https://github.com/acacia233/Project-WARP-Unlock
|
||||
* luoxue-bot 的成熟作品:https://github.com/luoxue-bot/warp_auto_change_ip
|
||||
* lmc999 的成熟作品: https://github.com/lmc999/RegionRestrictionCheck
|
||||
* WireProxy 作者: https://github.com/pufferffish/wireproxy
|
||||
* 获取公网 IP 及归属地查询: https://ifconfig.co/
|
||||
https://ip.gs/
|
||||
https://ip.sb/
|
||||
* 统计PV网:https://hits.seeyoufarm.com/
|
||||
* 获取公网 IP 及归属地查询: https://ifconfig.co/ , https://ip.gs/ , https://ip.sb/ , https://ip-api.com
|
||||
* 统计PV网: https://hits.seeyoufarm.com/
|
||||
* Coia 的网页版提出 Teams Token: https://web--public--warp-team-api--coia-mfs4.code.run
|
||||
|
||||
CloudFlare WARP 全球站点和服务状态:
|
||||
|
||||
@@ -66,7 +66,7 @@ register_account() {
|
||||
private_key=$(wg genkey)
|
||||
public_key=$(wg pubkey <<< "$private_key")
|
||||
else
|
||||
wg_api=$(curl -sSL https://fscarmen.cloudflare.now.cc/wg)
|
||||
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
|
||||
@@ -91,7 +91,10 @@ register_account() {
|
||||
--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
|
||||
|
||||
account=$(python3 -m json.tool <<< "$account" 2>&1 | sed "/\"account_type\"/i\ \"private_key\": \"$private_key\",")
|
||||
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
|
||||
fi
|
||||
[[ ! -s $register_path || $(grep 'error' $register_path) ]] && { rm -f $register_path; exit 1; } || { cat $register_path; exit 0; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 当前脚本版本号
|
||||
VERSION='3.0.9'
|
||||
VERSION='3.0.10'
|
||||
|
||||
# 环境变量用于在Debian或Ubuntu操作系统中设置非交互式(noninteractive)安装模式
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
@@ -13,8 +13,8 @@ trap "rm -f /tmp/{wireguard-go-*,best_mtu,best_endpoint,endpoint,ip}; exit" INT
|
||||
|
||||
E[0]="\n Language:\n 1. English (default) \n 2. 简体中文"
|
||||
C[0]="${E[0]}"
|
||||
E[1]="1. By multithreading, parallel processing of optimal MTU, optimal endpoint, downloading wireguard-go and installing dependencies, the script runtime is reduced by more than half; 2. Reverse proxy http://ip-api.com/json and https://hits.seeyoufarm.com with cloudflare worker for better dual-stack support and faster fetching; 3. DNS Priority: Cloudflare 1.1.1.1 > Google 8.8.8.8"
|
||||
C[1]="1. 通过多线程,并行处理最优 MTU,最优 endpoint,下载 wireguard-go 和安装依赖, 脚本运行时间缩短一半以上; 2. 用 Cloudflare worker 反向代理 http://ip-api.com/json 和 https://hits.seeyoufarm.com,以更好支持双栈及提升获取速度; 3. DNS 优先级: Cloudflare 1.1.1.1 > Google 8.8.8.8"
|
||||
E[1]="Publish warp api, you can register account, join Zero Trust, check account information and all other operations. Detailed instructions: https://warp.cloudflare.now.cc/; 2. Scripts to update the warp api."
|
||||
C[1]="发布 warp api,可以注册账户,加入 Zero Trust,查账户信息等所有的操作。详细使用说明: https://warp.cloudflare.now.cc/; 2. 脚本更新 warp api"
|
||||
E[2]="The script must be run as root, you can enter sudo -i and then download and run again. Feedback: [https://github.com/fscarmen/warp-sh/issues]"
|
||||
C[2]="必须以root方式运行脚本,可以输入 sudo -i 后重新下载运行,问题反馈:[https://github.com/fscarmen/warp-sh/issues]"
|
||||
E[3]="The TUN module is not loaded. You should turn it on in the control panel. Ask the supplier for more help. Feedback: [https://github.com/fscarmen/warp-sh/issues]"
|
||||
@@ -499,13 +499,12 @@ check_dependencies() {
|
||||
if [ "$SYSTEM" = 'Alpine' ]; then
|
||||
CHECK_WGET=$(wget 2>&1 | head -n 1)
|
||||
grep -qi 'busybox' <<< "$CHECK_WGET" && ${PACKAGE_INSTALL[int]} wget >/dev/null 2>&1
|
||||
DEPS_CHECK=("ping" "curl" "grep" "bash" "xxd" "ip" "python3" "virt-what")
|
||||
DEPS_INSTALL=("iputils-ping" "curl" "grep" "bash" "xxd" "iproute2" "python3" "virt-what")
|
||||
DEPS_CHECK=("ping" "curl" "grep" "bash" "ip" "python3" "virt-what")
|
||||
DEPS_INSTALL=("iputils-ping" "curl" "grep" "bash" "iproute2" "python3" "virt-what")
|
||||
else
|
||||
# 对于 CentOS 系统,xxd 需要依赖 vim-common
|
||||
[ "$SYSTEM" = 'CentOS' ] && ${PACKAGE_INSTALL[int]} vim-common >/dev/null 2>&1
|
||||
DEPS_CHECK=("ping" "xxd" "wget" "curl" "systemctl" "ip" "python3")
|
||||
DEPS_INSTALL=("iputils-ping" "xxd" "wget" "curl" "systemctl" "iproute2" "python3")
|
||||
# 对于三大系统需要的依赖
|
||||
DEPS_CHECK=("ping" "wget" "curl" "systemctl" "ip" "python3")
|
||||
DEPS_INSTALL=("iputils-ping" "wget" "curl" "systemctl" "iproute2" "python3")
|
||||
fi
|
||||
|
||||
for g in "${!DEPS_CHECK[@]}"; do
|
||||
@@ -523,12 +522,79 @@ check_dependencies() {
|
||||
PING6='ping -6' && [ -x "$(type -p ping6)" ] && PING6='ping6'
|
||||
}
|
||||
|
||||
# 只保留Teams账户,删除其他账户
|
||||
cancel_account(){
|
||||
local FILE=$1
|
||||
if [ -s "$FILE" ]; then
|
||||
grep -oqE '"id":[ ]+"t.[A-F0-9a-f]{8}-' $FILE || bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --cancle --file $FILE >/dev/null 2>&1
|
||||
# 获取 warp 账户信息
|
||||
warp_api(){
|
||||
local RUN=$1
|
||||
local FILE_PATH=$2
|
||||
local WARP_LICENSE=$3
|
||||
local WARP_DEVICE_NAME=$4
|
||||
local WARP_TEAM_TOKEN=$5
|
||||
local WARP_CONVERT=$6
|
||||
local WARP_CONVERT_MODE=$7
|
||||
local WARP_API_URL="warp.cloudflare.now.cc"
|
||||
|
||||
if [ -s "$FILE_PATH" ]; then
|
||||
# Teams 账户文件
|
||||
if grep -q 'xml version' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(grep 'correlation_id' $FILE_PATH | sed "s#.*>\(.*\)<.*#\1#")
|
||||
local WARP_TOKEN=$(grep 'warp_token' $FILE_PATH | sed "s#.*>\(.*\)<.*#\1#")
|
||||
local WARP_CLIENT_ID=$(grep 'client_id' $FILE_PATH | sed "s#.*client_id":"\([^&]\{4\}\)&.*#\1#")
|
||||
|
||||
# 官方 api 文件
|
||||
elif grep -q 'client_id' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(grep -m1 '"id' "$FILE_PATH" | cut -d\" -f4)
|
||||
local WARP_TOKEN=$(grep '"token' "$FILE_PATH" | cut -d\" -f4)
|
||||
local WARP_CLIENT_ID=$(grep 'client_id' "$FILE_PATH" | cut -d\" -f4)
|
||||
|
||||
# client 文件,默认存放路径为 /var/lib/cloudflare-warp/reg.json
|
||||
elif grep -q 'registration_id' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(cut -d\" -f4 "$FILE_PATH")
|
||||
local WARP_TOKEN=$(cut -d\" -f8 "$FILE_PATH")
|
||||
|
||||
# wgcf 文件,默认存放路径为 /etc/wireguard/wgcf-account.toml
|
||||
elif grep -q 'access_token' $FILE_PATH; then
|
||||
id=$(grep 'device_id' "$FILE_PATH" | cut -d\' -f2)
|
||||
token=$(grep 'access_token' "$FILE_PATH" | cut -d\' -f2)
|
||||
|
||||
# warp-go 文件,默认存放路径为 /opt/warp-go/warp.conf
|
||||
elif grep -q 'PrivateKey' $FILE_PATH; then
|
||||
id=$(awk -F' *= *' '/^Device/{print $2}' "$FILE_PATH")
|
||||
token=$(awk -F' *= *' '/^Token/{print $2}' "$FILE_PATH")
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$RUN" in
|
||||
register )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=register&team_token=${WARP_TEAM_TOKE}"
|
||||
;;
|
||||
device )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=device&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}"
|
||||
;;
|
||||
name )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=name&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}&device_name=${WARP_DEVICE_NAME}"
|
||||
;;
|
||||
license )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=license&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}&license=${WARP_LICENSE}"
|
||||
;;
|
||||
cancel )
|
||||
# 只保留Teams账户,删除其他账户
|
||||
grep -oqE '"id":[ ]+"t.[A-F0-9a-f]{8}-' $FILE_PATH || curl -m5 -sL "https://${WARP_API_URL}/?run=cancel&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}"
|
||||
;;
|
||||
convert )
|
||||
if [ "$WARP_CONVERT_MODE" = decode ]; then
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT}" | grep -A4 'reserved' | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
elif [ "$WARP_CONVERT_MODE" = encode ]; then
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT//[ \[\]]}" | awk -F '"' '/client_id/{print $(NF-1)}'
|
||||
elif [ "$WARP_CONVERT_MODE" = file ]; then
|
||||
if grep -sq '"reserved"' $FILE_PATH; then
|
||||
grep -A4 'reserved' $FILE_PATH | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
else
|
||||
local WARP_CONVERT=$(awk -F '"' '/"client_id"/{print $(NF-1)}' $FILE_PATH)
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT}" | grep -A4 'reserved' | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 聚合 IP api 函数
|
||||
@@ -830,15 +896,15 @@ change_ip() {
|
||||
warning " $(text 126) "
|
||||
wg-quick down warp >/dev/null 2>&1
|
||||
[ -s /etc/wireguard/info.log ] && grep -q 'Device name' /etc/wireguard/info.log && local LICENSE=$(cat /etc/wireguard/license) && local NAME=$(awk '/Device name/{print $NF}' /etc/wireguard/info.log)
|
||||
cancel_account /etc/wireguard/warp-account.conf
|
||||
bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's#cat $register_path; ##') --register --file /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf" >/dev/null 2>&1
|
||||
warp_api "register" > /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
# 如原来是 plus 账户,以相同的 license 升级,并修改账户和 warp 配置文件
|
||||
if [[ -n "$LICENSE" && -n "$NAME" ]]; then
|
||||
[ -n "$LICENSE" ] && bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --license $LICENSE >/dev/null 2>&1
|
||||
[ -n "$NAME" ] && bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --name $NAME >/dev/null 2>&1
|
||||
[ -n "$LICENSE" ] && warp_api "license" "/etc/wireguard/warp-account.conf" "$LICENSE" >/dev/null 2>&1
|
||||
[ -n "$NAME" ] && warp_api "name" "/etc/wireguard/warp-account.conf" "" "$NAME" >/dev/null 2>&1
|
||||
local PRIVATEKEY="$(grep 'private_key' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local ADDRESS6="$(grep '"v6.*"$' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local CLIENT_ID="$(reserved_and_clientid /etc/wireguard/warp-account.conf file)"
|
||||
local CLIENT_ID="$(warp_api "convert" "/etc/wireguard/warp-account.conf" "" "" "" "" "file")"
|
||||
[ -s /etc/wireguard/warp.conf ] && sed -i "s#\(PrivateKey[ ]\+=[ ]\+\).*#\1$PRIVATEKEY#g; s#\(Address[ ]\+=[ ]\+\).*\(/128$\)#\1$ADDRESS6\2#g; s#\(.*Reserved[ ]\+=[ ]\+\).*#\1$CLIENT_ID#g" /etc/wireguard/warp.conf
|
||||
sed -i "s#\([ ]\+\"license\": \"\).*#\1$LICENSE\"#g; s#\"account_type\".*#\"account_type\": \"limited\",#g; s#\([ ]\+\"name\": \"\).*#\1$NAME\"#g" /etc/wireguard/warp-account.conf
|
||||
fi
|
||||
@@ -1078,7 +1144,7 @@ uninstall() {
|
||||
systemctl disable --now wg-quick@warp >/dev/null 2>&1; sleep 3
|
||||
[ -x "$(type -p rpm)" ] && rpm -e wireguard-tools 2>/dev/null
|
||||
systemctl restart systemd-resolved >/dev/null 2>&1; sleep 3
|
||||
cancel_account /etc/wireguard/warp-account.conf
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf" >/dev/null 2>&1
|
||||
rm -rf /usr/bin/wireguard-go /usr/bin/warp /etc/dnsmasq.d/warp.conf /usr/bin/wireproxy /etc/local.d/warp.start
|
||||
[ -e /etc/gai.conf ] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf
|
||||
[ -e /usr/bin/tun.sh ] && rm -f /usr/bin/tun.sh
|
||||
@@ -1107,7 +1173,7 @@ uninstall() {
|
||||
systemctl disable --now wireproxy
|
||||
fi
|
||||
|
||||
cancel_account /etc/wireguard/warp-account.conf
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf" >/dev/null 2>&1
|
||||
rm -rf /usr/bin/wireguard-go /usr/bin/warp /etc/dnsmasq.d/warp.conf /usr/bin/wireproxy /lib/systemd/system/wireproxy.service
|
||||
[ -e /etc/gai.conf ] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf
|
||||
[ -e /usr/bin/tun.sh ] && rm -f /usr/bin/tun.sh && sed -i '/tun.sh/d' /etc/crontab
|
||||
@@ -1588,12 +1654,12 @@ input_url_token() {
|
||||
[ -n "$ADDRESS6" ] && PRIVATEKEY=$(expr "$TEAMS_CONTENT" : '.*private_key">\([^<]*\).*')
|
||||
[[ -n "$ADDRESS6" && -z "$PRIVATEKEY" ]] && PRIVATEKEY=$(expr "$TEAMS_CONTENT" : '.*private_key">\([^<]\+\).*')
|
||||
RESERVED=$(expr "$TEAMS_CONTENT" : '.*;client_id":"\([^&]\{4\}\)')
|
||||
CLIENT_ID=$(reserved_and_clientid "$RESERVED" decode)
|
||||
CLIENT_ID="$(warp_api "convert" "" "" "" "" "$RESERVED" "decode")"
|
||||
else
|
||||
ADDRESS6=$(expr "$TEAMS_CONTENT" : '.*"v6":[ ]*"\([^["]\+\).*')
|
||||
PRIVATEKEY=$(expr "$TEAMS_CONTENT" : '.*"private_key":[ ]*"\([^"]\+\).*')
|
||||
RESERVED=$(expr "$TEAMS_CONTENT" : '.*"client_id":[ ]*"\([^"]\+\).*')
|
||||
CLIENT_ID=$(reserved_and_clientid "$RESERVED" decode)
|
||||
CLIENT_ID="$(warp_api "convert" "" "" "" "" "$RESERVED" "decode")"
|
||||
fi
|
||||
|
||||
elif [ "$1" = 'token' ]; then
|
||||
@@ -1613,11 +1679,11 @@ input_url_token() {
|
||||
[ -z "$TEAM_TOKEN" ] && return
|
||||
|
||||
unset TEAMS ADDRESS6 PRIVATEKEY CLIENT_ID
|
||||
TEAMS=$(bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's# > $register_path##; /cat $register_path/d') --register --token $TEAM_TOKEN)
|
||||
TEAMS=$(warp_api "register" "" "" "" "$TEAM_TOKEN" 2>&1)
|
||||
ADDRESS6=$(expr "$TEAMS" : '.*"v6":[ ]*"\([^"]*\).*')
|
||||
PRIVATEKEY=$(expr "$TEAMS" : '.*"private_key":[ ]*"\([^"]*\).*')
|
||||
RESERVED=$(expr "$TEAMS" : '.*"client_id":[ ]*"\([^"]*\).*')
|
||||
CLIENT_ID=$(reserved_and_clientid "$RESERVED" decode)
|
||||
CLIENT_ID="$(warp_api "convert" "" "" "" "" "$RESERVED" "decode")"
|
||||
done
|
||||
|
||||
elif [ "$1" = 'input' ]; then
|
||||
@@ -1627,10 +1693,10 @@ input_url_token() {
|
||||
[[ -n "$PRIVATEKEY" && -n "$ADDRESS6" ]] && reading " Reserved or client_id: " RESERVED_OR_CLIENT_ID || return
|
||||
if [[ "$RESERVED_OR_CLIENT_ID" =~ ^[a-zA-Z+/]{4}$ ]]; then
|
||||
RESERVED=$RESERVED_OR_CLIENT_ID
|
||||
CLIENT_ID=$(reserved_and_clientid "$RESERVED" decode)
|
||||
CLIENT_ID="$(warp_api "convert" "" "" "" "" "$RESERVED" "decode")"
|
||||
elif [[ "$RESERVED_OR_CLIENT_ID" =~ ([0-9]{1,3}){3} ]]; then
|
||||
RESERVED=$(reserved_and_clientid "$RESERVED_OR_CLIENT_ID" encode)
|
||||
CLIENT_ID=$(reserved_and_clientid "$RESERVED" decode)
|
||||
RESERVED=$(warp_api "convert" "" "" "" "" "$RESERVED_OR_CLIENT_ID" "encode")
|
||||
CLIENT_ID="$(warp_api "convert" "" "" "" "" "$RESERVED" "decode")"
|
||||
fi
|
||||
|
||||
elif [ "$1" = 'share' ]; then
|
||||
@@ -1746,6 +1812,7 @@ server=/gstatic.com/8.8.8.8
|
||||
# > Custom ChatGPT
|
||||
ipset=/openai.com/warp
|
||||
ipset=/ai.com/warp
|
||||
ipset=/chatgpt.com/warp
|
||||
|
||||
# > IP api
|
||||
ipset=/ip.sb/warp
|
||||
@@ -1881,21 +1948,6 @@ best_endpoint() {
|
||||
[ ! -e /tmp/noudp ] && echo "$ENDPOINT" > /tmp/best_endpoint
|
||||
}
|
||||
|
||||
# Reserved 与 Client id 互换
|
||||
reserved_and_clientid() {
|
||||
if [ "$2" = decode ]; then
|
||||
echo "$1" | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}'
|
||||
elif [ "$2" = encode ]; then
|
||||
BYTE[0]=$(grep -oE '[0-9]+' <<< "$1" | head -n 1)
|
||||
BYTE[1]=$(grep -oE '[0-9]+' <<< "$1" | sed -n '2p')
|
||||
BYTE[2]=$(grep -oE '[0-9]+' <<< "$1" | tail -n 1)
|
||||
echo "$RESERVED" | printf '%02x' ${BYTE[0]} ${BYTE[1]} ${BYTE[2]} | xxd -r -p | base64
|
||||
elif [ "$2" = file ]; then
|
||||
local FILE_PATH=$1
|
||||
grep 'client_id' $FILE_PATH | cut -d\" -f4 | base64 -d | xxd -p | fold -w2 | while read HEX; do printf '%d ' "0x${HEX}"; done | awk '{print "["$1", "$2", "$3"]"}'
|
||||
fi
|
||||
}
|
||||
|
||||
# WARP 或 WireProxy 安装
|
||||
install() {
|
||||
# 后台优选最佳 MTU
|
||||
@@ -1994,13 +2046,13 @@ install() {
|
||||
|
||||
# 注册 WARP 账户 ( warp-account.conf 使用默认值加快速度)。如有 WARP+ 账户,修改 license 并升级,并把设备名等信息保存到 /etc/wireguard/info.log
|
||||
mkdir -p /etc/wireguard/ >/dev/null 2>&1
|
||||
bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's#cat $register_path; ##') --register --file /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
warp_api "register" > /etc/wireguard/warp-account.conf "$LICENSE" 2>/dev/null
|
||||
|
||||
# 有 License 来升级账户
|
||||
if [ -n "$LICENSE" ]; then
|
||||
local UPDATE_RESULT=$(bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --license $LICENSE)
|
||||
local UPDATE_RESULT=$(warp_api "license" "/etc/wireguard/warp-account.conf" "$LICENSE")
|
||||
if grep -q '"warp_plus": true' <<< "$UPDATE_RESULT"; then
|
||||
[ -n "$NAME" ] && bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --name $NAME >/dev/null 2>&1
|
||||
[ -n "$NAME" ] && warp_api "name" "/etc/wireguard/warp-account.conf" "" "$NAME" >/dev/null 2>&1
|
||||
sed -i "s#\([ ]\+\"license\": \"\).*#\1$LICENSE\"#g; s#\"account_type\".*#\"account_type\": \"limited\",#g; s#\([ ]\+\"name\": \"\).*#\1$NAME\"#g" /etc/wireguard/warp-account.conf
|
||||
echo "$LICENSE" > /etc/wireguard/license
|
||||
echo -e "Device name : $NAME" > /etc/wireguard/info.log
|
||||
@@ -2022,7 +2074,7 @@ Address = 172.16.0.2/32
|
||||
Address = $(grep '"v6.*"$' /etc/wireguard/warp-account.conf | cut -d\" -f4)/128
|
||||
DNS = 8.8.8.8
|
||||
MTU = 1280
|
||||
#Reserved = $(reserved_and_clientid /etc/wireguard/warp-account.conf file)
|
||||
#Reserved = $(warp_api "convert" "/etc/wireguard/warp-account.conf" "" "" "" "" "file")
|
||||
#Table = off
|
||||
#PostUp = /etc/wireguard/NonGlobalUp.sh
|
||||
#PostDown = /etc/wireguard/NonGlobalDown.sh
|
||||
@@ -2288,7 +2340,7 @@ EOF
|
||||
# 如成功升级 Teams ,根据新账户信息修改配置文件并注销旧账户; 如失败则还原为原账户
|
||||
wireproxy_onoff no_output
|
||||
if [[ "$WIREPROXY_TRACE4$WIREPROXY_TRACE6" =~ on|plus ]]; then
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
else
|
||||
ACCOUNT_CHANGE_FAILED='Teams' && warning "\n $(text 187) \n"
|
||||
@@ -2333,7 +2385,7 @@ EOF
|
||||
|
||||
# 如成功升级 Teams ,根据新账户信息修改配置文件并注销旧账户; 如失败则还原为原账户
|
||||
if [[ "$TRACE4$TRACE6" =~ on|plus ]]; then
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
else
|
||||
ACCOUNT_CHANGE_FAILED='Teams' && warning "\n $(text 187) \n"
|
||||
@@ -2541,7 +2593,7 @@ check_quota() {
|
||||
if [ "$CHECK_TYPE" = 'client' ]; then
|
||||
QUOTA=$(warp-cli --accept-tos registration show 2>/dev/null | awk -F' ' '/Quota/{print $NF}')
|
||||
elif [ -e /etc/wireguard/warp-account.conf ]; then
|
||||
QUOTA=$(bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --device | awk '/quota/{print $NF}' | sed "s#,##")
|
||||
QUOTA=$(warp_api "device" "/etc/wireguard/warp-account.conf" | awk '/quota/{print $NF}' | sed "s#,##")
|
||||
fi
|
||||
|
||||
# 部分系统没有依赖 bc,所以两个小数不能用 $(echo "scale=2; $QUOTA/1000000000000000" | bc),改为从右往左数字符数的方法
|
||||
@@ -2661,16 +2713,16 @@ change_to_free() {
|
||||
esac
|
||||
|
||||
# 流程3:注册新账户
|
||||
bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's#cat $register_path; ##') --register --file /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
warp_api "register" > /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
|
||||
# 流程4:如成功,根据新账户信息修改配置文件并注销旧账户; 如失败则还原为原账户
|
||||
# 如升级成功的处理: 删除原账户信息文件,注销原账户
|
||||
if grep -q 'warp_plus' /etc/wireguard/warp-account.conf; then
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
local PRIVATEKEY="$(grep 'private_key' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local ADDRESS6="$(grep '"v6.*"$' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local CLIENT_ID="$(reserved_and_clientid /etc/wireguard/warp-account.conf file)"
|
||||
local CLIENT_ID="$(warp_api "convert" "/etc/wireguard/warp-account.conf" "" "" "" "" "file")"
|
||||
sed -i "s#\(PrivateKey[ ]\+=[ ]\+\).*#\1$PRIVATEKEY#g; s#\(Address[ ]\+=[ ]\+\).*\(/128$\)#\1$ADDRESS6\2#g; s#\(.*Reserved[ ]\+=[ ]\+\).*#\1$CLIENT_ID#g" /etc/wireguard/warp.conf
|
||||
[ "$UPDATE_ACCOUNT" = 'wireproxy' ] && sed -i "s#\(PrivateKey[ ]\+=[ ]\+\).*#\1$PRIVATEKEY#g; s#\(Address[ ]\+=[ ]\+\).*\(/128$\)#\1$ADDRESS6\2#g" /etc/wireguard/proxy.conf
|
||||
TYPE=' Free' && [ -e /etc/wireguard/info.log ] && TYPE=' Teams' && grep -q 'Device name' /etc/wireguard/info.log && TYPE='+'
|
||||
@@ -2776,20 +2828,20 @@ change_to_plus() {
|
||||
esac
|
||||
|
||||
# 流程3:注册新账户
|
||||
bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's#cat $register_path; ##') --register --file /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
warp_api "register" > /etc/wireguard/warp-account.conf 2>/dev/null
|
||||
|
||||
# 流程4:使用 License 升级账户
|
||||
local UPDATE_RESULT=$(bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --license $LICENSE)
|
||||
local UPDATE_RESULT=$(warp_api "license" "/etc/wireguard/warp-account.conf" "$LICENSE")
|
||||
|
||||
# 流程5:如成功,根据新账户信息修改配置文件并注销旧账户; 如失败则还原为原账户
|
||||
# 如升级成功的处理: 删除原账户信息文件,注销原账户
|
||||
if grep -q '"warp_plus": true' <<< "$UPDATE_RESULT"; then
|
||||
[ -n "$NAME" ] && bash <(curl -m5 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /etc/wireguard/warp-account.conf --name $NAME >/dev/null 2>&1
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
[ -n "$NAME" ] && warp_api "name" "/etc/wireguard/warp-account.conf" "" "$NAME" >/dev/null 2>&1
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
local PRIVATEKEY="$(grep 'private_key' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local ADDRESS6="$(grep '"v6.*"$' /etc/wireguard/warp-account.conf | cut -d\" -f4)"
|
||||
local CLIENT_ID="$(reserved_and_clientid /etc/wireguard/warp-account.conf file)"
|
||||
local CLIENT_ID="$(warp_api "convert" "/etc/wireguard/warp-account.conf" "" "" "" "" "file")"
|
||||
sed -i "s#\(PrivateKey[ ]\+=[ ]\+\).*#\1$PRIVATEKEY#g; s#\(Address[ ]\+=[ ]\+\).*\(/128$\)#\1$ADDRESS6\2#g; s#\(.*Reserved[ ]\+=[ ]\+\).*#\1$CLIENT_ID#g" /etc/wireguard/warp.conf
|
||||
[ "$UPDATE_ACCOUNT" = 'wireproxy' ] && sed -i "s#\(PrivateKey[ ]\+=[ ]\+\).*#\1$PRIVATEKEY#g; s#\(Address[ ]\+=[ ]\+\).*\(/128$\)#\1$ADDRESS6\2#g" /etc/wireguard/proxy.conf
|
||||
sed -i "s#\([ ]\+\"license\": \"\).*#\1$LICENSE\"#g; s#\"account_type\".*#\"account_type\": \"limited\",#g; s#\([ ]\+\"name\": \"\).*#\1$NAME\"#g" /etc/wireguard/warp-account.conf
|
||||
@@ -2888,7 +2940,7 @@ change_to_teams() {
|
||||
warp )
|
||||
net
|
||||
if [[ "$TRACE4$TRACE6" =~ on|plus ]]; then
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
TYPE=' Free' && [ -e /etc/wireguard/info.log ] && TYPE=' Teams' && grep -q 'Device name' /etc/wireguard/info.log && TYPE='+'
|
||||
info "\n $(text 62) \n"
|
||||
@@ -2902,7 +2954,7 @@ change_to_teams() {
|
||||
wireproxy )
|
||||
wireproxy_onoff
|
||||
if [[ "$WIREPROXY_TRACE4$WIREPROXY_TRACE6" =~ on|plus ]]; then
|
||||
cancel_account /etc/wireguard/warp-account.conf.bak
|
||||
warp_api "cancel" "/etc/wireguard/warp-account.conf.bak" >/dev/null 2>&1
|
||||
backup_restore_delete delete
|
||||
TYPE=' Free' && [ -e /etc/wireguard/info.log ] && TYPE=' Teams' && grep -q 'Device name' /etc/wireguard/info.log && TYPE='+'
|
||||
info "\n $(text 62) \n"
|
||||
|
||||
+91
-16
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 当前脚本版本号和新增功能
|
||||
VERSION='1.1.8'
|
||||
VERSION='1.1.9'
|
||||
|
||||
# 判断 Teams token 最少字符数
|
||||
TOKEN_LENGTH=800
|
||||
@@ -16,8 +16,8 @@ trap "rm -f /tmp/warp-go*; exit" INT
|
||||
|
||||
E[0]="Language:\n 1.English (default) \n 2.简体中文"
|
||||
C[0]="${E[0]}"
|
||||
E[1]="Support Alpine edge system."
|
||||
C[1]="支持 Alpine edge 系统"
|
||||
E[1]="1. Publish warp api, you can register account, join Zero Trust, check account information and all other operations. Detailed instructions: https://warp.cloudflare.now.cc/ ; 2. Scripts to update the warp api."
|
||||
C[1]="1. 发布 warp api,可以注册账户,加入 Zero Trust,查账户信息等所有的操作。详细使用说明: https://warp.cloudflare.now.cc/; 2. 脚本更新 warp api"
|
||||
E[2]="warp-go h (help)\n warp-go o (temporary warp-go switch)\n warp-go u (uninstall WARP web interface and warp-go)\n warp-go v (sync script to latest version)\n warp-go i (replace IP with Netflix support)\n warp-go 4/6 ( WARP IPv4/IPv6 single-stack)\n warp-go d (WARP dual-stack)\n warp-go n (WARP IPv4 non-global)\n warp-go g (WARP global/non-global switching)\n warp-go e (output wireguard and sing-box configuration file)\n warp-go a (Change to Free, WARP+ or Teams account)"
|
||||
C[2]="warp-go h (帮助)\n warp-go o (临时 warp-go 开关)\n warp-go u (卸载 WARP 网络接口和 warp-go)\n warp-go v (同步脚本至最新版本)\n warp-go i (更换支持 Netflix 的IP)\n warp-go 4/6 (WARP IPv4/IPv6 单栈)\n warp-go d (WARP 双栈)\n warp-go n (WARP IPv4 非全局)\n warp-go g (WARP 全局 / 非全局相互切换)\n warp-go e (输出 wireguard 和 sing-box 配置文件)\n warp-go a (更换到 Free,WARP+ 或 Teams 账户)"
|
||||
E[3]="This project is designed to add WARP network interface for VPS, using warp-go core, using various interfaces of CloudFlare-WARP, integrated wireguard-go, can completely replace WGCF. Save Hong Kong, Toronto and other VPS, can also get WARP IP. Thanks again @CoiaPrant and his team. Project address: https://gitlab.com/ProjectWARP/warp-go/-/tree/master/"
|
||||
@@ -369,13 +369,13 @@ check_arch() {
|
||||
check_dependencies() {
|
||||
# 对于 Alpine 和 OpenWrt 系统,升级库并重新安装依赖
|
||||
if [[ "$SYSTEM" =~ Alpine|OpenWrt ]]; then
|
||||
DEPS_CHECK=("ping" "curl" "wget" "grep" "bash" "xxd" "ip" "python3" "tar" "virt-what")
|
||||
DEPS_INSTALL=("iputils-ping" "curl" "wget" "grep" "bash" "xxd" "iproute2" "python3" "tar" "virt-what")
|
||||
DEPS_CHECK=("ping" "curl" "wget" "grep" "bash" "ip" "python3" "tar" "virt-what")
|
||||
DEPS_INSTALL=("iputils-ping" "curl" "wget" "grep" "bash" "iproute2" "python3" "tar" "virt-what")
|
||||
else
|
||||
# 对于 CentOS 系统,xxd 需要依赖 vim-common
|
||||
# 对于三大系统需要的依赖
|
||||
[ "${SYSTEM}" = 'CentOS' ] && ${PACKAGE_INSTALL[int]} vim-common
|
||||
DEPS_CHECK=("ping" "xxd" "wget" "curl" "systemctl" "ip" "python3")
|
||||
DEPS_INSTALL=("iputils-ping" "xxd" "wget" "curl" "systemctl" "iproute2" "python3")
|
||||
DEPS_CHECK=("ping" "wget" "curl" "systemctl" "ip" "python3")
|
||||
DEPS_INSTALL=("iputils-ping" "wget" "curl" "systemctl" "iproute2" "python3")
|
||||
fi
|
||||
|
||||
for c in "${!DEPS_CHECK[@]}"; do
|
||||
@@ -391,6 +391,81 @@ check_dependencies() {
|
||||
PING6='ping -6' && [ $(type -p ping6) ] && PING6='ping6'
|
||||
}
|
||||
|
||||
# 获取 warp 账户信息
|
||||
warp_api(){
|
||||
local RUN=$1
|
||||
local FILE_PATH=$2
|
||||
local WARP_LICENSE=$3
|
||||
local WARP_DEVICE_NAME=$4
|
||||
local WARP_TEAM_TOKEN=$5
|
||||
local WARP_CONVERT=$6
|
||||
local WARP_CONVERT_MODE=$7
|
||||
local WARP_API_URL="warp.cloudflare.now.cc"
|
||||
|
||||
if [ -s "$FILE_PATH" ]; then
|
||||
# Teams 账户文件
|
||||
if grep -q 'xml version' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(grep 'correlation_id' $FILE_PATH | sed "s#.*>\(.*\)<.*#\1#")
|
||||
local WARP_TOKEN=$(grep 'warp_token' $FILE_PATH | sed "s#.*>\(.*\)<.*#\1#")
|
||||
local WARP_CLIENT_ID=$(grep 'client_id' $FILE_PATH | sed "s#.*client_id":"\([^&]\{4\}\)&.*#\1#")
|
||||
|
||||
# 官方 api 文件
|
||||
elif grep -q 'client_id' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(grep -m1 '"id' "$FILE_PATH" | cut -d\" -f4)
|
||||
local WARP_TOKEN=$(grep '"token' "$FILE_PATH" | cut -d\" -f4)
|
||||
local WARP_CLIENT_ID=$(grep 'client_id' "$FILE_PATH" | cut -d\" -f4)
|
||||
|
||||
# client 文件,默认存放路径为 /var/lib/cloudflare-warp/reg.json
|
||||
elif grep -q 'registration_id' $FILE_PATH; then
|
||||
local WARP_DEVICE_ID=$(cut -d\" -f4 "$FILE_PATH")
|
||||
local WARP_TOKEN=$(cut -d\" -f8 "$FILE_PATH")
|
||||
|
||||
# wgcf 文件,默认存放路径为 /etc/wireguard/wgcf-account.toml
|
||||
elif grep -q 'access_token' $FILE_PATH; then
|
||||
id=$(grep 'device_id' "$FILE_PATH" | cut -d\' -f2)
|
||||
token=$(grep 'access_token' "$FILE_PATH" | cut -d\' -f2)
|
||||
|
||||
# warp-go 文件,默认存放路径为 /opt/warp-go/warp.conf
|
||||
elif grep -q 'PrivateKey' $FILE_PATH; then
|
||||
id=$(awk -F' *= *' '/^Device/{print $2}' "$FILE_PATH")
|
||||
token=$(awk -F' *= *' '/^Token/{print $2}' "$FILE_PATH")
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$RUN" in
|
||||
register )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=register&team_token=${WARP_TEAM_TOKE}"
|
||||
;;
|
||||
device )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=device&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}"
|
||||
;;
|
||||
name )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=name&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}&device_name=${WARP_DEVICE_NAME}"
|
||||
;;
|
||||
license )
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=license&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}&license=${WARP_LICENSE}"
|
||||
;;
|
||||
cancel )
|
||||
# 只保留Teams账户,删除其他账户
|
||||
grep -oqE '"id":[ ]+"t.[A-F0-9a-f]{8}-' $FILE_PATH || curl -m5 -sL "https://${WARP_API_URL}/?run=cancel&device_id=${WARP_DEVICE_ID}&token=${WARP_TOKEN}"
|
||||
;;
|
||||
convert )
|
||||
if [ "$WARP_CONVERT_MODE" = decode ]; then
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT}" | grep -A4 'reserved' | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
elif [ "$WARP_CONVERT_MODE" = encode ]; then
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT//[ \[\]]}" | awk -F '"' '/client_id/{print $(NF-1)}'
|
||||
elif [ "$WARP_CONVERT_MODE" = file ]; then
|
||||
if grep -sq '"reserved"' $FILE_PATH; then
|
||||
grep -A4 'reserved' $FILE_PATH | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
else
|
||||
local WARP_CONVERT=$(awk -F '"' '/"client_id"/{print $(NF-1)}' $FILE_PATH)
|
||||
curl -m5 -sL "https://${WARP_API_URL}/?run=id&convert=${WARP_CONVERT}" | grep -A4 'reserved' | sed 's/.*\(\[.*\)/\1/g; s/],/]/' | tr -d '[:space:]'
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 检测 warp-go 的安装状态。STATUS: 0-未安装; 1-已安装未启动; 2-已安装启动中; 3-脚本安装中
|
||||
check_install() {
|
||||
if [ -s /opt/warp-go/warp.conf ]; then
|
||||
@@ -510,7 +585,7 @@ change_ip() {
|
||||
sed -i '1,6!d' /opt/warp-go/warp.conf.tmp2
|
||||
tail -n +7 /opt/warp-go/warp.conf.tmp1 >> /opt/warp-go/warp.conf.tmp2
|
||||
mv /opt/warp-go/warp.conf.tmp2 /opt/warp-go/warp.conf
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/warp.conf.tmp1 --cancle >/dev/null 2>&1
|
||||
warp_api "cancel" "/opt/warp-go/warp.conf.tmp1" >/dev/null 2>&1
|
||||
rm -f /opt/warp-go/warp.conf.tmp*
|
||||
${SYSTEMCTL_RESTART[int]}
|
||||
sleep $l
|
||||
@@ -608,7 +683,7 @@ uninstall() {
|
||||
# 卸载
|
||||
systemctl disable --now warp-go >/dev/null 2>&1
|
||||
kill -15 $(pgrep warp-go) >/dev/null 2>&1
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/warp.conf --cancle >/dev/null 2>&1
|
||||
warp_api "cancel" "/opt/warp-go/warp.conf" >/dev/null 2>&1
|
||||
rm -rf /opt/warp-go /lib/systemd/system/warp-go.service /usr/bin/warp-go /tmp/warp-go*
|
||||
[ -s /opt/warp-go/tun.sh ] && rm -f /opt/warp-go/tun.sh && sed -i '/tun.sh/d' /etc/crontab
|
||||
|
||||
@@ -679,7 +754,7 @@ register_api() {
|
||||
if ! grep -sq 'PrivateKey' /opt/warp-go/$REGISTER_FILE; then
|
||||
unset CF_API_REGISTER API_DEVICE_ID API_ACCESS_TOKEN API_PRIVATEKEY API_TYPE
|
||||
rm -f /opt/warp-go/$REGISTER_FILE
|
||||
CF_API_REGISTER="$(bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh | sed 's# > $register_path##g; /cat $register_path/d') --register --token $TOKEN 2>/dev/null)"
|
||||
CF_API_REGISTER="$(warp_api "register" "" "" "" "$TOKEN" 2>/dev/null)"
|
||||
[[ -n "$NF" && -n "$EXPECT" && -s /opt/warp-go/License ]] && LICENSE=$(cat /opt/warp-go/License) && NAME=$(cat /opt/warp-go/Device_Name)
|
||||
[[ -z "$LICENSE" && -s /opt/warp-go/License ]] && rm -f /opt/warp-go/License /opt/warp-go/Device_Name
|
||||
if grep -q 'private_key' <<< "$CF_API_REGISTER"; then
|
||||
@@ -713,9 +788,9 @@ EOF
|
||||
if grep -sq 'Account' /opt/warp-go/$REGISTER_FILE; then
|
||||
echo -e "\n[Script]\nPostUp =\nPostDown =" >> /opt/warp-go/$REGISTER_FILE && sed -i 's/\r//' /opt/warp-go/$REGISTER_FILE
|
||||
if [ -n "$LICENSE" ]; then
|
||||
local RESULT=$(bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/$REGISTER_FILE --license $LICENSE)
|
||||
local RESULT=$(warp_api "license" "/opt/warp-go/$REGISTER_FILE" "$LICENSE" >/dev/null 2>&1)
|
||||
if [[ "$RESULT" =~ '"warp_plus": true' ]]; then
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/$REGISTER_FILE --name $NAME >/dev/null 2>&1
|
||||
warp_api "name" "/opt/warp-go/$REGISTER_FILE" "" "$NAME" >/dev/null 2>&1
|
||||
echo "$LICENSE" > /opt/warp-go/License
|
||||
echo "$NAME" > /opt/warp-go/Device_Name
|
||||
sed -i "s/Type =.*/Type = plus/g" /opt/warp-go/$REGISTER_FILE
|
||||
@@ -725,8 +800,8 @@ EOF
|
||||
fi
|
||||
elif [[ -s /opt/warp-go/License && -s /opt/warp-go/Device_Name ]]; then
|
||||
if [ -s /opt/warp-go/warp.conf.tmp ]; then
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/$REGISTER_FILE --license $(cat /opt/warp-go/License 2>/dev/null) >/dev/null 2>&1
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/$REGISTER_FILE --name $(cat /opt/warp-go/Device_Name 2>/dev/null) >/dev/null 2>&1
|
||||
[ -s /opt/warp-go/License ] && warp_api "license" "/opt/warp-go/$REGISTER_FILE" "$(cat /opt/warp-go/License)" >/dev/null 2>&1
|
||||
[ -s /opt/warp-go/Device_Name ] && warp_api "name" "/opt/warp-go/$REGISTER_FILE" "" "$(cat /opt/warp-go/Device_Name)" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
@@ -1022,7 +1097,7 @@ update() {
|
||||
update_license
|
||||
esac
|
||||
cp -f /opt/warp-go/warp.conf{,.tmp1}
|
||||
bash <(curl -m8 -sSL https://gitlab.com/fscarmen/warp/-/raw/main/api.sh) --file /opt/warp-go/warp.conf --cancle >/dev/null 2>&1
|
||||
warp_api "cancel" "/opt/warp-go/warp.conf" >/dev/null 2>&1
|
||||
[ -s /opt/warp-go/warp.conf ] && rm -f /opt/warp-go/warp.conf
|
||||
register_api warp.conf 58 59
|
||||
head -n +6 /opt/warp-go/warp.conf > /opt/warp-go/warp.conf.tmp2
|
||||
|
||||
Reference in New Issue
Block a user