mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-06-08 05:14:38 +00:00
Confirm before close if the websocket is still open
This commit is contained in:
@@ -59,6 +59,8 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||
print('User %s not found' % user)
|
||||
else:
|
||||
self.user = user
|
||||
|
||||
butterfly_dir = os.getcwd()
|
||||
try:
|
||||
os.chdir(self.path or self.pw.pw_dir)
|
||||
except:
|
||||
@@ -76,7 +78,7 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||
env["COLORTERM"] = "butterfly"
|
||||
env["LOCATION"] = "http://%s:%d/" % (
|
||||
tornado.options.options.host, tornado.options.options.port)
|
||||
env["BUTTERFLY_DIR"] = os.getcwd()
|
||||
env["BUTTERFLY_DIR"] = butterfly_dir
|
||||
env["SHELL"] = self.pw.pw_shell or '/bin/sh'
|
||||
env["PATH"] = '%s:%s' % (os.path.abspath(os.path.join(
|
||||
os.path.dirname(__file__), '..', 'bin')), env.get("PATH"))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
term = ws = null
|
||||
cols = rows = null
|
||||
quit = false
|
||||
$ = document.querySelectorAll.bind(document)
|
||||
|
||||
ws_url = 'ws://' + document.location.host + '/ws' + location.pathname
|
||||
@@ -26,12 +27,17 @@ ws.onclose = ->
|
||||
if term
|
||||
term.destroy()
|
||||
console.log "WebSocket closed", arguments
|
||||
quit = true
|
||||
open('','_self').close()
|
||||
|
||||
ws.onerror = -> console.log "WebSocket error", arguments
|
||||
ws.onmessage = (event) ->
|
||||
term.write event.data
|
||||
|
||||
addEventListener 'beforeunload', ->
|
||||
if not quit
|
||||
'This will exit the terminal session'
|
||||
|
||||
addEventListener 'resize', resize = ->
|
||||
main = $('main')[0]
|
||||
fake_term = document.createElement('div')
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
var $, cols, resize, rows, term, ws, ws_url;
|
||||
var $, cols, quit, resize, rows, term, ws, ws_url;
|
||||
|
||||
term = ws = null;
|
||||
|
||||
cols = rows = null;
|
||||
|
||||
quit = false;
|
||||
|
||||
$ = document.querySelectorAll.bind(document);
|
||||
|
||||
ws_url = 'ws://' + document.location.host + '/ws' + location.pathname;
|
||||
@@ -34,6 +36,7 @@ ws.onclose = function() {
|
||||
term.destroy();
|
||||
}
|
||||
console.log("WebSocket closed", arguments);
|
||||
quit = true;
|
||||
return open('', '_self').close();
|
||||
};
|
||||
|
||||
@@ -45,6 +48,12 @@ ws.onmessage = function(event) {
|
||||
return term.write(event.data);
|
||||
};
|
||||
|
||||
addEventListener('beforeunload', function() {
|
||||
if (!quit) {
|
||||
return 'This will exit the terminal session';
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener('resize', resize = function() {
|
||||
var eh, ew, fake_term, fake_term_div, fake_term_line, main, main_bb;
|
||||
main = $('main')[0];
|
||||
|
||||
Reference in New Issue
Block a user