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
30550fd4
Commit
30550fd4
authored
Apr 28, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改session
parent
424f76bf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
94 deletions
+10
-94
hello.go
cmd/hello.go
+0
-85
sshd.go
cmd/sshd.go
+0
-1
session.go
pkg/sshd/handler/session.go
+10
-8
No files found.
cmd/hello.go
deleted
100644 → 0
View file @
424f76bf
package
main
import
(
"fmt"
"golang.org/x/crypto/ssh/terminal"
"log"
"os"
"time"
"golang.org/x/crypto/ssh"
)
func
connect
(
user
,
password
,
host
string
,
port
int
)
(
*
ssh
.
Session
,
error
)
{
var
(
auth
[]
ssh
.
AuthMethod
addr
string
clientConfig
*
ssh
.
ClientConfig
client
*
ssh
.
Client
session
*
ssh
.
Session
err
error
)
// get auth method
auth
=
make
([]
ssh
.
AuthMethod
,
0
)
auth
=
append
(
auth
,
ssh
.
Password
(
password
))
clientConfig
=
&
ssh
.
ClientConfig
{
User
:
user
,
Auth
:
auth
,
Timeout
:
30
*
time
.
Second
,
HostKeyCallback
:
ssh
.
InsecureIgnoreHostKey
(),
}
// connet to ssh
addr
=
fmt
.
Sprintf
(
"%s:%d"
,
host
,
port
)
if
client
,
err
=
ssh
.
Dial
(
"tcp"
,
addr
,
clientConfig
);
err
!=
nil
{
return
nil
,
err
}
// create session
if
session
,
err
=
client
.
NewSession
();
err
!=
nil
{
return
nil
,
err
}
return
session
,
nil
}
func
main
()
{
session
,
err
:=
connect
(
"root"
,
"redhat"
,
"192.168.244.143"
,
22
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
session
.
Close
()
fd
:=
int
(
os
.
Stdin
.
Fd
())
oldState
,
err
:=
terminal
.
MakeRaw
(
fd
)
if
err
!=
nil
{
panic
(
err
)
}
defer
terminal
.
Restore
(
fd
,
oldState
)
// excute command
session
.
Stdout
=
os
.
Stdout
session
.
Stderr
=
os
.
Stderr
session
.
Stdin
=
os
.
Stdin
termWidth
,
termHeight
,
err
:=
terminal
.
GetSize
(
fd
)
if
err
!=
nil
{
panic
(
err
)
}
// Set up terminal modes
modes
:=
ssh
.
TerminalModes
{
ssh
.
ECHO
:
1
,
// enable echoing
ssh
.
TTY_OP_ISPEED
:
14400
,
// input speed = 14.4kbaud
ssh
.
TTY_OP_OSPEED
:
14400
,
// output speed = 14.4kbaud
}
// Request pseudo terminal
if
err
:=
session
.
RequestPty
(
"xterm-256color"
,
termHeight
,
termWidth
,
modes
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
session
.
Run
(
"top"
)
}
cmd/sshd.go
deleted
100644 → 0
View file @
424f76bf
package
main
pkg/sshd/handler/session.go
View file @
30550fd4
...
...
@@ -57,13 +57,15 @@ func SessionHandler(sess ssh.Session) {
}
type
InteractiveHandler
struct
{
sess
ssh
.
Session
term
*
terminal
.
Terminal
user
*
sdk
.
User
assets
model
.
AssetList
searchResult
model
.
AssetList
nodes
model
.
NodeList
onceLoad
sync
.
Once
sess
ssh
.
Session
term
*
terminal
.
Terminal
user
*
sdk
.
User
assetSelect
*
sdk
.
Asset
systemUserSelect
*
sdk
.
SystemUser
assets
model
.
AssetList
searchResult
model
.
AssetList
nodes
model
.
NodeList
onceLoad
sync
.
Once
sync
.
RWMutex
}
...
...
@@ -328,7 +330,7 @@ func (i *InteractiveHandler) searchNodeAssets(num int) (assets []sdk.Asset) {
}
func
(
i
*
InteractiveHandler
)
Proxy
(
ctx
context
.
Context
)
{
p
:=
proxy
.
ProxyServer
{
Session
:
i
.
sess
}
p
:=
proxy
.
ProxyServer
{
Session
:
i
.
sess
,
Asset
:
i
.
assetSelect
,
SystemUser
:
i
.
systemUserSelect
}
p
.
Proxy
(
ctx
)
}
...
...
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