V2RayController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use App\Models\NodeCertificate;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Http\Request;
  7. class V2RayController extends BaseController
  8. {
  9. // 获取节点信息
  10. public function getNodeInfo($id): JsonResponse
  11. {
  12. $node = Node::find($id);
  13. $nodeDv = NodeCertificate::whereDomain($node->v2_host)->first();
  14. return $this->returnData('获取节点信息成功', 'success', 200, [
  15. 'id' => $node->id,
  16. 'is_udp' => $node->is_udp ? true : false,
  17. 'speed_limit' => $node->speed_limit,
  18. 'client_limit' => $node->client_limit,
  19. 'push_port' => $node->push_port,
  20. 'redirect_url' => sysConfig('redirect_url'),
  21. 'secret' => $node->auth->secret,
  22. 'key' => $nodeDv->key ?? '',
  23. 'pem' => $nodeDv->pem ?? '',
  24. 'v2_license' => sysConfig('v2ray_license'),
  25. 'v2_alter_id' => $node->v2_alter_id,
  26. 'v2_port' => $node->v2_port,
  27. 'v2_method' => $node->v2_method,
  28. 'v2_net' => $node->v2_net,
  29. 'v2_type' => $node->v2_type,
  30. 'v2_host' => $node->v2_host,
  31. 'v2_path' => $node->v2_path,
  32. 'v2_tls' => $node->v2_tls ? true : false,
  33. 'v2_tls_provider' => $node->tls_provider ?: sysConfig('v2ray_tls_provider'),
  34. ]
  35. );
  36. }
  37. // 获取节点可用的用户列表
  38. public function getUserList($id): JsonResponse
  39. {
  40. $users = Node::find($id)->node_access_users;
  41. $data = [];
  42. foreach ($users as $user) {
  43. $data[] = [
  44. 'uid' => $user->id,
  45. 'vmess_uid' => $user->vmess_id,
  46. 'speed_limit' => $user->speed_limit,
  47. ];
  48. }
  49. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  50. }
  51. // 上报节点伪装域名证书信息
  52. public function addCertificate(Request $request, $id): JsonResponse
  53. {
  54. $key = $request->input('key');
  55. $pem = $request->input('pem');
  56. if ($request->has(['key', 'pem'])) {
  57. $node = Node::find($id);
  58. $Dv = NodeCertificate::whereDomain($node->v2_host)->first();
  59. if ($Dv) {
  60. $ret = NodeCertificate::whereId($Dv->id)->update(['key' => $key, 'pem' => $pem]);
  61. } else {
  62. $ret = new NodeCertificate();
  63. $ret->domain = $node->server;
  64. $ret->key = $request->input('key');
  65. $ret->pem = $request->input('pem');
  66. $ret->save();
  67. }
  68. if ($ret) {
  69. return $this->returnData('上报节点伪装域名证书成功', 'success', 200);
  70. }
  71. }
  72. return $this->returnData('上报节点伪装域名证书失败,请检查字段');
  73. }
  74. }