VNetController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class VNetController extends BaseController
  6. {
  7. // 获取节点信息
  8. public function getNodeInfo(Node $node): JsonResponse
  9. {
  10. return $this->returnData('获取节点信息成功', 'success', 200, [
  11. 'id' => $node->id,
  12. 'method' => $node->method,
  13. 'protocol' => $node->protocol,
  14. 'obfs' => $node->obfs,
  15. 'obfs_param' => $node->obfs_param ?? '',
  16. 'is_udp' => $node->is_udp,
  17. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  18. 'client_limit' => $node->client_limit,
  19. 'single' => $node->single,
  20. 'port' => (string) $node->port,
  21. 'passwd' => $node->passwd ?? '',
  22. 'push_port' => $node->push_port,
  23. 'secret' => $node->auth->secret,
  24. 'redirect_url' => sysConfig('redirect_url'),
  25. ]);
  26. }
  27. // 获取节点可用的用户列表
  28. public function getUserList(Node $node): JsonResponse
  29. {
  30. foreach ($node->users() as $user) {
  31. $data[] = [
  32. 'uid' => $user->id,
  33. 'port' => $user->port,
  34. 'passwd' => $user->passwd,
  35. 'method' => $user->method,
  36. 'protocol' => $user->protocol,
  37. 'obfs' => $user->obfs,
  38. 'obfs_param' => $node->obfs_param,
  39. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  40. 'enable' => $user->enable,
  41. ];
  42. }
  43. if (isset($data)) {
  44. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  45. }
  46. return $this->returnData('获取用户列表失败');
  47. }
  48. }