VNetController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Components\Helpers;
  4. use App\Models\Node;
  5. use App\Models\User;
  6. use Illuminate\Http\JsonResponse;
  7. class VNetController extends BaseController {
  8. // 获取节点信息
  9. public function getNodeInfo($id): JsonResponse {
  10. $node = Node::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 = Node::find($id);
  31. $users = User::query()->activeUser()->groupUserPermit($node->id)->where('level', '>=', $node->level)->get();
  32. $data = [];
  33. foreach($users as $user){
  34. $new = [
  35. 'uid' => $user->id,
  36. 'port' => $user->port,
  37. 'passwd' => $user->passwd,
  38. 'method' => $user->method,
  39. 'protocol' => $user->protocol,
  40. 'obfs' => $user->obfs,
  41. 'obfs_param' => $node->obfs_param,
  42. 'speed_limit' => $user->speed_limit,
  43. 'enable' => $user->enable
  44. ];
  45. $data[] = $new;
  46. }
  47. if($data){
  48. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  49. }
  50. return $this->returnData('获取用户列表失败');
  51. }
  52. }