Skip to content

Commit

Permalink
chore: disallow some restful api for CMFA
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Sep 30, 2024
1 parent fc9d5cf commit a330fa1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
8 changes: 5 additions & 3 deletions hub/route/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
func configRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getConfigs)
r.Put("/", updateConfigs)
r.Post("/geo", updateGeoDatabases)
r.Patch("/", patchConfigs)
if !embedMode { // disallow update/patch configs in embed mode
r.Put("/", updateConfigs)
r.Post("/geo", updateGeoDatabases)
r.Patch("/", patchConfigs)
}
return r
}

Expand Down
2 changes: 1 addition & 1 deletion hub/route/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/metacubex/mihomo/tunnel"
)

func GroupRouter() http.Handler {
func groupRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getGroups)

Expand Down
7 changes: 7 additions & 0 deletions hub/route/patch_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build android && cmfa

package route

func init() {
SetEmbedMode(true) // set embed mode default
}
14 changes: 11 additions & 3 deletions hub/route/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ var (
tlsServer *http.Server
unixServer *http.Server
pipeServer *http.Server

embedMode = false
)

func SetEmbedMode(embed bool) {
embedMode = embed
}

type Traffic struct {
Up int64 `json:"up"`
Down int64 `json:"down"`
Expand Down Expand Up @@ -114,15 +120,17 @@ func router(isDebug bool, secret string, dohServer string, cors Cors) *chi.Mux {
r.Get("/version", version)
r.Mount("/configs", configRouter())
r.Mount("/proxies", proxyRouter())
r.Mount("/group", GroupRouter())
r.Mount("/group", groupRouter())
r.Mount("/rules", ruleRouter())
r.Mount("/connections", connectionRouter())
r.Mount("/providers/proxies", proxyProviderRouter())
r.Mount("/providers/rules", ruleProviderRouter())
r.Mount("/cache", cacheRouter())
r.Mount("/dns", dnsRouter())
r.Mount("/restart", restartRouter())
r.Mount("/upgrade", upgradeRouter())
if !embedMode { // disallow restart and upgrade in embed mode
r.Mount("/restart", restartRouter())
r.Mount("/upgrade", upgradeRouter())
}
addExternalRouters(r)

})
Expand Down

0 comments on commit a330fa1

Please sign in to comment.