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
82dd5009
Commit
82dd5009
authored
Jul 11, 2019
by
Eric
Committed by
Eric_Lee
Jul 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sftp permssion cache
parent
24dd3c40
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
sftp.go
pkg/handler/sftp.go
+11
-1
sftpvolume.go
pkg/httpd/sftpvolume.go
+11
-1
No files found.
pkg/handler/sftp.go
View file @
82dd5009
...
@@ -51,12 +51,15 @@ type sftpHandler struct {
...
@@ -51,12 +51,15 @@ type sftpHandler struct {
assets
model
.
AssetList
assets
model
.
AssetList
rootPath
string
// tmp || home || ~
rootPath
string
// tmp || home || ~
hosts
map
[
string
]
*
HostNameDir
hosts
map
[
string
]
*
HostNameDir
permCache
map
[
string
]
bool
}
}
func
(
fs
*
sftpHandler
)
initial
()
{
func
(
fs
*
sftpHandler
)
initial
()
{
fs
.
loadAssets
()
fs
.
loadAssets
()
fs
.
hosts
=
make
(
map
[
string
]
*
HostNameDir
)
fs
.
hosts
=
make
(
map
[
string
]
*
HostNameDir
)
fs
.
rootPath
=
config
.
GetConf
()
.
SftpRoot
fs
.
rootPath
=
config
.
GetConf
()
.
SftpRoot
fs
.
permCache
=
make
(
map
[
string
]
bool
)
for
i
,
item
:=
range
fs
.
assets
{
for
i
,
item
:=
range
fs
.
assets
{
tmpDir
:=
&
HostNameDir
{
tmpDir
:=
&
HostNameDir
{
rootPath
:
fs
.
rootPath
,
rootPath
:
fs
.
rootPath
,
...
@@ -401,9 +404,16 @@ func (fs *sftpHandler) Close() {
...
@@ -401,9 +404,16 @@ func (fs *sftpHandler) Close() {
}
}
func
(
fs
*
sftpHandler
)
validatePermission
(
aid
,
suid
,
operate
string
)
bool
{
func
(
fs
*
sftpHandler
)
validatePermission
(
aid
,
suid
,
operate
string
)
bool
{
return
service
.
ValidateUserAssetPermission
(
permKey
:=
fmt
.
Sprintf
(
"%s_%s_%s"
,
aid
,
suid
,
operate
)
permission
,
ok
:=
fs
.
permCache
[
permKey
]
if
ok
{
return
permission
}
permission
=
service
.
ValidateUserAssetPermission
(
fs
.
user
.
ID
,
aid
,
suid
,
operate
,
fs
.
user
.
ID
,
aid
,
suid
,
operate
,
)
)
fs
.
permCache
[
permKey
]
=
permission
return
permission
}
}
type
HostNameDir
struct
{
type
HostNameDir
struct
{
...
...
pkg/httpd/sftpvolume.go
View file @
82dd5009
...
@@ -48,6 +48,8 @@ type UserVolume struct {
...
@@ -48,6 +48,8 @@ type UserVolume struct {
hosts
map
[
string
]
*
hostnameVolume
hosts
map
[
string
]
*
hostnameVolume
localTmpPath
string
localTmpPath
string
permCache
map
[
string
]
bool
}
}
func
(
u
*
UserVolume
)
initial
()
{
func
(
u
*
UserVolume
)
initial
()
{
...
@@ -55,6 +57,7 @@ func (u *UserVolume) initial() {
...
@@ -55,6 +57,7 @@ func (u *UserVolume) initial() {
u
.
loadAssets
()
u
.
loadAssets
()
u
.
rootPath
=
conf
.
SftpRoot
u
.
rootPath
=
conf
.
SftpRoot
u
.
localTmpPath
=
filepath
.
Join
(
conf
.
RootPath
,
"data"
,
"tmp"
)
u
.
localTmpPath
=
filepath
.
Join
(
conf
.
RootPath
,
"data"
,
"tmp"
)
u
.
permCache
=
make
(
map
[
string
]
bool
)
_
=
common
.
EnsureDirExist
(
u
.
localTmpPath
)
_
=
common
.
EnsureDirExist
(
u
.
localTmpPath
)
u
.
hosts
=
make
(
map
[
string
]
*
hostnameVolume
)
u
.
hosts
=
make
(
map
[
string
]
*
hostnameVolume
)
for
i
,
item
:=
range
u
.
assets
{
for
i
,
item
:=
range
u
.
assets
{
...
@@ -939,9 +942,16 @@ func (u *UserVolume) CreateFTPLog(data *model.FTPLog) {
...
@@ -939,9 +942,16 @@ func (u *UserVolume) CreateFTPLog(data *model.FTPLog) {
}
}
func
(
u
*
UserVolume
)
validatePermission
(
aid
,
suid
,
operate
string
)
bool
{
func
(
u
*
UserVolume
)
validatePermission
(
aid
,
suid
,
operate
string
)
bool
{
return
service
.
ValidateUserAssetPermission
(
permKey
:=
fmt
.
Sprintf
(
"%s_%s_%s"
,
aid
,
suid
,
operate
)
permission
,
ok
:=
u
.
permCache
[
permKey
]
if
ok
{
return
permission
}
permission
=
service
.
ValidateUserAssetPermission
(
u
.
user
.
ID
,
aid
,
suid
,
operate
,
u
.
user
.
ID
,
aid
,
suid
,
operate
,
)
)
u
.
permCache
[
permKey
]
=
permission
return
permission
}
}
type
hostnameVolume
struct
{
type
hostnameVolume
struct
{
...
...
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