update: add random port

This commit is contained in:
tokumeikoi 2022-02-17 02:44:49 +08:00
parent c8c96365ea
commit a1ada9183c
2 changed files with 15 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use App\Models\User;
use App\Models\ServerV2ray; use App\Models\ServerV2ray;
use App\Models\ServerTrojan; use App\Models\ServerTrojan;
use App\Utils\CacheKey; use App\Utils\CacheKey;
use App\Utils\Helper;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
class ServerService class ServerService
@ -34,6 +35,9 @@ class ServerService
} }
array_push($servers, $v2ray[$i]->toArray()); array_push($servers, $v2ray[$i]->toArray());
} }
if (strpos($v2ray[$i]['port'], '-') !== false) {
$v2ray[$i]['port'] = Helper::randomPort($v2ray[$i]['port']);
}
} }
@ -59,6 +63,9 @@ class ServerService
} }
array_push($servers, $trojan[$i]->toArray()); array_push($servers, $trojan[$i]->toArray());
} }
if (strpos($trojan[$i]['port'], '-') !== false) {
$trojan[$i]['port'] = Helper::randomPort($trojan[$i]['port']);
}
} }
return $servers; return $servers;
} }
@ -82,7 +89,9 @@ class ServerService
} }
array_push($servers, $shadowsocks[$i]->toArray()); array_push($servers, $shadowsocks[$i]->toArray());
} }
if (strpos($shadowsocks[$i]['port'], '-') !== false) {
$shadowsocks[$i]['port'] = Helper::randomPort($shadowsocks[$i]['port']);
}
} }
return $servers; return $servers;
} }

View File

@ -112,4 +112,9 @@ class Helper
} }
return $subscribeUrl; return $subscribeUrl;
} }
public static function randomPort($range) {
$portRange = explode('-', $range);
return rand($portRange[0], $portRange[1]);
}
} }