增加全局VNC与TELNET设置

This commit is contained in:
dushixiang
2021-02-10 21:56:05 +08:00
committed by dushixiang
parent 622fa65241
commit 25c3c6b929
11 changed files with 783 additions and 765 deletions

View File

@ -1,6 +1,7 @@
package api
import (
"encoding/json"
"errors"
"github.com/labstack/echo/v4"
"next-terminal/pkg/model"
@ -68,10 +69,17 @@ func AssetUpdateEndpoint(c echo.Context) error {
return err
}
var item model.Asset
if err := c.Bind(&item); err != nil {
m := echo.Map{}
if err := c.Bind(&m); err != nil {
return err
}
data, _ := json.Marshal(m)
var item model.Asset
if err := json.Unmarshal(data, &item); err != nil {
return err
}
switch item.AccountType {
case "credential":
item.Username = "-"
@ -102,6 +110,9 @@ func AssetUpdateEndpoint(c echo.Context) error {
}
model.UpdateAssetById(&item, id)
if err := model.UpdateAssetAttributes(id, item.Protocol, m); err != nil {
return err
}
return Success(c, nil)
}
@ -151,8 +162,16 @@ func AssetGetEndpoint(c echo.Context) (err error) {
if item, err = model.FindAssetById(id); err != nil {
return err
}
attributeMap, err := model.FindAssetAttrMapByAssetId(id)
if err != nil {
return err
}
itemMap := utils.StructToMap(item)
for key := range attributeMap {
itemMap[key] = attributeMap[key]
}
return Success(c, item)
return Success(c, itemMap)
}
func AssetTcpingEndpoint(c echo.Context) (err error) {

View File

@ -1,8 +1,10 @@
package api
import (
"errors"
"fmt"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
"next-terminal/pkg/model"
)
@ -19,11 +21,23 @@ func PropertyUpdateEndpoint(c echo.Context) error {
for key := range item {
value := fmt.Sprintf("%v", item[key])
if value == "" {
value = "-"
}
property := model.Property{
Name: key,
Value: value,
}
model.UpdatePropertyByName(&property, key)
_, err := model.FindPropertyByName(key)
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
if err := model.CreateNewProperty(&property); err != nil {
return err
}
} else {
model.UpdatePropertyByName(&property, key)
}
}
return Success(c, nil)
}

View File

@ -74,8 +74,6 @@ func SetupRoutes() *echo.Echo {
assets.GET("/paging", AssetPagingEndpoint)
assets.POST("/:id/tcping", AssetTcpingEndpoint)
assets.PUT("/:id", AssetUpdateEndpoint)
assets.GET("/:id/attributes", AssetGetAttributeEndpoint)
assets.PUT("/:id/attributes", AssetUpdateAttributeEndpoint)
assets.DELETE("/:id", AssetDeleteEndpoint)
assets.GET("/:id", AssetGetEndpoint)
assets.POST("/:id/change-owner", Admin(AssetChangeOwnerEndpoint))