- Notifications
You must be signed in to change notification settings - Fork28
Webssh implemented by github.com/gorilla/websocket and golang.org/x/crypto/ssh
License
NotificationsYou must be signed in to change notification settings
leffss/gowebssh
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
English docREADME
使用github.com/gorilla/websocket
与golang.org/x/crypto/ssh
实现的 webssh,支持颜色以及自动补全
参考:https://github.com/myml/webssh ,在原项目的基础上新增 publickey 登陆、zmodem 上传下载(支持禁用 sz 或者 rz)
...import (..."github.com/gorilla/websocket""github.com/leffss/gowebssh")...id:=r.Header.Get("Sec-WebSocket-Key")webssh:=gowebssh.NewWebSSH()webssh.SetTerm(gowebssh.TermLinux)webssh.SetBuffSize(8192)webssh.SetId(id)webssh.SetConnTimeOut(15*time.Second)webssh.DisableSZ()//webssh.DisableRZ()...upGrader:= websocket.Upgrader{CheckOrigin:func(r*http.Request)bool {returntrue },//Subprotocols: []string{r.Header.Get("Sec-WebSocket-Protocol")},Subprotocols: []string{"webssh"},ReadBufferSize:8192,WriteBufferSize:8192,}ws,_:=upGrader.Upgrade(w,r,nil)webssh.AddWebsocket(ws)
typemessageTypestringconst (messageTypeAddr="addr"messageTypeTerm="term"messageTypeLogin="login"messageTypePassword="password"messageTypePublickey="publickey"messageTypeStdin="stdin"messageTypeStdout="stdout"messageTypeStderr="stderr"messageTypeResize="resize"messageTypeIgnore="ignore"messageTypeConsole="console")typemessagestruct {TypemessageType`json:"type"`Data []byte`json:"data,omitempty"`Colsint`json:"cols,omitempty"`Rowsint`json:"rows,omitempty"`}
- 地址
{type:"addr",data:"$addr"}
地址格式: ip:port,例如 192.168.223.111:22 - 登录
{type:"login",data:"$username"}
- 设置 term 终端类型
{type:"term",data:"$term"}
# 可不设置,默认 xterm - 验证
{type:"password",data:"$password"}
or{type:"publickey",data:"$publickey",passphrase:"$passphrase"}
- 窗口大小调整
{type:"resize",cols:40,rows:80}
- 忽略数据流
{type:"ignore",data:"$data"}
# 客户端发送到服务端,服务器忽略,可以用于 zmodem 文件传输记录 - console 数据流
{type:"console",data:"$data"}
# 服务端发送到客户端,客户端显示到 console 控制台的数据,可以用于 zmodem 文件传输时的 debug 信息 - alert 数据流
{type:"alert",data:"$data"}
# # 服务端发送到客户端的 alert 信息 - 标准流数据
{type:"stdin",data:"$data"}
{type:"stdout",data:"$data"}
{type:"stderr",data:"$data"}
客户端发送 stdin, 接收 stdout, stderr
消息的 data 数据使用 base64 编码传输,JavaScript 的atob & btoa
可用于 base64 编码,但对 utf8 有兼容性问题,要使用decodeURIComponent & encodeURIComponent
做包裹, 以下是实现
functionutf8_to_b64(rawString){returnbtoa(unescape(encodeURIComponent(rawString)));}functionb64_to_utf8(encodeString){returndecodeURIComponent(escape(atob(encodeString)));}
具体实例参考example
文件夹
About
Webssh implemented by github.com/gorilla/websocket and golang.org/x/crypto/ssh
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.