fix warp rules for xray

This commit is contained in:
mercury
2025-11-26 10:22:35 +04:00
parent 34f5f32a82
commit bc28be571b
+32 -12
View File
@@ -2921,32 +2921,52 @@ DNS-over-HTTPS with IP:
]; ];
} }
if (!empty($c['warplist']) && !empty(array_filter($c['warplist']))) { if (!empty($c['warplist']) && !empty(array_filter($c['warplist']))) {
$rules[] = [ $domains = array_keys(array_filter($c['warplist'], function ($v, $k){
"type" => "field",
"outboundTag" => "warp",
"domain" => array_keys(array_filter($c['warplist'], function ($v, $k){
if (!empty($v)) { if (!empty($v)) {
if (!preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) { if (!preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) {
return true; return true;
} }
} }
return false; return false;
}, ARRAY_FILTER_USE_BOTH)), }, ARRAY_FILTER_USE_BOTH));
]; if (!empty($domains)) {
$rules[] = [
"type" => "field",
"outboundTag" => "warp",
"domain" => array_keys(array_filter($c['warplist'], function ($v, $k){
if (!empty($v)) {
if (!preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) {
return true;
}
}
return false;
}, ARRAY_FILTER_USE_BOTH)),
];
}
} }
if (!empty($c['warplist']) && !empty(array_filter($c['warplist']))) { if (!empty($c['warplist']) && !empty(array_filter($c['warplist']))) {
$rules[] = [ $ips = array_keys(array_filter($c['warplist'], function ($v, $k){
"type" => "field",
"outboundTag" => "warp",
"ip" => array_keys(array_filter($c['warplist'], function ($v, $k){
if (!empty($v)) { if (!empty($v)) {
if (preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) { if (preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) {
return true; return true;
} }
} }
return false; return false;
}, ARRAY_FILTER_USE_BOTH)), }, ARRAY_FILTER_USE_BOTH));
]; if (!empty($ips)) {
$rules[] = [
"type" => "field",
"outboundTag" => "warp",
"ip" => array_keys(array_filter($c['warplist'], function ($v, $k){
if (!empty($v)) {
if (preg_match('~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2})?$~', $k)) {
return true;
}
}
return false;
}, ARRAY_FILTER_USE_BOTH)),
];
}
} }
$xr['routing']['rules'] = $rules ?: []; $xr['routing']['rules'] = $rules ?: [];
$this->restartXray($xr); $this->restartXray($xr);