A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.8 KiB

  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. "strings"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/private"
  10. "code.gitea.io/gitea/modules/setting"
  11. "gitea.com/macaron/binding"
  12. "gitea.com/macaron/macaron"
  13. )
  14. // CheckInternalToken check internal token is set
  15. func CheckInternalToken(ctx *macaron.Context) {
  16. tokens := ctx.Req.Header.Get("Authorization")
  17. fields := strings.Fields(tokens)
  18. if len(fields) != 2 || fields[0] != "Bearer" || fields[1] != setting.InternalToken {
  19. log.Debug("Forbidden attempt to access internal url: Authorization header: %s", tokens)
  20. ctx.Error(403)
  21. }
  22. }
  23. // RegisterRoutes registers all internal APIs routes to web application.
  24. // These APIs will be invoked by internal commands for example `gitea serv` and etc.
  25. func RegisterRoutes(m *macaron.Macaron) {
  26. bind := binding.Bind
  27. m.Group("/", func() {
  28. m.Post("/ssh/authorized_keys", AuthorizedPublicKeyByContent)
  29. m.Post("/ssh/:id/update/:repoid", UpdatePublicKeyInRepo)
  30. m.Post("/hook/pre-receive/:owner/:repo", bind(private.HookOptions{}), HookPreReceive)
  31. m.Post("/hook/post-receive/:owner/:repo", bind(private.HookOptions{}), HookPostReceive)
  32. m.Post("/hook/set-default-branch/:owner/:repo/:branch", SetDefaultBranch)
  33. m.Get("/serv/none/:keyid", ServNoCommand)
  34. m.Get("/serv/command/:keyid/:owner/:repo", ServCommand)
  35. m.Post("/manager/shutdown", Shutdown)
  36. m.Post("/manager/restart", Restart)
  37. m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues)
  38. }, CheckInternalToken)
  39. }