Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Fix <stop_scan>. #53

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ospd/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ def create_scan(self, scan_id='', targets='', target_str=None,
scan_info['options'] = options
scan_info['start_time'] = int(time.time())
scan_info['end_time'] = "0"
scan_info['status'] = ""
if scan_id is None or scan_id == '':
scan_id = str(uuid.uuid4())
scan_info['scan_id'] = scan_id
self.scans_table[scan_id] = scan_info
return scan_id

def set_status(self, scan_id, status):
""" Sets scan_id scan's status. """
self.scans_table[scan_id]['status'] = status

def get_status(self, scan_id):
""" Get scan_id scans's status."""

return self.scans_table[scan_id]['status']

def get_options(self, scan_id):
""" Get scan_id scan's options list. """

Expand Down
13 changes: 13 additions & 0 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ def handle_stop_scan_command(self, scan_et):
if not scan_process.is_alive():
raise OSPDError('Scan already stopped or finished.', 'stop_scan')

self.set_scan_status(scan_id, "stopped")
logger.info('{0}: Scan stopping {1}.'.format(scan_id, scan_process.ident))
self.stop_scan(scan_id)
scan_process.terminate()
Expand Down Expand Up @@ -850,6 +851,10 @@ def start_scan(self, scan_id, targets, parallel=1):
self.set_scan_progress(scan_id, progress)
time.sleep(1)

if self.get_scan_status(scan_id) == "stopped":
self.finish_scan(scan_id)
return

logger.info("{0}: Host scan started on ports {1}.".format(target[0],target[1]))
scan_process = multiprocessing.Process(target=self.parallel_scan,
args=(scan_id, target[0]))
Expand Down Expand Up @@ -896,6 +901,14 @@ def set_scan_target_progress(self, scan_id, target, progress):
""" Sets target's progress. """
self.scan_collection.set_target_progress(scan_id, target, progress)

def set_scan_status(self, scan_id, status):
""" Set the scan's status."""
self.scan_collection.set_status(scan_id, status)

def get_scan_status(self, scan_id):
""" Get scan_id scans's status."""
return self.scan_collection.get_status(scan_id)

def scan_exists(self, scan_id):
""" Checks if a scan with ID scan_id is in collection.
Expand Down