add admin conf

This commit is contained in:
ljw
2024-11-11 22:26:15 +08:00
parent 15a518c1ac
commit 7bb2ce0a43
5 changed files with 102 additions and 1 deletions

View File

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

1
conf/hello.html Normal file
View File

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

View File

@@ -17,10 +17,15 @@ type App struct {
WebClient int `mapstructure:"web-client"`
Register bool `mapstructure:"register"`
}
type Admin struct {
Title string `mapstructure:"title"`
Hello string `mapstructure:"hello"`
HelloFile string `mapstructure:"hello-file"`
}
type Config struct {
Lang string `mapstructure:"lang"`
App App
Admin Admin
Gorm Gorm
Mysql Mysql
Gin Gin

View File

@@ -0,0 +1,79 @@
package admin
import (
"Gwen/global"
"Gwen/http/response"
"Gwen/service"
"github.com/gin-gonic/gin"
"os"
"strings"
)
type Config struct {
}
// ServerConfig RUSTDESK服务配置
// @Tags ADMIN
// @Summary RUSTDESK服务配置
// @Description 服务配置,给webclient提供api-server
// @Accept json
// @Produce json
// @Success 200 {object} response.Response
// @Failure 500 {object} response.Response
// @Router /admin/config/server [get]
// @Security token
func (co *Config) ServerConfig(c *gin.Context) {
cf := &response.ServerConfigResponse{
IdServer: global.Config.Rustdesk.IdServer,
Key: global.Config.Rustdesk.Key,
RelayServer: global.Config.Rustdesk.RelayServer,
ApiServer: global.Config.Rustdesk.ApiServer,
}
response.Success(c, cf)
}
// AppConfig APP服务配置
// @Tags ADMIN
// @Summary APP服务配置
// @Description APP服务配置
// @Accept json
// @Produce json
// @Success 200 {object} response.Response
// @Failure 500 {object} response.Response
// @Router /admin/config/app [get]
// @Security token
func (co *Config) AppConfig(c *gin.Context) {
response.Success(c, &gin.H{
"web_client": global.Config.App.WebClient,
})
}
// AdminConfig ADMIN服务配置
// @Tags ADMIN
// @Summary ADMIN服务配置
// @Description ADMIN服务配置
// @Accept json
// @Produce json
// @Success 200 {object} response.Response
// @Failure 500 {object} response.Response
// @Router /admin/config/admin [get]
// @Security token
func (co *Config) AdminConfig(c *gin.Context) {
u := service.AllService.UserService.CurUser(c)
hello := global.Config.Admin.Hello
helloFile := global.Config.Admin.HelloFile
if helloFile != "" {
b, err := os.ReadFile(helloFile)
if err == nil && len(b) > 0 {
hello = string(b)
}
}
//replace {{username}} to username
hello = strings.Replace(hello, "{{username}}", u.Username, -1)
response.Success(c, &gin.H{
"title": global.Config.Admin.Title,
"hello": hello,
})
}

View File

@@ -31,9 +31,14 @@ func Init(g *gin.Engine) {
AddressBookCollectionBind(adg)
AddressBookCollectionRuleBind(adg)
UserTokenBind(adg)
ConfigBind(adg)
//deprecated by ConfigBind
rs := &admin.Rustdesk{}
adg.GET("/server-config", rs.ServerConfig)
adg.GET("/app-config", rs.AppConfig)
//deprecated end
//访问静态文件
//g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/upload"))
}
@@ -188,6 +193,13 @@ func UserTokenBind(rg *gin.RouterGroup) {
aR.GET("/list", cont.List)
aR.POST("/delete", cont.Delete)
}
func ConfigBind(rg *gin.RouterGroup) {
aR := rg.Group("/config")
rs := &admin.Config{}
aR.GET("/server", rs.ServerConfig)
aR.GET("/app", rs.AppConfig)
aR.GET("/admin", rs.AdminConfig)
}
/*
func FileBind(rg *gin.RouterGroup) {