SSRController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class SSRController extends CoreController
  6. {
  7. // 获取节点信息
  8. public function getNodeInfo(Node $node): JsonResponse
  9. {
  10. return $this->returnData('获取节点信息成功', 200, 'success', $this->nodeData($node));
  11. }
  12. // 生成节点信息
  13. public function nodeData(Node $node): array
  14. {
  15. return [
  16. 'id' => $node->id,
  17. 'method' => $node->profile['method'] ?? '',
  18. 'protocol' => $node->profile['protocol'] ?? '',
  19. 'obfs' => $node->profile['obfs'] ?? '',
  20. 'obfs_param' => $node->profile['obfs_param'] ?? '',
  21. 'is_udp' => $node->is_udp,
  22. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  23. 'client_limit' => $node->client_limit,
  24. 'single' => isset($node->profile['passwd']) ? 1 : 0,
  25. 'port' => (string) $node->port,
  26. 'passwd' => $node->profile['passwd'] ?? '',
  27. 'push_port' => $node->push_port,
  28. 'secret' => $node->auth->secret,
  29. 'redirect_url' => sysConfig('redirect_url'),
  30. ];
  31. }
  32. // 获取节点可用的用户列表
  33. public function getUserList(Node $node): JsonResponse
  34. {
  35. foreach ($node->users() as $user) {
  36. $data[] = [
  37. 'uid' => $user->id,
  38. 'port' => $user->port,
  39. 'passwd' => $user->passwd,
  40. 'method' => $user->method,
  41. 'protocol' => $user->protocol,
  42. 'obfs' => $user->obfs,
  43. 'obfs_param' => $node->profile['obfs_param'] ?? '',
  44. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  45. 'enable' => $user->enable,
  46. ];
  47. }
  48. return $this->returnData('获取用户列表成功', 200, 'success', $data ?? [], ['updateTime' => time()]);
  49. }
  50. }