V2RayController.php 3.1 KB

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