()
| 74 | const response = await axios.get("https://warp.cloudflare.now.cc/?run=register", { timeout: 8000 }); |
| 75 | const dataStr = typeof response.data === "string" ? response.data : JSON.stringify(response.data); |
| 76 | |
| 77 | const pkMatch = dataStr.match(/"private_key"\s*:\s*"([A-Za-z0-9+/=]{20,})"/); |
| 78 | const v6Match = dataStr.match(/"v6"\s*:\s*"([0-9a-fA-F:]+)"/); |
| 79 | |
| 80 | if (!pkMatch || !v6Match) { |
| 81 | throw new Error("注册响应格式错误"); |
| 82 | } |
| 83 | |
| 84 | const privateKey = pkMatch[1]; |
| 85 | const address6 = v6Match[1]; |
| 86 | const accountData = JSON.stringify({ type: "free", private_key: privateKey, v6: address6 }, null, 2); |
| 87 | |
| 88 | await SystemExecutor.runSudo(`mkdir -p /etc/wireguard`); |
| 89 | await execAsync(`sudo bash -lc 'cat > ${WARP_CONFIG_FILE} <<"EOF"\n${accountData}\nEOF'`); |
| 90 | |
| 91 | return { privateKey, address6 }; |
| 92 | } catch (error: any) { |
| 93 | throw new Error(`账户注册失败: ${error.message}`); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // wireproxy 管理 |
| 99 | class WireproxyManager { |
| 100 | private static async _getOrCreateAccount(): Promise<{ privateKey: string; address6: string }> { |
| 101 | // 优先读取本地账户文件 |
| 102 | try { |
no test coverage detected