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
834a0e68
Commit
834a0e68
authored
Apr 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] bai
parent
e922cceb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
66 deletions
+78
-66
util.go
pkg/common/util.go
+0
-3
client.go
pkg/sdk/client.go
+25
-25
banner.go
pkg/sshd/handler/banner.go
+19
-4
session.go
pkg/sshd/handler/session.go
+32
-32
server.go
pkg/sshd/server.go
+2
-2
No files found.
pkg/common/util.go
deleted
100644 → 0
View file @
e922cceb
package
common
import
"fmt"
pkg/sdk/client.go
View file @
834a0e68
...
@@ -42,47 +42,47 @@ func (c *WrapperClient) CheckAuth() error {
...
@@ -42,47 +42,47 @@ func (c *WrapperClient) CheckAuth() error {
}
}
func
(
c
*
WrapperClient
)
Get
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
func
(
c
*
WrapperClient
)
Get
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
//
if needAuth {
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
//
c.Http.SetAuth(c.Auth.Sign())
}
else
{
//
} else {
c
.
Http
.
SetAuth
(
""
)
//
c.Http.SetAuth("")
}
//
}
return
c
.
Http
.
Get
(
c
.
BaseHost
+
url
,
res
)
return
c
.
Http
.
Get
(
c
.
BaseHost
+
url
,
res
)
}
}
func
(
c
*
WrapperClient
)
Post
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
func
(
c
*
WrapperClient
)
Post
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
//
if needAuth {
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
//
c.Http.SetAuth(c.Auth.Sign())
}
else
{
//
} else {
c
.
Http
.
SetAuth
(
""
)
//
c.Http.SetAuth("")
}
//
}
return
c
.
Http
.
Post
(
url
,
data
,
res
)
return
c
.
Http
.
Post
(
url
,
data
,
res
)
}
}
func
(
c
*
WrapperClient
)
Delete
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
func
(
c
*
WrapperClient
)
Delete
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
//
if needAuth {
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
//
c.Http.SetAuth(c.Auth.Sign())
}
else
{
//
} else {
c
.
Http
.
SetAuth
(
""
)
//
c.Http.SetAuth("")
}
//
}
return
c
.
Http
.
Delete
(
url
,
res
)
return
c
.
Http
.
Delete
(
url
,
res
)
}
}
func
(
c
*
WrapperClient
)
Put
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
func
(
c
*
WrapperClient
)
Put
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
//
if needAuth {
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
//
c.Http.SetAuth(c.Auth.Sign())
}
else
{
//
} else {
c
.
Http
.
SetAuth
(
""
)
//
c.Http.SetAuth("")
}
//
}
return
c
.
Http
.
Put
(
url
,
data
,
res
)
return
c
.
Http
.
Put
(
url
,
data
,
res
)
}
}
func
(
c
*
WrapperClient
)
Patch
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
func
(
c
*
WrapperClient
)
Patch
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
//
if needAuth {
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
//
c.Http.SetAuth(c.Auth.Sign())
}
else
{
//
} else {
c
.
Http
.
SetAuth
(
""
)
//
c.Http.SetAuth("")
}
//
}
return
c
.
Http
.
Patch
(
url
,
data
,
res
)
return
c
.
Http
.
Patch
(
url
,
data
,
res
)
}
}
pkg/sshd/handler/banner.go
View file @
834a0e68
package
handler
package
handler
import
(
import
(
"bytes"
"cocogo/pkg/config"
"cocogo/pkg/config"
"fmt"
"fmt"
"io"
"io"
...
@@ -14,8 +15,26 @@ import (
...
@@ -14,8 +15,26 @@ import (
const
defaultTitle
=
`Welcome to use Jumpserver open source fortress system`
const
defaultTitle
=
`Welcome to use Jumpserver open source fortress system`
type
MenuItem
struct
{
type
MenuItem
struct
{
id
int
instruct
string
instruct
string
helpText
string
helpText
string
showText
string
}
func
(
mi
*
MenuItem
)
Text
()
string
{
if
mi
.
showText
!=
""
{
return
mi
.
showText
}
cm
:=
ColorMeta
{
GreenBoldColor
:
"
\0
33[1;32m"
,
ColorEnd
:
"
\0
33[0m"
}
line
:=
fmt
.
Sprintf
(
"
\t
%d) Enter {{.GreenBoldColor}}%s{{.ColorEnd}} to %s.
\r\n
"
,
mi
.
id
,
mi
.
instruct
,
mi
.
helpText
)
tmpl
:=
template
.
Must
(
template
.
New
(
"item"
)
.
Parse
(
line
))
var
buf
bytes
.
Buffer
err
:=
tmpl
.
Execute
(
&
buf
,
cm
)
if
err
!=
nil
{
logger
.
Error
(
err
)
}
mi
.
showText
=
string
(
buf
.
Bytes
())
return
mi
.
showText
}
}
type
Menu
[]
MenuItem
type
Menu
[]
MenuItem
...
@@ -32,10 +51,6 @@ var menu = Menu{
...
@@ -32,10 +51,6 @@ var menu = Menu{
{
instruct
:
"q"
,
helpText
:
"exit"
},
{
instruct
:
"q"
,
helpText
:
"exit"
},
}
}
type
Banner
struct
{
user
string
}
type
ColorMeta
struct
{
type
ColorMeta
struct
{
GreenBoldColor
string
GreenBoldColor
string
ColorEnd
string
ColorEnd
string
...
...
pkg/sshd/handler/session.go
View file @
834a0e68
...
@@ -63,7 +63,7 @@ func (i *InteractiveHandler) preDispatch() {
...
@@ -63,7 +63,7 @@ func (i *InteractiveHandler) preDispatch() {
})
})
}
}
func
(
i
*
InteractiveHandler
)
watchSizeChange
(
winCh
<-
chan
ssh
.
Window
)
{
func
(
i
*
InteractiveHandler
)
watch
Win
SizeChange
(
winCh
<-
chan
ssh
.
Window
)
{
ctx
,
cancelFunc
:=
context
.
WithCancel
(
i
.
sess
.
Context
())
ctx
,
cancelFunc
:=
context
.
WithCancel
(
i
.
sess
.
Context
())
defer
cancelFunc
()
defer
cancelFunc
()
for
{
for
{
...
@@ -85,7 +85,7 @@ func (i *InteractiveHandler) Dispatch() {
...
@@ -85,7 +85,7 @@ func (i *InteractiveHandler) Dispatch() {
i
.
preDispatch
()
i
.
preDispatch
()
_
,
winCh
,
_
:=
i
.
sess
.
Pty
()
_
,
winCh
,
_
:=
i
.
sess
.
Pty
()
for
{
for
{
go
i
.
watchSizeChange
(
winCh
)
go
i
.
watch
Win
SizeChange
(
winCh
)
line
,
err
:=
i
.
term
.
ReadLine
()
line
,
err
:=
i
.
term
.
ReadLine
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -163,36 +163,36 @@ func (i *InteractiveHandler) chooseSystemUser(systemUsers []sdk.SystemUser) sdk.
...
@@ -163,36 +163,36 @@ func (i *InteractiveHandler) chooseSystemUser(systemUsers []sdk.SystemUser) sdk.
// 当资产的数量为1的时候,就进行代理转化
// 当资产的数量为1的时候,就进行代理转化
func
(
i
*
InteractiveHandler
)
displayAssetsOrProxy
(
assets
[]
sdk
.
Asset
)
{
func
(
i
*
InteractiveHandler
)
displayAssetsOrProxy
(
assets
[]
sdk
.
Asset
)
{
if
len
(
assets
)
==
1
{
//
if len(assets) == 1 {
var
systemUser
sdk
.
SystemUser
//
var systemUser sdk.SystemUser
switch
len
(
assets
[
0
]
.
SystemUsers
)
{
//
switch len(assets[0].SystemUsers) {
case
0
:
//
case 0:
// 有授权的资产,但是资产用户信息,无法登陆
//
// 有授权的资产,但是资产用户信息,无法登陆
i
.
displayAssets
(
assets
)
//
i.displayAssets(assets)
return
//
return
case
1
:
//
case 1:
systemUser
=
assets
[
0
]
.
SystemUsers
[
0
]
//
systemUser = assets[0].SystemUsers[0]
default
:
//
default:
systemUser
=
i
.
chooseSystemUser
(
assets
[
0
]
.
SystemUsers
)
//
systemUser = i.chooseSystemUser(assets[0].SystemUsers)
}
//
}
//
authInfo
,
err
:=
sdk
.
GetSystemUserAssetAuthInfo
(
systemUser
.
Id
,
assets
[
0
]
.
Id
)
//
authInfo, err := sdk.GetSystemUserAssetAuthInfo(systemUser.Id, assets[0].Id)
if
err
!=
nil
{
//
if err != nil {
return
//
return
}
//
}
if
ok
:=
service
.
ValidateUserAssetPermission
(
i
.
user
.
Id
,
systemUser
.
Id
,
assets
[
0
]
.
Id
);
!
ok
{
//
if ok := service.ValidateUserAssetPermission(i.user.Id, systemUser.Id, assets[0].Id); !ok {
// 检查user 是否对该资产有权限
//
// 检查user 是否对该资产有权限
return
//
return
}
//
}
//
err
=
i
.
Proxy
(
assets
[
0
],
authInfo
)
//
err = i.Proxy(assets[0], authInfo)
if
err
!=
nil
{
//
if err != nil {
logger
.
Info
(
err
)
//
logger.Info(err)
}
//
}
return
//
return
}
else
{
//
} else {
i
.
displayAssets
(
assets
)
//
i.displayAssets(assets)
}
//
}
}
}
func
(
i
*
InteractiveHandler
)
displayAssets
(
assets
model
.
AssetList
)
{
func
(
i
*
InteractiveHandler
)
displayAssets
(
assets
model
.
AssetList
)
{
...
...
pkg/sshd/server.go
View file @
834a0e68
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"cocogo/pkg/config"
"cocogo/pkg/config"
"cocogo/pkg/logger"
"cocogo/pkg/logger"
"
.
/handler"
"
cocogo/pkg/sshd
/handler"
)
)
var
(
var
(
...
@@ -31,7 +31,7 @@ func StartServer() {
...
@@ -31,7 +31,7 @@ func StartServer() {
KeyboardInteractiveHandler
:
auth
.
CheckMFA
,
KeyboardInteractiveHandler
:
auth
.
CheckMFA
,
HostSigners
:
[]
ssh
.
Signer
{
signer
},
HostSigners
:
[]
ssh
.
Signer
{
signer
},
Version
:
"coco-v1.4"
,
Version
:
"coco-v1.4"
,
Handler
:
handler
.
Test
Handler
,
Handler
:
handler
.
Session
Handler
,
}
}
logger
.
Fatal
(
srv
.
ListenAndServe
())
logger
.
Fatal
(
srv
.
ListenAndServe
())
}
}
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