Skip to content

Commit d62430a

Browse files
authored
Merge pull request #299 from karin0/external-controller
feat: support external controller and its override settings
2 parents fec7df0 + bacc753 commit d62430a

File tree

9 files changed

+60
-1
lines changed

9 files changed

+60
-1
lines changed

core/src/foss/golang/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/Kr328/tun2socket v0.0.0-20220414050025-d07c78d06d34 // indirect
1212
github.com/RyuaNerin/go-krypto v1.2.4 // indirect
1313
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
14+
github.com/ajg/form v1.5.1 // indirect
1415
github.com/andybalholm/brotli v1.0.6 // indirect
1516
github.com/bahlo/generic-list-go v0.2.0 // indirect
1617
github.com/buger/jsonparser v1.1.1 // indirect
@@ -23,6 +24,9 @@ require (
2324
github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 // indirect
2425
github.com/fsnotify/fsnotify v1.7.0 // indirect
2526
github.com/gaukas/godicttls v0.0.4 // indirect
27+
github.com/go-chi/chi/v5 v5.1.0 // indirect
28+
github.com/go-chi/cors v1.2.1 // indirect
29+
github.com/go-chi/render v1.0.3 // indirect
2630
github.com/go-ole/go-ole v1.3.0 // indirect
2731
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
2832
github.com/gobwas/httphead v0.1.0 // indirect

core/src/foss/golang/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/RyuaNerin/go-krypto v1.2.4 h1:mXuNdK6M317aPV0llW6Xpjbo4moOlPF7Yxz4tb4
77
github.com/RyuaNerin/go-krypto v1.2.4/go.mod h1:QqCYkoutU3yInyD9INt2PGolVRsc3W4oraQadVGXJ/8=
88
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 h1:cDVUiFo+npB0ZASqnw4q90ylaVAbnYyx0JYqK4YcGok=
99
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
10+
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
11+
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
1012
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
1113
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
1214
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
@@ -39,6 +41,12 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
3941
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
4042
github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
4143
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
44+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
45+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
46+
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
47+
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
48+
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
49+
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
4250
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
4351
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
4452
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=

core/src/main/golang/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/3andne/restls-client-go v0.1.6 // indirect
2121
github.com/RyuaNerin/go-krypto v1.2.4 // indirect
2222
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
23+
github.com/ajg/form v1.5.1 // indirect
2324
github.com/andybalholm/brotli v1.0.6 // indirect
2425
github.com/bahlo/generic-list-go v0.2.0 // indirect
2526
github.com/buger/jsonparser v1.1.1 // indirect
@@ -31,6 +32,9 @@ require (
3132
github.com/ericlagergren/subtle v0.0.0-20220507045147-890d697da010 // indirect
3233
github.com/fsnotify/fsnotify v1.7.0 // indirect
3334
github.com/gaukas/godicttls v0.0.4 // indirect
35+
github.com/go-chi/chi/v5 v5.1.0 // indirect
36+
github.com/go-chi/cors v1.2.1 // indirect
37+
github.com/go-chi/render v1.0.3 // indirect
3438
github.com/go-ole/go-ole v1.3.0 // indirect
3539
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
3640
github.com/gobwas/httphead v0.1.0 // indirect

core/src/main/golang/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/RyuaNerin/go-krypto v1.2.4 h1:mXuNdK6M317aPV0llW6Xpjbo4moOlPF7Yxz4tb4
77
github.com/RyuaNerin/go-krypto v1.2.4/go.mod h1:QqCYkoutU3yInyD9INt2PGolVRsc3W4oraQadVGXJ/8=
88
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 h1:cDVUiFo+npB0ZASqnw4q90ylaVAbnYyx0JYqK4YcGok=
99
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
10+
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
11+
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
1012
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
1113
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
1214
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
@@ -39,6 +41,12 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
3941
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
4042
github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
4143
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
44+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
45+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
46+
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
47+
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
48+
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
49+
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
4250
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
4351
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
4452
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=

core/src/main/golang/native/config/load.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/metacubex/mihomo/config"
1515
"github.com/metacubex/mihomo/hub/executor"
16+
"github.com/metacubex/mihomo/hub/route"
1617
)
1718

1819
func logDns(cfg *config.RawConfig) {
@@ -76,6 +77,17 @@ func Load(path string) error {
7677
return err
7778
}
7879

80+
// Start the external controller like in hub.Parse(), but we have set its
81+
// default override value to end with ":0" for security.
82+
//
83+
// It would be difficult to update configurations for external controller
84+
// inbound, so changes will require a restart after a profile is loaded.
85+
if cfg.Controller.ExternalController != "" && !strings.HasSuffix(cfg.Controller.ExternalController, ":0") {
86+
go route.Start(cfg.Controller.ExternalController, cfg.Controller.ExternalControllerTLS,
87+
cfg.Controller.Secret, cfg.TLS.Certificate, cfg.TLS.PrivateKey, cfg.Controller.ExternalDohServer,
88+
cfg.General.LogLevel == log.DEBUG)
89+
}
90+
7991
executor.ApplyConfig(cfg, true)
8092

8193
app.ApplySubtitlePattern(rawCfg.ClashForAndroid.UiSubtitlePattern)

core/src/main/golang/native/config/process.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func patchOverride(cfg *config.RawConfig, _ string) error {
4141
func patchGeneral(cfg *config.RawConfig, _ string) error {
4242
cfg.Interface = ""
4343
cfg.ExternalUI = ""
44-
cfg.ExternalController = ""
4544

4645
return nil
4746
}

core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ data class ConfigurationOverride(
4141
@SerialName("ipv6")
4242
var ipv6: Boolean? = null,
4343

44+
@SerialName("external-controller")
45+
var externalController: String? = "127.0.0.1:0",
46+
47+
@SerialName("secret")
48+
var secret: String? = null,
49+
4450
@SerialName("hosts")
4551
var hosts: Map<String, String>? = null,
4652

design/src/main/java/com/github/kr328/clash/design/OverrideSettingsDesign.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ class OverrideSettingsDesign(
185185
empty = R.string.default_
186186
)
187187

188+
editableText(
189+
value = configuration::externalController,
190+
adapter = NullableTextAdapter.String,
191+
title = R.string.external_controller,
192+
placeholder = R.string.dont_modify,
193+
empty = R.string.default_
194+
)
195+
196+
editableText(
197+
value = configuration::secret,
198+
adapter = NullableTextAdapter.String,
199+
title = R.string.secret,
200+
placeholder = R.string.dont_modify,
201+
empty = R.string.default_
202+
)
203+
188204
selectableList(
189205
value = configuration::mode,
190206
values = arrayOf(

design/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
<string name="mode">Mode</string>
145145
<string name="log_level">Log Level</string>
146146
<string name="ipv6">IPv6</string>
147+
<string name="external_controller">External Controller</string>
148+
<string name="secret">Secret</string>
147149
<string name="hosts">Hosts</string>
148150
<string name="sideload_geoip">Sideload GEOIP</string>
149151
<string name="sideload_geoip_summary">External GEOIP database</string>

0 commit comments

Comments
 (0)