From 1f9aefa3907d67c938fd24475c55cbde00ab8186 Mon Sep 17 00:00:00 2001 From: Eric_Lee Date: Mon, 8 Jun 2020 17:33:20 +0800 Subject: [PATCH 1/4] Dev token (#298) * ssh token connect * remove first connect auth --- pkg/httpd/websshws.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/httpd/websshws.go b/pkg/httpd/websshws.go index 96a92641a..5250e9de2 100644 --- a/pkg/httpd/websshws.go +++ b/pkg/httpd/websshws.go @@ -45,10 +45,8 @@ func OnNamespaceConnected(ns *neffos.NSConn, msg neffos.Message) error { userConn, err := NewUserWebsocketConnWithSession(ns) if err != nil { - ns.Emit("data", neffos.Marshal(err.Error())) - ns.Emit("disconnect", []byte("")) - ns.Conn.Close() - return err + logger.Errorf("Ws %s check session failed, may use token", ns.Conn.ID()) + return nil } logger.Infof("Accepted user %s connect ssh ws", userConn.User.Username) websocketManager.AddUserCon(ns.Conn.ID(), userConn) @@ -203,13 +201,14 @@ func OnTokenHandler(ns *neffos.NSConn, msg neffos.Message) (err error) { } userConn, err := NewUserWebsocketConnWithTokenUser(ns, tokenUser) if err != nil { - msg := "User id error" + msg := "check token error" dataMsg := DataMsg{Data: msg, Room: roomID} ns.Emit("data", neffos.Marshal(dataMsg)) ns.Emit("disconnect", neffos.Marshal([]byte(""))) logger.Error("Token Event: ", msg) return errors.New("user id error") } + logger.Infof("Ws %s accepted user %s connect by token", ns.Conn.ID(), userConn.User.Username) websocketManager.AddUserCon(ns.Conn.ID(), userConn) go userConn.loopHandler() hostMsg := HostMsg{ From 6e40bbb374b34fee96a928835bf3895f155036cf Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 8 Jun 2020 18:21:34 +0800 Subject: [PATCH 2/4] fix database pagination bug --- pkg/handler/dbpaginator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/handler/dbpaginator.go b/pkg/handler/dbpaginator.go index 2f3817907..527ac44cf 100644 --- a/pkg/handler/dbpaginator.go +++ b/pkg/handler/dbpaginator.go @@ -16,16 +16,16 @@ type DatabasePaginator interface { SearchKeys() []string } -func NewLocalDatabasePaginator(data [] model.Database, pageSize int) DatabasePaginator { +func NewLocalDatabasePaginator(data []model.Database, pageSize int) DatabasePaginator { p := localDatabasePaginator{ allData: data, currentData: data, - pageSize: pageSize, currentOffset: 0, currentPage: 1, search: make([]string, 0, 4), lock: new(sync.RWMutex), } + p.SetPageSize(pageSize) return &p } @@ -177,7 +177,7 @@ func searchFromLocalDBs(dbs []model.Database, key string) []model.Database { displayDBs := make([]model.Database, 0, len(dbs)) key = strings.ToLower(key) for _, db := range dbs { - contents := []string{strings.ToLower(db.Name),strings.ToLower(db.DBName), + contents := []string{strings.ToLower(db.Name), strings.ToLower(db.DBName), strings.ToLower(db.Host), strings.ToLower(db.Comment)} if isSubstring(contents, key) { displayDBs = append(displayDBs, db) From 93ad8cbe2411266edfd95340b31bc0eb852ca50a Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 10 Jun 2020 14:21:20 +0800 Subject: [PATCH 3/4] modify SystemUserFilterRule Json data --- pkg/model/assets.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/model/assets.go b/pkg/model/assets.go index cb9892b8c..0925c9320 100644 --- a/pkg/model/assets.go +++ b/pkg/model/assets.go @@ -295,14 +295,10 @@ const ( ) type SystemUserFilterRule struct { - Priority int `json:"priority"` - Type struct { - Value string `json:"value"` - } `json:"type"` - Content string `json:"content"` - Action struct { - Value RuleAction `json:"value"` - } `json:"action"` + Priority int `json:"priority"` + Type string `json:"type"` + Content string `json:"content"` + Action RuleAction `json:"action"` pattern *regexp.Regexp compiled bool @@ -313,7 +309,7 @@ func (sf *SystemUserFilterRule) Pattern() *regexp.Regexp { return sf.pattern } var regexs string - if sf.Type.Value == TypeCmd { + if sf.Type == TypeCmd { var regex []string for _, cmd := range strings.Split(sf.Content, "\r\n") { cmd = regexp.QuoteMeta(cmd) @@ -346,5 +342,5 @@ func (sf *SystemUserFilterRule) Match(cmd string) (RuleAction, string) { if found == "" { return ActionUnknown, "" } - return sf.Action.Value, found + return sf.Action, found } From 4a66acc6b910acfff9f0ae6fa53ca2352887c4ff Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 18 Jun 2020 10:27:06 +0800 Subject: [PATCH 4/4] version to 2.0.0 --- pkg/koko/koko.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/koko/koko.go b/pkg/koko/koko.go index 0e03ef50c..17e62bf64 100644 --- a/pkg/koko/koko.go +++ b/pkg/koko/koko.go @@ -17,7 +17,7 @@ import ( "github.com/jumpserver/koko/pkg/sshd" ) -const Version = "1.5.9" +const Version = "2.0.0" type Coco struct { }