VNetController.php 1.7 KB

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