mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 12:07:28 +08:00
feat: machine mode, ECH subscriptions, batch ops & security hardening
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user