VNetController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Components\Helpers;
  4. use App\Models\SsNode;
  5. use App\Models\User;
  6. use Illuminate\Http\JsonResponse;
  7. class VNetController extends BaseController {
  8. // 获取节点信息
  9. public function getNodeInfo($id): JsonResponse {
  10. $node = SsNode::find($id);
  11. return $this->returnData('获取节点信息成功', 'success', 200, [
  12. 'id' => $node->id,
  13. 'method' => $node->method,
  14. 'protocol' => $node->protocol,
  15. 'obfs' => $node->obfs,
  16. 'obfs_param' => $node->obfs_param?: '',
  17. 'is_udp' => $node->is_udp,
  18. 'speed_limit' => $node->speed_limit,
  19. 'client_limit' => $node->client_limit,
  20. 'single' => $node->single,
  21. 'port' => (string) $node->port,
  22. 'passwd' => $node->passwd?: '',
  23. 'push_port' => $node->push_port,
  24. 'secret' => $node->auth->secret,
  25. 'redirect_url' => Helpers::systemConfig()['redirect_url']
  26. ]);
  27. }
  28. // 获取节点可用的用户列表
  29. public function getUserList($id): JsonResponse {
  30. $node = SsNode::find($id);
  31. $users = User::query()
  32. ->where('status', '<>', -1)
  33. ->whereEnable(1)
  34. ->groupUserPermit($node->id)
  35. ->where('level', '>=', $node->level)
  36. ->get();
  37. $data = [];
  38. foreach($users as $user){
  39. $new = [
  40. 'uid' => $user->id,
  41. 'port' => $user->port,
  42. 'passwd' => $user->passwd,
  43. 'method' => $user->method,
  44. 'protocol' => $user->protocol,
  45. 'obfs' => $user->obfs,
  46. 'obfs_param' => $node->obfs_param,
  47. 'speed_limit' => $user->speed_limit,
  48. 'enable' => $user->enable
  49. ];
  50. $data[] = $new;
  51. }
  52. if($data){
  53. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  54. }
  55. return $this->returnData('获取用户列表失败');
  56. }
  57. }