feat: machine mode, ECH subscriptions, batch ops & security hardening

This commit is contained in:
xboard
2026-04-17 02:27:47 +08:00
parent edbd8de356
commit e297b5fe9f
25 changed files with 1564 additions and 343 deletions
+47
View File
@@ -207,6 +207,53 @@ class Helper
return Arr::random($fingerprints);
}
public static function normalizeEchSettings($ech = null): ?array
{
if (!is_array($ech) && !is_object($ech)) {
return null;
}
if (!data_get($ech, 'enabled')) {
return null;
}
return array_filter([
'enabled' => true,
'config' => self::trimToNull(data_get($ech, 'config')),
'query_server_name' => self::trimToNull(data_get($ech, 'query_server_name')),
'key' => self::trimToNull(data_get($ech, 'key')),
'key_path' => self::trimToNull(data_get($ech, 'key_path')),
'config_path' => self::trimToNull(data_get($ech, 'config_path')),
], static fn($value) => $value !== null);
}
public static function toMihomoEchConfig(?string $config): ?string
{
$config = self::trimToNull($config);
if (!$config) {
return null;
}
if (str_starts_with($config, '-----BEGIN')) {
if (preg_match('/-----BEGIN ECH CONFIGS-----\s*(.*?)\s*-----END ECH CONFIGS-----/s', $config, $matches)) {
return preg_replace('/\s+/', '', $matches[1]);
}
return null;
}
return preg_replace('/\s+/', '', $config);
}
public static function trimToNull($value): ?string
{
if (!is_string($value)) {
return null;
}
$value = trim($value);
return $value === '' ? null : $value;
}
public static function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);