mirror of
https://github.com/nicksherron/bashhub-server.git
synced 2025-01-04 06:13:06 +08:00
get command by uuid
This commit is contained in:
parent
9d2d414bee
commit
0cc8b84cc4
2 changed files with 34 additions and 2 deletions
|
@ -433,6 +433,20 @@ func (cmd Command) commandGet() []Query {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cmd Command) commandGetUUID() Query {
|
||||||
|
var result Query
|
||||||
|
err := DB.QueryRow(`SELECT "command","path", "created" , "uuid", "exit_status", "system_name"
|
||||||
|
FROM commands
|
||||||
|
WHERE "uuid" = $1
|
||||||
|
AND "user_id" = $2`, cmd.Uuid, cmd.User.ID).Scan(
|
||||||
|
&result.Command, &result.Path, &result.Created, &result.Uuid,
|
||||||
|
&result.ExitStatus, &result.SystemName)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func (sys System) systemInsert() int64 {
|
func (sys System) systemInsert() int64 {
|
||||||
|
|
||||||
t := time.Now().Unix()
|
t := time.Now().Unix()
|
||||||
|
|
|
@ -25,6 +25,10 @@ type Query struct {
|
||||||
Uuid string `form:"uuid" json:"uuid" xml:"uuid"`
|
Uuid string `form:"uuid" json:"uuid" xml:"uuid"`
|
||||||
Command string `form:"command" json:"command" xml:"command"`
|
Command string `form:"command" json:"command" xml:"command"`
|
||||||
Created int64 `form:"created" json:"created" xml:"created"`
|
Created int64 `form:"created" json:"created" xml:"created"`
|
||||||
|
Path string `form:"path" json:"path" xml:"path"`
|
||||||
|
ExitStatus int `form:"exitStatus" json:"exitStatus" xml:"exitStatus"`
|
||||||
|
Username string `form:"username" json:"username" xml:"username"`
|
||||||
|
SystemName string `gorm:"-" json:"systemName" `
|
||||||
}
|
}
|
||||||
type SystemQuery struct {
|
type SystemQuery struct {
|
||||||
ID uint `form:"id" json:"id" xml:"id" gorm:"primary_key"`
|
ID uint `form:"id" json:"id" xml:"id" gorm:"primary_key"`
|
||||||
|
@ -81,8 +85,8 @@ func Run() {
|
||||||
authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{
|
authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{
|
||||||
Realm: "bashhub-server zone",
|
Realm: "bashhub-server zone",
|
||||||
Key: []byte(secret),
|
Key: []byte(secret),
|
||||||
Timeout: 1000 * time.Hour,
|
Timeout: 10000 * time.Hour,
|
||||||
MaxRefresh: 1000 * time.Hour,
|
MaxRefresh: 10000 * time.Hour,
|
||||||
IdentityKey: "username",
|
IdentityKey: "username",
|
||||||
LoginResponse: func(c *gin.Context, code int, token string, expire time.Time) {
|
LoginResponse: func(c *gin.Context, code int, token string, expire time.Time) {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
@ -208,6 +212,20 @@ func Run() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
r.GET("/api/v1/command/:uuid", func(c *gin.Context) {
|
||||||
|
var command Command
|
||||||
|
command.Uuid = c.Param("uuid")
|
||||||
|
var user User
|
||||||
|
claims := jwt.ExtractClaims(c)
|
||||||
|
user.Username = claims["username"].(string)
|
||||||
|
command.User.ID = user.userGetId()
|
||||||
|
result := command.commandGetUUID()
|
||||||
|
result.Username = user.Username
|
||||||
|
|
||||||
|
c.IndentedJSON(http.StatusOK, result)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
r.POST("/api/v1/command", func(c *gin.Context) {
|
r.POST("/api/v1/command", func(c *gin.Context) {
|
||||||
var command Command
|
var command Command
|
||||||
if err := c.ShouldBindJSON(&command); err != nil {
|
if err := c.ShouldBindJSON(&command); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue