Files
terminal/server/api/stub_apis.go
T

388 lines
9.8 KiB
Go

package api
import (
"context"
"strconv"
"next-terminal/server/common/maps"
"next-terminal/server/model"
"next-terminal/server/repository"
"github.com/labstack/echo/v4"
)
type SessionCommandApi struct{}
func (api SessionCommandApi) AllEndpoint(c echo.Context) error {
sessionId := c.QueryParam("sessionId")
items, err := repository.SessionCommandRepository.FindBySessionId(context.TODO(), sessionId)
if err != nil {
return err
}
return Success(c, items)
}
func (api SessionCommandApi) PagingEndpoint(c echo.Context) error {
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
sessionId := c.QueryParam("sessionId")
items, total, err := repository.SessionCommandRepository.FindByPage(context.TODO(), pageIndex, pageSize, sessionId)
if err != nil {
return err
}
return Success(c, maps.Map{
"total": total,
"items": items,
})
}
func (api SessionCommandApi) GetEndpoint(c echo.Context) error {
id := c.Param("id")
var item model.SessionCommand
err := repository.SessionCommandRepository.GetDB(context.TODO()).Where("id = ?", id).First(&item).Error
if err != nil {
return err
}
return Success(c, item)
}
type OperationLogApi struct{}
func (api OperationLogApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api OperationLogApi) PagingEndpoint(c echo.Context) error {
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
accountName := c.QueryParam("accountName")
action := c.QueryParam("action")
status := c.QueryParam("status")
order := c.QueryParam("order")
field := c.QueryParam("field")
items, total, err := repository.OperationLogRepository.FindByPage(context.TODO(), pageIndex, pageSize, accountName, action, status, order, field)
if err != nil {
return err
}
result := make([]maps.Map, 0)
for _, item := range items {
result = append(result, maps.Map{
"id": item.ID,
"accountId": item.AccountId,
"accountName": item.AccountName,
"action": item.Action,
"content": item.Content,
"ip": item.IP,
"region": item.Region,
"userAgent": item.UserAgent,
"status": item.Status,
"errorMessage": item.ErrorMessage,
"remark": item.Remark,
"createdAt": item.Created,
})
}
return Success(c, maps.Map{
"total": total,
"items": result,
})
}
func (api OperationLogApi) ClearEndpoint(c echo.Context) error {
if err := repository.OperationLogRepository.DeleteAll(context.TODO()); err != nil {
return err
}
return Success(c, nil)
}
func (api OperationLogApi) DeleteEndpoint(c echo.Context) error {
id := c.Param("id")
if err := repository.OperationLogRepository.DeleteById(context.TODO(), id); err != nil {
return err
}
return Success(c, nil)
}
type OidcClientApi struct{}
func (api OidcClientApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api OidcClientApi) PagingEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"total": 0,
"items": []interface{}{},
})
}
func (api OidcClientApi) CreateEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"client": maps.Map{},
"secret": "",
})
}
func (api OidcClientApi) UpdateEndpoint(c echo.Context) error {
return Success(c, nil)
}
func (api OidcClientApi) DeleteEndpoint(c echo.Context) error {
return Success(c, nil)
}
func (api OidcClientApi) GetEndpoint(c echo.Context) error {
return Success(c, nil)
}
func (api OidcClientApi) RegenerateSecretEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"clientSecret": "",
})
}
func (api OidcClientApi) UpdateStatusEndpoint(c echo.Context) error {
return Success(c, nil)
}
type LoginLockedApi struct{}
func (api LoginLockedApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api LoginLockedApi) PagingEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"total": 0,
"items": []interface{}{},
})
}
func (api LoginLockedApi) DeleteEndpoint(c echo.Context) error {
return Success(c, nil)
}
type FilesystemLogApi struct{}
func (api FilesystemLogApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api FilesystemLogApi) PagingEndpoint(c echo.Context) error {
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
action := c.QueryParam("action")
items, total, err := repository.FilesystemLogRepository.FindByPage(context.TODO(), pageIndex, pageSize, action)
if err != nil {
return err
}
result := make([]maps.Map, 0)
for _, item := range items {
var assetName, userName string
if item.AssetId != "" {
asset, _ := repository.AssetRepository.FindById(context.TODO(), item.AssetId)
assetName = asset.Name
}
if item.UserId != "" {
user, _ := repository.UserRepository.FindById(context.TODO(), item.UserId)
userName = user.Username
}
result = append(result, maps.Map{
"id": item.ID,
"assetId": item.AssetId,
"sessionId": item.SessionId,
"userId": item.UserId,
"action": item.Action,
"fileName": item.FileName,
"createdAt": item.Created,
"assetName": assetName,
"userName": userName,
})
}
return Success(c, maps.Map{
"total": total,
"items": result,
})
}
func (api FilesystemLogApi) DeleteEndpoint(c echo.Context) error {
id := c.Param("id")
if err := repository.FilesystemLogRepository.DeleteById(context.TODO(), id); err != nil {
return err
}
return Success(c, nil)
}
func (api FilesystemLogApi) ClearEndpoint(c echo.Context) error {
if err := repository.FilesystemLogRepository.DeleteAll(context.TODO()); err != nil {
return err
}
return Success(c, nil)
}
type AgentGatewayTokenApi struct{}
func (api AgentGatewayTokenApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AgentGatewayTokenApi) PagingEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"total": 0,
"items": []interface{}{},
})
}
func (api AgentGatewayTokenApi) CreateEndpoint(c echo.Context) error {
return Success(c, "")
}
func (api AgentGatewayTokenApi) UpdateEndpoint(c echo.Context) error {
return Success(c, nil)
}
func (api AgentGatewayTokenApi) DeleteEndpoint(c echo.Context) error {
return Success(c, nil)
}
func (api AgentGatewayTokenApi) GetEndpoint(c echo.Context) error {
return Success(c, nil)
}
type AccessLogApi struct{}
func (api AccessLogApi) AllEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) PagingEndpoint(c echo.Context) error {
pageIndex, _ := strconv.Atoi(c.QueryParam("pageIndex"))
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
domain := c.QueryParam("domain")
websiteId := c.QueryParam("websiteId")
accountId := c.QueryParam("accountId")
items, total, err := repository.AccessLogRepository.FindByPage(context.TODO(), pageIndex, pageSize, domain, websiteId, accountId)
if err != nil {
return err
}
result := make([]maps.Map, 0)
for _, item := range items {
result = append(result, maps.Map{
"id": item.ID,
"domain": item.Domain,
"websiteId": item.WebsiteId,
"accountId": item.AccountId,
"method": item.Method,
"uri": item.Uri,
"statusCode": item.StatusCode,
"responseSize": item.ResponseSize,
"clientIp": item.ClientIp,
"region": item.Region,
"userAgent": item.UserAgent,
"referer": item.Referer,
"requestTime": item.RequestTime,
"responseTime": item.ResponseTime,
"createdAt": item.Created,
})
}
return Success(c, maps.Map{
"total": total,
"items": result,
})
}
func (api AccessLogApi) DeleteEndpoint(c echo.Context) error {
id := c.Param("id")
if err := repository.AccessLogRepository.DeleteById(context.TODO(), id); err != nil {
return err
}
return Success(c, nil)
}
func (api AccessLogApi) ClearEndpoint(c echo.Context) error {
if err := repository.AccessLogRepository.DeleteAll(context.TODO()); err != nil {
return err
}
return Success(c, nil)
}
func (api AccessLogApi) GetDomainStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetDailyStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetStatusCodeStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetHourlyStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetTotalStatsEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"totalRequests": 0,
"uniqueDomains": 0,
"uniqueVisitors": 0,
"avgResponseTime": 0,
})
}
func (api AccessLogApi) GetWebsiteStatsEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"websiteId": "",
"websiteName": "",
"domain": "",
"pv": 0,
"uv": 0,
"ip": 0,
"traffic": 0,
"requests": 0,
"realtimeTraffic": 0,
"requestsPerSecond": 0,
"avgResponseTime": 0,
})
}
func (api AccessLogApi) GetWebsiteTrafficTrendEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetTopPagesEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetTopReferersEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetRealtimeMetricsEndpoint(c echo.Context) error {
return Success(c, maps.Map{
"currentOnline": 0,
"requestsPerSecond": 0,
"trafficPerSecond": 0,
"avgResponseTime": 0,
"errorRate": 0,
})
}
func (api AccessLogApi) GetWebsiteHourlyStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}
func (api AccessLogApi) GetWebsiteStatusCodeStatsEndpoint(c echo.Context) error {
return Success(c, []interface{}{})
}