File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,11 @@ def loop_read(self):
9393 if not data :
9494 self .close (3333 )
9595 break
96- self .send (bytes_data = data )
96+ try :
97+ text = data .decode ()
98+ except UnicodeDecodeError :
99+ text = data .decode (encoding = 'GBK' , errors = 'ignore' )
100+ self .send (text_data = text )
97101
98102 def receive (self , text_data = None , bytes_data = None ):
99103 data = text_data or bytes_data
@@ -120,15 +124,15 @@ def connect(self):
120124 self .close ()
121125
122126 def _init (self ):
123- self .send (bytes_data = b '\r \33 [KConnecting ...\r ' )
127+ self .send (text_data = '\r \33 [KConnecting ...\r ' )
124128 host = Host .objects .filter (pk = self .id ).first ()
125129 if not host :
126130 self .send (text_data = 'Unknown host\r \n ' )
127131 self .close ()
128132 try :
129133 self .ssh = host .get_ssh ().get_client ()
130134 except Exception as e :
131- self .send (bytes_data = f'Exception: { e } \r \n ' .encode ())
135+ self .send (text_data = f'Exception: { e } \r \n ' .encode ())
132136 self .close ()
133137 return
134138 self .chan = self .ssh .invoke_shell (term = 'xterm' )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ function WebSSH(props) {
2424 term . write ( 'WebSocket connecting ... ' ) ;
2525 const protocol = window . location . protocol === 'https:' ? 'wss:' : 'ws:' ;
2626 const socket = new WebSocket ( `${ protocol } //${ window . location . host } /api/ws/ssh/${ props . id } /?x-token=${ X_TOKEN } ` ) ;
27- socket . onmessage = e => _read_as_text ( e . data ) ;
27+ socket . onmessage = e => term . write ( e . data )
2828 socket . onopen = ( ) => {
2929 term . write ( 'ok' )
3030 term . focus ( ) ;
@@ -68,12 +68,6 @@ function WebSSH(props) {
6868 }
6969 }
7070
71- function _read_as_text ( data ) {
72- const reader = new window . FileReader ( ) ;
73- reader . onload = ( ) => term . write ( reader . result ) ;
74- reader . readAsText ( data , 'utf-8' )
75- }
76-
7771 return (
7872 < div className = { styles . termContainer } >
7973 < div className = { styles . terminal } ref = { container } />
You can’t perform that action at this time.
0 commit comments