TrojanController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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('获取节点信息成功', 'success', 200, [
  12. 'id' => $node->id,
  13. 'is_udp' => $node->is_udp ? true : false,
  14. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  15. 'client_limit' => $node->client_limit,
  16. 'push_port' => $node->push_port,
  17. 'redirect_url' => sysConfig('redirect_url'),
  18. 'trojan_port' => $node->port,
  19. 'secret' => $node->auth->secret,
  20. 'license' => sysConfig('trojan_license'),
  21. ]);
  22. }
  23. // 获取节点可用的用户列表
  24. public function getUserList($id): JsonResponse
  25. {
  26. $users = Node::find($id)->node_access_users;
  27. $data = [];
  28. foreach ($users as $user) {
  29. $data[] = [
  30. 'uid' => $user->id,
  31. 'password' => $user->passwd,
  32. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  33. ];
  34. }
  35. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  36. }
  37. }