config.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/service"
  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. if u == nil || u.Id == 0 {
  59. response.Success(c, &gin.H{
  60. "title": global.Config.Admin.Title,
  61. })
  62. return
  63. }
  64. hello := global.Config.Admin.Hello
  65. helloFile := global.Config.Admin.HelloFile
  66. if helloFile != "" {
  67. b, err := os.ReadFile(helloFile)
  68. if err == nil && len(b) > 0 {
  69. hello = string(b)
  70. }
  71. }
  72. //replace {{username}} to username
  73. hello = strings.Replace(hello, "{{username}}", u.Username, -1)
  74. response.Success(c, &gin.H{
  75. "title": global.Config.Admin.Title,
  76. "hello": hello,
  77. })
  78. }