TrojanController.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Helpers\WebApiResponse;
  4. use App\Models\Node;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Routing\Controller;
  7. class TrojanController extends Controller
  8. {
  9. use WebApiResponse;
  10. public function getNodeInfo(Node $node): JsonResponse // 获取节点信息
  11. {
  12. return $this->succeed([
  13. 'id' => $node->id,
  14. 'is_udp' => (bool) $node->is_udp,
  15. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  16. 'client_limit' => $node->client_limit,
  17. 'push_port' => $node->push_port,
  18. 'redirect_url' => sysConfig('redirect_url'),
  19. 'trojan_port' => $node->port,
  20. 'secret' => $node->auth->secret,
  21. 'license' => sysConfig('trojan_license'),
  22. ]);
  23. }
  24. public function getUserList(Node $node): JsonResponse // 获取节点可用的用户列表
  25. {
  26. foreach ($node->users() as $user) {
  27. $data[] = [
  28. 'uid' => $user->id,
  29. 'password' => $user->passwd,
  30. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  31. ];
  32. }
  33. return $this->succeed($data ?? [], ['updateTime' => time()]);
  34. }
  35. }