mirror of
https://github.com/XZB-1248/Spark
synced 2025-10-12 19:30:41 +08:00
optimize: performance of front-end and back-end
optimize: security vulnerability
This commit is contained in:
@@ -7,13 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var AuthHandler gin.HandlerFunc
|
||||
|
||||
// InitRouter will initialize http and websocket routers.
|
||||
func InitRouter(ctx *gin.RouterGroup, auth gin.HandlerFunc) {
|
||||
func InitRouter(ctx *gin.RouterGroup) {
|
||||
ctx.Any(`/bridge/push`, bridgePush)
|
||||
ctx.Any(`/bridge/pull`, bridgePull)
|
||||
ctx.Any(`/device/terminal`, initTerminal) // Browser, handle websocket events for web terminal.
|
||||
ctx.Any(`/client/update`, checkUpdate) // Client, for update.
|
||||
group := ctx.Group(`/`, auth)
|
||||
ctx.Any(`/client/update`, checkUpdate) // Client, for update.
|
||||
group := ctx.Group(`/`, AuthHandler)
|
||||
{
|
||||
group.POST(`/device/screenshot/get`, getScreenshot)
|
||||
group.POST(`/device/process/list`, listDeviceProcesses)
|
||||
@@ -26,6 +27,7 @@ func InitRouter(ctx *gin.RouterGroup, auth gin.HandlerFunc) {
|
||||
group.POST(`/device/:act`, callDevice)
|
||||
group.POST(`/client/check`, checkClient)
|
||||
group.POST(`/client/generate`, generateClient)
|
||||
group.Any(`/device/terminal`, initTerminal) // Browser, handle websocket events for web terminal.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,16 +39,16 @@ func checkForm(ctx *gin.Context, form interface{}) (string, bool) {
|
||||
Device string `json:"device" yaml:"device" form:"device"`
|
||||
}
|
||||
if form != nil && ctx.ShouldBind(form) != nil {
|
||||
ctx.JSON(http.StatusBadRequest, modules.Packet{Code: -1, Msg: `${i18n|invalidParameter}`})
|
||||
ctx.AbortWithStatusJSON(http.StatusBadRequest, modules.Packet{Code: -1, Msg: `${i18n|invalidParameter}`})
|
||||
return ``, false
|
||||
}
|
||||
if ctx.ShouldBind(&base) != nil || (len(base.Conn) == 0 && len(base.Device) == 0) {
|
||||
ctx.JSON(http.StatusBadRequest, modules.Packet{Code: -1, Msg: `${i18n|invalidParameter}`})
|
||||
ctx.AbortWithStatusJSON(http.StatusBadRequest, modules.Packet{Code: -1, Msg: `${i18n|invalidParameter}`})
|
||||
return ``, false
|
||||
}
|
||||
connUUID, ok := common.CheckDevice(base.Device, base.Conn)
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusBadGateway, modules.Packet{Code: 1, Msg: `${i18n|deviceNotExists}`})
|
||||
ctx.AbortWithStatusJSON(http.StatusBadGateway, modules.Packet{Code: 1, Msg: `${i18n|deviceNotExists}`})
|
||||
return ``, false
|
||||
}
|
||||
return connUUID, true
|
||||
|
Reference in New Issue
Block a user