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
981f283e
Unverified
Commit
981f283e
authored
Oct 25, 2019
by
Eric_Lee
Committed by
GitHub
Oct 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] select system user info (#119)
parent
4c1125a8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
27 deletions
+107
-27
koko.po
cmd/locale/en_US/LC_MESSAGES/koko.po
+20
-0
koko.mo
cmd/locale/zh_CN/LC_MESSAGES/koko.mo
+0
-0
koko.po
cmd/locale/zh_CN/LC_MESSAGES/koko.po
+32
-8
banner.go
pkg/handler/banner.go
+4
-0
session.go
pkg/handler/session.go
+51
-19
No files found.
cmd/locale/en_US/LC_MESSAGES/koko.po
View file @
981f283e
...
@@ -126,6 +126,26 @@ msgstr ""
...
@@ -126,6 +126,26 @@ msgstr ""
msgid "Refresh done"
msgid "Refresh done"
msgstr ""
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:101
msgid "Tips: Enter system user ID and directly login the asset [ %s(%s) ]"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:102
msgid "Back: B/b"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:103
msgid "Name"
msgstr ""
#. i18n.T
#: pkg/handler/banner.go:104
msgid "Username"
msgstr ""
#. i18n.T
#. i18n.T
#: pkg/proxy/parser.go:131
#: pkg/proxy/parser.go:131
msgid "Command `%s` is forbidden"
msgid "Command `%s` is forbidden"
...
...
cmd/locale/zh_CN/LC_MESSAGES/koko.mo
View file @
981f283e
No preview for this file type
cmd/locale/zh_CN/LC_MESSAGES/koko.po
View file @
981f283e
...
@@ -20,7 +20,7 @@ msgstr "欢迎使用Jumpserver开源堡垒机系统"
...
@@ -20,7 +20,7 @@ msgstr "欢迎使用Jumpserver开源堡垒机系统"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:48
#: pkg/handler/banner.go:48
msgid "directly login"
msgid "directly login"
msgstr "直接登
陆
"
msgstr "直接登
录
"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:49
#: pkg/handler/banner.go:49
...
@@ -35,12 +35,12 @@ msgstr "进行搜索登录(如果唯一)"
...
@@ -35,12 +35,12 @@ msgstr "进行搜索登录(如果唯一)"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:50
msgid "/ + IP, Hostname, Comment"
msgid "/ + IP, Hostname, Comment"
msgstr "/ + IP
,
主机名 or 备注"
msgstr "/ + IP
,
主机名 or 备注"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:50
#: pkg/handler/banner.go:50
msgid "to search, such as: /192.168"
msgid "to search, such as: /192.168"
msgstr "搜索, 如
:
/192.168"
msgstr "搜索, 如
:
/192.168"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:51
#: pkg/handler/banner.go:51
...
@@ -90,7 +90,7 @@ msgstr "备注"
...
@@ -90,7 +90,7 @@ msgstr "备注"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:94
#: pkg/handler/banner.go:94
msgid "Page: %d, Count: %d, Total Page: %d, Total Count: %d"
msgid "Page: %d, Count: %d, Total Page: %d, Total Count: %d"
msgstr "页码
: %d, 每页行数: %d, 总页数: %d, 总数量:
%d"
msgstr "页码
:%d,每页行数:%d,总页数:%d,总数量:
%d"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:95
#: pkg/handler/banner.go:95
...
@@ -105,7 +105,7 @@ msgid ""
...
@@ -105,7 +105,7 @@ msgid ""
"Tips: Enter the asset ID and directly login the asset.\n"
"Tips: Enter the asset ID and directly login the asset.\n"
msgstr ""
msgstr ""
"\n"
"\n"
"提示
: 输入资产ID,直接登录资产.
\n"
"提示
:输入资产ID,登录资产
\n"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:97
#: pkg/handler/banner.go:97
...
@@ -114,23 +114,47 @@ msgid ""
...
@@ -114,23 +114,47 @@ msgid ""
"Page up: P/p\tPage down: Enter|N/n\tBACK: b.\n"
"Page up: P/p\tPage down: Enter|N/n\tBACK: b.\n"
msgstr ""
msgstr ""
"\n"
"\n"
"上一页
: P/p 下一页: Enter|N/n 返回:
B/b\n"
"上一页
:P/p 下一页:Enter|N/n 返回:
B/b\n"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:98
#: pkg/handler/banner.go:98
msgid "Node: [ ID.Name(Asset amount) ]"
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点
:
[ ID.名称(资产数量) ]"
msgstr "节点
:
[ ID.名称(资产数量) ]"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:99
#: pkg/handler/banner.go:99
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示
: 输入 g+节点ID 显示节点下主机.
如: g1"
msgstr "提示
:输入 g+节点ID 显示节点下主机,
如: g1"
#. i18n.T
#. i18n.T
#: pkg/handler/banner.go:100
#: pkg/handler/banner.go:100
msgid "Refresh done"
msgid "Refresh done"
msgstr "刷新完成"
msgstr "刷新完成"
#. i18n.T
#: pkg/handler/banner.go:101
#, fuzzy
msgid "Tips: Enter system user ID and directly login the asset [ %s(%s) ]"
msgstr ""
"\n"
"提示:输入系统用户ID,登录资产[ %s(%s) ]\n"
#. i18n.T
#: pkg/handler/banner.go:102
msgid "Back: B/b"
msgstr "返回:B/b"
#. i18n.T
#: pkg/handler/banner.go:103
msgid "Name"
msgstr "名称"
#. i18n.T
#: pkg/handler/banner.go:104
#, fuzzy
msgid "Username"
msgstr "用户名"
#. i18n.T
#. i18n.T
#: pkg/proxy/parser.go:131
#: pkg/proxy/parser.go:131
msgid "Command `%s` is forbidden"
msgid "Command `%s` is forbidden"
...
...
pkg/handler/banner.go
View file @
981f283e
...
@@ -98,6 +98,10 @@ func getI18nFromMap(name string) string {
...
@@ -98,6 +98,10 @@ func getI18nFromMap(name string) string {
"NodeHeaderTip"
:
i18n
.
T
(
"Node: [ ID.Name(Asset amount) ]"
),
"NodeHeaderTip"
:
i18n
.
T
(
"Node: [ ID.Name(Asset amount) ]"
),
"NodeEndTip"
:
i18n
.
T
(
"Tips: Enter g+NodeID to display the host under the node, such as g1"
),
"NodeEndTip"
:
i18n
.
T
(
"Tips: Enter g+NodeID to display the host under the node, such as g1"
),
"RefreshDone"
:
i18n
.
T
(
"Refresh done"
),
"RefreshDone"
:
i18n
.
T
(
"Refresh done"
),
"SelectUserTip"
:
i18n
.
T
(
"Tips: Enter system user ID and directly login the asset [ %s(%s) ]"
),
"BackTip"
:
i18n
.
T
(
"Back: B/b"
),
"Name"
:
i18n
.
T
(
"Name"
),
"Username"
:
i18n
.
T
(
"Username"
),
}
}
})
})
return
i18nMap
[
name
]
return
i18nMap
[
name
]
...
...
pkg/handler/session.go
View file @
981f283e
...
@@ -8,10 +8,10 @@ import (
...
@@ -8,10 +8,10 @@ import (
"strings"
"strings"
"github.com/gliderlabs/ssh"
"github.com/gliderlabs/ssh"
"github.com/olekukonko/tablewriter"
"github.com/xlab/treeprint"
"github.com/xlab/treeprint"
"github.com/jumpserver/koko/pkg/cctx"
"github.com/jumpserver/koko/pkg/cctx"
"github.com/jumpserver/koko/pkg/common"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/model"
...
@@ -195,45 +195,71 @@ func (h *interactiveHandler) displayAllAssets() {
...
@@ -195,45 +195,71 @@ func (h *interactiveHandler) displayAllAssets() {
}
}
}
}
func
(
h
*
interactiveHandler
)
chooseSystemUser
(
systemUsers
[]
model
.
SystemUser
)
model
.
SystemUser
{
func
(
h
*
interactiveHandler
)
chooseSystemUser
(
asset
model
.
Asset
,
systemUsers
[]
model
.
SystemUser
)
(
systemUser
model
.
SystemUser
,
ok
bool
)
{
length
:=
len
(
systemUsers
)
length
:=
len
(
systemUsers
)
switch
length
{
switch
length
{
case
0
:
case
0
:
return
model
.
SystemUser
{}
return
model
.
SystemUser
{}
,
false
case
1
:
case
1
:
return
systemUsers
[
0
]
return
systemUsers
[
0
]
,
true
default
:
default
:
}
}
displaySystemUsers
:=
selectHighestPrioritySystemUsers
(
systemUsers
)
displaySystemUsers
:=
selectHighestPrioritySystemUsers
(
systemUsers
)
if
len
(
displaySystemUsers
)
==
1
{
if
len
(
displaySystemUsers
)
==
1
{
return
displaySystemUsers
[
0
]
return
displaySystemUsers
[
0
]
,
true
}
}
table
:=
tablewriter
.
NewWriter
(
h
.
term
)
Labels
:=
[]
string
{
getI18nFromMap
(
"ID"
),
getI18nFromMap
(
"Name"
),
getI18nFromMap
(
"Username"
)}
table
.
SetHeader
([]
string
{
"ID"
,
"Name"
})
fields
:=
[]
string
{
"ID"
,
"Name"
,
"Username"
}
for
i
:=
0
;
i
<
len
(
displaySystemUsers
);
i
++
{
table
.
Append
([]
string
{
strconv
.
Itoa
(
i
+
1
),
displaySystemUsers
[
i
]
.
Name
})
data
:=
make
([]
map
[
string
]
string
,
len
(
displaySystemUsers
))
for
i
,
j
:=
range
displaySystemUsers
{
row
:=
make
(
map
[
string
]
string
)
row
[
"ID"
]
=
strconv
.
Itoa
(
i
+
1
)
row
[
"Name"
]
=
j
.
Name
row
[
"Username"
]
=
j
.
Username
data
[
i
]
=
row
}
}
table
.
SetBorder
(
false
)
w
,
_
:=
h
.
term
.
GetSize
()
table
.
SetHeaderAlignment
(
tablewriter
.
ALIGN_LEFT
)
table
:=
common
.
WrapperTable
{
table
.
SetAlignment
(
tablewriter
.
ALIGN_LEFT
)
Fields
:
fields
,
Labels
:
Labels
,
FieldsSize
:
map
[
string
][
3
]
int
{
"ID"
:
{
0
,
0
,
5
},
"Name"
:
{
0
,
8
,
0
},
"Username"
:
{
0
,
10
,
0
},
},
Data
:
data
,
TotalSize
:
w
,
TruncPolicy
:
common
.
TruncMiddle
,
}
table
.
Initial
()
h
.
term
.
SetPrompt
(
"ID> "
)
h
.
term
.
SetPrompt
(
"ID> "
)
defer
h
.
term
.
SetPrompt
(
"Opt> "
)
defer
h
.
term
.
SetPrompt
(
"Opt> "
)
for
count
:=
0
;
count
<
3
;
count
++
{
selectUserTip
:=
fmt
.
Sprintf
(
getI18nFromMap
(
"SelectUserTip"
),
asset
.
Hostname
,
asset
.
IP
)
table
.
Render
()
for
{
utils
.
IgnoreErrWriteString
(
h
.
term
,
table
.
Display
())
utils
.
IgnoreErrWriteString
(
h
.
term
,
selectUserTip
)
utils
.
IgnoreErrWriteString
(
h
.
term
,
getI18nFromMap
(
"BackTip"
))
utils
.
IgnoreErrWriteString
(
h
.
term
,
"
\r\n
"
)
line
,
err
:=
h
.
term
.
ReadLine
()
line
,
err
:=
h
.
term
.
ReadLine
()
if
err
!=
nil
{
if
err
!=
nil
{
break
return
}
}
line
=
strings
.
TrimSpace
(
line
)
line
=
strings
.
TrimSpace
(
line
)
switch
strings
.
ToLower
(
line
)
{
case
"q"
,
"b"
,
"quit"
,
"exit"
,
"back"
:
return
}
if
num
,
err
:=
strconv
.
Atoi
(
line
);
err
==
nil
{
if
num
,
err
:=
strconv
.
Atoi
(
line
);
err
==
nil
{
if
num
>
0
&&
num
<=
len
(
displaySystemUsers
)
{
if
num
>
0
&&
num
<=
len
(
displaySystemUsers
)
{
return
displaySystemUsers
[
num
-
1
]
return
displaySystemUsers
[
num
-
1
]
,
true
}
}
}
}
}
}
return
displaySystemUsers
[
0
]
}
}
func
(
h
*
interactiveHandler
)
displayAssets
(
assets
model
.
AssetList
)
{
func
(
h
*
interactiveHandler
)
displayAssets
(
assets
model
.
AssetList
)
{
...
@@ -245,7 +271,10 @@ func (h *interactiveHandler) displayAssets(assets model.AssetList) {
...
@@ -245,7 +271,10 @@ func (h *interactiveHandler) displayAssets(assets model.AssetList) {
selectOneAssets
:=
pag
.
Start
()
selectOneAssets
:=
pag
.
Start
()
if
len
(
selectOneAssets
)
==
1
{
if
len
(
selectOneAssets
)
==
1
{
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
selectOneAssets
[
0
]
.
ID
)
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
selectOneAssets
[
0
]
.
ID
)
systemUser
:=
h
.
chooseSystemUser
(
systemUsers
)
systemUser
,
ok
:=
h
.
chooseSystemUser
(
selectOneAssets
[
0
],
systemUsers
)
if
!
ok
{
return
}
h
.
assetSelect
=
&
selectOneAssets
[
0
]
h
.
assetSelect
=
&
selectOneAssets
[
0
]
h
.
systemUserSelect
=
&
systemUser
h
.
systemUserSelect
=
&
systemUser
h
.
Proxy
(
context
.
TODO
())
h
.
Proxy
(
context
.
TODO
())
...
@@ -359,7 +388,10 @@ func (h *interactiveHandler) searchNodeAssets(num int) (assets model.AssetList)
...
@@ -359,7 +388,10 @@ func (h *interactiveHandler) searchNodeAssets(num int) (assets model.AssetList)
func
(
h
*
interactiveHandler
)
ProxyAsset
(
assetSelect
model
.
Asset
)
{
func
(
h
*
interactiveHandler
)
ProxyAsset
(
assetSelect
model
.
Asset
)
{
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
assetSelect
.
ID
)
systemUsers
:=
service
.
GetUserAssetSystemUsers
(
h
.
user
.
ID
,
assetSelect
.
ID
)
systemUserSelect
:=
h
.
chooseSystemUser
(
systemUsers
)
systemUserSelect
,
ok
:=
h
.
chooseSystemUser
(
assetSelect
,
systemUsers
)
if
!
ok
{
return
}
h
.
systemUserSelect
=
&
systemUserSelect
h
.
systemUserSelect
=
&
systemUserSelect
h
.
assetSelect
=
&
assetSelect
h
.
assetSelect
=
&
assetSelect
h
.
Proxy
(
context
.
Background
())
h
.
Proxy
(
context
.
Background
())
...
...
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