TrojanController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class TrojanController 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. 'is_udp' => $node->is_udp ? true : false,
  18. 'speed_limit' => $node->speed_limit,
  19. 'client_limit' => $node->client_limit,
  20. 'push_port' => $node->push_port,
  21. 'redirect_url' => sysConfig('redirect_url'),
  22. 'trojan_port' => $node->port,
  23. 'secret' => $node->auth->secret,
  24. 'license' => sysConfig('trojan_license'),
  25. ]
  26. );
  27. }
  28. // 获取节点可用的用户列表
  29. public function getUserList($id): JsonResponse
  30. {
  31. $users = Node::find($id)->node_access_users;
  32. $data = [];
  33. foreach ($users as $user) {
  34. $data[] = [
  35. 'uid' => $user->id,
  36. 'password' => $user->passwd,
  37. 'speed_limit' => $user->speed_limit,
  38. ];
  39. }
  40. return $this->returnData(
  41. '获取用户列表成功',
  42. 'success',
  43. 200,
  44. $data,
  45. ['updateTime' => time()]
  46. );
  47. }
  48. }