VNetController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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($id): JsonResponse
  9. {
  10. $node = Node::find($id);
  11. return $this->returnData('获取节点信息成功', 'success', 200, [
  12. 'id' => $node->id,
  13. 'method' => $node->method,
  14. 'protocol' => $node->protocol,
  15. 'obfs' => $node->obfs,
  16. 'obfs_param' => $node->obfs_param ?? '',
  17. 'is_udp' => $node->is_udp,
  18. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  19. 'client_limit' => $node->client_limit,
  20. 'single' => $node->single,
  21. 'port' => (string) $node->port,
  22. 'passwd' => $node->passwd ?? '',
  23. 'push_port' => $node->push_port,
  24. 'secret' => $node->auth->secret,
  25. 'redirect_url' => sysConfig('redirect_url'),
  26. ]);
  27. }
  28. // 获取节点可用的用户列表
  29. public function getUserList($id): JsonResponse
  30. {
  31. $node = Node::find($id);
  32. $users = $node->node_access_users;
  33. $data = [];
  34. foreach ($users as $user) {
  35. $data[] = [
  36. 'uid' => $user->id,
  37. 'port' => $user->port,
  38. 'passwd' => $user->passwd,
  39. 'method' => $user->method,
  40. 'protocol' => $user->protocol,
  41. 'obfs' => $user->obfs,
  42. 'obfs_param' => $node->obfs_param,
  43. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  44. 'enable' => $user->enable,
  45. ];
  46. }
  47. if ($data) {
  48. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  49. }
  50. return $this->returnData('获取用户列表失败');
  51. }
  52. }