From 0e867b1a1f91fe6be2b0b6a995a542d3680b1be4 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 30 Sep 2024 12:25:06 +0800 Subject: [PATCH] adopt `external-controller-cors` and must set it in ConfigurationOverride not config.yaml --- core/src/main/golang/native/config/process.go | 2 ++ .../clash/core/model/ConfigurationOverride.kt | 12 ++++++++++++ .../kr328/clash/design/OverrideSettingsDesign.kt | 14 ++++++++++++++ design/src/main/res/values/strings.xml | 2 ++ 4 files changed, 30 insertions(+) diff --git a/core/src/main/golang/native/config/process.go b/core/src/main/golang/native/config/process.go index 9c9869619..4e3fe4a13 100644 --- a/core/src/main/golang/native/config/process.go +++ b/core/src/main/golang/native/config/process.go @@ -44,6 +44,8 @@ func patchOverride(cfg *config.RawConfig, _ string) error { func patchExternalController(cfg *config.RawConfig, _ string) error { cfg.ExternalController = "" cfg.ExternalControllerTLS = "" + cfg.ExternalControllerCors.AllowOrigins = []string{} + cfg.ExternalControllerCors.AllowPrivateNetwork = false return nil } diff --git a/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt b/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt index bceef3f29..3587a1d87 100644 --- a/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt +++ b/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt @@ -47,6 +47,9 @@ data class ConfigurationOverride( @SerialName("external-controller-tls") var externalControllerTLS: String? = null, + @SerialName("external-controller-cors") + var externalControllerCors: ExternalControllerCors = ExternalControllerCors(), + @SerialName("secret") var secret: String? = null, @@ -210,6 +213,15 @@ data class ConfigurationOverride( var geosite: String? = null, ) + @Serializable + data class ExternalControllerCors( + @SerialName("allow-origins") + var allowOrigins: List? = null, + + @SerialName("allow-private-network") + var allowPrivateNetwork: Boolean? = null, + ) + override fun writeToParcel(parcel: Parcel, flags: Int) { Parcelizer.encodeToParcel(serializer(), parcel, this) } diff --git a/design/src/main/java/com/github/kr328/clash/design/OverrideSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/OverrideSettingsDesign.kt index 1b91ce4aa..e35944ca4 100644 --- a/design/src/main/java/com/github/kr328/clash/design/OverrideSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/OverrideSettingsDesign.kt @@ -157,6 +157,20 @@ class OverrideSettingsDesign( empty = R.string.default_ ) + editableTextList( + value = configuration.externalControllerCors::allowOrigins, + adapter = TextAdapter.String, + title = R.string.allow_origins, + placeholder = R.string.dont_modify, + ) + + selectableList( + value = configuration.externalControllerCors::allowPrivateNetwork, + values = booleanValues, + valuesText = booleanValuesText, + title = R.string.allow_private_network, + ) + editableText( value = configuration::secret, adapter = NullableTextAdapter.String, diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml index 783d980f6..622adbb94 100644 --- a/design/src/main/res/values/strings.xml +++ b/design/src/main/res/values/strings.xml @@ -150,6 +150,8 @@ IPv6 External Controller External Controller TLS + External Controller Allow Origins + External Controller Allow Private Network Secret Hosts New