config.go 2.3 KB

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