VNetController.php 1.6 KB

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