Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
jumpserver
Commits
ade8fb92
Commit
ade8fb92
authored
Mar 15, 2016
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
31708c0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
91 deletions
+66
-91
run_server.py
run_server.py
+2
-2
webterminal.js
static/js/webterminal.js
+64
-89
No files found.
run_server.py
View file @
ade8fb92
...
...
@@ -338,7 +338,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if
not
self
.
term
.
remote_ip
:
self
.
term
.
remote_ip
=
self
.
request
.
remote_ip
self
.
ssh
=
self
.
term
.
get_connection
()
self
.
channel
=
self
.
ssh
.
invoke_shell
()
self
.
channel
=
self
.
ssh
.
invoke_shell
(
term
=
'xterm'
)
WebTerminalHandler
.
tasks
.
append
(
MyThread
(
target
=
self
.
forward_outbound
))
WebTerminalHandler
.
clients
.
append
(
self
)
...
...
@@ -412,7 +412,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if
self
.
term
.
vim_flag
:
self
.
term
.
vim_data
+=
recv
try
:
print
chardet
.
detect
(
data
)
#
print chardet.detect(data)
if
chardet
.
detect
(
data
)[
'encoding'
]
==
'GB2312'
:
data
=
data
.
decode
(
'gb2312'
)
.
encode
(
'utf8'
)
self
.
write_message
(
data
)
...
...
static/js/webterminal.js
View file @
ade8fb92
/**
* Created by liuzheng on 3/3/16.
*/
var
rowHeight
=
1
;
var
colWidth
=
1
;
//function WSSHClient() {
//}
//WSSHClient.prototype._generateEndpoint = function (options) {
// console.log(options);
// if (window.location.protocol == 'https:') {
// var protocol = 'wss://';
// } else {
// var protocol = 'ws://';
// }
//
// var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '/ws/terminal' + document.URL.match(/(\?.*)/);
// return endpoint;
//};
//WSSHClient.prototype.connect = function (options) {
// var endpoint = this._generateEndpoint(options);
//
// if (window.WebSocket) {
// this._connection = new WebSocket(endpoint);
// }
// else if (window.MozWebSocket) {
// this._connection = MozWebSocket(endpoint);
// }
// else {
// options.onError('WebSocket Not Supported');
// return;
// }
//
// this._connection.onopen = function () {
// options.onConnect();
// };
//
// this._connection.onmessage = function (evt) {
// var data = JSON.parse(evt.data.toString());
// if (data.error !== undefined) {
// options.onError(data.error);
// }
// else {
// options.onData(data.data);
// }
// };
//
// this._connection.onclose = function (evt) {
// options.onClose();
// };
//};
//
//WSSHClient.prototype.send = function (data) {
// this._connection.send(JSON.stringify({'data': data}));
//};
function
openTerminal
(
options
)
{
function
WSSHClient
()
{
}
WSSHClient
.
prototype
.
_generateEndpoint
=
function
(
options
)
{
console
.
log
(
options
);
if
(
window
.
location
.
protocol
==
'https:'
)
{
var
protocol
=
'wss://'
;
}
else
{
var
protocol
=
'ws://'
;
}
var
endpoint
=
protocol
+
document
.
URL
.
match
(
RegExp
(
'//(.*?)/'
))[
1
]
+
'/ws/terminal'
+
document
.
URL
.
match
(
/
(\?
.*
)
/
)[
1
];
var
sock
=
new
WebSocket
(
endpoint
);
//var client = new WSSHClient();
var
endpoint
=
protocol
+
document
.
URL
.
match
(
RegExp
(
'//(.*?)/'
))[
1
]
+
'/ws/terminal'
+
document
.
URL
.
match
(
/
(\?
.*
)
/
);
return
endpoint
;
};
WSSHClient
.
prototype
.
connect
=
function
(
options
)
{
var
endpoint
=
this
.
_generateEndpoint
(
options
);
if
(
window
.
WebSocket
)
{
this
.
_connection
=
new
WebSocket
(
endpoint
);
}
else
if
(
window
.
MozWebSocket
)
{
this
.
_connection
=
MozWebSocket
(
endpoint
);
}
else
{
options
.
onError
(
'WebSocket Not Supported'
);
return
;
}
this
.
_connection
.
onopen
=
function
()
{
options
.
onConnect
();
};
this
.
_connection
.
onmessage
=
function
(
evt
)
{
var
data
=
JSON
.
parse
(
evt
.
data
.
toString
());
if
(
data
.
error
!==
undefined
)
{
options
.
onError
(
data
.
error
);
}
else
{
options
.
onData
(
data
.
data
);
}
};
this
.
_connection
.
onclose
=
function
(
evt
)
{
options
.
onClose
();
};
};
WSSHClient
.
prototype
.
send
=
function
(
data
)
{
this
.
_connection
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
};
function
openTerminal
(
options
)
{
var
client
=
new
WSSHClient
();
var
term
=
new
Terminal
({
rows
:
rowHeight
,
cols
:
colWidth
,
...
...
@@ -72,46 +64,29 @@ function openTerminal(options) {
});
term
.
open
();
term
.
on
(
'data'
,
function
(
data
)
{
sock
.
send
(
JSON
.
stringify
({
'data'
:
data
})
)
client
.
send
(
data
)
});
$
(
'.terminal'
).
detach
().
appendTo
(
'#term'
);
term
.
resize
(
80
,
24
);
term
.
write
(
'Connecting...'
);
sock
.
onopen
=
function
()
{
// Erase our connecting message
term
.
write
(
'
\
r'
);
};
sock
.
onclose
=
function
()
{
term
.
write
(
'Connection Reset By Peer'
);
};
sock
.
onmessage
=
function
(
data
)
{
try
{
term
.
write
(
data
.
data
)
}
catch
(
e
)
{
term
.
write
(
JSON
.
parse
(
data
.
data
)[
'data'
])
client
.
connect
(
$
.
extend
(
options
,
{
onError
:
function
(
error
)
{
term
.
write
(
'Error: '
+
error
+
'
\
r
\
n'
);
},
onConnect
:
function
()
{
// Erase our connecting message
term
.
write
(
'
\
r'
);
},
onClose
:
function
()
{
term
.
write
(
'Connection Reset By Peer'
);
},
onData
:
function
(
data
)
{
term
.
write
(
data
);
}
};
sock
.
onerror
=
function
()
{
term
.
write
(
'Connection Reset By Peer'
);
};
//client.connect($.extend(options, {
// onError: function (error) {
// term.write('Error: ' + error + '\r\n');
// },
// onConnect: function () {
// // Erase our connecting message
// term.write('\r');
// },
// onClose: function () {
// term.write('Connection Reset By Peer');
// },
// onData: function (data) {
// term.write(data);
// }
//}));
}));
rowHeight
=
0.0
+
1.00
*
$
(
'.terminal'
).
height
()
/
24
;
colWidth
=
0.0
+
1.00
*
$
(
'.terminal'
).
width
()
/
80
;
return
{
'term'
:
term
,
'client'
:
sock
};
return
{
'term'
:
term
,
'client'
:
client
};
}
function
resize
()
{
...
...
@@ -135,7 +110,7 @@ $(document).ready(function () {
var
geom
=
resize
();
console
.
log
(
geom
);
term_client
.
term
.
resize
(
geom
.
cols
,
geom
.
rows
);
term_client
.
client
.
send
(
JSON
.
stringify
({
'data'
:{
'resize'
:
{
'rows'
:
geom
.
rows
,
'cols'
:
geom
.
cols
}}})
);
term_client
.
client
.
send
(
{
'resize'
:
{
'rows'
:
geom
.
rows
,
'cols'
:
geom
.
cols
}}
);
$
(
'#ssh'
).
show
();
}
...
...
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