V2RayController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. public function getUserList($id): JsonResponse
  38. {
  39. $users = Node::find($id)->node_access_users;
  40. $data = [];
  41. foreach ($users as $user) {
  42. $data[] = [
  43. 'uid' => $user->id,
  44. 'vmess_uid' => $user->vmess_id,
  45. 'speed_limit' => $user->speed_limit,
  46. ];
  47. }
  48. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  49. }
  50. // 上报节点伪装域名证书信息
  51. public function addCertificate(Request $request, $id): JsonResponse
  52. {
  53. $key = $request->input('key');
  54. $pem = $request->input('pem');
  55. if ($request->has(['key', 'pem'])) {
  56. $node = Node::find($id);
  57. $Dv = NodeCertificate::whereDomain($node->v2_host)->first();
  58. if ($Dv) {
  59. $ret = NodeCertificate::whereId($Dv->id)->update(['key' => $key, 'pem' => $pem]);
  60. } else {
  61. $ret = new NodeCertificate();
  62. $ret->domain = $node->server;
  63. $ret->key = $request->input('key');
  64. $ret->pem = $request->input('pem');
  65. $ret->save();
  66. }
  67. if ($ret) {
  68. return $this->returnData('上报节点伪装域名证书成功', 'success', 200);
  69. }
  70. }
  71. return $this->returnData('上报节点伪装域名证书失败,请检查字段');
  72. }
  73. }