|
|
@@ -179,7 +179,7 @@ class URL
|
|
|
|
|
|
/**
|
|
|
* 获取全部节点
|
|
|
- *
|
|
|
+ *
|
|
|
* ```
|
|
|
* $Rule = [
|
|
|
* 'type' => 'all | ss | ssr | vmess | trojan',
|
|
|
@@ -275,7 +275,7 @@ class URL
|
|
|
14 => 'getTrojanItem', // Trojan
|
|
|
];
|
|
|
$class = $node_class[$node->sort];
|
|
|
- $item = self::$class($user, $node, $emoji);
|
|
|
+ $item = $node->$class($user, 0, 0, 0, $emoji);
|
|
|
if ($item != null) {
|
|
|
$return_array[] = $item;
|
|
|
}
|
|
|
@@ -295,10 +295,10 @@ class URL
|
|
|
if ($relay_rule != null && $relay_rule->dist_node() != null) {
|
|
|
$relay_rule_id = $relay_rule->id;
|
|
|
}
|
|
|
- $item = self::getItem($user, $node, 0, $relay_rule_id, $ss, $emoji);
|
|
|
+ $item = $node->getItem($user, 0, $relay_rule_id, $ss, $emoji);
|
|
|
} else {
|
|
|
// SS 非中转
|
|
|
- $item = self::getItem($user, $node, 0, 0, $ss, $emoji);
|
|
|
+ $item = $node->getItem($user, 0, 0, $ss, $emoji);
|
|
|
}
|
|
|
if ($item != null) {
|
|
|
$return_array[] = $item;
|
|
|
@@ -318,10 +318,10 @@ class URL
|
|
|
if ($relay_rule != null && $relay_rule->dist_node() != null) {
|
|
|
$relay_rule_id = $relay_rule->id;
|
|
|
}
|
|
|
- $item = self::getItem($user, $node, $mu_node->server, $relay_rule_id, $ss, $emoji);
|
|
|
+ $item = $node->getItem($user, $mu_node->server, $relay_rule_id, $ss, $emoji);
|
|
|
} else {
|
|
|
// SS 非中转
|
|
|
- $item = self::getItem($user, $node, $mu_node->server, 0, $ss, $emoji);
|
|
|
+ $item = $node->getItem($user, $mu_node->server, 0, $ss, $emoji);
|
|
|
}
|
|
|
if ($item != null) {
|
|
|
$return_array[] = $item;
|
|
|
@@ -339,7 +339,7 @@ class URL
|
|
|
|
|
|
/**
|
|
|
* 获取全部节点 Url
|
|
|
- *
|
|
|
+ *
|
|
|
* ```
|
|
|
* $Rule = [
|
|
|
* 'type' => 'ss | ssr | vmess',
|
|
|
@@ -407,7 +407,7 @@ class URL
|
|
|
$return_array = array();
|
|
|
$nodes = self::getNodes($user, 13);
|
|
|
foreach ($nodes as $node) {
|
|
|
- $item = self::getV2RayPluginItem($user, $node, $emoji);
|
|
|
+ $item = $node->getV2RayPluginItem($user, 0, 0, 0, $emoji);
|
|
|
if ($item != null) {
|
|
|
$return_array[] = $item;
|
|
|
}
|
|
|
@@ -416,49 +416,6 @@ class URL
|
|
|
return $return_array;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取 V2RayPlugin | obfs 节点
|
|
|
- *
|
|
|
- * @param User $user 用户
|
|
|
- * @param Node $node 节点
|
|
|
- * @param bool $emoji
|
|
|
- *
|
|
|
- * @return array|null
|
|
|
- */
|
|
|
- public static function getV2RayPluginItem(User $user, Node $node, bool $emoji = false)
|
|
|
- {
|
|
|
- $return_array = Tools::ssv2Array($node->server);
|
|
|
- // 非 AEAD 加密无法使用
|
|
|
- if ($return_array['net'] != 'obfs' && !in_array($user->method, Config::getSupportParam('ss_aead_method'))) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- $return_array['remark'] = ($emoji ? Tools::addEmoji($node->name) : $node->name);
|
|
|
- $return_array['address'] = $return_array['add'];
|
|
|
- $return_array['method'] = $user->method;
|
|
|
- $return_array['passwd'] = $user->passwd;
|
|
|
- $return_array['protocol'] = 'origin';
|
|
|
- $return_array['protocol_param'] = '';
|
|
|
- if ($return_array['net'] == 'obfs') {
|
|
|
- $return_array['obfs_param'] = $user->getMuMd5();
|
|
|
- } else {
|
|
|
- $return_array['obfs'] = 'v2ray';
|
|
|
- if ($return_array['tls'] == 'tls' && $return_array['net'] == 'ws') {
|
|
|
- $return_array['obfs_param'] = ('mode=ws;security=tls;path=' . $return_array['path'] .
|
|
|
- ';host=' . $return_array['host']);
|
|
|
- } else {
|
|
|
- $return_array['obfs_param'] = ('mode=ws;security=none;path=' . $return_array['path'] .
|
|
|
- ';host=' . $return_array['host']);
|
|
|
- }
|
|
|
- $return_array['path'] = ($return_array['path'] . '?redirect=' . $user->getMuMd5());
|
|
|
- }
|
|
|
- $return_array['class'] = $node->node_class;
|
|
|
- $return_array['group'] = $_ENV['appName'];
|
|
|
- $return_array['type'] = 'ss';
|
|
|
- $return_array['ratio'] = $node->traffic_rate;
|
|
|
-
|
|
|
- return $return_array;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取 V2Ray 节点
|
|
|
*
|
|
|
@@ -486,23 +443,6 @@ class URL
|
|
|
return $item;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取 V2Ray 节点
|
|
|
- *
|
|
|
- * @param User $user
|
|
|
- * @param Node $node
|
|
|
- * @param bool $emoji
|
|
|
- */
|
|
|
- public static function getV2RayItem(User $user, Node $node, bool $emoji = false): array
|
|
|
- {
|
|
|
- $item = Tools::v2Array($node->server);
|
|
|
- $item['type'] = 'vmess';
|
|
|
- $item['remark'] = ($emoji ? Tools::addEmoji($node->name) : $node->name);
|
|
|
- $item['id'] = $user->getUuid();
|
|
|
- $item['class'] = $node->node_class;
|
|
|
- return $item;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取全部 V2Ray 节点
|
|
|
*
|
|
|
@@ -563,7 +503,7 @@ class URL
|
|
|
$return_array = array();
|
|
|
$nodes = self::getNodes($user, 14);
|
|
|
foreach ($nodes as $node) {
|
|
|
- $item = self::getTrojanItem($user, $node, $emoji);
|
|
|
+ $item = $node->getTrojanItem($user, 0, 0, 0, $emoji);
|
|
|
if ($item != null) {
|
|
|
$return_array[] = $item;
|
|
|
}
|
|
|
@@ -572,33 +512,6 @@ class URL
|
|
|
return $return_array;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Trojan 节点
|
|
|
- *
|
|
|
- * @param User $user 用户
|
|
|
- * @param Node $node
|
|
|
- * @param bool $emoji
|
|
|
- */
|
|
|
- public static function getTrojanItem(User $user, Node $node, bool $emoji = false): array
|
|
|
- {
|
|
|
- $server = explode(';', $node->server);
|
|
|
- $opt = [];
|
|
|
- if (isset($server[1])) {
|
|
|
- $opt = self::parse_args($server[1]);
|
|
|
- }
|
|
|
- $item['remark'] = ($emoji ? Tools::addEmoji($node->name) : $node->name);
|
|
|
- $item['type'] = 'trojan';
|
|
|
- $item['address'] = $server[0];
|
|
|
- $item['port'] = (isset($opt['port']) ? (int) $opt['port'] : 443);
|
|
|
- $item['passwd'] = $user->getUuid();
|
|
|
- $item['host'] = $item['address'];
|
|
|
- if (isset($opt['host'])) {
|
|
|
- $item['host'] = $opt['address'];
|
|
|
- }
|
|
|
-
|
|
|
- return $item;
|
|
|
- }
|
|
|
-
|
|
|
public static function getJsonObfs(array $item): string
|
|
|
{
|
|
|
$ss_obfs_list = Config::getSupportParam('ss_obfs');
|
|
|
@@ -635,74 +548,6 @@ class URL
|
|
|
return $plugin;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * Conn info
|
|
|
- * address
|
|
|
- * port
|
|
|
- * passwd
|
|
|
- * method
|
|
|
- * remark
|
|
|
- * protocol
|
|
|
- * protocol_param
|
|
|
- * obfs
|
|
|
- * obfs_param
|
|
|
- */
|
|
|
- public static function getItem(User $user, Node $node, int $mu_port = 0, int $relay_rule_id = 0, int $is_ss = 0, bool $emoji = false):? array
|
|
|
- {
|
|
|
- $relay_rule = Relay::where('id', $relay_rule_id)->where(
|
|
|
- static function ($query) use ($user) {
|
|
|
- $query->Where('user_id', '=', $user->id)
|
|
|
- ->orWhere('user_id', '=', 0);
|
|
|
- }
|
|
|
- )->orderBy('priority', 'DESC')->orderBy('id')->first();
|
|
|
- $node_name = $node->name;
|
|
|
- if ($relay_rule != null) {
|
|
|
- $node_name .= ' - ' . $relay_rule->dist_node()->name;
|
|
|
- }
|
|
|
- if ($mu_port != 0) {
|
|
|
- $mu_user = User::where('port', '=', $mu_port)->where('is_multi_user', '<>', 0)->first();
|
|
|
- if ($mu_user == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- $mu_user->obfs_param = $user->getMuMd5();
|
|
|
- $mu_user->protocol_param = $user->id . ':' . $user->passwd;
|
|
|
- $user = $mu_user;
|
|
|
- $node_name .= ($_ENV['disable_sub_mu_port'] ? '' : ' - ' . $mu_port . ' 单端口');
|
|
|
- }
|
|
|
- if ($is_ss) {
|
|
|
- if (!self::SSCanConnect($user)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- $user = self::getSSConnectInfo($user);
|
|
|
- $return_array['type'] = 'ss';
|
|
|
- } else {
|
|
|
- if (!self::SSRCanConnect($user)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- $user = self::getSSRConnectInfo($user);
|
|
|
- $return_array['type'] = 'ssr';
|
|
|
- }
|
|
|
- $return_array['address'] = $node->getServer();
|
|
|
- $return_array['port'] = $user->port;
|
|
|
- $return_array['protocol'] = $user->protocol;
|
|
|
- $return_array['protocol_param'] = $user->protocol_param;
|
|
|
- $return_array['obfs'] = $user->obfs;
|
|
|
- $return_array['obfs_param'] = $user->obfs_param;
|
|
|
- if ($mu_port != 0 && strpos($node->server, ';') !== false) {
|
|
|
- $node_tmp = Tools::OutPort($node->server, $node->name, $mu_port);
|
|
|
- $return_array['port'] = $node_tmp['port'];
|
|
|
- $node_name = $node_tmp['name'];
|
|
|
- }
|
|
|
- $return_array['passwd'] = $user->passwd;
|
|
|
- $return_array['method'] = $user->method;
|
|
|
- $return_array['remark'] = ($emoji ? Tools::addEmoji($node_name) : $node_name);
|
|
|
- $return_array['class'] = $node->node_class;
|
|
|
- $return_array['group'] = $_ENV['appName'];
|
|
|
- $return_array['ratio'] = ($relay_rule != null ? $node->traffic_rate + $relay_rule->dist_node()->traffic_rate : $node->traffic_rate);
|
|
|
-
|
|
|
- return $return_array;
|
|
|
- }
|
|
|
-
|
|
|
public static function cloneUser(User $user): User
|
|
|
{
|
|
|
return clone $user;
|