feat: update

parent ae020d43
...@@ -24,10 +24,12 @@ class SSHws(Namespace): ...@@ -24,10 +24,12 @@ class SSHws(Namespace):
# self.chan.settimeout(0.1) # self.chan.settimeout(0.1)
self.socketio.start_background_task(self.sent_data, self, self.clients[request.sid]["chan"][connection], self.socketio.start_background_task(self.sent_data, self, self.clients[request.sid]["chan"][connection],
self.clients[request.sid]["room"], self.clients[request.sid]["room"],
connection) connection, request.sid)
def sent_data(self, s, chan, room, connection): def sent_data(self, s, chan, room, connection, sid):
while True: while True:
if connection not in s.clients[sid]["chan"].keys():
return
try: try:
data = chan.recv(2048).decode('utf-8', 'replace') data = chan.recv(2048).decode('utf-8', 'replace')
s.emit(event='data', data={"data": data, "room": connection}, room=room) s.emit(event='data', data={"data": data, "room": connection}, room=room)
...@@ -61,8 +63,8 @@ class SSHws(Namespace): ...@@ -61,8 +63,8 @@ class SSHws(Namespace):
def on_host(self, message): def on_host(self, message):
connection = str(uuid.uuid4()) connection = str(uuid.uuid4())
self.ssh_with_password(connection)
self.emit('room', {'room': connection, 'secret': message['secret']}) self.emit('room', {'room': connection, 'secret': message['secret']})
self.ssh_with_password(connection)
def on_resize(self, message): def on_resize(self, message):
self.clients[request.sid]["cols"] = message.get('cols', 80) self.clients[request.sid]["cols"] = message.get('cols', 80)
...@@ -84,11 +86,19 @@ class SSHws(Namespace): ...@@ -84,11 +86,19 @@ class SSHws(Namespace):
def on_disconnect(self): def on_disconnect(self):
print("disconnect") print("disconnect")
for connection in self.clients[request.sid]["chan"]:
self.on_logout(connection)
pass pass
def on_leave(self): def on_leave(self):
leave_room(self.room) leave_room(self.room)
def on_logout(self, connection):
print("logout", connection)
if connection:
self.clients[request.sid]["chan"][connection].close()
del self.clients[request.sid]["chan"][connection]
@app.route('/luna/<path:path>') @app.route('/luna/<path:path>')
def send_js(path): def send_js(path):
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {TermWS} from '../../globals';
// export class Term { // export class Term {
// machine: string; // machine: string;
...@@ -30,6 +31,7 @@ export class View { ...@@ -30,6 +31,7 @@ export class View {
closed: boolean; closed: boolean;
host: any; host: any;
user: any; user: any;
room: string;
Rdp: Rdp; Rdp: Rdp;
Term: any; Term: any;
} }
...@@ -63,8 +65,12 @@ export class ControlComponent implements OnInit { ...@@ -63,8 +65,12 @@ export class ControlComponent implements OnInit {
} }
static TerminalDisconnect(id) { static TerminalDisconnect(id) {
NavList.List[id].connected = false; console.log(id);
NavList.List[id].Term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n'); if (NavList.List[id].connected) {
NavList.List[id].connected = false;
NavList.List[id].Term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
TermWS.emit('logout', NavList.List[id].room);
}
} }
static RdpDisconnect(id) { static RdpDisconnect(id) {
......
...@@ -15,7 +15,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -15,7 +15,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
@Input() host: any; @Input() host: any;
@Input() userid: any; @Input() userid: any;
@Input() index: number; @Input() index: number;
@Input() room: string; // @Input() room: string;
@ViewChild('term') el: ElementRef; @ViewChild('term') el: ElementRef;
secret: string; secret: string;
term: any; term: any;
...@@ -31,6 +31,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -31,6 +31,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
useStyle: true, useStyle: true,
screenKeys: true, screenKeys: true,
}); });
// NavList.List[this.index].room = this.room;
} }
ngAfterViewInit() { ngAfterViewInit() {
...@@ -74,11 +75,11 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -74,11 +75,11 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
TermWS.emit('host', {'uuid': this.host.id, 'userid': this.userid, 'secret': this.secret}); TermWS.emit('host', {'uuid': this.host.id, 'userid': this.userid, 'secret': this.secret});
this.term.on('data', function (data) { this.term.on('data', function (data) {
TermWS.emit('data', {'data': data, 'room': that.room}); TermWS.emit('data', {'data': data, 'room': NavList.List[that.index].room});
}); });
TermWS.on('data', function (data) { TermWS.on('data', function (data) {
if (data['room'] === that.room) { if (data['room'] === NavList.List[that.index].room) {
that.term.write(data['data']); that.term.write(data['data']);
} }
}); });
...@@ -88,7 +89,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -88,7 +89,7 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
}); });
TermWS.on('room', function (data) { TermWS.on('room', function (data) {
if (data['secret'] === that.secret) { if (data['secret'] === that.secret) {
that.room = data['room']; NavList.List[that.index].room = data['room'];
} }
}); });
} }
...@@ -97,5 +98,6 @@ export class ElementTermComponent implements OnInit, AfterViewInit { ...@@ -97,5 +98,6 @@ export class ElementTermComponent implements OnInit, AfterViewInit {
TerminalDisconnect() { TerminalDisconnect() {
NavList.List[this.index].connected = false; NavList.List[this.index].connected = false;
this.term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n'); this.term.write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
TermWS.emit('logout', NavList.List[this.index].room);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment