Unverified Commit f502a139 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #50 from jumpserver/dev

support whether show hidden file (#49)
parents 04b83c9f 2eb2a9bf
...@@ -25,6 +25,7 @@ type Config struct { ...@@ -25,6 +25,7 @@ type Config struct {
TelnetRegex string `json:"TERMINAL_TELNET_REGEX"` TelnetRegex string `json:"TERMINAL_TELNET_REGEX"`
MaxIdleTime time.Duration `json:"SECURITY_MAX_IDLE_TIME"` MaxIdleTime time.Duration `json:"SECURITY_MAX_IDLE_TIME"`
SftpRoot string `json:"TERMINAL_SFTP_ROOT" yaml:"SFTP_ROOT"` SftpRoot string `json:"TERMINAL_SFTP_ROOT" yaml:"SFTP_ROOT"`
ShowHiddenFile bool `yaml:"SFTP_SHOW_HIDDEN_FILE"`
Name string `yaml:"NAME"` Name string `yaml:"NAME"`
SecretKey string `yaml:"SECRET_KEY"` SecretKey string `yaml:"SECRET_KEY"`
HostKeyFile string `yaml:"HOST_KEY_FILE"` HostKeyFile string `yaml:"HOST_KEY_FILE"`
...@@ -129,6 +130,7 @@ var Conf = &Config{ ...@@ -129,6 +130,7 @@ var Conf = &Config{
CommandStorage: map[string]interface{}{"TYPE": "server"}, CommandStorage: map[string]interface{}{"TYPE": "server"},
UploadFailedReplay: true, UploadFailedReplay: true,
SftpRoot: "/tmp", SftpRoot: "/tmp",
ShowHiddenFile: false,
} }
func SetConf(conf *Config) { func SetConf(conf *Config) {
......
...@@ -29,7 +29,9 @@ func NewUserSFTP(user *model.User, addr string, assets ...model.Asset) *UserSftp ...@@ -29,7 +29,9 @@ func NewUserSFTP(user *model.User, addr string, assets ...model.Asset) *UserSftp
type UserSftp struct { type UserSftp struct {
User *model.User User *model.User
Addr string Addr string
RootPath string RootPath string
ShowHidden bool
hosts map[string]*HostnameDir // key hostname or hostname.orgName hosts map[string]*HostnameDir // key hostname or hostname.orgName
sftpClients map[string]*SftpConn // key %s@%s suName hostName sftpClients map[string]*SftpConn // key %s@%s suName hostName
...@@ -37,8 +39,9 @@ type UserSftp struct { ...@@ -37,8 +39,9 @@ type UserSftp struct {
} }
func (u *UserSftp) initial(assets []model.Asset) { func (u *UserSftp) initial(assets []model.Asset) {
conf := config.GetConf()
u.RootPath = config.GetConf().SftpRoot u.RootPath = conf.SftpRoot
u.ShowHidden = conf.ShowHiddenFile
u.hosts = make(map[string]*HostnameDir) u.hosts = make(map[string]*HostnameDir)
u.sftpClients = make(map[string]*SftpConn) u.sftpClients = make(map[string]*SftpConn)
u.LogChan = make(chan *model.FTPLog, 10) u.LogChan = make(chan *model.FTPLog, 10)
...@@ -85,8 +88,17 @@ func (u *UserSftp) ReadDir(path string) (res []os.FileInfo, err error) { ...@@ -85,8 +88,17 @@ func (u *UserSftp) ReadDir(path string) (res []os.FileInfo, err error) {
if conn == nil { if conn == nil {
return res, sftp.ErrSshFxPermissionDenied return res, sftp.ErrSshFxPermissionDenied
} }
logger.Debug("intersftp read dir real path: ", realPath) logger.Debug("inter sftp read dir real path: ", realPath)
res, err = conn.client.ReadDir(realPath) res, err = conn.client.ReadDir(realPath)
if !u.ShowHidden {
noHiddenFiles := make([]os.FileInfo, 0, len(res))
for i:=0; i<len(res);i++ {
if !strings.HasPrefix(res[i].Name(), ".") {
noHiddenFiles = append(noHiddenFiles,res[i])
}
}
return noHiddenFiles, err
}
return res, err return res, err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment