Files

325 lines
8.7 KiB
Go
Raw Permalink Normal View History

2024-09-13 15:57:29 +08:00
package router
import (
"github.com/gin-gonic/gin"
2025-02-12 19:46:39 +08:00
_ "github.com/lejianwen/rustdesk-api/v2/docs/admin"
"github.com/lejianwen/rustdesk-api/v2/global"
"github.com/lejianwen/rustdesk-api/v2/http/controller/admin"
"github.com/lejianwen/rustdesk-api/v2/http/controller/admin/my"
"github.com/lejianwen/rustdesk-api/v2/http/middleware"
2024-09-13 15:57:29 +08:00
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
func Init(g *gin.Engine) {
//swagger
//g.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
2024-12-18 12:50:09 +08:00
if global.Config.App.ShowSwagger == 1 {
g.GET("/admin/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.InstanceName("admin")))
}
2024-09-13 15:57:29 +08:00
adg := g.Group("/api/admin")
LoginBind(adg)
2024-10-31 15:14:30 +08:00
adg.POST("/user/register", (&admin.User{}).Register)
2025-02-12 21:10:07 +08:00
ConfigBind(adg)
2025-02-12 22:09:52 +08:00
adg.Use(middleware.BackendUserAuth())
2024-09-13 15:57:29 +08:00
//FileBind(adg)
UserBind(adg)
GroupBind(adg)
TagBind(adg)
AddressBookBind(adg)
PeerBind(adg)
2024-09-19 10:44:49 +08:00
OauthBind(adg)
LoginLogBind(adg)
2024-10-18 15:05:58 +08:00
AuditBind(adg)
2024-10-28 14:19:30 +08:00
AddressBookCollectionBind(adg)
AddressBookCollectionRuleBind(adg)
2024-10-31 22:29:12 +08:00
UserTokenBind(adg)
2024-11-11 22:26:15 +08:00
//deprecated by ConfigBind
2024-12-13 12:32:36 +08:00
//rs := &admin.Rustdesk{}
//adg.GET("/server-config", rs.ServerConfig)
//adg.GET("/app-config", rs.AppConfig)
2024-11-11 22:26:15 +08:00
//deprecated end
2024-12-13 12:32:36 +08:00
ShareRecordBind(adg)
MyBind(adg)
2024-12-31 23:16:15 +08:00
RustdeskCmdBind(adg)
2025-02-23 21:35:42 +08:00
DeviceGroupBind(adg)
2024-09-13 15:57:29 +08:00
//访问静态文件
//g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/upload"))
}
2024-12-31 23:16:15 +08:00
func RustdeskCmdBind(adg *gin.RouterGroup) {
cont := &admin.Rustdesk{}
rg := adg.Group("/rustdesk")
rg.POST("/sendCmd", cont.SendCmd)
rg.GET("/cmdList", cont.CmdList)
rg.POST("/cmdDelete", cont.CmdDelete)
rg.POST("/cmdCreate", cont.CmdCreate)
}
2024-09-13 15:57:29 +08:00
func LoginBind(rg *gin.RouterGroup) {
cont := &admin.Login{}
rg.POST("/login", cont.Login)
2024-12-18 12:43:55 +08:00
rg.GET("/captcha", cont.Captcha)
2024-09-13 15:57:29 +08:00
rg.POST("/logout", cont.Logout)
2024-10-31 09:21:30 +08:00
rg.GET("/login-options", cont.LoginOptions)
rg.POST("/oidc/auth", cont.OidcAuth)
rg.GET("/oidc/auth-query", cont.OidcAuthQuery)
2024-09-13 15:57:29 +08:00
}
func UserBind(rg *gin.RouterGroup) {
aR := rg.Group("/user")
{
cont := &admin.User{}
aR.GET("/current", cont.Current)
aR.POST("/changeCurPwd", cont.ChangeCurPwd)
2024-09-19 10:44:49 +08:00
aR.POST("/myOauth", cont.MyOauth)
2024-12-17 21:41:56 +08:00
//aR.GET("/myPeer", cont.MyPeer)
2024-10-28 14:19:30 +08:00
aR.POST("/groupUsers", cont.GroupUsers)
2024-09-13 15:57:29 +08:00
}
aRP := rg.Group("/user").Use(middleware.AdminPrivilege())
{
cont := &admin.User{}
aRP.GET("/list", cont.List)
aRP.GET("/detail/:id", cont.Detail)
aRP.POST("/create", cont.Create)
aRP.POST("/update", cont.Update)
aRP.POST("/delete", cont.Delete)
aRP.POST("/changePwd", cont.UpdatePassword)
}
}
func GroupBind(rg *gin.RouterGroup) {
aR := rg.Group("/group").Use(middleware.AdminPrivilege())
{
cont := &admin.Group{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
}
}
2025-02-23 21:35:42 +08:00
func DeviceGroupBind(rg *gin.RouterGroup) {
aR := rg.Group("/device_group").Use(middleware.AdminPrivilege())
{
cont := &admin.DeviceGroup{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
}
}
2024-09-13 15:57:29 +08:00
func TagBind(rg *gin.RouterGroup) {
2024-12-17 21:41:56 +08:00
aR := rg.Group("/tag").Use(middleware.AdminPrivilege())
2024-09-13 15:57:29 +08:00
{
cont := &admin.Tag{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
}
}
func AddressBookBind(rg *gin.RouterGroup) {
aR := rg.Group("/address_book")
{
cont := &admin.AddressBook{}
aR.POST("/shareByWebClient", cont.ShareByWebClient)
2024-12-13 16:27:12 +08:00
2024-09-29 11:53:58 +08:00
arp := aR.Use(middleware.AdminPrivilege())
2024-12-17 21:41:56 +08:00
arp.GET("/list", cont.List)
//arp.GET("/detail/:id", cont.Detail)
arp.POST("/create", cont.Create)
arp.POST("/update", cont.Update)
arp.POST("/delete", cont.Delete)
2024-09-29 11:53:58 +08:00
arp.POST("/batchCreate", cont.BatchCreate)
2024-12-13 16:27:12 +08:00
arp.POST("/batchCreateFromPeers", cont.BatchCreateFromPeers)
2024-12-06 19:45:41 +08:00
2024-09-13 15:57:29 +08:00
}
}
func PeerBind(rg *gin.RouterGroup) {
aR := rg.Group("/peer")
2024-11-02 18:49:16 +08:00
aR.POST("/simpleData", (&admin.Peer{}).SimpleData)
aR.Use(middleware.AdminPrivilege())
2024-09-13 15:57:29 +08:00
{
cont := &admin.Peer{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
2024-11-02 18:49:16 +08:00
aR.POST("/batchDelete", cont.BatchDelete)
2024-09-13 15:57:29 +08:00
}
}
2024-09-19 10:44:49 +08:00
func OauthBind(rg *gin.RouterGroup) {
aR := rg.Group("/oauth")
{
cont := &admin.Oauth{}
aR.POST("/confirm", cont.Confirm)
aR.POST("/bind", cont.ToBind)
aR.POST("/bindConfirm", cont.BindConfirm)
aR.POST("/unbind", cont.Unbind)
aR.GET("/info", cont.Info)
}
arp := aR.Use(middleware.AdminPrivilege())
{
cont := &admin.Oauth{}
arp.GET("/list", cont.List)
arp.GET("/detail/:id", cont.Detail)
arp.POST("/create", cont.Create)
arp.POST("/update", cont.Update)
arp.POST("/delete", cont.Delete)
}
}
func LoginLogBind(rg *gin.RouterGroup) {
cont := &admin.LoginLog{}
2024-12-27 19:25:59 +08:00
aR := rg.Group("/login_log").Use(middleware.AdminPrivilege())
2024-09-19 10:44:49 +08:00
aR.GET("/list", cont.List)
aR.POST("/delete", cont.Delete)
2024-11-12 09:08:10 +08:00
aR.POST("/batchDelete", cont.BatchDelete)
2024-09-19 10:44:49 +08:00
}
2024-10-18 15:05:58 +08:00
func AuditBind(rg *gin.RouterGroup) {
cont := &admin.Audit{}
aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege())
aR.GET("/list", cont.ConnList)
aR.POST("/delete", cont.ConnDelete)
2024-11-12 09:08:10 +08:00
aR.POST("/batchDelete", cont.BatchConnDelete)
2024-10-21 21:08:25 +08:00
afR := rg.Group("/audit_file").Use(middleware.AdminPrivilege())
afR.GET("/list", cont.FileList)
afR.POST("/delete", cont.FileDelete)
2024-11-12 09:08:10 +08:00
afR.POST("/batchDelete", cont.BatchFileDelete)
2024-10-18 15:05:58 +08:00
}
2024-10-28 14:19:30 +08:00
func AddressBookCollectionBind(rg *gin.RouterGroup) {
2024-12-17 21:41:56 +08:00
aR := rg.Group("/address_book_collection").Use(middleware.AdminPrivilege())
2024-10-28 14:19:30 +08:00
{
cont := &admin.AddressBookCollection{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
}
}
func AddressBookCollectionRuleBind(rg *gin.RouterGroup) {
2024-12-17 21:41:56 +08:00
aR := rg.Group("/address_book_collection_rule").Use(middleware.AdminPrivilege())
2024-10-28 14:19:30 +08:00
{
cont := &admin.AddressBookCollectionRule{}
aR.GET("/list", cont.List)
aR.GET("/detail/:id", cont.Detail)
aR.POST("/create", cont.Create)
aR.POST("/update", cont.Update)
aR.POST("/delete", cont.Delete)
}
}
2024-10-31 22:29:12 +08:00
func UserTokenBind(rg *gin.RouterGroup) {
aR := rg.Group("/user_token").Use(middleware.AdminPrivilege())
cont := &admin.UserToken{}
aR.GET("/list", cont.List)
aR.POST("/delete", cont.Delete)
2024-12-06 10:36:27 +08:00
aR.POST("/batchDelete", cont.BatchDelete)
2024-10-31 22:29:12 +08:00
}
2024-11-11 22:26:15 +08:00
func ConfigBind(rg *gin.RouterGroup) {
aR := rg.Group("/config")
rs := &admin.Config{}
2025-02-12 21:10:07 +08:00
aR.GET("/admin", rs.AdminConfig)
2025-02-12 22:09:52 +08:00
aR.Use(middleware.BackendUserAuth())
2024-11-11 22:26:15 +08:00
aR.GET("/server", rs.ServerConfig)
aR.GET("/app", rs.AppConfig)
2025-02-12 21:10:07 +08:00
2024-11-11 22:26:15 +08:00
}
2024-09-19 10:44:49 +08:00
2024-09-13 15:57:29 +08:00
/*
func FileBind(rg *gin.RouterGroup) {
aR := rg.Group("/file")
{
cont := &admin.File{}
aR.POST("/notify", cont.Notify)
aR.OPTIONS("/oss_token", nil)
aR.OPTIONS("/upload", nil)
aR.GET("/oss_token", cont.OssToken)
aR.POST("/upload", cont.Upload)
}
}*/
2024-12-13 12:32:36 +08:00
func MyBind(rg *gin.RouterGroup) {
{
2024-12-17 21:41:56 +08:00
cont := &my.ShareRecord{}
rg.GET("/my/share_record/list", cont.List)
rg.POST("/my/share_record/delete", cont.Delete)
rg.POST("/my/share_record/batchDelete", cont.BatchDelete)
}
{
cont := &my.AddressBook{}
rg.GET("/my/address_book/list", cont.List)
rg.POST("/my/address_book/create", cont.Create)
rg.POST("/my/address_book/update", cont.Update)
rg.POST("/my/address_book/delete", cont.Delete)
rg.POST("/my/address_book/batchCreateFromPeers", cont.BatchCreateFromPeers)
rg.POST("/my/address_book/batchUpdateTags", cont.BatchUpdateTags)
}
{
cont := &my.Tag{}
rg.GET("/my/tag/list", cont.List)
rg.POST("/my/tag/create", cont.Create)
rg.POST("/my/tag/update", cont.Update)
rg.POST("/my/tag/delete", cont.Delete)
}
{
cont := &my.AddressBookCollection{}
rg.GET("/my/address_book_collection/list", cont.List)
rg.POST("/my/address_book_collection/create", cont.Create)
rg.POST("/my/address_book_collection/update", cont.Update)
rg.POST("/my/address_book_collection/delete", cont.Delete)
}
{
cont := &my.AddressBookCollectionRule{}
rg.GET("/my/address_book_collection_rule/list", cont.List)
rg.POST("/my/address_book_collection_rule/create", cont.Create)
rg.POST("/my/address_book_collection_rule/update", cont.Update)
rg.POST("/my/address_book_collection_rule/delete", cont.Delete)
}
{
cont := &my.Peer{}
rg.GET("/my/peer/list", cont.List)
2024-12-13 16:27:12 +08:00
2024-12-13 12:32:36 +08:00
}
2024-12-27 19:25:59 +08:00
{
cont := &my.LoginLog{}
rg.GET("/my/login_log/list", cont.List)
rg.POST("/my/login_log/delete", cont.Delete)
rg.POST("/my/login_log/batchDelete", cont.BatchDelete)
}
2024-12-13 12:32:36 +08:00
}
func ShareRecordBind(rg *gin.RouterGroup) {
aR := rg.Group("/share_record").Use(middleware.AdminPrivilege())
{
cont := &admin.ShareRecord{}
aR.GET("/list", cont.List)
aR.POST("/delete", cont.Delete)
aR.POST("/batchDelete", cont.BatchDelete)
}
}