Skip to content

Commit ef506be

Browse files
committed
Fixes input with timeout
1 parent 1012b6d commit ef506be

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

deltascan/cli/cmd.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import signal
1919
import select
2020
import sys
21+
from time import sleep
2122

2223

2324
def interactive_shell(_app, _ui, _is_interactive):
@@ -44,6 +45,10 @@ def interactive_shell(_app, _ui, _is_interactive):
4445
a, b, c = select.select([sys.stdin], [], [], 2)
4546
if a == [] and b == [] and c == []:
4647
continue
48+
else:
49+
# the line below is necessary since we are clearing the stdin buffer
50+
# if we ommit this line, the stdin buffer is not getting cleared
51+
sys.stdin.readline().strip()
4752

4853
_ui["ui_live"].stop()
4954
try:
@@ -136,9 +141,6 @@ def do_scan(self, v):
136141
return
137142
v1, v2 = v.split(" ")
138143
_r = self._app.add_scan(v1, v2)
139-
if self._app.is_running is False:
140-
_dscan_thread = threading.Thread(target=self._app.scan)
141-
_dscan_thread.start()
142144
if _r is False:
143145
print("Not starting scan. Check your host and profile. Maybe the scan is already in the queue.")
144146
return
@@ -219,6 +221,12 @@ def do_quit(self, _):
219221
def do_exit(self, _):
220222
"""exit
221223
Exit Deltascan"""
224+
print("Shutting down...")
225+
self._app.cleanup()
226+
while self._app.cleaning_up is False or self._app.is_running is True:
227+
sleep(1)
228+
continue
229+
print("Cancelled all scans. Exiting with grace ...")
222230
os._exit(0)
223231

224232

deltascan/core/deltascan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _scan_orchestrator(self):
188188
self._remove_finished_scan_from_list()
189189
if self.scans_to_wait == 0 and self.scans_to_execute == 0:
190190
time.sleep(2)
191-
if self.scans_to_wait == 0 and self.scans_to_execute == 0:
191+
if self.cleaning_up:
192192
self._is_running = False
193193
break
194194
continue

deltascan/core/nmap/libnmap_wrapper.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ def _run(self, queue: Queue, event: Event):
143143
"""
144144
np = NmapProcess(targets=self.target, options=self.scan_args)
145145
np.sudo_run_background()
146+
_cancelled = False
146147

147148
while np.is_running() or np.is_successful() is False or np.rc != 0:
148149
if event.is_set():
149150
np.stop()
151+
_cancelled = True
150152
break
151153
queue.put(self._create_queue_message(
152154
QueueMsg.PROGRESS, self.target, {
@@ -156,7 +158,7 @@ def _run(self, queue: Queue, event: Event):
156158
))
157159
sleep(0.5)
158160

159-
if np.rc != 0:
161+
if np.rc != 0 or _cancelled is True:
160162
queue.put(self._create_queue_message(
161163
QueueMsg.EXIT, self.target, np.rc
162164
))

0 commit comments

Comments
 (0)