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
387f824c
Commit
387f824c
authored
Jul 10, 2019
by
Eric
Committed by
Eric_Lee
Jul 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] support sftp home dir
parent
b9394148
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
23 deletions
+102
-23
sftp.go
pkg/handler/sftp.go
+32
-10
sftpvolume.go
pkg/httpd/sftpvolume.go
+70
-13
No files found.
pkg/handler/sftp.go
View file @
387f824c
...
...
@@ -116,7 +116,6 @@ func (fs *sftpHandler) Filelist(r *sftp.Request) (sftp.ListerAt, error) {
if
!
ok
{
return
nil
,
sftp
.
ErrSshFxNoSuchFile
}
realPath
=
sysUserDir
.
ParsePath
(
r
.
Filepath
)
if
!
fs
.
validatePermission
(
hostDir
.
asset
.
ID
,
sysUserDir
.
systemUser
.
ID
,
model
.
ConnectAction
)
{
return
nil
,
sftp
.
ErrSshFxPermissionDenied
...
...
@@ -127,10 +126,15 @@ func (fs *sftpHandler) Filelist(r *sftp.Request) (sftp.ListerAt, error) {
if
err
!=
nil
{
return
nil
,
sftp
.
ErrSshFxPermissionDenied
}
sysUserDir
.
homeDirpath
,
err
=
client
.
Getwd
()
if
err
!=
nil
{
return
nil
,
err
}
sysUserDir
.
client
=
client
sysUserDir
.
conn
=
conn
}
realPath
=
sysUserDir
.
ParsePath
(
r
.
Filepath
)
switch
r
.
Method
{
case
"List"
:
logger
.
Debug
(
"List method"
)
...
...
@@ -189,6 +193,10 @@ func (fs *sftpHandler) Filecmd(r *sftp.Request) (err error) {
if
err
!=
nil
{
return
sftp
.
ErrSshFxPermissionDenied
}
suDir
.
homeDirpath
,
err
=
client
.
Getwd
()
if
err
!=
nil
{
return
err
}
suDir
.
client
=
client
suDir
.
conn
=
conn
}
...
...
@@ -267,6 +275,10 @@ func (fs *sftpHandler) Filewrite(r *sftp.Request) (io.WriterAt, error) {
if
err
!=
nil
{
return
nil
,
sftp
.
ErrSshFxPermissionDenied
}
suDir
.
homeDirpath
,
err
=
client
.
Getwd
()
if
err
!=
nil
{
return
nil
,
err
}
suDir
.
client
=
client
suDir
.
conn
=
conn
}
...
...
@@ -324,6 +336,10 @@ func (fs *sftpHandler) Fileread(r *sftp.Request) (io.ReaderAt, error) {
if
err
!=
nil
{
return
nil
,
sftp
.
ErrSshFxPermissionDenied
}
suDir
.
homeDirpath
,
err
=
ftpClient
.
Getwd
()
if
err
!=
nil
{
return
nil
,
err
}
suDir
.
client
=
ftpClient
suDir
.
conn
=
client
}
...
...
@@ -416,13 +432,14 @@ func (h *HostNameDir) Sys() interface{} {
}
type
SysUserDir
struct
{
ID
string
prefix
string
rootPath
string
systemUser
*
model
.
SystemUser
time
time
.
Time
client
*
sftp
.
Client
conn
*
gossh
.
Client
ID
string
prefix
string
rootPath
string
systemUser
*
model
.
SystemUser
time
time
.
Time
homeDirpath
string
client
*
sftp
.
Client
conn
*
gossh
.
Client
}
func
(
su
*
SysUserDir
)
Name
()
string
{
return
su
.
systemUser
.
Name
}
...
...
@@ -443,10 +460,15 @@ func (su *SysUserDir) Sys() interface{} {
func
(
su
*
SysUserDir
)
ParsePath
(
path
string
)
string
{
var
realPath
string
realPath
=
strings
.
ReplaceAll
(
path
,
su
.
prefix
,
su
.
rootPath
)
fmt
.
Println
(
"root path"
,
su
.
rootPath
)
switch
strings
.
ToLower
(
su
.
rootPath
)
{
case
"home"
,
"~"
,
""
:
realPath
=
strings
.
ReplaceAll
(
path
,
su
.
prefix
,
su
.
homeDirpath
)
default
:
realPath
=
strings
.
ReplaceAll
(
path
,
su
.
prefix
,
su
.
rootPath
)
}
logger
.
Debug
(
"real path: "
,
realPath
)
return
realPath
}
type
FakeFile
struct
{
...
...
pkg/httpd/sftpvolume.go
View file @
387f824c
...
...
@@ -121,16 +121,21 @@ func (u *UserVolume) Info(path string) (elfinder.FileDir, error) {
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
dirname
:=
filepath
.
Dir
(
path
)
fileInfos
,
err
:=
sysUserVol
.
client
.
Stat
(
realPath
)
if
err
!=
nil
{
...
...
@@ -194,16 +199,21 @@ func (u *UserVolume) List(path string) []elfinder.FileDir {
if
!
ok
{
return
dirs
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
dirs
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
dirs
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
subFiles
,
err
:=
sysUserVol
.
client
.
ReadDir
(
realPath
)
if
err
!=
nil
{
return
dirs
...
...
@@ -269,16 +279,21 @@ func (u *UserVolume) GetFile(path string) (reader io.ReadCloser, err error) {
return
nil
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
nil
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
nil
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
logData
:=
&
model
.
FTPLog
{
User
:
fmt
.
Sprintf
(
"%s (%s)"
,
u
.
user
.
Name
,
u
.
user
.
Username
),
Hostname
:
hostVol
.
asset
.
Hostname
,
...
...
@@ -334,16 +349,22 @@ func (u *UserVolume) UploadFile(dir, filename string, reader io.Reader) (elfinde
if
!
ok
{
return
rest
,
os
.
ErrNotExist
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
realFilenamePath
:=
filepath
.
Join
(
realPath
,
filename
)
if
!
u
.
validatePermission
(
hostVol
.
asset
.
ID
,
sysUserVol
.
systemUser
.
ID
,
model
.
UploadAction
)
{
return
rest
,
os
.
ErrPermission
...
...
@@ -436,16 +457,21 @@ func (u *UserVolume) MergeChunk(cid, total int, dirPath, filename string) (elfin
return
rest
,
os
.
ErrPermission
}
realDirPath
:=
sysUserVol
.
ParsePath
(
dirPath
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realDirPath
:=
sysUserVol
.
ParsePath
(
dirPath
)
filenamePath
:=
filepath
.
Join
(
realDirPath
,
filename
)
logData
:=
&
model
.
FTPLog
{
User
:
fmt
.
Sprintf
(
"%s (%s)"
,
u
.
user
.
Name
,
u
.
user
.
Username
),
...
...
@@ -536,15 +562,20 @@ func (u *UserVolume) MakeDir(dir, newDirname string) (elfinder.FileDir, error) {
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
realDirPath
:=
filepath
.
Join
(
realPath
,
newDirname
)
err
:=
sysUserVol
.
client
.
MkdirAll
(
realDirPath
)
logData
:=
&
model
.
FTPLog
{
...
...
@@ -604,16 +635,21 @@ func (u *UserVolume) MakeFile(dir, newFilename string) (elfinder.FileDir, error)
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
realFilePath
:=
filepath
.
Join
(
realPath
,
newFilename
)
_
,
err
:=
sysUserVol
.
client
.
Create
(
realFilePath
)
logData
:=
&
model
.
FTPLog
{
...
...
@@ -667,16 +703,21 @@ func (u *UserVolume) Rename(oldNamePath, newName string) (elfinder.FileDir, erro
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
oldNamePath
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
oldNamePath
)
dirpath
:=
filepath
.
Dir
(
realPath
)
newFilePath
:=
filepath
.
Join
(
dirpath
,
newName
)
...
...
@@ -737,16 +778,21 @@ func (u *UserVolume) Remove(path string) error {
return
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
path
)
logData
:=
&
model
.
FTPLog
{
User
:
fmt
.
Sprintf
(
"%s (%s)"
,
u
.
user
.
Name
,
u
.
user
.
Username
),
Hostname
:
hostVol
.
asset
.
Hostname
,
...
...
@@ -803,16 +849,20 @@ func (u *UserVolume) Paste(dir, filename, suffix string, reader io.ReadCloser) (
return
rest
,
os
.
ErrPermission
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
if
sysUserVol
.
client
==
nil
{
sftClient
,
conn
,
err
:=
u
.
GetSftpClient
(
hostVol
.
asset
,
sysUserVol
.
systemUser
)
if
err
!=
nil
{
return
rest
,
os
.
ErrPermission
}
sysUserVol
.
homeDirpath
,
err
=
sftClient
.
Getwd
()
if
err
!=
nil
{
return
rest
,
err
}
sysUserVol
.
client
=
sftClient
sysUserVol
.
conn
=
conn
}
realPath
:=
sysUserVol
.
ParsePath
(
dir
)
realFilePath
:=
filepath
.
Join
(
realPath
,
filename
)
_
,
err
:=
sysUserVol
.
client
.
Stat
(
realFilePath
)
if
err
!=
nil
{
...
...
@@ -923,8 +973,9 @@ type sysUserVolume struct {
rootPath
string
systemUser
*
model
.
SystemUser
client
*
sftp
.
Client
conn
*
gossh
.
Client
homeDirpath
string
client
*
sftp
.
Client
conn
*
gossh
.
Client
}
func
(
su
*
sysUserVolume
)
info
()
elfinder
.
FileDir
{
...
...
@@ -940,7 +991,13 @@ func (su *sysUserVolume) info() elfinder.FileDir {
}
func
(
su
*
sysUserVolume
)
ParsePath
(
path
string
)
string
{
realPath
:=
strings
.
ReplaceAll
(
path
,
su
.
suPath
,
su
.
rootPath
)
var
realPath
string
switch
strings
.
ToLower
(
su
.
rootPath
)
{
case
"home"
,
"~"
,
""
:
realPath
=
strings
.
ReplaceAll
(
path
,
su
.
suPath
,
su
.
homeDirpath
)
default
:
realPath
=
strings
.
ReplaceAll
(
path
,
su
.
suPath
,
su
.
rootPath
)
}
logger
.
Debug
(
"real path: "
,
realPath
)
return
realPath
}
...
...
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