Skip to content

Commit

Permalink
deal with command input manually log bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy201602 committed Jul 1, 2018
1 parent 57867ca commit 38989d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webterminal/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def receive(self,text=None, bytes=None, **kwargs):
self.openterminal(ip,id,channel,width,height,elementid=elementid)
elif len(data) >0 and isinstance(data,list) and data[0] == 'command':
command = data[1].strip('\n')
self.queue.publish(data[2], json.dumps(['stdin','{0}\n'.format(command)]))
self.queue.publish(data[2], json.dumps(['stdin','{0}\r'.format(command)]))
elif len(data) >0 and isinstance(data,list) and data[0] == 'stdin':
self.queue.publish(data[2], json.dumps(['stdin',data[1]]))
elif len(data) >0 and isinstance(data,list) and data[0] == 'close':
Expand Down
16 changes: 14 additions & 2 deletions webterminal/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def run(self):
#fix the first login 1 bug
first_flag = True
command = list()
if self.elementid:
logobj = Log.objects.get(channel=self.elementid)
else:
logobj = Log.objects.get(channel=channel)
while (not self._stop_event.is_set()):
text = self.queue.get_message()
if text:
Expand All @@ -202,7 +206,15 @@ def run(self):
self.chan.resize_pty(width=data[3], height=data[4])
break
elif data[0] in ['stdin','stdout']:
#print(data)
if '\r' not in str(data[1]):
command.append(data[1])
else:
command.append(data[1])
record_command = CommandDeal().deal_command(''.join(command))
if len(record_command) != 0:
print('command input stdin',record_command)
command = list()
CommandLog.objects.create(log=logobj,command=record_command)
self.chan.send(data[1])

elif isinstance(data,(int,long)):
Expand All @@ -213,7 +225,7 @@ def run(self):
else:
try:
#get user command and block user action in the future
if '\r' not in str(data):
if '\r' not in str(data) or '\n' not in str(data):
command.append(str(data))
else:
record_command = CommandDeal().deal_command(''.join(command))
Expand Down

0 comments on commit 38989d9

Please sign in to comment.