Update registe api method.

Former-commit-id: 9fbab92d050b23ae43090fa4f8c6f184af2e24c9
This commit is contained in:
fscarmen
2023-06-27 16:42:38 +00:00
parent e83f64aa9d
commit 5b66e840ef
3 changed files with 8 additions and 22 deletions
+3 -5
View File
@@ -51,7 +51,7 @@ fetch_account_information() {
# 注册warp账户
registe_account() {
# 生成 wireguard 公私钥
# 生成 wireguard 公私钥,并且补上 private key
if [ $(type -p wg) ]; then
private_key=$(wg genkey)
public_key=$(wg pubkey <<< "$private_key")
@@ -75,11 +75,9 @@ registe_account() {
--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.%3NZ")'","model":"PC","serial_number":"'${install_id}'","locale":"zh_CN"}' \
| python3 -m json.tool > $registe_path
| python3 -m json.tool | sed "/\"account_type\"/i\ \"private_key\": \"$private_key\"" > $registe_path
# 补上 private key
sed -i "/\"account_type\"/i\ \"private_key\": \"$private_key\"" $registe_path
[ -e $registe_path ] && cat $registe_path && grep -q 'error code' $registe_path && rm -f $registe_path
[ -s $registe_path ] && cat $registe_path && grep -q 'error code' $registe_path && rm -f $registe_path
}
# 获取设备信息
+1 -1
View File
@@ -1299,7 +1299,7 @@ EOF
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)}}')
[[ "$LAN6" != "::1" && "$LAN6" =~ ^([a-f0-9]{1,4}:){2,4}[a-f0-9]{1,4} ]] && INET6=1 && $PING6 -c2 -w10 2606:4700:d0::a29f:c001 >/dev/null 2>&1 && IPV6=1 && CDN=-6 && ip_case 6 wgcf
[[ "$LAN4" =~ ^([0-9]{1,3}\.){3} ]] && INET4=1 && ping -c2 -W3 162.159.193.10 >/dev/null 2>&1 && IPV4=1 && CDN=-4 && ip_case 4
[[ "$LAN4" =~ ^([0-9]{1,3}\.){3} ]] && INET4=1 && ping -c2 -W3 162.159.193.10 >/dev/null 2>&1 && IPV4=1 && CDN=-4 && ip_case 4 wgcf
# 判断当前 WARP 状态,决定变量 PLAN,变量 PLAN 含义:1=单栈 2=双栈 3=WARP已开启
[[ "$TRACE4$TRACE6" =~ on|plus ]] && PLAN=3 || PLAN=$((IPV4+IPV6))
+4 -16
View File
@@ -604,14 +604,6 @@ net() {
[ -n "$QUOTA" ] && info " $(text 26): $QUOTA "
}
# 提取注册账户信息
copy_config() {
local REGISTE_FILE="$1"
local UPDATE_DEVICE_ID=$(awk -F' *= *' '/^Device/{print $2}' /opt/warp-go/$REGISTE_FILE)
local UPDATE_DEVICE_TOKEN=$(awk -F' *= *' '/^Token/{print $2}' /opt/warp-go/$REGISTE_FILE)
echo -e "\"id\": \"$UPDATE_DEVICE_ID\"\n\"token\": \"$UPDATE_DEVICE_TOKEN\"" > /opt/warp-go/warp.conf.tmp
}
# api 注册账户, 使用官方 api 脚本
registe_api() {
local REGISTE_FILE="$1"
@@ -658,10 +650,9 @@ EOF
if grep -sq 'Account' /opt/warp-go/$REGISTE_FILE; then
echo -e "\n[Script]\nPostUp =\nPostDown =" >> /opt/warp-go/$REGISTE_FILE && sed -i 's/\r//' /opt/warp-go/$REGISTE_FILE
if [ -n "$LICENSE" ]; then
copy_config $REGISTE_FILE
local RESULT=$(bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/warp.conf.tmp --license $LICENSE)
local RESULT=$(bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/$REGISTE_FILE --license $LICENSE)
if [[ "$RESULT" =~ '"warp_plus": true' ]]; then
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/warp.conf.tmp --name $NAME >/dev/null 2>&1
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/$REGISTE_FILE --name $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/$REGISTE_FILE
@@ -669,13 +660,10 @@ EOF
else
warning "\n License: $LICENSE $(text_eval 106) \n"
fi
rm -f /opt/warp-go/warp.conf.tmp
elif [[ -s /opt/warp-go/License && -s /opt/warp-go/Device_Name ]]; then
if [ -s /opt/warp-go/warp.conf.tmp ]; then
copy_config $REGISTE_FILE
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/warp.conf.tmp --license $(cat /opt/warp-go/License 2>/dev/null) >/dev/null 2>&1
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/warp.conf.tmp --name $(cat /opt/warp-go/Device_Name 2>/dev/null) >/dev/null 2>&1
rm -f /opt/warp-go/warp.conf.tmp
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/$REGISTE_FILE --license $(cat /opt/warp-go/License 2>/dev/null) >/dev/null 2>&1
bash <(curl -m8 -sSL https://raw.githubusercontent.com/fscarmen/warp/main/api.sh) --file /opt/warp-go/$REGISTE_FILE --name $(cat /opt/warp-go/Device_Name 2>/dev/null) >/dev/null 2>&1
fi
fi
else