Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
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
luna
Commits
45b95a66
Commit
45b95a66
authored
Feb 20, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Change] 拆分view
parent
299f0aa9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
234 additions
and
31 deletions
+234
-31
index.html
luna/dist/index.html
+1
-1
service.js
luna/dist/ts/service.js
+4
-4
luna.py
luna/luna.py
+1
-0
nav.py
luna/nav.py
+107
-0
__init__.py
luna/views/__init__.py
+2
-0
views.py
luna/views/views.py
+24
-0
websocket.py
luna/views/websocket.py
+85
-0
views123.py
luna/views123.py
+10
-26
No files found.
luna/dist/index.html
View file @
45b95a66
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<head
lang=
"en"
>
<head
lang=
"en"
>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
Bifrost
</title>
<title>
Bifrost
</title>
<base
href=
"/
bifrost
/"
>
<base
href=
"/
luna
/"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"main.min.css"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"main.min.css"
/>
<!--script src="node_modules/requirejs/require.js"></script-->
<!--script src="node_modules/requirejs/require.js"></script-->
...
...
luna/dist/ts/service.js
View file @
45b95a66
...
@@ -64,8 +64,8 @@ exports.DataStore = {
...
@@ -64,8 +64,8 @@ exports.DataStore = {
Path
:
{},
Path
:
{},
error
:
{},
error
:
{},
msg
:
{},
msg
:
{},
leftbar
:
"/
bifrost
/api/leftbar"
,
leftbar
:
"/
luna
/api/leftbar"
,
leftbarrightclick
:
"/
bifrost
/api/leftbarrightclick"
,
leftbarrightclick
:
"/
luna
/api/leftbarrightclick"
,
loglevel
:
0
,
loglevel
:
0
,
term
:
[],
term
:
[],
termActive
:
0
,
termActive
:
0
,
...
@@ -104,7 +104,7 @@ var AppService = (function () {
...
@@ -104,7 +104,7 @@ var AppService = (function () {
exports
.
DataStore
.
socket
.
on
(
'popup'
,
function
(
data
)
{
exports
.
DataStore
.
socket
.
on
(
'popup'
,
function
(
data
)
{
layer
.
msg
(
data
);
layer
.
msg
(
data
);
});
});
exports
.
DataStore
.
socket
.
emit
(
'
api'
,
'all
'
);
exports
.
DataStore
.
socket
.
emit
(
'
nav
'
);
});
});
}
}
AppService
.
prototype
.
checklogin
=
function
(
path
)
{
AppService
.
prototype
.
checklogin
=
function
(
path
)
{
...
@@ -324,7 +324,7 @@ var AppService = (function () {
...
@@ -324,7 +324,7 @@ var AppService = (function () {
document
.
title
=
title
;
document
.
title
=
title
;
});
});
exports
.
DataStore
.
term
[
id
][
"term"
].
open
(
document
.
getElementById
(
'term-'
+
id
));
exports
.
DataStore
.
term
[
id
][
"term"
].
open
(
document
.
getElementById
(
'term-'
+
id
));
exports
.
DataStore
.
term
[
id
][
"term"
].
write
(
'
\
x1b[3
1
mWelcome to Jumpserver!
\
x1b[m
\
r
\
n'
);
exports
.
DataStore
.
term
[
id
][
"term"
].
write
(
'
\
x1b[3
2
mWelcome to Jumpserver!
\
x1b[m
\
r
\
n'
);
socket
.
on
(
'connect'
,
function
()
{
socket
.
on
(
'connect'
,
function
()
{
socket
.
emit
(
'machine'
,
uuid
);
socket
.
emit
(
'machine'
,
uuid
);
exports
.
DataStore
.
term
[
id
][
"term"
].
on
(
'data'
,
function
(
data
)
{
exports
.
DataStore
.
term
[
id
][
"term"
].
on
(
'data'
,
function
(
data
)
{
...
...
luna/luna.py
View file @
45b95a66
...
@@ -31,6 +31,7 @@ class Luna(Flask, AppMixin):
...
@@ -31,6 +31,7 @@ class Luna(Flask, AppMixin):
'HEATBEAT_INTERVAL'
:
5
,
'HEATBEAT_INTERVAL'
:
5
,
})
})
app_service
=
None
app_service
=
None
clients
=
{}
def
bootstrap
(
self
):
def
bootstrap
(
self
):
self
.
app_service
=
AppService
(
app_name
=
self
.
config
[
'NAME'
],
self
.
app_service
=
AppService
(
app_name
=
self
.
config
[
'NAME'
],
...
...
luna/nav.py
0 → 100644
View file @
45b95a66
nav
=
[{
"id"
:
"File"
,
"name"
:
"Server"
,
"children"
:
[
{
"id"
:
"NewConnection"
,
"href"
:
"Aaaa"
,
"name"
:
"New connection"
,
"disable"
:
True
},
{
"id"
:
"Connect"
,
"href"
:
"Aaaa"
,
"name"
:
"Connect"
,
"disable"
:
True
},
{
"id"
:
"Disconnect"
,
"click"
:
"Disconnect"
,
"name"
:
"Disconnect"
},
{
"id"
:
"DisconnectAll"
,
"click"
:
"DisconnectAll"
,
"name"
:
"Disconnect all"
},
{
"id"
:
"Duplicate"
,
"href"
:
"Aaaa"
,
"name"
:
"Duplicate"
,
"disable"
:
True
},
{
"id"
:
"Upload"
,
"href"
:
"Aaaa"
,
"name"
:
"Upload"
,
"disable"
:
True
},
{
"id"
:
"Download"
,
"href"
:
"Aaaa"
,
"name"
:
"Download"
,
"disable"
:
True
},
{
"id"
:
" Search"
,
"href"
:
"Aaaa"
,
"name"
:
"Search"
,
"disable"
:
True
},
{
"id"
:
"Reload"
,
"click"
:
"ReloadLeftbar"
,
"name"
:
"Reload"
}
]},
{
"id"
:
"View"
,
"name"
:
"View"
,
"children"
:
[
{
"id"
:
"HindLeftManager"
,
"click"
:
"HideLeft"
,
"name"
:
"Hind left manager"
},
{
"id"
:
"SplitVertical"
,
"href"
:
"Aaaa"
,
"name"
:
"Split vertical"
,
"disable"
:
True
},
{
"id"
:
"CommandBar"
,
"href"
:
"Aaaa"
,
"name"
:
"Command bar"
,
"disable"
:
True
},
{
"id"
:
"ShareSession"
,
"href"
:
"Aaaa"
,
"name"
:
"Share session (read/write)"
,
"disable"
:
True
},
{
"id"
:
"Language"
,
"href"
:
"Aaaa"
,
"name"
:
"Language"
,
"disable"
:
True
}]},
{
"id"
:
"Help"
,
"name"
:
"Help"
,
"children"
:
[
{
"id"
:
"EnterLicense"
,
"click"
:
"EnterLicense"
,
"name"
:
"Enter License"
},
{
"id"
:
"Website"
,
"click"
:
"Website"
,
"name"
:
"Website"
},
{
"id"
:
"BBS"
,
"click"
:
"BBS"
,
"name"
:
"BBS"
}]
}]
#
luna/views/__init__.py
0 → 100644
View file @
45b95a66
from
.views
import
*
from
.websocket
import
*
luna/views/views.py
0 → 100644
View file @
45b95a66
# ~*~ coding: utf-8 ~*~
from
..
import
app
from
flask
import
render_template
,
send_from_directory
__all__
=
[
'index'
,
'luna'
,
'send_dist'
]
@app.route
(
'/'
)
def
index
():
return
render_template
(
'index.html'
)
@app.route
(
'/luna/'
)
def
luna
():
return
render_template
(
'index.html'
)
@app.route
(
'/luna/<path:path>'
)
def
send_dist
(
path
):
return
send_from_directory
(
'dist'
,
path
)
luna/views/websocket.py
0 → 100644
View file @
45b95a66
# ~*~ coding: utf-8 ~*~
#!/usr/bin/env python
# coding: utf-8
import
select
import
threading
import
collections
import
json
import
paramiko
from
..
import
app
,
socket_io
from
..nav
import
nav
clients
=
app
.
clients
__all__
=
[
'handle_api'
,
'handle_term_connect'
,
'handle_machine'
,
'handle_data'
,
'handle_term_disconnect'
,
'handle_term_resize'
]
@socket_io.on
(
'nav'
)
def
handle_api
(
sid
):
socket_io
.
emit
(
'nav'
,
json
.
dumps
(
nav
),
room
=
sid
)
@socket_io.on
(
'connect'
,
namespace
=
'/'
)
def
handle_term_connect
(
sid
,
environ
):
clients
[
sid
]
=
collections
.
defaultdict
(
dict
)
@socket_io.on
(
'machine'
)
def
handle_machine
(
sid
,
message
):
clients
[
sid
][
'host'
]
=
host
=
'192.168.152.129'
clients
[
sid
][
'port'
]
=
port
=
22
t
=
threading
.
Thread
(
target
=
forward
,
args
=
(
sid
,))
t
.
setDaemon
(
True
)
t
.
start
()
# global thread
# if thread is None:
# thread = socket_io.start_background_task(forward, sid)
socket_io
.
emit
(
'data'
,
'Connect to
%
s:
%
s
\r\n
'
%
(
host
,
port
),
room
=
sid
)
print
(
t
.
is_alive
())
@socket_io.on
(
'data'
)
def
handle_data
(
sid
,
message
):
print
(
'Receive data:
%
s'
%
message
)
if
clients
[
sid
][
'chan'
]:
clients
[
sid
][
'chan'
]
.
send
(
message
)
@socket_io.on
(
'disconnect'
)
def
handle_term_disconnect
(
sid
):
del
clients
[
sid
]
print
(
'term disconnect'
)
@socket_io.on
(
'resize'
)
def
handle_term_resize
(
sid
,
json
):
print
(
json
)
def
forward
(
sid
):
try
:
host
=
clients
[
sid
][
'host'
]
port
=
clients
[
sid
][
'port'
]
except
KeyError
as
e
:
socket_io
.
emit
(
'data'
,
e
,
room
=
sid
)
return
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
host
,
port
=
port
,
username
=
'root'
,
password
=
'redhat'
)
clients
[
sid
][
'ssh'
]
=
ssh
clients
[
sid
][
'chan'
]
=
chan
=
ssh
.
invoke_shell
()
while
True
:
r
,
w
,
x
=
select
.
select
([
chan
],
[],
[])
if
chan
in
r
:
data
=
chan
.
recv
(
1024
)
if
not
len
(
data
):
break
socket_io
.
emit
(
'data'
,
data
,
room
=
sid
)
luna/views.py
→
luna/views
123
.py
View file @
45b95a66
#!/usr/bin/env python
#!/usr/bin/env python
# coding: utf-8
# coding: utf-8
import
time
import
select
import
select
import
threading
import
threading
import
collections
import
collections
import
json
import
paramiko
import
paramiko
from
flask.globals
import
_request_ctx_stack
,
_app_ctx_stack
from
flask
import
render_template
,
send_from_directory
from
flask
import
request
from
flask
import
render_template
,
send_from_directory
,
jsonify
,
g
from
flask_socketio
import
emit
from
.
import
app
,
socket_io
from
.
import
app
,
socket_io
from
.nav
import
nav
thread
=
None
clients
=
app
.
clients
clients
=
collections
.
defaultdict
(
dict
)
@app.route
(
'/'
)
@app.route
(
'/'
)
...
@@ -24,30 +20,19 @@ def index():
...
@@ -24,30 +20,19 @@ def index():
return
render_template
(
'index.html'
)
return
render_template
(
'index.html'
)
@app.route
(
'/get_site'
)
@app.route
(
'/luna/'
)
def
get_site
():
def
luna
():
return
jsonify
({
"hello"
:
"world"
})
@app.route
(
'/bifrost/'
)
def
bifrost
():
return
render_template
(
'index.html'
)
return
render_template
(
'index.html'
)
@app.route
(
'/
bifrost
/<path:path>'
)
@app.route
(
'/
luna
/<path:path>'
)
def
send_dist
(
path
):
def
send_dist
(
path
):
return
send_from_directory
(
'dist'
,
path
)
return
send_from_directory
(
'dist'
,
path
)
@socket_io.on
(
'api'
)
@socket_io.on
(
'nav'
)
def
handle_api
(
sid
,
api
):
def
handle_api
(
sid
):
if
api
==
'nav'
:
socket_io
.
emit
(
'nav'
,
json
.
dumps
(
nav
),
room
=
sid
)
socket_io
.
emit
(
'nav'
,
'[{"id":"File","name":"Server","children":[{"id":"NewConnection","href":"Aaaa","name":"New connection","disable":true},{"id":"Connect","href":"Aaaa","name":"Connect","disable":true},{"id":"Disconnect","click":"Disconnect","name":"Disconnect"},{"id":"DisconnectAll","click":"DisconnectAll","name":"Disconnect all"},{"id":"Duplicate","href":"Aaaa","name":"Duplicate","disable":true},{"id":"Upload","href":"Aaaa","name":"Upload","disable":true},{"id":"Download","href":"Aaaa","name":"Download","disable":true},{"id":"Search","href":"Aaaa","name":"Search","disable":true},{"id":"Reload","click":"ReloadLeftbar","name":"Reload"}]},{"id":"View","name":"View","children":[{"id":"HindLeftManager","click":"HideLeft","name":"Hind left manager"},{"id":"SplitVertical","href":"Aaaa","name":"Split vertical","disable":true},{"id":"CommandBar","href":"Aaaa","name":"Command bar","disable":true},{"id":"ShareSession","href":"Aaaa","name":"Share session (read/write)","disable":true},{"id":"Language","href":"Aaaa","name":"Language","disable":true}]},{"id":"Help","name":"Help","children":[{"id":"EnterLicense","click":"EnterLicense","name":"Enter License"},{"id":"Website","click":"Website","name":"Website"},{"id":"BBS","click":"BBS","name":"BBS"}]}]'
,
room
=
sid
)
# print('received json: ' + str(json))
elif
api
==
'all'
:
socket_io
.
emit
(
'nav'
,
'[{"id":"File","name":"Server","children":[{"id":"NewConnection","href":"Aaaa","name":"New connection","disable":true},{"id":"Connect","href":"Aaaa","name":"Connect","disable":true},{"id":"Disconnect","click":"Disconnect","name":"Disconnect"},{"id":"DisconnectAll","click":"DisconnectAll","name":"Disconnect all"},{"id":"Duplicate","href":"Aaaa","name":"Duplicate","disable":true},{"id":"Upload","href":"Aaaa","name":"Upload","disable":true},{"id":"Download","href":"Aaaa","name":"Download","disable":true},{"id":"Search","href":"Aaaa","name":"Search","disable":true},{"id":"Reload","click":"ReloadLeftbar","name":"Reload"}]},{"id":"View","name":"View","children":[{"id":"HindLeftManager","click":"HideLeft","name":"Hind left manager"},{"id":"SplitVertical","href":"Aaaa","name":"Split vertical","disable":true},{"id":"CommandBar","href":"Aaaa","name":"Command bar","disable":true},{"id":"ShareSession","href":"Aaaa","name":"Share session (read/write)","disable":true},{"id":"Language","href":"Aaaa","name":"Language","disable":true}]},{"id":"Help","name":"Help","children":[{"id":"EnterLicense","click":"EnterLicense","name":"Enter License"},{"id":"Website","click":"Website","name":"Website"},{"id":"BBS","click":"BBS","name":"BBS"}]}]'
,
room
=
sid
)
@socket_io.on
(
'connect'
,
namespace
=
'/'
)
@socket_io.on
(
'connect'
,
namespace
=
'/'
)
...
@@ -84,7 +69,6 @@ def handle_term_disconnect(sid):
...
@@ -84,7 +69,6 @@ def handle_term_disconnect(sid):
@socket_io.on
(
'resize'
)
@socket_io.on
(
'resize'
)
def
handle_term_resize
(
sid
,
json
):
def
handle_term_resize
(
sid
,
json
):
print
(
json
)
print
(
json
)
...
...
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