ljw 1 год назад
Родитель
Сommit
7bb2ce0a43
5 измененных файлов с 102 добавлено и 1 удалено
  1. 4 0
      conf/config.yaml
  2. 1 0
      conf/hello.html
  3. 6 1
      config/config.go
  4. 79 0
      http/controller/admin/config.go
  5. 12 0
      http/router/admin.go

+ 4 - 0
conf/config.yaml

@@ -2,6 +2,10 @@ lang: "zh-CN"
2 2
 app:
3 3
   web-client: 1  # 1:启用 0:禁用
4 4
   register: false #是否开启注册
5
+admin:
6
+  title: "RustDesk Api Admin"
7
+  hello-file: "./conf/hello.html"  #优先使用file
8
+  hello: "👏 你好 <strong>{{username}}</strong>, 欢迎使用 RustDesk Api Admin。 <a href='https://github.com/lejianwen/rustdesk-api' target='_blank'>Github</a>"
5 9
 gin:
6 10
   api-addr: "0.0.0.0:21114"
7 11
   mode: "release" #release,debug,test

+ 1 - 0
conf/hello.html

@@ -0,0 +1 @@
1
+👏👏👏 你好 <strong>{{username}}</strong>, 欢迎使用 RustDesk Api Admin。 <a href='https://github.com/lejianwen/rustdesk-api' target='_blank'>Github</a>

+ 6 - 1
config/config.go

@@ -17,10 +17,15 @@ type App struct {
17 17
 	WebClient int  `mapstructure:"web-client"`
18 18
 	Register  bool `mapstructure:"register"`
19 19
 }
20
-
20
+type Admin struct {
21
+	Title     string `mapstructure:"title"`
22
+	Hello     string `mapstructure:"hello"`
23
+	HelloFile string `mapstructure:"hello-file"`
24
+}
21 25
 type Config struct {
22 26
 	Lang     string `mapstructure:"lang"`
23 27
 	App      App
28
+	Admin    Admin
24 29
 	Gorm     Gorm
25 30
 	Mysql    Mysql
26 31
 	Gin      Gin

+ 79 - 0
http/controller/admin/config.go

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

+ 12 - 0
http/router/admin.go

@@ -31,9 +31,14 @@ func Init(g *gin.Engine) {
31 31
 	AddressBookCollectionBind(adg)
32 32
 	AddressBookCollectionRuleBind(adg)
33 33
 	UserTokenBind(adg)
34
+	ConfigBind(adg)
35
+
36
+	//deprecated by ConfigBind
34 37
 	rs := &admin.Rustdesk{}
35 38
 	adg.GET("/server-config", rs.ServerConfig)
36 39
 	adg.GET("/app-config", rs.AppConfig)
40
+	//deprecated end
41
+
37 42
 	//访问静态文件
38 43
 	//g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/upload"))
39 44
 }
@@ -188,6 +193,13 @@ func UserTokenBind(rg *gin.RouterGroup) {
188 193
 	aR.GET("/list", cont.List)
189 194
 	aR.POST("/delete", cont.Delete)
190 195
 }
196
+func ConfigBind(rg *gin.RouterGroup) {
197
+	aR := rg.Group("/config")
198
+	rs := &admin.Config{}
199
+	aR.GET("/server", rs.ServerConfig)
200
+	aR.GET("/app", rs.AppConfig)
201
+	aR.GET("/admin", rs.AdminConfig)
202
+}
191 203
 
192 204
 /*
193 205
 func FileBind(rg *gin.RouterGroup) {