VNetController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\SsNode;
  4. use App\Models\User;
  5. use Illuminate\Http\Request;
  6. class VNetController extends BaseController {
  7. // 获取节点信息
  8. public function getNodeInfo($id) {
  9. $node = SsNode::query()->whereId($id)->first();
  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' => strval($node->port),
  21. 'passwd' => $node->passwd?: '',
  22. 'push_port' => $node->push_port,
  23. 'secret' => $node->auth->secret
  24. ]);
  25. }
  26. // 获取节点可用的用户列表
  27. public function getUserList(Request $request, $id) {
  28. $node = SsNode::query()->whereId($id)->first();
  29. $users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
  30. $data = [];
  31. foreach($users as $user){
  32. $new = [
  33. 'uid' => $user->id,
  34. 'port' => $user->port,
  35. 'passwd' => $user->passwd,
  36. 'method' => $user->method,
  37. 'protocol' => $user->protocol,
  38. 'obfs' => $user->obfs,
  39. 'obfs_param' => $node->obfs_param,
  40. 'speed_limit' => $user->speed_limit,
  41. 'enable' => $user->enable
  42. ];
  43. array_push($data, $new);
  44. }
  45. if($data){
  46. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  47. }
  48. return $this->returnData('获取用户列表失败');
  49. }
  50. }