From 49f4e3f0deaa4c165d1f3d2bcc1d35368544401f Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Mon, 1 Jan 2024 21:11:57 +0800 Subject: [PATCH 01/10] fix: fix Security vulnerability (#1646) Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- docker-compose.yml | 2 +- pkg/common/discoveryregister/kubernetes/kubernetes.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5b1e11d4e..fd71896a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -124,7 +124,7 @@ services: ## Uncomment and configure the following services as needed # openim-admin: - # image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-admin-front:v3.4.0 + # image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-admin:toc-base-open-docker.35 # container_name: openim-admin # restart: always # ports: diff --git a/pkg/common/discoveryregister/kubernetes/kubernetes.go b/pkg/common/discoveryregister/kubernetes/kubernetes.go index 2ff1539e6..c10518056 100644 --- a/pkg/common/discoveryregister/kubernetes/kubernetes.go +++ b/pkg/common/discoveryregister/kubernetes/kubernetes.go @@ -55,14 +55,17 @@ func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.Dial return nil } + func (cli *K8sDR) UnRegister() error { return nil } + func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error { return nil } + func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error { return nil @@ -123,6 +126,8 @@ func getMsgGatewayHost(ctx context.Context) []string { log.ZInfo(ctx, "getMsgGatewayHost", "instance", instance, "selfPodName", selfPodName, "replicas", replicas, "ns", ns, "ret", ret) return ret } + +// GetConns returns the gRPC client connections to the specified service. func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) { if serviceName != config.Config.RpcRegisterName.OpenImMessageGatewayName { @@ -142,6 +147,7 @@ func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc return ret, nil } } + func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...) @@ -151,9 +157,11 @@ func (cli *K8sDR) GetSelfConnTarget() string { return cli.rpcRegisterAddr } + func (cli *K8sDR) AddOption(opts ...grpc.DialOption) { cli.options = append(cli.options, opts...) } + func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) { conn.Close() } From 3fffc2f2123c35bc151e9202595cb0d39293893d Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Tue, 2 Jan 2024 11:51:09 +0800 Subject: [PATCH 02/10] feat: support websocket first message method response code (#1651) * upgrade package and rtc convert * upgrade package and rtc convert * upgrade package and rtc convert * upgrade package and rtc convert * friend user * s3 form data * s3 form data * s3 form data * s3 form data * s3 form data * s3 form data * s3 form data * s3 form data * s3 form data * ws * ws * ws * ws * ws --- internal/msggateway/constant.go | 1 + internal/msggateway/n_ws_server.go | 131 +++++++++++++++++------------ 2 files changed, 77 insertions(+), 55 deletions(-) diff --git a/internal/msggateway/constant.go b/internal/msggateway/constant.go index fe5f09bdc..045629b4e 100644 --- a/internal/msggateway/constant.go +++ b/internal/msggateway/constant.go @@ -26,6 +26,7 @@ const ( Compression = "compression" GzipCompressionProtocol = "gzip" BackgroundStatus = "isBackground" + MsgResp = "isMsgResp" ) const ( diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 70c2f8fe0..cdc3d719c 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -16,7 +16,10 @@ package msggateway import ( "context" + "encoding/json" "errors" + "fmt" + "github.com/OpenIMSDK/tools/apiresp" "net/http" "os" "os/signal" @@ -422,84 +425,102 @@ func (ws *WsServer) unregisterClient(client *Client) { ) } -func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) { - connContext := newContext(w, r) +func (ws *WsServer) ParseWSArgs(r *http.Request) (args *WSArgs, err error) { + var v WSArgs + defer func() { + args = &v + }() + query := r.URL.Query() + v.MsgResp, _ = strconv.ParseBool(query.Get(MsgResp)) if ws.onlineUserConnNum.Load() >= ws.wsMaxConnNum { - httpError(connContext, errs.ErrConnOverMaxNumLimit) - return + return nil, errs.ErrConnOverMaxNumLimit.Wrap("over max conn num limit") } - var ( - token string - userID string - platformIDStr string - exists bool - compression bool - ) - - token, exists = connContext.Query(Token) - if !exists { - httpError(connContext, errs.ErrConnArgsErr) - return + if v.Token = query.Get(Token); v.Token == "" { + return nil, errs.ErrConnArgsErr.Wrap("token is empty") } - userID, exists = connContext.Query(WsUserID) - if !exists { - httpError(connContext, errs.ErrConnArgsErr) - return + if v.UserID = query.Get(WsUserID); v.UserID == "" { + return nil, errs.ErrConnArgsErr.Wrap("sendID is empty") } - platformIDStr, exists = connContext.Query(PlatformID) - if !exists { - httpError(connContext, errs.ErrConnArgsErr) - return + platformIDStr := query.Get(PlatformID) + if platformIDStr == "" { + return nil, errs.ErrConnArgsErr.Wrap("platformID is empty") } platformID, err := strconv.Atoi(platformIDStr) if err != nil { - httpError(connContext, errs.ErrConnArgsErr) - return + return nil, errs.ErrConnArgsErr.Wrap("platformID is not int") + } + v.PlatformID = platformID + if err = authverify.WsVerifyToken(v.Token, v.UserID, platformID); err != nil { + return nil, err + } + if query.Get(Compression) == GzipCompressionProtocol { + v.Compression = true } - if err = authverify.WsVerifyToken(token, userID, platformID); err != nil { - httpError(connContext, err) - return + if r.Header.Get(Compression) == GzipCompressionProtocol { + v.Compression = true } - m, err := ws.cache.GetTokensWithoutError(context.Background(), userID, platformID) + m, err := ws.cache.GetTokensWithoutError(context.Background(), v.UserID, platformID) if err != nil { - httpError(connContext, err) - return + return nil, err } - if v, ok := m[token]; ok { + if v, ok := m[v.Token]; ok { switch v { case constant.NormalToken: case constant.KickedToken: - httpError(connContext, errs.ErrTokenKicked.Wrap()) - return + return nil, errs.ErrTokenKicked.Wrap() default: - httpError(connContext, errs.ErrTokenUnknown.Wrap()) - return + return nil, errs.ErrTokenUnknown.Wrap(fmt.Sprintf("token status is %d", v)) } } else { - httpError(connContext, errs.ErrTokenNotExist.Wrap()) - return + return nil, errs.ErrTokenNotExist.Wrap() } + return &v, nil +} - wsLongConn := newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize) - err = wsLongConn.GenerateLongConn(w, r) - if err != nil { - httpError(connContext, err) - return - } - compressProtoc, exists := connContext.Query(Compression) - if exists { - if compressProtoc == GzipCompressionProtocol { - compression = true +type WSArgs struct { + Token string + UserID string + PlatformID int + Compression bool + MsgResp bool +} + +func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) { + connContext := newContext(w, r) + args, pErr := ws.ParseWSArgs(r) + var wsLongConn *GWebSocket + if args.MsgResp { + wsLongConn = newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize) + if err := wsLongConn.GenerateLongConn(w, r); err != nil { + httpError(connContext, err) + return } - } - compressProtoc, exists = connContext.GetHeader(Compression) - if exists { - if compressProtoc == GzipCompressionProtocol { - compression = true + data, err := json.Marshal(apiresp.ParseError(pErr)) + if err != nil { + _ = wsLongConn.Close() + return + } + if err := wsLongConn.WriteMessage(MessageText, data); err != nil { + _ = wsLongConn.Close() + return + } + if pErr != nil { + _ = wsLongConn.Close() + return + } + } else { + if pErr != nil { + httpError(connContext, pErr) + return + } + wsLongConn = newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize) + if err := wsLongConn.GenerateLongConn(w, r); err != nil { + httpError(connContext, err) + return } } client := ws.clientPool.Get().(*Client) - client.ResetClient(connContext, wsLongConn, connContext.GetBackground(), compression, ws, token) + client.ResetClient(connContext, wsLongConn, connContext.GetBackground(), args.Compression, ws, args.Token) ws.registerChan <- client go client.readMessage() } From d594d6f5171b4e54772803b3e4573d357f4ad34f Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Tue, 2 Jan 2024 12:42:46 +0800 Subject: [PATCH 03/10] fix: install-im-server (#1648) Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- scripts/install-im-server.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/install-im-server.sh b/scripts/install-im-server.sh index 47db34433..e52a1a21a 100755 --- a/scripts/install-im-server.sh +++ b/scripts/install-im-server.sh @@ -45,8 +45,19 @@ pushd "${OPENIM_ROOT}" ${DOCKER_COMPOSE_COMMAND} stop curl https://gitee.com/openimsdk/openim-docker/raw/main/example/full-openim-server-and-chat.yml -o docker-compose.yml ${DOCKER_COMPOSE_COMMAND} up -d -sleep 60 + +# Wait for a short period to allow containers to initialize +sleep 10 + +# Check the status of the containers +if ! ${DOCKER_COMPOSE_COMMAND} ps | grep -q 'Up'; then + echo "Error: One or more docker containers failed to start." + ${DOCKER_COMPOSE_COMMAND} logs + exit 1 +fi + +sleep 50 # Keep the original 60-second wait, adjusted for the 10-second check above ${DOCKER_COMPOSE_COMMAND} logs openim-server ${DOCKER_COMPOSE_COMMAND} ps -popd \ No newline at end of file +popd From c19bafc49dad633e83b669e3601d5b361a5c8ce0 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:37:05 +0800 Subject: [PATCH 04/10] fix: modify dismissed group's status. (#1655) * fix: add notifications for some notifications. * fix: modify dismissed group's status. --- pkg/common/db/controller/group.go | 2 +- pkg/common/db/mgo/group.go | 4 ++-- pkg/common/db/mgo/group_member.go | 10 +++++++--- pkg/common/db/table/relation/group.go | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/common/db/controller/group.go b/pkg/common/db/controller/group.go index 4147d59c0..decd868d6 100644 --- a/pkg/common/db/controller/group.go +++ b/pkg/common/db/controller/group.go @@ -197,7 +197,7 @@ func (g *groupDatabase) UpdateGroup(ctx context.Context, groupID string, data ma func (g *groupDatabase) DismissGroup(ctx context.Context, groupID string, deleteMember bool) error { return g.ctxTx.Transaction(ctx, func(ctx context.Context) error { c := g.cache.NewCache() - if err := g.groupDB.UpdateState(ctx, groupID, constant.GroupStatusDismissed); err != nil { + if err := g.groupDB.UpdateStatus(ctx, groupID, constant.GroupStatusDismissed); err != nil { return err } if deleteMember { diff --git a/pkg/common/db/mgo/group.go b/pkg/common/db/mgo/group.go index 65dbbca59..a9c6d1eb8 100644 --- a/pkg/common/db/mgo/group.go +++ b/pkg/common/db/mgo/group.go @@ -49,8 +49,8 @@ func (g *GroupMgo) Create(ctx context.Context, groups []*relation.GroupModel) (e return mgoutil.InsertMany(ctx, g.coll, groups) } -func (g *GroupMgo) UpdateState(ctx context.Context, groupID string, state int32) (err error) { - return g.UpdateMap(ctx, groupID, map[string]any{"state": state}) +func (g *GroupMgo) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) { + return g.UpdateMap(ctx, groupID, map[string]any{"status": status}) } func (g *GroupMgo) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) { diff --git a/pkg/common/db/mgo/group_member.go b/pkg/common/db/mgo/group_member.go index 8c3041901..8e3dd1efa 100644 --- a/pkg/common/db/mgo/group_member.go +++ b/pkg/common/db/mgo/group_member.go @@ -51,7 +51,11 @@ func (g *GroupMemberMgo) Create(ctx context.Context, groupMembers []*relation.Gr } func (g *GroupMemberMgo) Delete(ctx context.Context, groupID string, userIDs []string) (err error) { - return mgoutil.DeleteMany(ctx, g.coll, bson.M{"group_id": groupID, "user_id": bson.M{"$in": userIDs}}) + filter := bson.M{"group_id": groupID} + if len(userIDs) > 0 { + filter["user_id"] = bson.M{"$in": userIDs} + } + return mgoutil.DeleteMany(ctx, g.coll, filter) } func (g *GroupMemberMgo) UpdateRoleLevel(ctx context.Context, groupID string, userID string, roleLevel int32) error { @@ -84,8 +88,8 @@ func (g *GroupMemberMgo) FindRoleLevelUserIDs(ctx context.Context, groupID strin } func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (total int64, groupList []*relation.GroupMemberModel, err error) { - //TODO implement me - panic("implement me") + filter := bson.M{"group_id": groupID, "nickname": bson.M{"$regex": keyword}} + return mgoutil.FindPage[*relation.GroupMemberModel](ctx, g.coll, filter, pagination) } func (g *GroupMemberMgo) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) { diff --git a/pkg/common/db/table/relation/group.go b/pkg/common/db/table/relation/group.go index bb1ddd878..57d6b1d62 100644 --- a/pkg/common/db/table/relation/group.go +++ b/pkg/common/db/table/relation/group.go @@ -42,7 +42,7 @@ type GroupModel struct { type GroupModelInterface interface { Create(ctx context.Context, groups []*GroupModel) (err error) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) - UpdateState(ctx context.Context, groupID string, state int32) (err error) + UpdateStatus(ctx context.Context, groupID string, status int32) (err error) Find(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error) Take(ctx context.Context, groupID string) (group *GroupModel, err error) Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*GroupModel, err error) From 11108e1ddf3318bda80eed8cd9df0c4bb687614c Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Tue, 2 Jan 2024 20:59:26 +0800 Subject: [PATCH 05/10] fix: release openim version not auto build (#1660) --- build/goreleaser.yaml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/build/goreleaser.yaml b/build/goreleaser.yaml index ed7f7cd1b..93fe9f4c8 100644 --- a/build/goreleaser.yaml +++ b/build/goreleaser.yaml @@ -3,12 +3,36 @@ before: hooks: + - make clean # You may remove this if you don't use go modules. - make tidy - make copyright.add # you may remove this if you don't need go generate - go generate ./... +git: + # What should be used to sort tags when gathering the current and previous + # tags if there are more than one tag in the same commit. + # + # Default: '-version:refname' + tag_sort: -version:creatordate + + # What should be used to specify prerelease suffix while sorting tags when gathering + # the current and previous tags if there are more than one tag in the same commit. + # + # Since: v1.17 + prerelease_suffix: "-" + + # Tags to be ignored by GoReleaser. + # This means that GoReleaser will not pick up tags that match any of the + # provided values as either previous or current tags. + # + # Templates: allowed. + # Since: v1.21. + ignore_tags: + - nightly + # - "{{.Env.IGNORE_TAG}}" + snapshot: name_template: "{{ incpatch .Version }}-next" @@ -495,4 +519,4 @@ checksum: algorithm: sha256 release: - prerelease: auto \ No newline at end of file + prerelease: auto From f1ba5c2bffdc5b4f28a798fa3a6bdea2f59c3206 Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:07:01 +0800 Subject: [PATCH 06/10] fix: fix the error (#1653) --- internal/rpc/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 5a79fbc91..8219ec0bc 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -558,7 +558,7 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search accounts := make([]*pbuser.NotificationAccountInfo, 0) var total int64 for _, v := range users { - if v.AppMangerLevel == constant.AppNotificationAdmin || v.AppMangerLevel == constant.AppAdmin { + if v.AppMangerLevel == constant.AppNotificationAdmin { temp := &pbuser.NotificationAccountInfo{ UserID: v.UserID, FaceURL: v.FaceURL, From 5d1cf8c06150f75c5f6d7c2a4cb48b722edd3a0a Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:32:42 +0800 Subject: [PATCH 07/10] fix: Adjust the logic in multiTerminalLoginChecker to prevent onlineUserNum from decreasing below zero, thereby avoiding negative values. (#1658) * fix: add notifications for some notifications. * fix: modify dismissed group's status. * fix: Adjust the logic in multiTerminalLoginChecker to prevent onlineUserNum from decreasing below zero, thereby avoiding negative values. --- internal/msggateway/n_ws_server.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index cdc3d719c..7e8129105 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -345,11 +345,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien if !clientOK { return } - - isDeleteUser := ws.clients.deleteClients(newClient.UserID, oldClients) - if isDeleteUser { - ws.onlineUserNum.Add(-1) - } + ws.clients.deleteClients(newClient.UserID, oldClients) for _, c := range oldClients { err := c.KickOnlineMessage() if err != nil { From 587533df4dc29b2c4921259c03b3adee0107b0eb Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:46:38 +0800 Subject: [PATCH 08/10] fix: update Notification update resp (#1663) * fix: fix the error * fix: fix the SearchNotificationAccount resp * fix: fix the god * Update install-im-server.sh * Update install-im-server.sh --------- Co-authored-by: Xinwei Xiong <3293172751@qq.com> --- go.mod | 4 ++-- go.sum | 4 ++-- internal/rpc/user/user.go | 2 +- scripts/install-im-server.sh | 7 +++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 393e742de..f1b3239c3 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( firebase.google.com/go v3.13.0+incompatible - github.com/OpenIMSDK/protocol v0.0.42 + github.com/OpenIMSDK/protocol v0.0.43 github.com/OpenIMSDK/tools v0.0.21 github.com/bwmarrin/snowflake v0.3.0 // indirect github.com/dtm-labs/rockscache v0.1.1 @@ -155,4 +155,4 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.14.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect -) \ No newline at end of file +) diff --git a/go.sum b/go.sum index fc1d15242..e72d862e6 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c= github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ= -github.com/OpenIMSDK/protocol v0.0.42 h1:vIWXqZJZZ1ddleJA25fxhjZ1GyEHATpYM3wVWh4/+PY= -github.com/OpenIMSDK/protocol v0.0.42/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.43 h1:8B921vEyO7r0AfQfZd7kCycYja+hJ2vuIZsKge/WRhU= +github.com/OpenIMSDK/protocol v0.0.43/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.21 h1:iTapc2mIEVH/xl5Nd6jfwPub11Pgp44tVcE1rjB3a48= github.com/OpenIMSDK/tools v0.0.21/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 8219ec0bc..824b8a9bb 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -558,7 +558,7 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search accounts := make([]*pbuser.NotificationAccountInfo, 0) var total int64 for _, v := range users { - if v.AppMangerLevel == constant.AppNotificationAdmin { + if v.AppMangerLevel == constant.AppNotificationAdmin && !utils.IsContain(v.UserID, config.Config.IMAdmin.UserID) { temp := &pbuser.NotificationAccountInfo{ UserID: v.UserID, FaceURL: v.FaceURL, diff --git a/scripts/install-im-server.sh b/scripts/install-im-server.sh index e52a1a21a..a21ae134d 100755 --- a/scripts/install-im-server.sh +++ b/scripts/install-im-server.sh @@ -43,20 +43,19 @@ fi "${OPENIM_ROOT}"/scripts/init-config.sh pushd "${OPENIM_ROOT}" ${DOCKER_COMPOSE_COMMAND} stop -curl https://gitee.com/openimsdk/openim-docker/raw/main/example/full-openim-server-and-chat.yml -o docker-compose.yml +curl https://raw.githubusercontent.com/openimsdk/openim-docker/main/docker-compose.yaml -o docker-compose.yml ${DOCKER_COMPOSE_COMMAND} up -d # Wait for a short period to allow containers to initialize -sleep 10 +sleep 30 # Check the status of the containers if ! ${DOCKER_COMPOSE_COMMAND} ps | grep -q 'Up'; then echo "Error: One or more docker containers failed to start." ${DOCKER_COMPOSE_COMMAND} logs - exit 1 fi -sleep 50 # Keep the original 60-second wait, adjusted for the 10-second check above +sleep 30 # Keep the original 60-second wait, adjusted for the 10-second check above ${DOCKER_COMPOSE_COMMAND} logs openim-server ${DOCKER_COMPOSE_COMMAND} ps From 9e2a25681778a7889d0c434d3fe81da11847fdf4 Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 3 Jan 2024 17:24:02 +0800 Subject: [PATCH 09/10] fix: fix the imAdmin permission (#1664) * fix: fix the error * fix: fix the SearchNotificationAccount resp * fix: fix the god * Update install-im-server.sh * Update install-im-server.sh * fix: fix the searchNotificationAccounts * fix: fix the imAdmin competence * fix: fix the error * fix: fix the checkAdminV3 --------- Co-authored-by: Xinwei Xiong <3293172751@qq.com> --- internal/rpc/user/user.go | 2 +- pkg/authverify/token.go | 11 +++++++++-- pkg/common/db/controller/user.go | 7 +++++++ pkg/common/db/mgo/user.go | 4 ++++ pkg/common/db/table/relation/user.go | 1 + pkg/rpcclient/user.go | 3 +++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 824b8a9bb..51403d631 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -515,7 +515,7 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser. return resp, nil } - _, users, err := s.UserDatabase.Page(ctx, req.Pagination) + users, err := s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin) if err != nil { return nil, err } diff --git a/pkg/authverify/token.go b/pkg/authverify/token.go index d9aa0dbb1..e810dfecf 100644 --- a/pkg/authverify/token.go +++ b/pkg/authverify/token.go @@ -38,6 +38,9 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) { if utils.IsContain(opUserID, config.Config.Manager.UserID) { return nil } + if utils.IsContain(opUserID, config.Config.IMAdmin.UserID) { + return nil + } if opUserID == ownerUserID { return nil } @@ -45,13 +48,16 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) { } func IsAppManagerUid(ctx context.Context) bool { - return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) + return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) || utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID) } func CheckAdmin(ctx context.Context) error { if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) { return nil } + if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID) { + return nil + } return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx))) } func CheckIMAdmin(ctx context.Context) error { @@ -69,7 +75,8 @@ func ParseRedisInterfaceToken(redisToken any) (*tokenverify.Claims, error) { } func IsManagerUserID(opUserID string) bool { - return utils.IsContain(opUserID, config.Config.Manager.UserID) + return utils.IsContain(opUserID, config.Config.Manager.UserID) || utils.IsContain(opUserID, config.Config.IMAdmin.UserID) + } func WsVerifyToken(token, userID string, platformID int) error { diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go index 72bdf6b06..a109b81ef 100644 --- a/pkg/common/db/controller/user.go +++ b/pkg/common/db/controller/user.go @@ -40,6 +40,8 @@ type UserDatabase interface { Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) // Find userInfo By Nickname FindByNickname(ctx context.Context, nickname string) (users []*relation.UserModel, err error) + // Find notificationAccounts + FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error) // Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db Create(ctx context.Context, users []*relation.UserModel) (err error) // Update update (non-zero value) external guarantee userID exists @@ -140,6 +142,11 @@ func (u *userDatabase) FindByNickname(ctx context.Context, nickname string) (use return u.userDB.TakeByNickname(ctx, nickname) } +// Find notificationAccouts +func (u *userDatabase) FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error) { + return u.userDB.TakeNotification(ctx, level) +} + // Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db. func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) { return u.tx.Transaction(ctx, func(ctx context.Context) error { diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go index 0ca711ad8..27ca264dd 100644 --- a/pkg/common/db/mgo/user.go +++ b/pkg/common/db/mgo/user.go @@ -65,6 +65,10 @@ func (u *UserMgo) Take(ctx context.Context, userID string) (user *relation.UserM return mgoutil.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID}) } +func (u *UserMgo) TakeNotification(ctx context.Context, level int64) (user []*relation.UserModel, err error) { + return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level}) +} + func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*relation.UserModel, err error) { return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"nickname": nickname}) } diff --git a/pkg/common/db/table/relation/user.go b/pkg/common/db/table/relation/user.go index 8917ba55f..fc116adc2 100644 --- a/pkg/common/db/table/relation/user.go +++ b/pkg/common/db/table/relation/user.go @@ -53,6 +53,7 @@ type UserModelInterface interface { UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error) Find(ctx context.Context, userIDs []string) (users []*UserModel, err error) Take(ctx context.Context, userID string) (user *UserModel, err error) + TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error) TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error) Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error) Exist(ctx context.Context, userID string) (exist bool, err error) diff --git a/pkg/rpcclient/user.go b/pkg/rpcclient/user.go index de633ee30..451914cd3 100644 --- a/pkg/rpcclient/user.go +++ b/pkg/rpcclient/user.go @@ -64,6 +64,9 @@ func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClie // GetUsersInfo retrieves information for multiple users based on their user IDs. func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) { + if len(userIDs) == 0 { + return []*sdkws.UserInfo{}, nil + } resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{ UserIDs: userIDs, }) From 7bb44b8b88c1d10492e3752c1b02970c815402ab Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com> Date: Thu, 4 Jan 2024 15:40:14 +0800 Subject: [PATCH 10/10] 2023 Annual Summary Reflections and Aspirations Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- scripts/docker-start-all.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh index 3c83b02bb..85954a677 100755 --- a/scripts/docker-start-all.sh +++ b/scripts/docker-start-all.sh @@ -21,6 +21,25 @@ set -o pipefail #fixme This scripts is the total startup scripts #fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array +# Fixed ports inside the docker startup container +export OPENIM_WS_PORT=10001 +export API_OPENIM_PORT=10002 +export API_PROM_PORT=20100 +export USER_PROM_PORT=20110 +export FRIEND_PROM_PORT=20120 +export MESSAGE_PROM_PORT=20130 +export MSG_GATEWAY_PROM_PORT=20140 +export GROUP_PROM_PORT=20150 +export AUTH_PROM_PORT=20160 +export PUSH_PROM_PORT=20170 +export CONVERSATION_PROM_PORT=20230 +export RTC_PROM_PORT=21300 +export THIRD_PROM_PORT=21301 +export MSG_TRANSFER_PROM_PORT=21400 +export MSG_TRANSFER_PROM_PORT=21401 +export MSG_TRANSFER_PROM_PORT=21402 +export MSG_TRANSFER_PROM_PORT=21403 + OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${OPENIM_ROOT}/scripts/install/common.sh"