VNetController.php 2.1 KB

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