Skip to content

Commit

Permalink
Merge pull request #1279 from jumpserver/dev
Browse files Browse the repository at this point in the history
v3.10.1
  • Loading branch information
BaiJiangJie authored Dec 29, 2023
2 parents b5ca253 + 6f8b9e7 commit 38785ca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
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

0 comments on commit 38785ca

Please sign in to comment.