Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
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
coco
Commits
18ab2ac6
Commit
18ab2ac6
authored
Sep 19, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] Update
parent
be260238
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
59 additions
and
46 deletions
+59
-46
.run_dev_flask.py
.run_dev_flask.py
+2
-2
__init__.py
coco/httpd/__init__.py
+1
-1
app.py
coco/httpd/app.py
+2
-2
connector.py
coco/httpd/elfinder/connector.py
+4
-3
sftp.py
coco/httpd/elfinder/volumes/sftp.py
+5
-5
file_manager.html
coco/httpd/templates/elfinder/file_manager.html
+20
-8
utils.py
coco/httpd/utils.py
+5
-5
view.py
coco/httpd/view.py
+18
-18
ws.py
coco/httpd/ws.py
+2
-2
No files found.
.run_dev_flask.py
View file @
18ab2ac6
#!/usr/bin/python
#
from
coco.httpd
import
app
from
coco.httpd
import
app
,
socket_io
from
coco.logger
import
create_logger
create_logger
()
if
__name__
==
'__main__'
:
app
.
run
(
)
socket_io
.
run
(
app
,
debug
=
False
)
coco/httpd/__init__.py
View file @
18ab2ac6
# -*- coding: utf-8 -*-
#
from
.app
import
HttpServer
,
app
from
.app
import
HttpServer
,
app
,
socket_io
from
.
import
view
coco/httpd/app.py
View file @
18ab2ac6
...
...
@@ -16,8 +16,8 @@ socket_io = SocketIO()
socket_io
.
on_namespace
(
ProxyNamespace
(
'/ssh'
))
socket_io
.
on_namespace
(
ElfinderNamespace
(
'/elfinder'
))
init_kwargs
=
{
'async_mode'
:
'threading'
}
#
init_kwargs = {'async_mode': 'eventlet',}
#
init_kwargs = {'async_mode': 'threading'}
init_kwargs
=
{
'async_mode'
:
'eventlet'
,}
socket_io
.
init_app
(
app
,
**
init_kwargs
)
socket_io
.
on_error_default
(
lambda
x
:
logger
.
exception
(
x
))
...
...
coco/httpd/elfinder/connector.py
View file @
18ab2ac6
import
logging
import
json
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -33,7 +34,7 @@ class ElFinderConnector:
'cmd'
,
'target'
,
'targets[]'
,
'current'
,
'tree'
,
'name'
,
'content'
,
'src'
,
'dst'
,
'cut'
,
'init'
,
'type'
,
'width'
,
'height'
,
'upload[]'
,
'dirs[]'
,
'targets'
,
"chunk"
,
"range"
,
"cid"
,
'targets'
,
"chunk"
,
"range"
,
"cid"
,
'reload'
,
]
_options
=
{
...
...
@@ -214,10 +215,11 @@ class ElFinderConnector:
volume
=
list
(
self
.
volumes
.
values
())[
0
]
else
:
volume
=
self
.
get_volume
(
target
)
self
.
response
[
'cwd'
]
=
volume
.
info
(
target
)
files
=
volume
.
list
(
target
)
if
'tree'
in
self
.
data
:
if
'tree'
in
self
.
data
or
'reload'
in
self
.
data
:
parents
=
volume
.
parents
(
target
,
depth
=
0
)
parents
=
filter
(
lambda
x
:
x
not
in
files
,
parents
)
files
+=
parents
...
...
@@ -286,7 +288,6 @@ class ElFinderConnector:
volume
.
upload_chunk_merge
(
parent
,
self
.
data
.
get
(
'chunk'
))
)
else
:
print
(
"__UPLOAD {}"
.
format
(
self
.
data
))
self
.
response
.
update
(
volume
.
upload
(
self
.
request
.
files
,
parent
))
def
__size
(
self
):
...
...
coco/httpd/elfinder/volumes/sftp.py
View file @
18ab2ac6
import
logging
import
stat
import
re
import
threading
from
flask
import
send_file
from
coco.utils
import
get_logger
from
.base
import
BaseVolume
logger
=
logging
.
getLogger
(
__name__
)
logger
=
get_logger
(
__name__
)
class
SFTPVolume
(
BaseVolume
):
...
...
@@ -16,6 +15,7 @@ class SFTPVolume(BaseVolume):
self
.
root_name
=
'Home'
super
()
.
__init__
()
self
.
_stat_cache
=
{}
self
.
lock
=
threading
.
Lock
()
def
close
(
self
):
self
.
sftp
.
close
()
...
...
@@ -95,7 +95,7 @@ class SFTPVolume(BaseVolume):
""" Get the sub directory of directory
"""
path
=
self
.
_path
(
target
)
#
print("Tree {} {}".format(target, path))
print
(
"Tree {} {}"
.
format
(
target
,
path
))
infos
=
self
.
list
(
target
)
tree
=
list
(
filter
(
lambda
x
:
x
[
'mime'
]
==
'directory'
,
infos
))
return
tree
...
...
coco/httpd/templates/elfinder/file_manager.html
View file @
18ab2ac6
...
...
@@ -16,7 +16,9 @@
var
sid
=
msg
.
sid
;
init_elfinder
(
sid
);
});
$
().
ready
(
function
()
{
$
(
window
).
trigger
(
'resize'
);
});
function
init_elfinder
(
sid
)
{
var
elf
;
var
opts
=
{
...
...
@@ -31,7 +33,8 @@
]
},
customData
:
{
'sid'
:
sid
},
height
:
$
(
window
).
height
(),
height
:
'100%'
,
width
:
'100%'
,
url
:
'{{ url_for("sftp_host_connector_view", host=host) }}'
,
resizable
:
false
,
lang
:
'pl'
,
...
...
@@ -92,8 +95,6 @@
}
else
{
start
(
lng
);
}
};
load
();
var
resizeTimer
;
...
...
@@ -101,15 +102,26 @@
resizeTimer
&&
clearTimeout
(
resizeTimer
);
if
(
!
$
(
'#elfinder'
).
hasClass
(
'elfinder-fullscreen'
))
{
resizeTimer
=
setTimeout
(
function
()
{
var
h
=
parseInt
(
$
(
window
).
height
());
if
(
h
!=
parseInt
(
$
(
'#elfinder'
).
height
()))
{
elf
.
resize
(
'100%'
,
h
);
var
h
,
w
;
var
isTrue
=
window
==
parent
;
console
.
log
(
"Window == parent"
+
isTrue
);
if
(
window
!=
parent
)
{
h
=
parseInt
(
parent
.
$
(
'.window.active'
).
height
());
w
=
parseInt
(
parent
.
$
(
'.window.active'
).
width
());
}
else
{
h
=
parseInt
(
$
(
window
).
height
());
w
=
parseInt
(
$
(
window
).
width
());
}
var
ori_h
=
parseInt
(
$
(
'#elfinder'
).
height
());
var
ori_w
=
parseInt
(
$
(
'#elfinder'
).
width
());
console
.
log
(
"Height: "
+
h
+
" Wid: "
+
w
);
if
(
h
!==
ori_h
||
w
!=
ori_w
){
elf
.
resize
(
w
,
h
);
}
},
200
);
}
});
}
</script>
<div
id=
"elfinder"
></div>
</body>
...
...
coco/httpd/utils.py
View file @
18ab2ac6
# -*- coding: utf-8 -*-
#
__
volume
_cached
=
{}
__
sftp
_cached
=
{}
def
get_cache
_volume
(
sid
):
return
__
volume
_cached
.
get
(
sid
)
def
get_cache
d_sftp
(
sid
):
return
__
sftp
_cached
.
get
(
sid
)
def
set_cache_
volume
(
sid
,
volume
):
__
volume
_cached
[
sid
]
=
volume
def
set_cache_
sftp
(
sid
,
volume
):
__
sftp
_cached
[
sid
]
=
volume
coco/httpd/view.py
View file @
18ab2ac6
...
...
@@ -3,40 +3,40 @@
from
flask
import
render_template
,
request
,
jsonify
from
coco.utils
import
get_logger
from
.app
import
app
from
.elfinder
import
connector
,
volumes
from
..models
import
Connection
from
..sftp
import
InternalSFTPClient
from
.auth
import
login_required
from
.utils
import
get_cache
_volume
,
set_cache_volume
from
.utils
import
get_cache
d_sftp
,
set_cache_sftp
from
..service
import
app_service
logger
=
get_logger
(
__file__
)
@app.route
(
'/coco/elfinder/sftp/connector/<host>/'
,
methods
=
[
'GET'
,
'POST'
])
@login_required
def
sftp_host_connector_view
(
host
):
sid
=
request
.
args
.
get
(
"sid"
)
or
request
.
values
.
get
(
'sid'
)
print
(
"Get sid: {}"
.
format
(
sid
))
volume
=
None
if
sid
:
volume
=
get_cache_volume
(
sid
)
if
not
volume
:
print
(
"New volume"
)
sftp
=
get_cached_sftp
(
sid
)
if
sid
else
None
if
not
sftp
:
logger
.
debug
(
"New sftp, sid: {} host: {}"
.
format
(
sid
,
host
))
user
=
request
.
current_user
connection
=
Connection
(
addr
=
(
request
.
real_ip
,
0
))
connection
.
user
=
user
sftp
=
InternalSFTPClient
(
connection
)
volume
=
volumes
.
SFTPVolume
(
sftp
)
set_cache_volume
(
sid
,
volume
)
if
host
!=
'_'
:
asset
=
app_service
.
get_asset
(
host
)
if
not
asset
:
return
jsonify
({
'error'
:
'Not found this host'
})
hostname
=
asset
.
hostname
if
asset
.
org_id
:
hostname
=
"{}.{}"
.
format
(
asset
.
hostname
,
asset
.
org_name
)
volume
.
root_name
=
hostname
volume
.
base_path
=
'/'
+
hostname
set_cache_sftp
(
sid
,
sftp
)
volume
=
volumes
.
SFTPVolume
(
sftp
)
if
host
!=
'_'
:
asset
=
app_service
.
get_asset
(
host
)
if
not
asset
:
return
jsonify
({
'error'
:
'Not found this host'
})
hostname
=
asset
.
hostname
if
asset
.
org_id
:
hostname
=
"{}.{}"
.
format
(
asset
.
hostname
,
asset
.
org_name
)
volume
.
root_name
=
hostname
volume
.
base_path
=
'/'
+
hostname
handler
=
connector
.
ElFinderConnector
([
volume
])
handler
.
run
(
request
)
...
...
coco/httpd/ws.py
View file @
18ab2ac6
...
...
@@ -11,7 +11,7 @@ from ..proxy import ProxyServer
from
..utils
import
get_logger
from
..ctx
import
app_service
from
.base
import
BaseNamespace
from
.utils
import
get_cache
_volume
from
.utils
import
get_cache
d_sftp
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
...
...
@@ -203,6 +203,6 @@ class ElfinderNamespace(BaseNamespace):
def
on_disconnect
(
self
):
print
(
"On disconnect"
)
volume
=
get_cache
_volume
(
request
.
sid
)
volume
=
get_cache
d_sftp
(
request
.
sid
)
if
volume
:
volume
.
close
()
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