You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

internal.go 2.2 kB

3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. // Package private includes all internal routes. The package name internal is ideal but Golang is not allowed, so we use private as package name instead.
  5. package private
  6. import (
  7. "code.gitea.io/gitea/routers/repo"
  8. "strings"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/private"
  11. "code.gitea.io/gitea/modules/setting"
  12. "gitea.com/macaron/binding"
  13. "gitea.com/macaron/macaron"
  14. )
  15. // CheckInternalToken check internal token is set
  16. func CheckInternalToken(ctx *macaron.Context) {
  17. tokens := ctx.Req.Header.Get("Authorization")
  18. fields := strings.Fields(tokens)
  19. if len(fields) != 2 || fields[0] != "Bearer" || fields[1] != setting.InternalToken {
  20. log.Debug("Forbidden attempt to access internal url: Authorization header: %s", tokens)
  21. ctx.Error(403)
  22. }
  23. }
  24. // RegisterRoutes registers all internal APIs routes to web application.
  25. // These APIs will be invoked by internal commands for example `gitea serv` and etc.
  26. func RegisterRoutes(m *macaron.Macaron) {
  27. bind := binding.Bind
  28. m.Group("/", func() {
  29. m.Post("/ssh/authorized_keys", AuthorizedPublicKeyByContent)
  30. m.Post("/ssh/:id/update/:repoid", UpdatePublicKeyInRepo)
  31. m.Post("/hook/pre-receive/:owner/:repo", bind(private.HookOptions{}), HookPreReceive)
  32. m.Post("/hook/post-receive/:owner/:repo", bind(private.HookOptions{}), HookPostReceive)
  33. m.Post("/hook/set-default-branch/:owner/:repo/:branch", SetDefaultBranch)
  34. m.Get("/hook/env/:owner/:repo", HookEnv)
  35. m.Get("/serv/none/:keyid", ServNoCommand)
  36. m.Get("/serv/command/:keyid/:owner/:repo", ServCommand)
  37. m.Post("/manager/shutdown", Shutdown)
  38. m.Post("/manager/restart", Restart)
  39. m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues)
  40. m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt)
  41. m.Post("/tool/repo_stat/:date", RepoStatisticManually)
  42. m.Get("/tool/org_stat", OrgStatisticManually)
  43. m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit)
  44. m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration)
  45. }, CheckInternalToken)
  46. }