VNetController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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->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. // 获取节点可用的用户列表
  30. public function getUserList($id): JsonResponse
  31. {
  32. $node = Node::find($id);
  33. $users = $node->node_access_users;
  34. $data = [];
  35. foreach ($users as $user) {
  36. $data[] = [
  37. 'uid' => $user->id,
  38. 'port' => $user->port,
  39. 'passwd' => $user->passwd,
  40. 'method' => $user->method,
  41. 'protocol' => $user->protocol,
  42. 'obfs' => $user->obfs,
  43. 'obfs_param' => $node->obfs_param,
  44. 'speed_limit' => $user->speed_limit,
  45. 'enable' => $user->enable,
  46. ];
  47. }
  48. if ($data) {
  49. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  50. }
  51. return $this->returnData('获取用户列表失败');
  52. }
  53. }