Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
koko
Commits
0c7c4f48
Commit
0c7c4f48
authored
Sep 02, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update]fix selecting asset bugs
parent
c32db87d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
49 deletions
+63
-49
pagination.go
pkg/handler/pagination.go
+35
-33
session.go
pkg/handler/session.go
+27
-15
connmanager.go
pkg/srvconn/connmanager.go
+1
-1
No files found.
pkg/handler/pagination.go
View file @
0c7c4f48
...
...
@@ -2,6 +2,7 @@ package handler
import
(
"fmt"
"io"
"strconv"
"strings"
...
...
@@ -176,36 +177,31 @@ func (p *AssetPagination) displayPageAssets() {
}
func
(
p
*
AssetPagination
)
displayTipsInfo
()
{
tips
:=
[]
string
{
i18n
.
T
(
"
\n
Tips: Enter the asset ID and log directly into the asset.
\n
"
),
i18n
.
T
(
"
\n
Page up: P/p Page down: Enter|N/n BACK: b.
\n
"
),
}
for
_
,
tip
:=
range
tips
{
_
,
_
=
p
.
term
.
Write
([]
byte
(
tip
))
}
displayAssetPaginationTipsInfo
(
p
.
term
)
}
func
NewUserPagination
(
term
*
utils
.
Terminal
,
uid
,
search
string
,
p
rox
y
bool
)
*
UserAssetPagination
{
func
NewUserPagination
(
term
*
utils
.
Terminal
,
uid
,
search
string
,
p
olic
y
bool
)
*
UserAssetPagination
{
return
&
UserAssetPagination
{
UserID
:
uid
,
offset
:
0
,
limit
:
0
,
search
:
search
,
term
:
term
,
proxy
:
prox
y
,
Data
:
model
.
AssetsPaginationResponse
{},
UserID
:
uid
,
offset
:
0
,
limit
:
0
,
search
:
search
,
term
:
term
,
displayPolicy
:
polic
y
,
Data
:
model
.
AssetsPaginationResponse
{},
}
}
type
UserAssetPagination
struct
{
UserID
string
offset
int
limit
int
search
string
term
*
utils
.
Terminal
proxy
bool
Data
model
.
AssetsPaginationResponse
UserID
string
offset
int
limit
int
search
string
term
*
utils
.
Terminal
displayPolicy
bool
Data
model
.
AssetsPaginationResponse
IsNeedProxy
bool
}
func
(
p
*
UserAssetPagination
)
Start
()
[]
model
.
Asset
{
...
...
@@ -214,7 +210,8 @@ func (p *UserAssetPagination) Start() []model.Asset {
for
{
p
.
retrieveData
()
if
p
.
proxy
&&
p
.
Data
.
Total
==
1
{
if
p
.
displayPolicy
&&
p
.
Data
.
Total
==
1
{
p
.
IsNeedProxy
=
true
return
p
.
Data
.
Data
}
...
...
@@ -251,6 +248,7 @@ func (p *UserAssetPagination) Start() []model.Asset {
default
:
if
indexID
,
err
:=
strconv
.
Atoi
(
line
);
err
==
nil
{
if
indexID
>
0
&&
indexID
<=
len
(
p
.
Data
.
Data
)
{
p
.
IsNeedProxy
=
true
return
[]
model
.
Asset
{
p
.
Data
.
Data
[
indexID
-
1
]}
}
}
...
...
@@ -259,6 +257,7 @@ func (p *UserAssetPagination) Start() []model.Asset {
default
:
if
indexID
,
err
:=
strconv
.
Atoi
(
line
);
err
==
nil
{
if
indexID
>
0
&&
indexID
<=
len
(
p
.
Data
.
Data
)
{
p
.
IsNeedProxy
=
true
return
[]
model
.
Asset
{
p
.
Data
.
Data
[
indexID
-
1
]}
}
}
...
...
@@ -348,25 +347,18 @@ func (p *UserAssetPagination) displayPageAssets() {
}
func
(
p
*
UserAssetPagination
)
displayTipsInfo
()
{
tips
:=
[]
string
{
i18n
.
T
(
"
\n
Tips: Enter the asset ID and log directly into the asset.
\n
"
),
i18n
.
T
(
"
\n
Page up: P/p Page down: Enter|N/n BACK: b.
\n
"
),
}
for
_
,
tip
:=
range
tips
{
_
,
_
=
p
.
term
.
Write
([]
byte
(
tip
))
}
displayAssetPaginationTipsInfo
(
p
.
term
)
}
func
(
p
*
UserAssetPagination
)
retrieveData
()
{
p
.
limit
=
G
etPageSize
(
p
.
term
)
p
.
limit
=
g
etPageSize
(
p
.
term
)
if
p
.
limit
==
0
||
p
.
offset
<
0
||
p
.
limit
>=
p
.
Data
.
Total
{
p
.
offset
=
0
}
p
.
Data
=
service
.
GetUserAssets
(
p
.
UserID
,
p
.
search
,
p
.
limit
,
p
.
offset
)
}
func
G
etPageSize
(
term
*
utils
.
Terminal
)
int
{
func
g
etPageSize
(
term
*
utils
.
Terminal
)
int
{
var
(
pageSize
int
minHeight
=
8
// 分页显示的最小高度
...
...
@@ -391,3 +383,13 @@ func GetPageSize(term *utils.Terminal) int {
}
return
pageSize
}
func
displayAssetPaginationTipsInfo
(
w
io
.
Writer
)
{
tips
:=
[]
string
{
i18n
.
T
(
"
\n
Tips: Enter the asset ID and log directly into the asset.
\n
"
),
i18n
.
T
(
"
\n
Page up: P/p Page down: Enter|N/n BACK: b.
\n
"
),
}
for
_
,
tip
:=
range
tips
{
_
,
_
=
w
.
Write
([]
byte
(
tip
))
}
}
pkg/handler/session.go
View file @
0c7c4f48
...
...
@@ -189,9 +189,15 @@ func (h *interactiveHandler) displayAllAssets() {
<-
h
.
loadDataDone
h
.
displayAssets
(
h
.
allAssets
)
default
:
h
.
searchAsset
(
""
)
pag
:=
NewUserPagination
(
h
.
term
,
h
.
user
.
ID
,
""
,
false
)
result
:=
pag
.
Start
()
if
pag
.
IsNeedProxy
&&
len
(
result
)
==
1
{
h
.
searchResult
=
h
.
searchResult
[
:
0
]
h
.
ProxyAsset
(
result
[
0
])
}
else
{
h
.
searchResult
=
result
}
}
}
func
(
h
*
interactiveHandler
)
chooseSystemUser
(
systemUsers
[]
model
.
SystemUser
)
model
.
SystemUser
{
...
...
@@ -304,7 +310,13 @@ func (h *interactiveHandler) searchAsset(key string) {
h
.
displayAssets
(
assets
)
default
:
pag
:=
NewUserPagination
(
h
.
term
,
h
.
user
.
ID
,
key
,
false
)
h
.
searchResult
=
pag
.
Start
()
result
:=
pag
.
Start
()
if
pag
.
IsNeedProxy
&&
len
(
result
)
==
1
{
h
.
searchResult
=
h
.
searchResult
[
:
0
]
h
.
ProxyAsset
(
result
[
0
])
}
else
{
h
.
searchResult
=
result
}
}
}
...
...
@@ -312,11 +324,7 @@ func (h *interactiveHandler) searchAssetOrProxy(key string) {
if
indexNum
,
err
:=
strconv
.
Atoi
(
key
);
err
==
nil
&&
len
(
h
.
searchResult
)
>
0
{
if
indexNum
>
0
&&
indexNum
<=
len
(
h
.
searchResult
)
{
assetSelect
:=
h
.
searchResult
[
indexNum
-
1
]
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
assetSelect
.
ID
)
systemUserSelect
:=
h
.
chooseSystemUser
(
systemUsers
)
h
.
systemUserSelect
=
&
systemUserSelect
h
.
assetSelect
=
&
assetSelect
h
.
Proxy
(
context
.
Background
())
h
.
ProxyAsset
(
assetSelect
)
return
}
}
...
...
@@ -342,14 +350,10 @@ func (h *interactiveHandler) searchAssetOrProxy(key string) {
}
if
len
(
assets
)
==
1
{
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
assets
[
0
]
.
ID
)
systemUserSelect
:=
h
.
chooseSystemUser
(
systemUsers
)
h
.
systemUserSelect
=
&
systemUserSelect
h
.
assetSelect
=
&
assets
[
0
]
h
.
Proxy
(
context
.
Background
())
return
h
.
ProxyAsset
(
assets
[
0
])
}
else
{
h
.
searchResult
=
assets
}
h
.
searchResult
=
assets
}
func
(
h
*
interactiveHandler
)
searchNodeAssets
(
num
int
)
(
assets
model
.
AssetList
)
{
...
...
@@ -361,6 +365,14 @@ func (h *interactiveHandler) searchNodeAssets(num int) (assets model.AssetList)
return
}
func
(
h
*
interactiveHandler
)
ProxyAsset
(
assetSelect
model
.
Asset
)
{
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
assetSelect
.
ID
)
systemUserSelect
:=
h
.
chooseSystemUser
(
systemUsers
)
h
.
systemUserSelect
=
&
systemUserSelect
h
.
assetSelect
=
&
assetSelect
h
.
Proxy
(
context
.
Background
())
}
func
(
h
*
interactiveHandler
)
Proxy
(
ctx
context
.
Context
)
{
p
:=
proxy
.
ProxyServer
{
UserConn
:
h
.
sess
,
...
...
pkg/srvconn/connmanager.go
View file @
0c7c4f48
...
...
@@ -90,7 +90,7 @@ func KeepAlive(c *gossh.Client, closed <-chan struct{}, keepInterval time.Durati
case
<-
t
.
C
:
_
,
_
,
err
:=
c
.
SendRequest
(
"keepalive@jumpserver.org"
,
true
,
nil
)
if
err
!=
nil
{
logger
.
Error
(
"SSH client %p keep alive err: "
,
c
,
err
.
Error
())
logger
.
Error
f
(
"SSH client %p keep alive err: "
,
c
,
err
.
Error
())
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment