get command by uuid

This commit is contained in:
nicksherron 2020-02-09 19:30:26 -05:00
parent 9d2d414bee
commit 0cc8b84cc4
2 changed files with 34 additions and 2 deletions

View file

@ -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 {
t := time.Now().Unix()

View file

@ -25,6 +25,10 @@ type Query struct {
Uuid string `form:"uuid" json:"uuid" xml:"uuid"`
Command string `form:"command" json:"command" xml:"command"`
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 {
ID uint `form:"id" json:"id" xml:"id" gorm:"primary_key"`
@ -81,8 +85,8 @@ func Run() {
authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{
Realm: "bashhub-server zone",
Key: []byte(secret),
Timeout: 1000 * time.Hour,
MaxRefresh: 1000 * time.Hour,
Timeout: 10000 * time.Hour,
MaxRefresh: 10000 * time.Hour,
IdentityKey: "username",
LoginResponse: func(c *gin.Context, code int, token string, expire time.Time) {
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) {
var command Command
if err := c.ShouldBindJSON(&command); err != nil {