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
47ef2d26
Commit
47ef2d26
authored
Sep 11, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add zipMaxSize and zipTmpPath config
parent
acc58e40
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
16 deletions
+78
-16
config_example.yml
cmd/config_example.yml
+8
-2
go.mod
go.mod
+1
-1
go.sum
go.sum
+4
-2
client_test.go
pkg/common/client_test.go
+23
-7
httputil.go
pkg/common/httputil.go
+27
-0
config.go
pkg/config/config.go
+4
-0
elfhandler.go
pkg/httpd/elfhandler.go
+11
-4
No files found.
cmd/config_example.yml
View file @
47ef2d26
...
@@ -50,4 +50,10 @@ BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>
...
@@ -50,4 +50,10 @@ BOOTSTRAP_TOKEN: <PleasgeChangeSameWithJumpserver>
# REUSE_CONNECTION: true
# REUSE_CONNECTION: true
# 资产加载策略, 可根据资产规模自行调整. 默认异步加载资产, 异步搜索分页; 如果为all, 则资产全部加载, 本地搜索分页.
# 资产加载策略, 可根据资产规模自行调整. 默认异步加载资产, 异步搜索分页; 如果为all, 则资产全部加载, 本地搜索分页.
# ASSET_LOAD_POLICY:
# ASSET_LOAD_POLICY:
\ No newline at end of file
# zip压缩的最大额度 (单位: M)
# ZIP_MAX_SIZE: 1024M
# zip压缩存放的临时目录 /tmp
# ZIP_TMP_PATH: /tmp
\ No newline at end of file
go.mod
View file @
47ef2d26
...
@@ -6,7 +6,7 @@ require (
...
@@ -6,7 +6,7 @@ require (
github.com/Azure/azure-pipeline-go v0.1.9 // indirect
github.com/Azure/azure-pipeline-go v0.1.9 // indirect
github.com/Azure/azure-storage-blob-go v0.6.0
github.com/Azure/azure-storage-blob-go v0.6.0
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/LeeEirc/elfinder v0.0.
4
github.com/LeeEirc/elfinder v0.0.
6
github.com/aliyun/aliyun-oss-go-sdk v1.9.8
github.com/aliyun/aliyun-oss-go-sdk v1.9.8
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
github.com/aws/aws-sdk-go v1.19.46
github.com/aws/aws-sdk-go v1.19.46
...
...
go.sum
View file @
47ef2d26
...
@@ -5,8 +5,10 @@ github.com/Azure/azure-storage-blob-go v0.6.0 h1:SEATKb3LIHcaSIX+E6/K4kJpwfuozFE
...
@@ -5,8 +5,10 @@ github.com/Azure/azure-storage-blob-go v0.6.0 h1:SEATKb3LIHcaSIX+E6/K4kJpwfuozFE
github.com/Azure/azure-storage-blob-go v0.6.0/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
github.com/Azure/azure-storage-blob-go v0.6.0/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/LeeEirc/elfinder v0.0.4 h1:KPos/jYF5T86L8vyyHLxVhPzvhgS6ilhKwkv+kJZVmo=
github.com/LeeEirc/elfinder v0.0.5 h1:pZd1O0FDtWwMtfFlGtWPe5XdNTHWO8D8EDp49yPyNtI=
github.com/LeeEirc/elfinder v0.0.4/go.mod h1:d1bMAAydkZSBxSN/EuQjBg6B0xcPP3boHuYEpzEHYTs=
github.com/LeeEirc/elfinder v0.0.5/go.mod h1:d1bMAAydkZSBxSN/EuQjBg6B0xcPP3boHuYEpzEHYTs=
github.com/LeeEirc/elfinder v0.0.6 h1:J1UDm5hBlAIxE6k7yXaf09yZ+Oe3z+QOHg+AMfZeWEg=
github.com/LeeEirc/elfinder v0.0.6/go.mod h1:d1bMAAydkZSBxSN/EuQjBg6B0xcPP3boHuYEpzEHYTs=
github.com/aliyun/aliyun-oss-go-sdk v1.9.8 h1:BOflvK0Zs/zGmoabyFIzTg5c3kguktWTXEwewwbuba0=
github.com/aliyun/aliyun-oss-go-sdk v1.9.8 h1:BOflvK0Zs/zGmoabyFIzTg5c3kguktWTXEwewwbuba0=
github.com/aliyun/aliyun-oss-go-sdk v1.9.8/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/aliyun/aliyun-oss-go-sdk v1.9.8/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
...
...
pkg/common/client_test.go
View file @
47ef2d26
...
@@ -28,13 +28,13 @@ var userDeleteUrl = fmt.Sprintf("%s/%d", usersUrl, user.ID)
...
@@ -28,13 +28,13 @@ var userDeleteUrl = fmt.Sprintf("%s/%d", usersUrl, user.ID)
func
TestClient_Do
(
t
*
testing
.
T
)
{
func
TestClient_Do
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
10
,
""
)
c
:=
NewClient
(
10
,
""
)
err
:=
c
.
Do
(
"GET"
,
usersUrl
,
nil
,
nil
)
_
,
err
:=
c
.
Do
(
"GET"
,
usersUrl
,
nil
,
nil
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Error
(
"Failed Do(), want get err but not"
)
t
.
Error
(
"Failed Do(), want get err but not"
)
}
}
c
.
SetBasicAuth
(
username
,
password
)
c
.
SetBasicAuth
(
username
,
password
)
var
res
[]
User
var
res
[]
User
err
=
c
.
Do
(
"GET"
,
usersUrl
,
nil
,
&
res
)
_
,
err
=
c
.
Do
(
"GET"
,
usersUrl
,
nil
,
&
res
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed Do() error: %s"
,
err
.
Error
())
t
.
Errorf
(
"Failed Do() error: %s"
,
err
.
Error
())
}
}
...
@@ -45,12 +45,12 @@ func TestClient_Do(t *testing.T) {
...
@@ -45,12 +45,12 @@ func TestClient_Do(t *testing.T) {
func
TestClient_Get
(
t
*
testing
.
T
)
{
func
TestClient_Get
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
10
,
baseHost
)
c
:=
NewClient
(
10
,
baseHost
)
err
:=
c
.
Get
(
usersUrl
,
nil
)
_
,
err
:=
c
.
Get
(
usersUrl
,
nil
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Failed Get(%s): want get err but not"
,
usersUrl
)
t
.
Errorf
(
"Failed Get(%s): want get err but not"
,
usersUrl
)
}
}
c
.
SetBasicAuth
(
username
,
password
)
c
.
SetBasicAuth
(
username
,
password
)
err
=
c
.
Get
(
usersUrl
,
nil
)
_
,
err
=
c
.
Get
(
usersUrl
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed Get(%s): %s"
,
usersUrl
,
err
.
Error
())
t
.
Errorf
(
"Failed Get(%s): %s"
,
usersUrl
,
err
.
Error
())
}
}
...
@@ -59,7 +59,7 @@ func TestClient_Get(t *testing.T) {
...
@@ -59,7 +59,7 @@ func TestClient_Get(t *testing.T) {
func
TestClient_Post
(
t
*
testing
.
T
)
{
func
TestClient_Post
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
10
,
baseHost
)
c
:=
NewClient
(
10
,
baseHost
)
var
userCreated
User
var
userCreated
User
err
:=
c
.
Post
(
usersUrl
,
user
,
&
userCreated
)
_
,
err
:=
c
.
Post
(
usersUrl
,
user
,
&
userCreated
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed Post(): %s"
,
err
.
Error
())
t
.
Errorf
(
"Failed Post(): %s"
,
err
.
Error
())
}
}
...
@@ -71,7 +71,7 @@ func TestClient_Post(t *testing.T) {
...
@@ -71,7 +71,7 @@ func TestClient_Post(t *testing.T) {
func
TestClient_Put
(
t
*
testing
.
T
)
{
func
TestClient_Put
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
10
,
""
)
c
:=
NewClient
(
10
,
""
)
var
userUpdated
User
var
userUpdated
User
err
:=
c
.
Put
(
usersUrl
,
user
,
&
userUpdated
)
_
,
err
:=
c
.
Put
(
usersUrl
,
user
,
&
userUpdated
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed Put(): %s"
,
err
.
Error
())
t
.
Errorf
(
"Failed Put(): %s"
,
err
.
Error
())
}
}
...
@@ -83,7 +83,7 @@ func TestClient_Put(t *testing.T) {
...
@@ -83,7 +83,7 @@ func TestClient_Put(t *testing.T) {
func
TestClient_Delete
(
t
*
testing
.
T
)
{
func
TestClient_Delete
(
t
*
testing
.
T
)
{
c
:=
NewClient
(
10
,
baseHost
)
c
:=
NewClient
(
10
,
baseHost
)
c
.
SetBasicAuth
(
username
,
password
)
c
.
SetBasicAuth
(
username
,
password
)
err
:=
c
.
Delete
(
userDeleteUrl
,
nil
)
_
,
err
:=
c
.
Delete
(
userDeleteUrl
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed Delete(): %s"
,
err
.
Error
())
t
.
Errorf
(
"Failed Delete(): %s"
,
err
.
Error
())
}
}
...
@@ -120,3 +120,19 @@ func TestMain(m *testing.M) {
...
@@ -120,3 +120,19 @@ func TestMain(m *testing.M) {
code
:=
m
.
Run
()
code
:=
m
.
Run
()
os
.
Exit
(
code
)
os
.
Exit
(
code
)
}
}
func
TestConvertSizeToBytes
(
t
*
testing
.
T
)
{
data
:=
map
[
string
]
int
{
"100M"
:
100
*
1024
*
1024
,
"10M"
:
10
*
1024
*
1024
,
"1G"
:
1024
*
1024
*
1024
,
"1024"
:
1024
,
}
for
k
,
v
:=
range
data
{
convValue
:=
ConvertSizeToBytes
(
k
)
if
convValue
!=
v
{
t
.
Errorf
(
"%s should be equale to %d bytes, but conver to %d"
,
k
,
v
,
convValue
)
}
t
.
Logf
(
"%s convert to %d bytes"
,
k
,
convValue
)
}
}
pkg/common/httputil.go
View file @
47ef2d26
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strings"
"strings"
"time"
"time"
)
)
...
@@ -43,3 +44,29 @@ func MakeSureDirExit(filePath string) {
...
@@ -43,3 +44,29 @@ func MakeSureDirExit(filePath string) {
log
.
Info
(
"dir path exits:"
,
dirPath
)
log
.
Info
(
"dir path exits:"
,
dirPath
)
}
}
func
ConvertSizeToBytes
(
size
string
)
int
{
defaultSize
:=
1024
*
1024
*
1024
suffixs
:=
[]
string
{
"M"
,
"m"
,
"g"
,
"G"
}
for
i
:=
0
;
i
<
len
(
suffixs
);
i
++
{
if
strings
.
HasSuffix
(
size
,
suffixs
[
i
])
{
num
:=
strings
.
TrimSuffix
(
size
,
suffixs
[
i
])
switch
strings
.
ToLower
(
suffixs
[
i
])
{
case
"m"
:
if
sizeNum
,
err
:=
strconv
.
Atoi
(
num
);
err
==
nil
{
return
sizeNum
*
1024
*
1024
}
case
"g"
:
if
sizeNum
,
err
:=
strconv
.
Atoi
(
num
);
err
==
nil
{
return
sizeNum
*
1024
*
1024
*
1024
}
}
break
}
}
if
sizeNum
,
err
:=
strconv
.
Atoi
(
size
);
err
==
nil
&&
sizeNum
>
0
{
return
sizeNum
}
return
defaultSize
}
pkg/config/config.go
View file @
47ef2d26
...
@@ -46,6 +46,8 @@ type Config struct {
...
@@ -46,6 +46,8 @@ type Config struct {
LanguageCode
string
`yaml:"LANGUAGE_CODE"`
// Abandon
LanguageCode
string
`yaml:"LANGUAGE_CODE"`
// Abandon
UploadFailedReplay
bool
`yaml:"UPLOAD_FAILED_REPLAY_ON_START"`
UploadFailedReplay
bool
`yaml:"UPLOAD_FAILED_REPLAY_ON_START"`
AssetLoadPolicy
string
`yaml:"ASSET_LOAD_POLICY"`
// all
AssetLoadPolicy
string
`yaml:"ASSET_LOAD_POLICY"`
// all
ZipMaxSize
string
`yaml:"ZIP_MAX_SIZE"`
ZipTmpPath
string
`yaml:"ZIP_TMP_PATH"`
}
}
func
(
c
*
Config
)
EnsureConfigValid
()
{
func
(
c
*
Config
)
EnsureConfigValid
()
{
...
@@ -135,6 +137,8 @@ var Conf = &Config{
...
@@ -135,6 +137,8 @@ var Conf = &Config{
ShowHiddenFile
:
false
,
ShowHiddenFile
:
false
,
ReuseConnection
:
true
,
ReuseConnection
:
true
,
AssetLoadPolicy
:
""
,
AssetLoadPolicy
:
""
,
ZipMaxSize
:
"1024M"
,
ZipTmpPath
:
"/tmp"
,
}
}
func
SetConf
(
conf
*
Config
)
{
func
SetConf
(
conf
*
Config
)
{
...
...
pkg/httpd/elfhandler.go
View file @
47ef2d26
...
@@ -5,12 +5,15 @@ import (
...
@@ -5,12 +5,15 @@ import (
"fmt"
"fmt"
"html/template"
"html/template"
"net/http"
"net/http"
"strconv"
"strings"
"strings"
"github.com/LeeEirc/elfinder"
"github.com/LeeEirc/elfinder"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
"github.com/jumpserver/koko/pkg/cctx"
"github.com/jumpserver/koko/pkg/cctx"
"github.com/jumpserver/koko/pkg/common"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/service"
"github.com/jumpserver/koko/pkg/service"
...
@@ -48,8 +51,6 @@ func AuthDecorator(handler http.HandlerFunc) http.HandlerFunc {
...
@@ -48,8 +51,6 @@ func AuthDecorator(handler http.HandlerFunc) http.HandlerFunc {
}
}
}
}
func
sftpHostFinder
(
wr
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
sftpHostFinder
(
wr
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
req
)
vars
:=
mux
.
Vars
(
req
)
tmpl
:=
template
.
Must
(
template
.
ParseFiles
(
"./templates/elfinder/file_manager.html"
))
tmpl
:=
template
.
Must
(
template
.
ParseFiles
(
"./templates/elfinder/file_manager.html"
))
...
@@ -85,13 +86,19 @@ func sftpHostConnectorView(wr http.ResponseWriter, req *http.Request) {
...
@@ -85,13 +86,19 @@ func sftpHostConnectorView(wr http.ResponseWriter, req *http.Request) {
if
!
ok
{
if
!
ok
{
switch
strings
.
TrimSpace
(
hostID
)
{
switch
strings
.
TrimSpace
(
hostID
)
{
case
"_"
:
case
"_"
:
userV
=
NewUserVolume
(
user
,
remoteIP
,
""
)
userV
=
NewUserVolume
(
user
,
remoteIP
,
""
)
default
:
default
:
userV
=
NewUserVolume
(
user
,
remoteIP
,
hostID
)
userV
=
NewUserVolume
(
user
,
remoteIP
,
hostID
)
}
}
addUserVolume
(
sid
,
userV
)
addUserVolume
(
sid
,
userV
)
}
}
logger
.
Debugf
(
"Elfinder connector sid: %s"
,
sid
)
logger
.
Debugf
(
"Elfinder connector sid: %s"
,
sid
)
conn
:=
elfinder
.
NewElFinderConnector
([]
elfinder
.
Volume
{
userV
})
conf
:=
config
.
GetConf
()
maxSize
:=
common
.
ConvertSizeToBytes
(
conf
.
ZipMaxSize
)
options
:=
map
[
string
]
string
{
"ZipMaxSize"
:
strconv
.
Itoa
(
maxSize
),
"ZipTmpPath"
:
conf
.
ZipTmpPath
,
}
conn
:=
elfinder
.
NewElFinderConnectorWithOption
([]
elfinder
.
Volume
{
userV
},
options
)
conn
.
ServeHTTP
(
wr
,
req
)
conn
.
ServeHTTP
(
wr
,
req
)
}
}
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