Fixing some logic issues in sys_command
This commit is contained in:
parent
379113a015
commit
6a0e906ac7
|
|
@ -156,6 +156,7 @@ class sys_command():
|
||||||
|
|
||||||
alive = True
|
alive = True
|
||||||
trace_log = b''
|
trace_log = b''
|
||||||
|
last_trigger_pos = 0
|
||||||
while alive:
|
while alive:
|
||||||
for fileno, event in poller.poll(0.1):
|
for fileno, event in poller.poll(0.1):
|
||||||
try:
|
try:
|
||||||
|
|
@ -170,20 +171,27 @@ class sys_command():
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
lower = output.lower()
|
lower = output.lower()
|
||||||
|
broke = False
|
||||||
if 'triggers' in self.opts:
|
if 'triggers' in self.opts:
|
||||||
for trigger in list(self.opts['triggers']):
|
for trigger in list(self.opts['triggers']):
|
||||||
if trigger.lower() in trace_log.lower():
|
if trigger.lower() in trace_log[last_trigger_pos:].lower():
|
||||||
if 'debug' in self.opts and self.opts['debug']:
|
if 'debug' in self.opts and self.opts['debug']:
|
||||||
print('[N] Writing to subsystem: {}'.format(self.opts['triggers'][trigger].decode('UTF-8')))
|
print('[N] Writing to subsystem: {}'.format(self.opts['triggers'][trigger].decode('UTF-8')))
|
||||||
|
|
||||||
|
last_trigger_pos = len(trace_log)
|
||||||
os.write(child_fd, self.opts['triggers'][trigger])
|
os.write(child_fd, self.opts['triggers'][trigger])
|
||||||
del(self.opts['triggers'][trigger])
|
del(self.opts['triggers'][trigger])
|
||||||
|
broke = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if broke:
|
||||||
|
continue
|
||||||
|
|
||||||
## Adding a exit trigger:
|
## Adding a exit trigger:
|
||||||
if len(self.opts['triggers']) == 0:
|
if len(self.opts['triggers']) == 0:
|
||||||
if 'debug' in self.opts and self.opts['debug']:
|
if 'debug' in self.opts and self.opts['debug']:
|
||||||
print('[N] Waiting for last command to finish...')
|
print('[N] Waiting for last command to finish...')
|
||||||
if bytes(f'[root@{args["hostname"]} ~]#'.lower(), 'UTF-8') in output[-len(f'[root@{args["hostname"]} ~]#')-5:].lower():
|
if bytes(f'[root@{args["hostname"]} ~]#'.lower(), 'UTF-8') in trace_log[-len(f'[root@{args["hostname"]} ~]#')-5:].lower():
|
||||||
if 'debug' in self.opts and self.opts['debug']:
|
if 'debug' in self.opts and self.opts['debug']:
|
||||||
print('[N] Last command finished, exiting subsystem.')
|
print('[N] Last command finished, exiting subsystem.')
|
||||||
alive = False
|
alive = False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue