Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.10.1 #1279

Merged
merged 3 commits into from
Dec 29, 2023
Merged

v3.10.1 #1279

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/proxy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ func (p *Parser) parseInputState(b []byte) []byte {
p.inputState = true
// 用户又开始输入,并上次不处于输入状态,开始结算上次命令的结果
if !p.inputPreState {
p.sendCommandRecord()
if ps1 := p.cmdOutputParser.GetPs1(); ps1 != "" {
p.cmdInputParser.SetPs1(ps1)
}
p.sendCommandRecord()
}
}
return b
Expand Down
40 changes: 23 additions & 17 deletions pkg/srvconn/sftp_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ func (ad *AssetDir) RemoveDirectory(path string) (err error) {
if con == nil || con.isClosed {
return sftp.ErrSshFxConnectionLost
}
if con.IsRootPath(realPath) {
logger.Errorf("Diable to remove root setting path %s", realPath)
return sftp.ErrSshFxPermissionDenied
}
err = ad.removeDirectoryAll(con.client, realPath)
filename := realPath
isSuccess := false
Expand Down Expand Up @@ -532,25 +536,27 @@ func (ad *AssetDir) GetSFTPAndRealPath(su *model.PermAccount, path string) (conn
session.AddSession(traceSession)
ad.sftpTraceSessions[su.String()] = traceSession
}

platform := conn.token.Platform
sftpRoot := platform.Protocols.GetSftpPath(model.ProtocolSFTP)
accountUsername := su.Username
username := ad.user.Username
switch strings.ToLower(sftpRoot) {
case "home", "~", "":
realPath = filepath.Join(conn.HomeDirPath, strings.TrimPrefix(path, "/"))
default:
// ${ACCOUNT} 连接的账号用户名, ${USER} 当前用户用户名, ${HOME} 当前家目录
homeDir := conn.HomeDirPath
sftpRoot = strings.ReplaceAll(sftpRoot, "${ACCOUNT}", accountUsername)
sftpRoot = strings.ReplaceAll(sftpRoot, "${USER}", username)
sftpRoot = strings.ReplaceAll(sftpRoot, "${HOME}", homeDir)
if strings.Index(sftpRoot, "/") != 0 {
sftpRoot = fmt.Sprintf("/%s", sftpRoot)
if conn.rootDirPath == "" {
platform := conn.token.Platform
sftpRoot := platform.Protocols.GetSftpPath(model.ProtocolSFTP)
accountUsername := su.Username
username := ad.user.Username
switch strings.ToLower(sftpRoot) {
case "home", "~", "":
sftpRoot = conn.HomeDirPath
default:
// ${ACCOUNT} 连接的账号用户名, ${USER} 当前用户用户名, ${HOME} 当前家目录
homeDir := conn.HomeDirPath
sftpRoot = strings.ReplaceAll(sftpRoot, "${ACCOUNT}", accountUsername)
sftpRoot = strings.ReplaceAll(sftpRoot, "${USER}", username)
sftpRoot = strings.ReplaceAll(sftpRoot, "${HOME}", homeDir)
if strings.Index(sftpRoot, "/") != 0 {
sftpRoot = fmt.Sprintf("/%s", sftpRoot)
}
}
realPath = filepath.Join(sftpRoot, strings.TrimPrefix(path, "/"))
conn.rootDirPath = sftpRoot
}
realPath = filepath.Join(conn.rootDirPath, strings.TrimPrefix(path, "/"))
return
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/srvconn/sftpfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ type SftpConn struct {
client *sftp.Client
token *model.ConnectToken
isClosed bool
rootDirPath string
}

func (s *SftpConn) IsOverwriteFile() bool {
Expand All @@ -204,6 +205,10 @@ func (s *SftpConn) IsOverwriteFile() bool {
}
}

func (s *SftpConn) IsRootPath(path string) bool {
return s.rootDirPath == path
}

const (
FilenamePolicyReplace = "replace"
FilenamePolicySuffix = "suffix"
Expand Down
11 changes: 11 additions & 0 deletions ui/src/components/Terminal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ export default {
this.termSelectionText = term.getSelection().trim();
});
term.attachCustomKeyEventHandler((e) => {
if (e.altKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
switch (e.key) {
case 'ArrowRight':
this.sendEventToLuna('KEYEVENT', 'alt+right')
break
case 'ArrowLeft':
this.sendEventToLuna('KEYEVENT', 'alt+left')
break
}
}

if (e.ctrlKey && e.key === 'c' && term.hasSelection()) {
return false;
}
Expand Down