Skip to content

Commit

Permalink
fix(api): ssh cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ttktatakai committed Oct 11, 2024
1 parent 6961354 commit fa719b6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
15 changes: 9 additions & 6 deletions backend/api/controller/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ func (c *Controller) GetAccounts(ctx *gin.Context) {
db = db.Where("id IN ?", lo.Map(strings.Split(q, ","), func(s string, _ int) int { return cast.ToInt(s) }))
}

if info && !acl.IsAdmin(currentUser) {
ids, err := GetAccountIdsByAuthorization(ctx)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, &ApiError{Code: ErrInternal, Data: map[string]any{"err": err}})
return
if info {
db = db.Select("id", "name", "account")
if !acl.IsAdmin(currentUser) {
ids, err := GetAccountIdsByAuthorization(ctx)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, &ApiError{Code: ErrInternal, Data: map[string]any{"err": err}})
return
}
db = db.Where("id IN ?", ids)
}
db = db.Where("id IN ?", ids)
}

db = db.Order("name")
Expand Down
4 changes: 4 additions & 0 deletions backend/api/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ func hasPerm[T model.Model](ctx context.Context, md T, resourceTypeName, action
}

func handlePermissions[T any](ctx *gin.Context, data []T, resourceTypeName string) (err error) {
if info := cast.ToBool(ctx.Query("info")); info {
return
}

currentUser, _ := acl.GetSessionFromCtx(ctx)

if !lo.Contains(conf.PermResource, resourceTypeName) {
Expand Down
2 changes: 1 addition & 1 deletion backend/sshsrv/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func handler(sess ssh.Session) {
Request: &http.Request{
RemoteAddr: sess.RemoteAddr().String(),
URL: &url.URL{
RawQuery: fmt.Sprintf("w=%d&h=%d", pty.Window.Width, pty.Window.Height),
RawQuery: fmt.Sprintf("info=true&w=%d&h=%d", pty.Window.Width, pty.Window.Height),
},
},
}
Expand Down
1 change: 0 additions & 1 deletion backend/sshsrv/sshsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func init() {
Handler: handler,
PasswordHandler: func(ctx ssh.Context, password string) bool {
sess, err := acl.LoginByPassword(ctx, ctx.User(), password, util.IpFromNetAddr(ctx.RemoteAddr()))

ctx.SetValue("session", sess)
return err == nil
},
Expand Down
2 changes: 1 addition & 1 deletion backend/sshsrv/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (m *view) refresh() {

m.combines = make(map[string][3]int)
for _, asset := range assets {
for accountId, _ := range asset.Authorization {
for accountId := range asset.Authorization {
account, ok := accountMap[accountId]
if !ok {
continue
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.0"

services:
oneterm-api:
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-api:latest
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-api:latest # use latest or version like v24.10.1
container_name: oneterm-api
volumes:
- ./volume/replay:/replay
Expand Down

0 comments on commit fa719b6

Please sign in to comment.