config.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package admin
  2. import (
  3. "Gwen/global"
  4. "Gwen/http/response"
  5. "Gwen/service"
  6. "github.com/gin-gonic/gin"
  7. "os"
  8. "strings"
  9. )
  10. type Config struct {
  11. }
  12. // ServerConfig RUSTDESK服务配置
  13. // @Tags ADMIN
  14. // @Summary RUSTDESK服务配置
  15. // @Description 服务配置,给webclient提供api-server
  16. // @Accept json
  17. // @Produce json
  18. // @Success 200 {object} response.Response
  19. // @Failure 500 {object} response.Response
  20. // @Router /admin/config/server [get]
  21. // @Security token
  22. func (co *Config) ServerConfig(c *gin.Context) {
  23. cf := &response.ServerConfigResponse{
  24. IdServer: global.Config.Rustdesk.IdServer,
  25. Key: global.Config.Rustdesk.Key,
  26. RelayServer: global.Config.Rustdesk.RelayServer,
  27. ApiServer: global.Config.Rustdesk.ApiServer,
  28. }
  29. response.Success(c, cf)
  30. }
  31. // AppConfig APP服务配置
  32. // @Tags ADMIN
  33. // @Summary APP服务配置
  34. // @Description APP服务配置
  35. // @Accept json
  36. // @Produce json
  37. // @Success 200 {object} response.Response
  38. // @Failure 500 {object} response.Response
  39. // @Router /admin/config/app [get]
  40. // @Security token
  41. func (co *Config) AppConfig(c *gin.Context) {
  42. response.Success(c, &gin.H{
  43. "web_client": global.Config.App.WebClient,
  44. })
  45. }
  46. // AdminConfig ADMIN服务配置
  47. // @Tags ADMIN
  48. // @Summary ADMIN服务配置
  49. // @Description ADMIN服务配置
  50. // @Accept json
  51. // @Produce json
  52. // @Success 200 {object} response.Response
  53. // @Failure 500 {object} response.Response
  54. // @Router /admin/config/admin [get]
  55. // @Security token
  56. func (co *Config) AdminConfig(c *gin.Context) {
  57. u := service.AllService.UserService.CurUser(c)
  58. hello := global.Config.Admin.Hello
  59. helloFile := global.Config.Admin.HelloFile
  60. if helloFile != "" {
  61. b, err := os.ReadFile(helloFile)
  62. if err == nil && len(b) > 0 {
  63. hello = string(b)
  64. }
  65. }
  66. //replace {{username}} to username
  67. hello = strings.Replace(hello, "{{username}}", u.Username, -1)
  68. response.Success(c, &gin.H{
  69. "title": global.Config.Admin.Title,
  70. "hello": hello,
  71. })
  72. }