Node.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use Illuminate\Database\Eloquent\Relations\HasOne;
  7. /**
  8. * 节点配置信息
  9. *
  10. * @property int $id
  11. * @property int $type 服务类型:1-Shadowsocks(R)、2-V2ray、3-Trojan、4-VNet
  12. * @property string $name 名称
  13. * @property string $country_code 国家代码
  14. * @property string|null $server 服务器域名地址
  15. * @property string|null $ip 服务器IPV4地址
  16. * @property string|null $ipv6 服务器IPV6地址
  17. * @property int $level 等级:0-无等级,全部可见
  18. * @property int $speed_limit 节点限速,为0表示不限速,单位Byte
  19. * @property int $client_limit 设备数限制
  20. * @property string|null $relay_server 中转地址
  21. * @property int|null $relay_port 中转端口
  22. * @property string|null $description 节点简单描述
  23. * @property string|null $geo 节点地理位置
  24. * @property string $method 加密方式
  25. * @property string $protocol 协议
  26. * @property string|null $protocol_param 协议参数
  27. * @property string $obfs 混淆
  28. * @property string|null $obfs_param 混淆参数
  29. * @property float $traffic_rate 流量比率
  30. * @property int $is_subscribe 是否允许用户订阅该节点:0-否、1-是
  31. * @property int $is_ddns 是否使用DDNS:0-否、1-是
  32. * @property int $is_relay 是否中转节点:0-否、1-是
  33. * @property int $is_udp 是否启用UDP:0-不启用、1-启用
  34. * @property int $push_port 消息推送端口
  35. * @property int $detection_type 节点检测: 0-关闭、1-只检测TCP、2-只检测ICMP、3-检测全部
  36. * @property int $compatible 兼容SS
  37. * @property int $single 启用单端口功能:0-否、1-是
  38. * @property int|null $port 单端口的端口号或连接端口号
  39. * @property string|null $passwd 单端口的连接密码
  40. * @property int $sort 排序值,值越大越靠前显示
  41. * @property int $status 状态:0-维护、1-正常
  42. * @property int $v2_alter_id V2Ray额外ID
  43. * @property int $v2_port V2Ray服务端口
  44. * @property string $v2_method V2Ray加密方式
  45. * @property string $v2_net V2Ray传输协议
  46. * @property string $v2_type V2Ray伪装类型
  47. * @property string $v2_host V2Ray伪装的域名
  48. * @property string $v2_path V2Ray的WS/H2路径
  49. * @property int $v2_tls V2Ray连接TLS:0-未开启、1-开启
  50. * @property string|null $tls_provider V2Ray节点的TLS提供商授权信息
  51. * @property \Illuminate\Support\Carbon $created_at 创建时间
  52. * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
  53. * @property-read \App\Models\NodeAuth|null $auth
  54. * @property-read string $level_name
  55. * @property-read string $type_label
  56. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\NodeLabel[] $label
  57. * @property-read int|null $label_count
  58. * @method static Builder|Node groupNodePermit($group_id = 0)
  59. * @method static Builder|Node newModelQuery()
  60. * @method static Builder|Node newQuery()
  61. * @method static Builder|Node query()
  62. * @method static Builder|Node whereClientLimit($value)
  63. * @method static Builder|Node whereCompatible($value)
  64. * @method static Builder|Node whereCountryCode($value)
  65. * @method static Builder|Node whereCreatedAt($value)
  66. * @method static Builder|Node whereDescription($value)
  67. * @method static Builder|Node whereDetectionType($value)
  68. * @method static Builder|Node whereGeo($value)
  69. * @method static Builder|Node whereId($value)
  70. * @method static Builder|Node whereIp($value)
  71. * @method static Builder|Node whereIpv6($value)
  72. * @method static Builder|Node whereIsDdns($value)
  73. * @method static Builder|Node whereIsRelay($value)
  74. * @method static Builder|Node whereIsSubscribe($value)
  75. * @method static Builder|Node whereIsUdp($value)
  76. * @method static Builder|Node whereLevel($value)
  77. * @method static Builder|Node whereMethod($value)
  78. * @method static Builder|Node whereName($value)
  79. * @method static Builder|Node whereObfs($value)
  80. * @method static Builder|Node whereObfsParam($value)
  81. * @method static Builder|Node wherePasswd($value)
  82. * @method static Builder|Node wherePort($value)
  83. * @method static Builder|Node whereProtocol($value)
  84. * @method static Builder|Node whereProtocolParam($value)
  85. * @method static Builder|Node wherePushPort($value)
  86. * @method static Builder|Node whereRelayPort($value)
  87. * @method static Builder|Node whereRelayServer($value)
  88. * @method static Builder|Node whereServer($value)
  89. * @method static Builder|Node whereSingle($value)
  90. * @method static Builder|Node whereSort($value)
  91. * @method static Builder|Node whereSpeedLimit($value)
  92. * @method static Builder|Node whereStatus($value)
  93. * @method static Builder|Node whereTlsProvider($value)
  94. * @method static Builder|Node whereTrafficRate($value)
  95. * @method static Builder|Node whereType($value)
  96. * @method static Builder|Node whereUpdatedAt($value)
  97. * @method static Builder|Node whereV2AlterId($value)
  98. * @method static Builder|Node whereV2Host($value)
  99. * @method static Builder|Node whereV2Method($value)
  100. * @method static Builder|Node whereV2Net($value)
  101. * @method static Builder|Node whereV2Path($value)
  102. * @method static Builder|Node whereV2Port($value)
  103. * @method static Builder|Node whereV2Tls($value)
  104. * @method static Builder|Node whereV2Type($value)
  105. * @mixin \Eloquent
  106. */
  107. class Node extends Model {
  108. protected $table = 'ss_node';
  109. public function label(): HasMany {
  110. return $this->hasMany(NodeLabel::class, 'node_id', 'id');
  111. }
  112. public function auth(): HasOne {
  113. return $this->hasOne(NodeAuth::class, 'node_id', 'id');
  114. }
  115. public function getLevelNameAttribute(): string {
  116. return Level::whereLevel($this->attributes['level'])->first()->name;
  117. }
  118. // Node查询,查用户所在分组Node权限
  119. public function scopeGroupNodePermit($query, $group_id = 0) {
  120. $userGroup = UserGroup::find($group_id);
  121. if($userGroup){
  122. return $query->whereIn('id', $userGroup->nodes);
  123. }
  124. return $query;
  125. }
  126. public function getTypeLabelAttribute(): string {
  127. switch($this->attributes['type']){
  128. case 1:
  129. $type_label = 'ShadowsocksR';
  130. break;
  131. case 2:
  132. $type_label = 'V2Ray';
  133. break;
  134. case 3:
  135. $type_label = 'Trojan';
  136. break;
  137. case 4:
  138. $type_label = 'VNet';
  139. break;
  140. default:
  141. $type_label = 'UnKnown';
  142. }
  143. return $type_label;
  144. }
  145. }