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
be260238
Commit
be260238
authored
Sep 19, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 增加websocket
parent
90ce603e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
28 deletions
+75
-28
app.py
coco/app.py
+2
-2
app.py
coco/httpd/app.py
+4
-4
socket.io.js
coco/httpd/static/js/socket.io.js
+0
-0
common_sftp.html
coco/httpd/templates/elfinder/common_sftp.html
+0
-0
file_manager.html
coco/httpd/templates/elfinder/file_manager.html
+14
-2
read_file.html
coco/httpd/templates/elfinder/read_file.html
+0
-0
utils.py
coco/httpd/utils.py
+12
-0
view.py
coco/httpd/view.py
+27
-16
ws.py
coco/httpd/ws.py
+16
-4
No files found.
coco/app.py
View file @
be260238
...
...
@@ -4,8 +4,8 @@
import
eventlet
from
eventlet.debug
import
hub_prevent_multiple_readers
#
eventlet.monkey_patch()
#
hub_prevent_multiple_readers(False)
eventlet
.
monkey_patch
()
hub_prevent_multiple_readers
(
False
)
import
datetime
import
os
...
...
coco/httpd/app.py
View file @
be260238
...
...
@@ -6,7 +6,7 @@ from flask import Flask
from
coco.utils
import
get_logger
from
coco.config
import
config
from
coco.httpd.ws
import
ProxyNamespace
from
coco.httpd.ws
import
ProxyNamespace
,
ElfinderNamespace
logger
=
get_logger
(
__file__
)
...
...
@@ -14,10 +14,10 @@ app = Flask(__name__, template_folder='templates', static_folder='static')
app
.
config
.
update
(
config
)
socket_io
=
SocketIO
()
socket_io
.
on_namespace
(
ProxyNamespace
(
'/ssh'
))
socket_io
.
on_namespace
(
ProxyNamespace
(
'/coco/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/static/js/socket.io.js
0 → 100755
View file @
be260238
This diff is collapsed.
Click to expand it.
coco/httpd/templates/finder/common_sftp.html
→
coco/httpd/templates/
el
finder/common_sftp.html
View file @
be260238
File moved
coco/httpd/templates/finder/file_manager.html
→
coco/httpd/templates/
el
finder/file_manager.html
View file @
be260238
...
...
@@ -6,8 +6,18 @@
<link
rel=
"stylesheet"
type=
"text/css"
media=
"screen"
href=
"{{ url_for('static', filename='elfinder/css/theme-gray.css') }}"
>
<script
type=
"text/javascript"
src=
"{{ url_for('static', filename='elfinder/elfinder.full.js') }}"
></script>
<script
type=
"text/javascript"
src=
"{{ url_for('static', filename='elfinder/i18n/elfinder.pl.js') }}"
></script>
<script
type=
"text/javascript"
src=
"{{ url_for('static', filename='js/socket.io.js') }}"
></script>
<script
type=
"text/javascript"
charset=
"utf-8"
>
$
().
ready
(
function
()
{
var
socket
=
io
.
connect
(
'/elfinder'
);
socket
.
on
(
'connect'
,
function
()
{
console
.
log
(
"Connect"
)
});
socket
.
on
(
'data'
,
function
(
msg
)
{
var
sid
=
msg
.
sid
;
init_elfinder
(
sid
);
});
function
init_elfinder
(
sid
)
{
var
elf
;
var
opts
=
{
uiOptions
:
{
...
...
@@ -20,6 +30,7 @@
[
'view'
]
]
},
customData
:
{
'sid'
:
sid
},
height
:
$
(
window
).
height
(),
url
:
'{{ url_for("sftp_host_connector_view", host=host) }}'
,
resizable
:
false
,
...
...
@@ -97,7 +108,8 @@
},
200
);
}
});
});
}
</script>
<div
id=
"elfinder"
></div>
</body>
...
...
coco/httpd/templates/finder/read_file.html
→
coco/httpd/templates/
el
finder/read_file.html
View file @
be260238
File moved
coco/httpd/utils.py
0 → 100644
View file @
be260238
# -*- coding: utf-8 -*-
#
__volume_cached
=
{}
def
get_cache_volume
(
sid
):
return
__volume_cached
.
get
(
sid
)
def
set_cache_volume
(
sid
,
volume
):
__volume_cached
[
sid
]
=
volume
coco/httpd/view.py
View file @
be260238
...
...
@@ -8,26 +8,36 @@ 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
..service
import
app_service
@app.route
(
'/coco/elfinder/sftp/connector/<host>/'
,
methods
=
[
'GET'
,
'POST'
])
@login_required
def
sftp_host_connector_view
(
host
):
user
=
request
.
current_user
connection
=
Connection
(
addr
=
(
request
.
real_ip
,
0
))
connection
.
user
=
user
sftp
=
InternalSFTPClient
(
connection
)
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
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"
)
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
handler
=
connector
.
ElFinderConnector
([
volume
])
handler
.
run
(
request
)
...
...
@@ -40,11 +50,12 @@ def sftp_host_connector_view(host):
@app.route
(
'/coco/elfinder/sftp/<host>/'
)
def
sftp_host_finder
(
host
):
return
render_template
(
'finder/file_manager.html'
,
host
=
host
)
return
render_template
(
'
el
finder/file_manager.html'
,
host
=
host
)
@app.route
(
'/coco/elfinder/sftp/'
)
def
sftp_finder
():
return
render_template
(
'finder/file_manager.html'
,
host
=
'_'
)
return
render_template
(
'elfinder/file_manager.html'
,
host
=
'_'
)
coco/httpd/ws.py
View file @
be260238
...
...
@@ -3,14 +3,15 @@
import
os
import
uuid
from
flask_socketio
import
SocketIO
,
Namespace
,
join_room
from
flask
import
Flask
,
request
from
flask_socketio
import
join_room
from
flask
import
request
from
..models
import
Connection
,
WSProxy
from
..proxy
import
ProxyServer
from
..utils
import
get_logger
from
..ctx
import
app_service
from
.base
import
BaseNamespace
from
.utils
import
get_cache_volume
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
...
...
@@ -192,4 +193,16 @@ class ProxyNamespace(BaseNamespace):
pass
def
on_ping
(
self
):
self
.
emit
(
'pong'
)
\ No newline at end of file
self
.
emit
(
'pong'
)
class
ElfinderNamespace
(
BaseNamespace
):
def
on_connect
(
self
):
print
(
"on connect"
)
self
.
emit
(
'data'
,
{
"sid"
:
str
(
request
.
sid
)})
def
on_disconnect
(
self
):
print
(
"On disconnect"
)
volume
=
get_cache_volume
(
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